Path: blob/master/test/jdk/javax/sound/sampled/LineEvent/LineInfoNPE.java
41152 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.sound.sampled.Control;24import javax.sound.sampled.Line;25import javax.sound.sampled.LineEvent;26import javax.sound.sampled.LineListener;2728/**29* @test30* @bug 467286531* @summary LineEvent.toString() throws unexpected NullPointerException32*/33public class LineInfoNPE {3435static final int STATUS_PASSED = 0;36static final int STATUS_FAILED = 2;37static final int STATUS_TEMP = 95;3839public static void main(String argv[]) throws Exception {40int testExitStatus = run(argv, System.out);41if (testExitStatus != STATUS_PASSED) {42throw new Exception("test FAILED!");43}44}4546public static int run(String argv[], java.io.PrintStream out) {47int testResult = STATUS_PASSED;4849out.println("\n==> Test for LineEvent class:");5051Line testLine = new TestLine();52Line nullLine = null;5354LineEvent.Type testLineEventType = LineEvent.Type.OPEN;55LineEvent.Type nullLineEventType = null;5657LineEvent testedLineEvent = null;58out.println("\n>> LineEvent constructor for Line = null: ");59try {60testedLineEvent =61new LineEvent(nullLine, // the source Line of this event62testLineEventType, // LineEvent.Type - the event type63(long) 1000 // position - the number processed of sample frames64);65out.println("> No any Exception was thrown!");66out.println("> testedLineEvent.getType():");67try {68Line producedLine = testedLineEvent.getLine();69out.println("> PASSED: producedLine = " + producedLine);70} catch (Throwable thrown) {71out.println("## FAILED: unexpected Exception was thrown:");72thrown.printStackTrace(out);73testResult = STATUS_FAILED;74}75out.println("> testedLineEvent.toString():");76try {77String producedString = testedLineEvent.toString();78out.println("> PASSED: producedString = " + producedString);79} catch (Throwable thrown) {80out.println("## FAILED: unexpected Exception was thrown:");81thrown.printStackTrace(out);82testResult = STATUS_FAILED;83}84} catch (IllegalArgumentException illegArgExcept) {85out.println("> PASSED: expected IllegalArgumentException was thrown:");86illegArgExcept.printStackTrace(out);87} catch (NullPointerException nullPE) {88out.println("> PASSED: expected NullPointerException was thrown:");89nullPE.printStackTrace(out);90} catch (Throwable thrown) {91out.println("## FAILED: unexpected Exception was thrown:");92thrown.printStackTrace(out);93testResult = STATUS_FAILED;94}9596out.println("\n>> LineEvent constructor for LineEvent.Type = null: ");97try {98testedLineEvent =99new LineEvent(testLine, // the source Line of this event100nullLineEventType, // LineEvent.Type - the event type101(long) 1000 // position - the number processed of sample frames102);103out.println("> No any Exception was thrown!");104out.println("> testedLineEvent.getType():");105try {106LineEvent.Type producedType = testedLineEvent.getType();107out.println("> PASSED: producedType = " + producedType);108} catch (Throwable thrown) {109out.println("## FAILED: unexpected Exception was thrown:");110thrown.printStackTrace(out);111testResult = STATUS_FAILED;112}113out.println("> testedLineEvent.toString():");114try {115String producedString = testedLineEvent.toString();116out.println("> PASSED: producedString = " + producedString);117} catch (Throwable thrown) {118out.println("## FAILED: unexpected Exception was thrown:");119thrown.printStackTrace(out);120testResult = STATUS_FAILED;121}122} catch (IllegalArgumentException illegArgExcept) {123out.println("> PASSED: expected IllegalArgumentException was thrown:");124illegArgExcept.printStackTrace(out);125} catch (NullPointerException nullPE) {126out.println("> PASSED: expected NullPointerException was thrown:");127nullPE.printStackTrace(out);128} catch (Throwable thrown) {129out.println("## FAILED: unexpected Exception was thrown:");130thrown.printStackTrace(out);131testResult = STATUS_FAILED;132}133134if ( testResult == STATUS_FAILED ) {135out.println("\n==> test FAILED!");136} else {137out.println("\n==> test PASSED!");138}139return testResult;140}141} // end of test class142143class TestLine implements Line {144145public void addLineListener(LineListener listener) {146}147148public void close() {149}150151public Control getControl(Control.Type control) {152return null;153}154155public Control[] getControls() {156return new Control[0];157}158159public Line.Info getLineInfo() {160return null;161}162163public boolean isOpen() {164return false;165}166167public boolean isControlSupported(Control.Type control) {168return false;169}170171public void open() {172}173174public void removeLineListener(LineListener listener) {175}176}177178179