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