GetDevice.java revision 829:b06c29386f63
194742Sobrien/*
294742Sobrien * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
394742Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
495253Sru *
594742Sobrien * This code is free software; you can redistribute it and/or modify it
694772Simp * under the terms of the GNU General Public License version 2 only, as
794772Simp * published by the Free Software Foundation.  Sun designates this
896991Srwatson * particular file as subject to the "Classpath" exception as provided
996991Srwatson * by Sun in the LICENSE file that accompanied this code.
1096991Srwatson *
11102773Srwatson * This code is distributed in the hope that it will be useful, but WITHOUT
12102773Srwatson * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1394854Ssos * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1494917Simp * version 2 for more details (a copy is included in the LICENSE file that
1594917Simp * accompanied this code).
1694917Simp *
1794917Simp * You should have received a copy of the GNU General Public License version
1894845Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
1994845Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2094845Smarkm *
2195382Srnordier * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2294847Sjhb * CA 95054 USA or visit www.sun.com if you need additional information or
2394847Sjhb * have any questions.
2494847Sjhb */
2594849Sphk
2694849Sphk/* @test
2794849Sphk   @summary Test SoftProvider getDevice method */
2894849Sphk
2994849Sphkimport javax.sound.midi.MidiDevice;
3094849Sphkimport javax.sound.midi.MidiUnavailableException;
3194849Sphkimport javax.sound.midi.Patch;
3294855Sscottlimport javax.sound.sampled.*;
3394855Sscottlimport javax.sound.midi.MidiDevice.Info;
3494902Sbenno
3594915Skenimport com.sun.media.sound.*;
3699607Smjacob
3794915Skenpublic class GetDevice {
3894915Sken
3994915Sken    private static void assertEquals(Object a, Object b) throws Exception
4094915Sken    {
4194915Sken        if(!a.equals(b))
42105411Snjl            throw new RuntimeException("assertEquals fails!");
4394915Sken    }
4494915Sken
4594915Sken    private static void assertTrue(boolean value) throws Exception
4699607Smjacob    {
4799607Smjacob        if(!value)
4897611Sbillf            throw new RuntimeException("assertTrue fails!");
4994918Sgshapiro    }
5094918Sgshapiro
5194918Sgshapiro
5294918Sgshapiro    private static class FakeInfo extends Info {
5394918Sgshapiro        public FakeInfo() {
5494955Smurray            super("a", "b", "c", "d");
5594955Smurray        }
5695054Snectar    }
5795455Sdes
5898750Sdes    public static void main(String[] args) throws Exception {
5999606Sdes        SoftProvider provider = new SoftProvider();
6099606Sdes        Info[] infos = provider.getDeviceInfo();
6199606Sdes        assertTrue(infos.length > 0);
6296268Sgad        for (int i = 0; i < infos.length; i++) {
6396268Sgad            assertTrue(infos[i] != null);
6496268Sgad            MidiDevice d = provider.getDevice(infos[i]);
6596301Sgrog            assertTrue(d instanceof SoftSynthesizer);
6696332Speter        }
6796332Speter        assertTrue(provider.getDevice(new FakeInfo()) == null);
6896332Speter
6996332Speter    }
7096332Speter}
71100314Sru