1 /* 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /** 27 * @test 28 * @bug 4937708 29 * @summary Tests that AudioFormat.matches handle NOT_SPECIFIED value in all fields 30 * @run main Matches_NOT_SPECIFIED 31 * @author Alex Menkov 32 * 33 */ 34 35 import javax.sound.sampled.AudioFormat; 36 import javax.sound.sampled.AudioFormat.Encoding; 37 import javax.sound.sampled.AudioSystem; 38 39 40 public class Matches_NOT_SPECIFIED { 41 42 static boolean success = true; 43 static AudioFormat f1; 44 static AudioFormat f2; 45 46 public static void main(String[] args) throws Exception { 47 AudioFormat f3; 48 f1 = new AudioFormat(44100, 16, 2, true, false); 49 f2 = new AudioFormat(Encoding.PCM_SIGNED, 50 AudioSystem.NOT_SPECIFIED, 51 AudioSystem.NOT_SPECIFIED, 52 AudioSystem.NOT_SPECIFIED, 53 AudioSystem.NOT_SPECIFIED, 54 AudioSystem.NOT_SPECIFIED, false); 55 test(true); 56 57 // f1 = new AudioFormat(44100, 8, 16, true, false); 58 f2 = new AudioFormat(Encoding.PCM_SIGNED, 59 AudioSystem.NOT_SPECIFIED, 60 AudioSystem.NOT_SPECIFIED, 61 AudioSystem.NOT_SPECIFIED, 62 AudioSystem.NOT_SPECIFIED, 63 AudioSystem.NOT_SPECIFIED, true); 64 test(false); 65 66 f1 = new AudioFormat(44100, 8, 8, true, false); 67 test(true); 68 69 if (success) { 70 out("The test PASSED."); 71 } else { 72 out("The test FAILED."); 73 throw new Exception("The test FAILED"); 74 } 75 } 76 77 static void test(boolean shouldMatch) { 78 out("testing:"); 79 out(" - " + f1.toString()); 80 out(" - " + f2.toString()); 81 if (f1.matches(f2)) { 82 if (shouldMatch) { 83 out(" (OK) MATCHES"); 84 } else { 85 out(" (ERROR) MATCHES"); 86 success = false; 87 } 88 } else { 89 if (shouldMatch) { 90 out(" (ERROR) DOESNT MATCH!"); 91 success = false; 92 } else { 93 out(" (OK) DOESNT MATCH!"); 94 } 95 } 96 } 97 98 static void out(String s) { 99 System.out.println(s); 100 } 101 102 }