harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r425362 - in /incubator/harmony/enhanced/classlib/trunk/modules/sound/src: main/java/javax/sound/midi/ShortMessage.java test/java/org/apache/harmony/sound/tests/javax/sound/midi/ShortMessageTest.java
Date Tue, 25 Jul 2006 10:23:50 GMT
Author: mloenko
Date: Tue Jul 25 03:23:49 2006
New Revision: 425362

URL: http://svn.apache.org/viewvc?rev=425362&view=rev
Log:
fixes for HARMONY-970
[classlib][sound] Patches for class ShortMessage and test ShortMessageTest

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/ShortMessage.java
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/ShortMessageTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/ShortMessage.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/ShortMessage.java?rev=425362&r1=425361&r2=425362&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/ShortMessage.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/ShortMessage.java
Tue Jul 25 03:23:49 2006
@@ -14,9 +14,14 @@
  *  limitations under the License.
  */
 
+/**
+ * @author Evgeny S. Sidorenko
+ */
+
 package javax.sound.midi;
 
 public class ShortMessage extends MidiMessage {
+
     public static final int ACTIVE_SENSING = 254;
 
     public static final int CHANNEL_PRESSURE = 208;
@@ -53,57 +58,214 @@
 
     public static final int TUNE_REQUEST = 246;
 
+    private int data1;
+
+    private int data2;
+
+    private int channel;
+
+    private int command;
+
     public ShortMessage() {
-        //TODO
-        super(null);
+        super(new byte[] { -112, 64, 127 });
+        data1 = 64;
+        data2 = 127;
+        channel = 0;
+        command = 144;
     }
 
     protected ShortMessage(byte[] data) {
-        //TODO
         super(data);
+        if ((data == null) || (data.length == 0)) {
+            data1 = 0;
+            data2 = 0;
+            channel = 0;
+            command = 0;
+        } else if (data.length >= 3) {
+            data1 = (int) (data[1] & 0xFF);
+            data2 = (int) (data[2] & 0xFF);
+            channel = ((int) (data[0] & 0xFF)) % 16;
+            command = ((int) (data[0] & 0xFF)) - channel;
+        } else if (data.length == 2) {
+            data1 = (int) (data[1] & 0xFF);
+            data2 = 0;
+            channel = ((int) (data[0] & 0xFF)) % 16;
+            command = ((int) (data[0] & 0xFF)) - channel;
+        } else {
+            data1 = 0;
+            data2 = 0;
+            channel = ((int) (data[0] & 0xFF)) % 16;
+            command = ((int) (data[0] & 0xFF)) - channel;
+        }
     }
 
     public Object clone() {
-        //TODO
-        return null;
+        return new ShortMessage(this.getMessage());
     }
 
     public int getChannel() {
-        //TODO
-        return 1;
+        return channel;
     }
 
     public int getCommand() {
-        //TODO
-        return 1;
+        return command;
     }
 
     public int getData1() {
-        //TODO
-        return 1;
+        return data1;
     }
 
     public int getData2() {
-        //TODO
-        return 1;
+        return data2;
     }
 
-    protected final int getDataLength(int status) throws InvalidMidiDataException {
-        //TODO
-        return 1;
+    protected final int getDataLength(int status)
+            throws InvalidMidiDataException {
+        // FIXME
+        /*
+         * I have some question about this method. I didn't understand how
+         * should to work this method, but some results I get by experimental
+         * method. From 0 up to 127, from 256 up to 383 and so on this method
+         * throw out exception, i.e. after 256 begin cycle with some small
+         * differences in the first lap, from 0 up to 255. From the second lap
+         * and so on this method, getDataLenght(int), throw out exception with
+         * value of status from 496 up to 511, from 752 up to 767 and so on,
+         * i.e. on the last 16 number of 256-lap. And now differences in the
+         * first lap. This method don't throw out exception with value of status
+         * from 240 up to 255. It has next behavior: - value of status equals
+         * 240 -- throw out exception; - 241 -- return 1; - 242 -- return 2; -
+         * 243 -- return 1; - from 244 up to 245 -- throw out exception; - from
+         * 246 up to 255 -- return 0;
+         */
+        if (status < 0) {
+            throw new InvalidMidiDataException("Invalid status byte: " + status);
+        }
+        if (((status % 256) >= 0) && ((status % 256) <= 127)) {
+            throw new InvalidMidiDataException("Invalid status byte: " + status);
+        }
+        if (((status / 256) == 0)
+                && ((status == 240) || (status == 244) || (status == 245))) {
+            throw new InvalidMidiDataException("Invalid status byte: " + status);
+        }
+        if (((status / 256) != 0) && ((status % 256) >= 244)
+                && ((status % 256) <= 255)) {
+            throw new InvalidMidiDataException("Invalid status byte: " + status);
+        }
+
+        if ((status / 256) == 0) {
+            if ((status == 241) || (status == 243)) {
+                return 1;
+            } else if (status == 242) {
+                return 2;
+            } else if ((status >= 246) && (status <= 255)) {
+                return 0;
+            }
+        }
+        if (((status % 256) >= 128) && ((status % 256) <= 191)) {
+            return 2;
+        } else if (((status % 256) >= 192) && ((status % 256) <= 223)) {
+            return 1;
+        } else {
+            return 2;
+        }
     }
 
     public void setMessage(int status) throws InvalidMidiDataException {
-        //TODO
+        /**
+         * value of variable status is more or equals 246 and less or equals 255
+         */
+        if ((status < 246) || (status > 255)) {
+            throw new InvalidMidiDataException("Invalid status byte: " + status);
+        }
+        super.setMessage(new byte[] { (byte) status }, 1);
+        /**
+         * channel change from 0 up to 15, and channel + command == status
+         */
+        data1 = 0;
+        data2 = 0;
+        channel = status % 16;
+        command = status - channel;
     }
 
-    public void setMessage(int status, int data1, int data2) throws InvalidMidiDataException
{
-        //TODO
+    public void setMessage(int status, int data1, int data2)
+            throws InvalidMidiDataException {
+        // FIXME
+        /*
+         * In the Sun's implementation variables data1 and data2 don't use; I
+         * don't find situation when this variables influence on result of
+         * functions getData1() and getData2(). But function getDataLength(int)
+         * return 0 when I modify status byte from 246 up to 255, and so I think
+         * it's true.
+         */
+        /**
+         * value of variable status is more or equals 246 and less or equals 255
+         */
+        if ((status < 246) || (status > 255)) {
+            throw new InvalidMidiDataException("Invalid status byte: " + status);
+        }
+        super.setMessage(new byte[] { (byte) status }, 1);
+        /**
+         * channel change from 0 up to 15, and channel + command == status
+         */
+        this.data1 = 0;
+        this.data2 = 0;
+        channel = status % 16;
+        command = status - channel;
     }
 
     public void setMessage(int command, int channel, int data1, int data2)
             throws InvalidMidiDataException {
-        //TODO
+        // FIXME
+        /**
+         * value of variable command is more or equals 128 and less or equals
+         * 239
+         */
+        if ((command < 128) || (command > 239)) {
+            /*
+             * when this exception throw out, the value of variable command
+             * should be the hexadecimal number
+             */
+            throw new InvalidMidiDataException("command out of range: "
+                    + command);
+        }
+        /**
+         * value of variable channel is more or equals 0 and less or equals 15
+         */
+        if ((channel < 0) || (channel > 15)) {
+            throw new InvalidMidiDataException("channel out of range: "
+                    + channel);
+        }
+        /**
+         * value of data1 and data2 is more or equals 0 and less or equals 127,
+         * but when command more or equals 192 and less or equals 223 the second
+         * data, data2, is unused, because getDataLength(int) return 1 in this
+         * case, and in other cases it return 2
+         */
+        if ((data1 < 0) || (data1 > 127)) {
+            throw new InvalidMidiDataException("data1 out of range: " + data1);
+        }
+        if ((getDataLength(command) == 2) && ((data2 < 0) || (data2 > 127)))
{
+            throw new InvalidMidiDataException("data2 out of range: " + data2);
+        }
+
+        /**
+         * channel change from 0 up to 15, and channel + command == status
+         */
+        this.command = command - (command % 16);
+        this.channel = channel;
+        this.data1 = data1;
+        /**
+         * status in this case equals getCommand() + getChannel()
+         */
+        if (getDataLength(command) == 1) {
+            super.setMessage(new byte[] { (byte) (this.command + this.channel),
+                    (byte) data1 }, 2);
+            this.data2 = 0;
+        } else {
+            super.setMessage(new byte[] { (byte) (this.command + this.channel),
+                    (byte) data1, (byte) data2 }, 3);
+            this.data2 = data2;
+        }
     }
 
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/ShortMessageTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/ShortMessageTest.java?rev=425362&r1=425361&r2=425362&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/ShortMessageTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/ShortMessageTest.java
Tue Jul 25 03:23:49 2006
@@ -25,443 +25,563 @@
 
 import junit.framework.TestCase;
 
-public class ShortMessageTest extends TestCase
-{
+public class ShortMessageTest extends TestCase {
+
     /**
      * test constants
      *
      */
-    public void test_constants()
-    {
-        assertTrue( ShortMessage.ACTIVE_SENSING == 254 );
-        assertTrue( ShortMessage.CHANNEL_PRESSURE == 208 );
-        assertTrue( ShortMessage.CONTINUE == 251 );
-        assertTrue( ShortMessage.CONTROL_CHANGE == 176 );
-        assertTrue( ShortMessage.END_OF_EXCLUSIVE == 247 );
-        assertTrue( ShortMessage.MIDI_TIME_CODE == 241 );
-        assertTrue( ShortMessage.NOTE_OFF == 128 );
-        assertTrue( ShortMessage.NOTE_ON == 144 );
-        assertTrue( ShortMessage.PITCH_BEND == 224 );
-        assertTrue( ShortMessage.POLY_PRESSURE == 160 );
-        assertTrue( ShortMessage.PROGRAM_CHANGE == 192 );
-        assertTrue( ShortMessage.SONG_POSITION_POINTER == 242 );
-        assertTrue( ShortMessage.SONG_SELECT == 243 );
-        assertTrue( ShortMessage.START == 250 );
-        assertTrue( ShortMessage.STOP == 252 );
-        assertTrue( ShortMessage.SYSTEM_RESET == 255 );
-        assertTrue( ShortMessage.TIMING_CLOCK == 248 );
-        assertTrue( ShortMessage.TUNE_REQUEST == 246 );
+    public void test_constants() {
+        ShortMessage message = new ShortMessage();
+        assertEquals(254, message.ACTIVE_SENSING);
+        assertEquals(208, message.CHANNEL_PRESSURE);
+        assertEquals(251, message.CONTINUE);
+        assertEquals(176, message.CONTROL_CHANGE);
+        assertEquals(247, message.END_OF_EXCLUSIVE);
+        assertEquals(241, message.MIDI_TIME_CODE);
+        assertEquals(128, message.NOTE_OFF);
+        assertEquals(144, message.NOTE_ON);
+        assertEquals(224, message.PITCH_BEND);
+        assertEquals(160, message.POLY_PRESSURE);
+        assertEquals(192, message.PROGRAM_CHANGE);
+        assertEquals(242, message.SONG_POSITION_POINTER);
+        assertEquals(243, message.SONG_SELECT);
+        assertEquals(250, message.START);
+        assertEquals(252, message.STOP);
+        assertEquals(255, message.SYSTEM_RESET);
+        assertEquals(248, message.TIMING_CLOCK);
+        assertEquals(246, message.TUNE_REQUEST);
     }
-    
+
     /**
      * test constructors
      *
      */
-    public void test_constructor_ShortMessage1()
-    {
+    public void test_constructor_ShortMessage1() {
         ShortMessage1 message = new ShortMessage1();
-        assertTrue( message.getChannel() == 0 );
-        assertTrue( message.getCommand() == 144 );
-        assertTrue( message.getData1() == 64 );
-        assertTrue( message.getData2() == 127 );
-        assertTrue( message.getLength() == 3 );
-        assertTrue( message.getStatus() == 144 );
-        assertTrue( message.getMessage().length == 3 );
-        assertTrue( message.getMessage()[0] == -112 );
-        assertTrue( message.getMessage()[1] == 64 );
-        assertTrue( message.getMessage()[2] == 127 );
-                
-        ShortMessage1 message1 = new ShortMessage1( new byte[] { 95, -5, 9, 56, -18 } );
-        assertTrue( message1.getChannel() == 15 );
-        assertTrue( message1.getCommand() == 80 );
-        assertTrue( message1.getData1() == 251 );
-        assertTrue( message1.getData2() == 9 );
-        assertTrue( message1.getLength() == 5 );
-        assertTrue( message1.getStatus() == 95 );
-        assertTrue( message1.getMessage().length == 5 );
-        
-        ShortMessage1 message2 = new ShortMessage1( new byte[] { 95, 14 } );
-        assertTrue( message2.getChannel() == 15 );
-        assertTrue( message2.getCommand() == 80 );
-        assertTrue( message2.getData1() == 14 );
-        assertTrue( message2.getData2() == 0 );
-        assertTrue( message2.getLength() == 2 );
-        assertTrue( message2.getStatus() == 95 );
-        assertTrue( message2.getMessage().length == 2 );
-        
-        ShortMessage1 message3 = new ShortMessage1( null );
-        assertTrue( message3.getChannel() == 0 );
-        assertTrue( message3.getCommand() == 0 );
-        assertTrue( message3.getData1() == 0 );
-        assertTrue( message3.getData2() == 0 );
-        assertTrue( message3.getLength() == 0 );
-        assertTrue( message3.getStatus() == 0 );
+        assertEquals(0, message.getChannel());
+        assertEquals(144, message.getCommand());
+        assertEquals(64, message.getData1());
+        assertEquals(127, message.getData2());
+        assertEquals(3, message.getLength());
+        assertEquals(144, message.getStatus());
+        assertEquals(3, message.getMessage().length);
+        assertEquals(-112, message.getMessage()[0]);
+        assertEquals(64, message.getMessage()[1]);
+        assertEquals(127, message.getMessage()[2]);
+
+        ShortMessage1 message1 = new ShortMessage1(new byte[] { -95, -5, 9, 56,
+                -18 });
+        assertEquals(1, message1.getChannel());
+        assertEquals(160, message1.getCommand());
+        assertEquals(251, message1.getData1());
+        assertEquals(9, message1.getData2());
+        assertEquals(5, message1.getLength());
+        assertEquals(161, message1.getStatus());
+        assertEquals(5, message1.getMessage().length);
+        assertEquals(-95, message1.getMessage()[0]);
+        assertEquals(-5, message1.getMessage()[1]);
+        assertEquals(9, message1.getMessage()[2]);
+        assertEquals(56, message1.getMessage()[3]);
+        assertEquals(-18, message1.getMessage()[4]);
+
+        ShortMessage1 message2 = new ShortMessage1(new byte[] { 95, 14 });
+        assertEquals(15, message2.getChannel());
+        assertEquals(80, message2.getCommand());
+        assertEquals(14, message2.getData1());
+        assertEquals(0, message2.getData2());
+        assertEquals(2, message2.getLength());
+        assertEquals(95, message2.getStatus());
+        assertEquals(2, message2.getMessage().length);
+
+        ShortMessage1 message3 = new ShortMessage1(null);
+        assertEquals(0, message3.getChannel());
+        assertEquals(0, message3.getCommand());
+        assertEquals(0, message3.getData1());
+        assertEquals(0, message3.getData2());
+        assertEquals(0, message3.getLength());
+        assertEquals(0, message3.getStatus());
+        try {
+            message3.getMessage();
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {}
+
+        ShortMessage1 message4 = new ShortMessage1(new byte[] { 0 });
+        assertEquals(0, message4.getChannel());
+        assertEquals(0, message4.getCommand());
+        assertEquals(0, message4.getData1());
+        assertEquals(0, message4.getData2());
+        assertEquals(1, message4.getLength());
+        assertEquals(0, message4.getStatus());
     }
-    
+
     /**
      * test method setMessage( int ) of class ShortMessage
      */
-    public void test_setMessage1()
-    {
+    public void test_setMessage1() {
         ShortMessage1 message = new ShortMessage1();
         /**
          * value of variable status is more or equals 246 and
          * less or equals 255
          */
         try {
-            message.setMessage( 245 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-        try {
-            message.setMessage( 256 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
+            message.setMessage(245);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+        ;
+
+        try {
+            message.setMessage(256);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
         try {
-            message.setMessage( 250 );
-        } catch( InvalidMidiDataException e ) { }
+            message.setMessage(250);
+        } catch (InvalidMidiDataException e) {}
         /**
          * channel change from 0 up to 15, and
          * channel + command == status, so
          * the value of command divisible by 16
          */
-        assertTrue( message.getChannel() == 10 );
-        assertTrue( message.getCommand() == 240 );
-        assertTrue( message.getData1() == 0 );
-        assertTrue( message.getData2() == 0 );
-        assertTrue( message.getLength() == 1 );
-        assertTrue( message.getStatus() == 250 );
-        assertTrue( message.getMessage().length == 1 );
+        assertEquals(10, message.getChannel());
+        assertEquals(240, message.getCommand());
+        assertEquals(0, message.getData1());
+        assertEquals(0, message.getData2());
+        assertEquals(1, message.getLength());
+        assertEquals(250, message.getStatus());
+        assertEquals(1, message.getMessage().length);
     }
-    
+
     /**
      * test method setMessage( int, int, int ) of 
      * class ShortMessage
      */
-    public void test_setMessage2()
-    {
+    public void test_setMessage2() {
         ShortMessage1 message = new ShortMessage1();
         /**
          * value of variable status is more or equals 246 and
          * less or equals 255
          */
         try {
-            message.setMessage( 245, 34, 56 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-        try {
-            message.setMessage( 256, 34, 56 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
+            message.setMessage(245, 34, 56);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+        try {
+            message.setMessage(256, 34, 56);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
         try {
-            message.setMessage( 250, 34, 56 );
-        } catch( InvalidMidiDataException e ) { }
+            message.setMessage(250, 34, 56);
+        } catch (InvalidMidiDataException e) {}
         /**
          * channel change from 0 up to 15, and
          * channel + command == status, so
          * the value of command divisible by 16.
          */
-        assertTrue( message.getChannel() == 10 );
-        assertTrue( message.getCommand() == 240 );
-        assertTrue( message.getData1() == 0 );
-        assertTrue( message.getData2() == 0 );
-        assertTrue( message.getLength() == 1 );
-        assertTrue( message.getStatus() == 250 );
-        assertTrue( message.getMessage().length == 1 );
+        assertEquals(10, message.getChannel());
+        assertEquals(240, message.getCommand());
+        assertEquals(0, message.getData1());
+        assertEquals(0, message.getData2());
+        assertEquals(1, message.getLength());
+        assertEquals(250, message.getStatus());
+        assertEquals(1, message.getMessage().length);
     }
-    
+
     /**
      * test method setMessage( int, int, int ) of 
      * class ShortMessage
      */
-    public void test_setMessage3()
-    {
+    public void test_setMessage3() {
         ShortMessage1 message = new ShortMessage1();
         /**
          * value of variable command is more or equals 128 and
          * less or equals 239
          */
         try {
-            message.setMessage( 127, 10, 34, 56 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-        try {
-            message.setMessage( 240, 34, 56 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-        
+            message.setMessage(127, 10, 34, 56);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+        try {
+            message.setMessage(240, 34, 56, 13);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
         /**
          * value of variable channel is more or equals 0 and 
          * less or equals 15
          */
         try {
-            message.setMessage( 200, -1, 34, 56 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-        try {
-            message.setMessage( 200, 16, 34, 56 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-  
+            message.setMessage(200, -1, 34, 56);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+        try {
+            message.setMessage(200, 16, 34, 56);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
         /**
          * value of data1 and data2 is more or equals 0 and
          * less or equals 127, but when command more or
-         * equals 192 and less or equals 224 the second data,
-         * data2, is unused
+         * equals 192 and less or equals 223 the second data,
+         * data2, is unused, because getDataLength(int) return 1
+         * in this case, and in other cases it return 2
          */
         try {
-            message.setMessage( 200, 12, -1, 56 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-        try {
-            message.setMessage( 225, 8, 34, 456 );
-            fail( "InvalidMidiDataException expected" );
-        } catch( InvalidMidiDataException e ) { }
-        try {
-            message.setMessage( 200, 8, 34, 456 );
-        } catch( InvalidMidiDataException e ) { }
-                
+            message.setMessage(200, 12, -1, 56);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.setMessage(225, 8, 34, 456);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.setMessage(200, 8, 34, 456);
+        } catch (InvalidMidiDataException e) {}
+
         try {
-            message.setMessage( 200, 9, 34, 56 );
-        } catch( InvalidMidiDataException e ) { }
+            message.setMessage(200, 9, 34, 56);
+        } catch (InvalidMidiDataException e) {}
         /**
-         * channel change from 0 up to 15;
-         * 
+         * channel change from 0 up to 15
          * command must to divisible by 16, and so it less or 
-         * equals parameter command;
-         * 
+         * equals parametr command
          * status is sum of channel and command
          */
-        assertTrue( message.getChannel() == 9 );
-        assertTrue( message.getCommand() == 192 );
-        assertTrue( message.getData1() == 34 );
-        assertTrue( message.getData2() == 0 );
-        assertTrue( message.getLength() == 2 );
-        assertTrue( message.getStatus() == 201 );
-        assertTrue( message.getMessage().length == 2 );
-        
-        try {
-            message.setMessage( 148, 9, 34, 56 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getChannel() == 9 );
-        assertTrue( message.getCommand() == 144 );
-        assertTrue( message.getData1() == 34 );
-        assertTrue( message.getData2() == 56 );
-        assertTrue( message.getLength() == 3 );
-        assertTrue( message.getStatus() == 153 );
-        assertTrue( message.getMessage().length == 3 );
+        assertEquals(9, message.getChannel());
+        assertEquals(192, message.getCommand());
+        assertEquals(34, message.getData1());
+        assertEquals(0, message.getData2());
+        assertEquals(2, message.getLength());
+        assertEquals(201, message.getStatus());
+        assertEquals(2, message.getMessage().length);
+
+        try {
+            message.setMessage(148, 9, 34, 56);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(9, message.getChannel());
+        assertEquals(144, message.getCommand());
+        assertEquals(34, message.getData1());
+        assertEquals(56, message.getData2());
+        assertEquals(3, message.getLength());
+        assertEquals(153, message.getStatus());
+        assertEquals(3, message.getMessage().length);
     }
-    
+
     /**
      * test method getChannel() of class ShortMessage
      *
      */
-    public void test_getChannel()
-    {
+    public void test_getChannel() {
         ShortMessage message = new ShortMessage();
-        assertTrue( message.getChannel() == 0 );
-        
-        ShortMessage1 message1 = new ShortMessage1( new byte[] { 23, 16, 35 } );
-        assertTrue( message1.getChannel() == 7 );
-        
-        ShortMessage1 message2 = new ShortMessage1( null );
-        assertTrue( message2.getChannel() == 0 );
-        
-        try {
-            message.setMessage( 249 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getChannel() == 9 );
-        
-        try {
-            message.setMessage( 250, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getChannel() == 10 );
-        
-        try {
-            message.setMessage( 234, 15, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getChannel() == 15 );
-        
+        assertEquals(0, message.getChannel());
+
+        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        assertEquals(7, message1.getChannel());
+
+        ShortMessage1 message2 = new ShortMessage1(null);
+        assertEquals(0, message2.getChannel());
+
+        try {
+            message.setMessage(249);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(9, message.getChannel());
+
+        try {
+            message.setMessage(250, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(10, message.getChannel());
+
+        try {
+            message.setMessage(234, 15, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(15, message.getChannel());
+
     }
-    
+
     /**
      * test method getCommand() of class ShortMessage
      *
      */
-    public void test_getCommand()
-    {
+    public void test_getCommand() {
         ShortMessage message = new ShortMessage();
-        assertTrue( message.getCommand() == 144 );
-        
-        ShortMessage1 message1 = new ShortMessage1( new byte[] { 23, 16, 35 } );
-        assertTrue( message1.getCommand() == 16 );
-        
-        ShortMessage1 message2 = new ShortMessage1( null );
-        assertTrue( message2.getCommand() == 0 );
-        
-        try {
-            message.setMessage( 249 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getCommand() == 240 );
-        
-        try {
-            message.setMessage( 250, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getCommand() == 240 );
-        
-        try {
-            message.setMessage( 234, 15, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getCommand() == 224 );
+        assertEquals(144, message.getCommand());
+
+        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        assertEquals(16, message1.getCommand());
+
+        ShortMessage1 message2 = new ShortMessage1(null);
+        assertEquals(0, message2.getCommand());
+
+        try {
+            message.setMessage(249);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(240, message.getCommand());
+
+        try {
+            message.setMessage(250, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(240, message.getCommand());
+
+        try {
+            message.setMessage(234, 15, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(224, message.getCommand());
     }
-    
+
     /**
      * test method getLength() of class ShortMessage
      *
      */
-    public void test_getLength()
-    {
+    public void test_getLength() {
         ShortMessage message = new ShortMessage();
-        assertTrue( message.getLength() == 3 );
-        
-        ShortMessage1 message1 = new ShortMessage1( new byte[] { 23, 16, 35 } );
-        assertTrue( message1.getLength() == 3 );
-        
-        ShortMessage1 message2 = new ShortMessage1( null );
-        assertTrue( message2.getLength() == 0 );
-        
-        try {
-            message.setMessage( 249 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getLength() == 1 );
-        
-        try {
-            message.setMessage( 250, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getLength() == 1 );
-        
-        try {
-            message.setMessage( 234, 15, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getLength() == 3 );
-        
-        try {
-            message.setMessage( 214, 15, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getLength() == 2 );
+        assertEquals(3, message.getLength());
+
+        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        assertEquals(3, message1.getLength());
+
+        ShortMessage1 message2 = new ShortMessage1(null);
+        assertEquals(0, message2.getLength());
+
+        try {
+            message.setMessage(249);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(1, message.getLength());
+
+        try {
+            message.setMessage(250, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(1, message.getLength());
+
+        try {
+            message.setMessage(234, 15, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(3, message.getLength());
+
+        try {
+            message.setMessage(214, 15, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(2, message.getLength());
     }
-    
+
     /**
      * test method getStatus() of class ShortMessage
      *
      */
-    public void test_getStatus()
-    {
+    public void test_getStatus() {
         ShortMessage message = new ShortMessage();
-        assertTrue( message.getStatus() == 144 );
-        
-        ShortMessage1 message1 = new ShortMessage1( new byte[] { 23, 16, 35 } );
-        assertTrue( message1.getStatus() == 23 );
-        
-        ShortMessage1 message2 = new ShortMessage1( null );
-        assertTrue( message2.getStatus() == 0 );
-        
-        try {
-            message.setMessage( 249 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getStatus() == 249 );
-        
-        try {
-            message.setMessage( 250, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getStatus() == 250 );
-        
-        try {
-            message.setMessage( 234, 15, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getStatus() == 239 );
+        assertEquals(144, message.getStatus());
+
+        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        assertEquals(23, message1.getStatus());
+
+        ShortMessage1 message2 = new ShortMessage1(null);
+        assertEquals(0, message2.getStatus());
+
+        try {
+            message.setMessage(249);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(249, message.getStatus());
+
+        try {
+            message.setMessage(250, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(250, message.getStatus());
+
+        try {
+            message.setMessage(234, 15, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(239, message.getStatus());
     }
-    
+
     /**
      * test methods getData1() and getData2() of 
      * class ShortMessage
      *
      */
-    public void test_getData1_2()
-    {
+    public void test_getData1_2() {
         ShortMessage message = new ShortMessage();
-        assertTrue( message.getData1() == 64 );
-        assertTrue( message.getData2() == 127 );
-        
-        ShortMessage1 message1 = new ShortMessage1( new byte[] { 23, 16, 35 } );
-        assertTrue( message1.getData1() == 16 );
-        assertTrue( message1.getData2() == 35 );
-        
-        ShortMessage1 message11 = new ShortMessage1( new byte[] { 23, 16 } );
-        assertTrue( message11.getData1() == 16 );
-        assertTrue( message11.getData2() == 0 );
-        
-        ShortMessage1 message12 = new ShortMessage1( new byte[] { 23 } );
-        assertTrue( message12.getData1() == 0 );
-        assertTrue( message12.getData2() == 0 );
-        
-        ShortMessage1 message2 = new ShortMessage1( null );
-        assertTrue( message2.getData1() == 0 );
-        assertTrue( message2.getData2() == 0 );
-        
-        try {
-            message.setMessage( 249 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getData1() == 0 );
-        assertTrue( message.getData2() == 0 );
-        
-        try {
-            message.setMessage( 250, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getData1() == 0 );
-        assertTrue( message.getData2() == 0 );
-        
-        try {
-            message.setMessage( 234, 15, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getData1() == 14 );
-        assertTrue( message.getData2() == 62 );
-        
-        try {
-            message.setMessage( 198, 15, 14, 62 );
-        } catch( InvalidMidiDataException e ) { }
-        assertTrue( message.getData1() == 14 );
-        assertTrue( message.getData2() == 0 );
+        assertEquals(64, message.getData1());
+        assertEquals(127, message.getData2());
+
+        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        assertEquals(16, message1.getData1());
+        assertEquals(35, message1.getData2());
+
+        ShortMessage1 message11 = new ShortMessage1(new byte[] { 23, 16 });
+        assertEquals(16, message11.getData1());
+        assertEquals(0, message11.getData2());
+
+        ShortMessage1 message12 = new ShortMessage1(new byte[] { 23 });
+        assertEquals(0, message12.getData1());
+        assertEquals(0, message12.getData2());
+
+        ShortMessage1 message2 = new ShortMessage1(null);
+        assertEquals(0, message2.getData1());
+        assertEquals(0, message2.getData2());
+
+        try {
+            message.setMessage(249);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(0, message.getData1());
+        assertEquals(0, message.getData2());
+
+        try {
+            message.setMessage(250, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(0, message.getData1());
+        assertEquals(0, message.getData2());
+
+        try {
+            message.setMessage(234, 15, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(14, message.getData1());
+        assertEquals(62, message.getData2());
+
+        try {
+            message.setMessage(198, 15, 14, 62);
+        } catch (InvalidMidiDataException e) {}
+        assertEquals(14, message.getData1());
+        assertEquals(0, message.getData2());
     }
-    
+
     /**
      * test method getDataLength() of class ShortMessage
      *
      */
-    public void test_getDataLentgth()
-    {
-        //TODO
+    public void test_getDataLentgth() {
+        ShortMessage1 message = new ShortMessage1();
+
+        /*
+         * I have some question about this method. I didn't understand how
+         * should to work this method, but some results I get by
+         * experimental method.
+         * From 0 up to 127, from 256 up to 383 and so on this method throw
+         * out exception, i.e. after 256 begin cycle with some small 
+         * differences in the first lap, from 0 up to 255. From the second
+         * lap and so on this method, getDataLenght(int), throw out 
+         * exception with value of status from 496 up to 511, from 752 up to 
+         * 767 and so on, i.e. on the last 16 number of 256-lap.
+         * And now differences in the first lap. This method don't throw out 
+         * exception with value of status from 240 up to 255. It has next 
+         * behavior:
+         * - value of status equals 240 -- throw out exception;
+         * - 241 -- return 1; 
+         * - 242 -- return 2;
+         * - 243 -- return 1;
+         * - from 244 up to 245 -- throw out exception;
+         * - from 246 up to 255 -- return 0;
+         */
+        try {
+            message.getDataLength1(-1);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.getDataLength1(56);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.getDataLength1(127);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.getDataLength1(240);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.getDataLength1(244);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.getDataLength1(245);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.getDataLength1(256);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            message.getDataLength1(519);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(2, message.getDataLength1(128));
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(1, message.getDataLength1(200));
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(2, message.getDataLength1(230));
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(1, message.getDataLength1(241));
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(2, message.getDataLength1(242));
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(1, message.getDataLength1(243));
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(0, message.getDataLength1(250));
+        } catch (InvalidMidiDataException e) {}
+
+        try {
+            assertEquals(2, message.getDataLength1(647));
+        } catch (InvalidMidiDataException e) {}
+    }
+
+    public void test_clone() {
+        ShortMessage message = new ShortMessage();
+        assertTrue(message.clone() != message);
+        assertEquals(message.clone().getClass(), message.getClass());
+        ShortMessage tmessage;
+        tmessage = (ShortMessage) message.clone();
+        assertEquals(message.getLength(), tmessage.getLength());
+        assertEquals(message.getMessage().length, tmessage.getMessage().length);
+        assertEquals(message.getData1(), tmessage.getData1());
+        assertEquals(message.getData2(), tmessage.getData2());
+        assertEquals(message.getChannel(), tmessage.getChannel());
+        assertEquals(message.getCommand(), tmessage.getCommand());
+        assertEquals(message.getStatus(), tmessage.getStatus());
+        if (message.getMessage().length != 0) {
+            for (int i = 0; i < message.getMessage().length; i++) {
+                assertEquals(message.getMessage()[i], tmessage.getMessage()[i]);
+            }
+        }
     }
-    
+
     /**
      * Subsidiary class in order to use constructor
      * and method getDataLength( int ) of class Instrument, 
      * because its declared as protected
      */
-    static class ShortMessage1 extends ShortMessage
-    {
-        ShortMessage1()
-        {
+    static class ShortMessage1 extends ShortMessage {
+
+        ShortMessage1() {
             super();
         }
-        ShortMessage1( byte[] data )
-        {
-            super( data );
+
+        ShortMessage1(byte[] data) {
+            super(data);
         }
-        
-        public int getDataLength1( int status )
-                throws InvalidMidiDataException
-        {
-            return super.getDataLength( status );
+
+        public int getDataLength1(int status) throws InvalidMidiDataException {
+            return super.getDataLength(status);
         }
     }
 }



Mime
View raw message