Path: blob/master/test/jdk/javax/sound/sampled/Controls/CompoundControl/ToString.java
41154 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.CompoundControl;24import javax.sound.sampled.Control;2526/**27* @test28* @bug 462919029* @summary CompoundControl: getMemberControls() and toString() throw30* NullPointerException31*/32public class ToString {33public static void main(String args[]) throws Exception {34System.out.println();35System.out.println();36System.out.println("4629190: CompoundControl: getMemberControls() and toString() throw NullPointerException");3738String firstControlTypeName = "first_Control_Type_Name";39String secondControlTypeName = "second_Control_Type_Name";40String thirdControlTypeName = "third_Control_Type_Name";4142Control.Type firstControlType = new TestControlType(firstControlTypeName);43Control.Type secondControlType = new TestControlType(secondControlTypeName);44Control.Type thirdControlType = new TestControlType(thirdControlTypeName);4546Control firstControl = new TestControl(firstControlType);47Control secondControl = new TestControl(secondControlType);48Control thirdControl = new TestControl(thirdControlType);4950String testCompoundControlTypeName = "CompoundControl_Type_Name";51CompoundControl.Type testCompoundControlType52= new TestCompoundControlType(testCompoundControlTypeName);5354Control[] setControls = { firstControl, secondControl, thirdControl };55CompoundControl testedCompoundControl56= new TestCompoundControl(testCompoundControlType, setControls);5758// this may throw exception if bug applies59Control[] producedControls = testedCompoundControl.getMemberControls();60System.out.println("Got "+producedControls.length+" member controls.");6162// this may throw exception if bug applies63String producedString = testedCompoundControl.toString();64System.out.println("toString() returned: "+producedString);6566System.out.println("Test passed.");67}6869}7071class TestControl extends Control {7273TestControl(Control.Type type) {74super(type);75}76}7778class TestControlType extends Control.Type {7980TestControlType(String name) {81super(name);82}83}8485class TestCompoundControl extends CompoundControl {8687TestCompoundControl(CompoundControl.Type type, Control[] memberControls) {88super(type, memberControls);89}90}9192class TestCompoundControlType extends CompoundControl.Type {9394TestCompoundControlType(String name) {95super(name);96}97}9899100