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