jdk/test/javax/sound/sampled/AudioSystem/ProviderCacheing.java
author serb
Mon, 31 Oct 2016 14:50:09 +0300
changeset 41905 e8e5df013c6e
permissions -rw-r--r--
8167615: Opensource unit/regression tests for JavaSound Reviewed-by: amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41905
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     1
/*
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     4
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     8
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    13
 * accompanied this code).
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    14
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    18
 *
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    21
 * questions.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    22
 */
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    23
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    24
import java.util.List;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    25
import com.sun.media.sound.JDK13Services;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    26
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    27
/**
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    28
 * @test
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    29
 * @bug 4776511
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    30
 * @summary RFE: Setting the default MixerProvider. Test the cacheing of
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    31
 *          providers.
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    32
 * @modules java.desktop/com.sun.media.sound
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    33
 */
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    34
public class ProviderCacheing {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    35
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    36
    private static final Class[] providerClasses = {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    37
        javax.sound.sampled.spi.AudioFileReader.class,
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    38
        javax.sound.sampled.spi.AudioFileWriter.class,
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    39
        javax.sound.sampled.spi.FormatConversionProvider.class,
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    40
        javax.sound.sampled.spi.MixerProvider.class,
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    41
    };
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    42
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    44
        boolean allCached = true;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    45
        for (int i = 0; i < providerClasses.length; i++) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    46
            List list0 = JDK13Services.getProviders(providerClasses[i]);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    47
            List list1 = JDK13Services.getProviders(providerClasses[i]);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    48
            if (list0 == list1) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    49
                out("Providers should not be cached for " + providerClasses[i]);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    50
                allCached = false;
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    51
            }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    52
        }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    53
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    54
        if (! allCached) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    55
            throw new Exception("Test failed");
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    56
        } else {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    57
            out("Test passed");
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    58
        }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    59
    }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    60
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    61
    private static void out(String message) {
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    62
        System.out.println(message);
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    63
    }
e8e5df013c6e 8167615: Opensource unit/regression tests for JavaSound
serb
parents:
diff changeset
    64
}