Matches_NOT_SPECIFIED.java revision 8729:0242fce0f717
1101043Sdes/*
2228991Suqs * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3101043Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4101043Sdes *
5101043Sdes * This code is free software; you can redistribute it and/or modify it
6101043Sdes * under the terms of the GNU General Public License version 2 only, as
7101043Sdes * published by the Free Software Foundation.
8101043Sdes *
9101043Sdes * This code is distributed in the hope that it will be useful, but WITHOUT
10101043Sdes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11101043Sdes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12101043Sdes * version 2 for more details (a copy is included in the LICENSE file that
13101043Sdes * accompanied this code).
14101043Sdes *
15101043Sdes * You should have received a copy of the GNU General Public License version
16101043Sdes * 2 along with this work; if not, write to the Free Software Foundation,
17101043Sdes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18101043Sdes *
19101043Sdes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20101043Sdes * or visit www.oracle.com if you need additional information or have any
21101043Sdes * questions.
22101043Sdes */
23101043Sdes
24101043Sdes/**
25101043Sdes * @test
26101043Sdes * @bug 4937708
27101043Sdes * @summary Tests that AudioFormat.matches handle NOT_SPECIFIED value in all fields
28101043Sdes * @run main Matches_NOT_SPECIFIED
29101043Sdes * @author Alex Menkov
30101043Sdes *
31101043Sdes */
32101043Sdes
33101043Sdesimport javax.sound.sampled.AudioFormat;
34101043Sdesimport javax.sound.sampled.AudioFormat.Encoding;
35101043Sdesimport javax.sound.sampled.AudioSystem;
36101043Sdes
37101043Sdes
38101043Sdespublic class Matches_NOT_SPECIFIED {
39101043Sdes
40101043Sdes    static boolean success = true;
41101043Sdes    static AudioFormat f1;
42101163Sdes    static AudioFormat f2;
43101163Sdes
44101043Sdes    public static void main(String[] args) throws Exception {
45101043Sdes        AudioFormat f3;
46284354Stuexen        f1 = new AudioFormat(44100, 16, 2, true, false);
47101043Sdes        f2 = new AudioFormat(Encoding.PCM_SIGNED,
48285630Sdes                AudioSystem.NOT_SPECIFIED,
49285630Sdes                AudioSystem.NOT_SPECIFIED,
50101043Sdes                AudioSystem.NOT_SPECIFIED,
51101043Sdes                AudioSystem.NOT_SPECIFIED,
52101043Sdes                AudioSystem.NOT_SPECIFIED, false);
53101043Sdes        test(true);
54101043Sdes
55101043Sdes//        f1 = new AudioFormat(44100, 8, 16, true, false);
56101043Sdes        f2 = new AudioFormat(Encoding.PCM_SIGNED,
57101043Sdes                AudioSystem.NOT_SPECIFIED,
58101043Sdes                AudioSystem.NOT_SPECIFIED,
59101043Sdes                AudioSystem.NOT_SPECIFIED,
60101043Sdes                AudioSystem.NOT_SPECIFIED,
61101043Sdes                AudioSystem.NOT_SPECIFIED, true);
62101043Sdes        test(false);
63101043Sdes
64101043Sdes        f1 = new AudioFormat(44100, 8, 8, true, false);
65284636Shrs        test(true);
66284636Shrs
67284636Shrs        if (success) {
68284636Shrs            out("The test PASSED.");
69284636Shrs        } else {
70101043Sdes            out("The test FAILED.");
71101043Sdes            throw new Exception("The test FAILED");
72101043Sdes        }
73235870Sthompsa    }
74179115Sbms
75101043Sdes    static void test(boolean shouldMatch) {
76285630Sdes        out("testing:");
77101043Sdes        out("  - " + f1.toString());
78101043Sdes        out("  - " + f2.toString());
79101043Sdes        if (f1.matches(f2)) {
80164201Skeramida            if (shouldMatch) {
81164201Skeramida                out("  (OK) MATCHES");
82164201Skeramida            } else {
83284354Stuexen                out("  (ERROR) MATCHES");
84284636Shrs                success = false;
85164201Skeramida            }
86164201Skeramida        } else {
87164201Skeramida            if (shouldMatch) {
88164201Skeramida                out("  (ERROR) DOESNT MATCH!");
89101043Sdes                success = false;
90101043Sdes            } else {
91101043Sdes                out("  (OK) DOESNT MATCH!");
92101043Sdes            }
93101043Sdes        }
94101043Sdes    }
95284353Stuexen
96284353Stuexen    static void out(String s) {
97284353Stuexen        System.out.println(s);
98284353Stuexen    }
99284353Stuexen
100101043Sdes}
101101043Sdes