Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/sound/midi/Gervill/SimpleInstrument/AddModelInstrumentIntIntIntIntInt.java
38859 views
/*1* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@summary Test SimpleInstrument add(ModelInstrument,int,int,int,int,int) method */2526import javax.sound.sampled.*;2728import com.sun.media.sound.*;2930public class AddModelInstrumentIntIntIntIntInt {3132private static void assertEquals(Object a, Object b) throws Exception33{34if(!a.equals(b))35throw new RuntimeException("assertEquals fails!");36}3738public static void main(String[] args) throws Exception {3940SimpleInstrument instrument = new SimpleInstrument();4142ModelPerformer[] performers = new ModelPerformer[2];4344performers[0] = new ModelPerformer();45performers[0].setExclusiveClass(1);46performers[0].setKeyFrom(36);47performers[0].setKeyTo(48);48performers[0].setVelFrom(16);49performers[0].setVelTo(80);50performers[0].setSelfNonExclusive(true);51performers[0].setDefaultConnectionsEnabled(false);52performers[0].getConnectionBlocks().add(new ModelConnectionBlock());53performers[0].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));5455performers[1] = new ModelPerformer();56performers[1].setExclusiveClass(0);57performers[1].setKeyFrom(12);58performers[1].setKeyTo(24);59performers[1].setVelFrom(20);60performers[1].setVelTo(90);61performers[1].setSelfNonExclusive(false);62performers[0].setDefaultConnectionsEnabled(true);63performers[1].getConnectionBlocks().add(new ModelConnectionBlock());64performers[1].getOscillators().add(new ModelByteBufferWavetable(new ModelByteBuffer(new byte[] {1,2,3})));6566SimpleInstrument subins = new SimpleInstrument();67subins.add(performers[0]);68instrument.add(subins,18,40,20,75,12);69ModelPerformer[] performers2 = instrument.getPerformers();70for (int i = 0; i < performers2.length; i++) {71assertEquals(performers[i].getConnectionBlocks(), performers2[i].getConnectionBlocks());72assertEquals(12, performers2[i].getExclusiveClass());73if(performers[i].getKeyFrom() < 18)74assertEquals(18, performers2[i].getKeyFrom());75else76assertEquals(performers[i].getKeyFrom(), performers2[i].getKeyFrom());77if(performers[i].getKeyTo() > 40)78assertEquals(40, performers2[i].getKeyTo());79else80assertEquals(performers[i].getKeyTo(), performers2[i].getKeyTo());81if(performers[i].getVelFrom() < 20)82assertEquals(20, performers2[i].getVelFrom());83else84assertEquals(performers[i].getVelFrom(), performers2[i].getVelFrom());85if(performers[i].getVelTo() > 75)86assertEquals(75, performers2[i].getVelTo());87else88assertEquals(performers[i].getVelTo(), performers2[i].getVelTo());89assertEquals(performers[i].getOscillators(), performers2[i].getOscillators());90assertEquals(performers[i].isSelfNonExclusive(), performers2[i].isSelfNonExclusive());91assertEquals(performers[i].isDefaultConnectionsEnabled(), performers2[i].isDefaultConnectionsEnabled());92}93}94}959697