harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r426930 - in /incubator/harmony/enhanced/classlib/trunk/modules/sound/src: main/java/javax/sound/midi/ test/java/org/apache/harmony/sound/tests/javax/sound/midi/
Date Sun, 30 Jul 2006 20:12:01 GMT
Author: ndbeyer
Date: Sun Jul 30 13:12:00 2006
New Revision: 426930

URL: http://svn.apache.org/viewvc?rev=426930&view=rev
Log:
Apply patch and mods for HARMONY-989: [classlib][sound] Some improvements/fix bugs in classes ShortMessage, MidiMessage, MetaMessage

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MetaMessage.java
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiMessage.java
    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/MetaMessageTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiMessageTest.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/MetaMessage.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MetaMessage.java?rev=426930&r1=426929&r2=426930&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MetaMessage.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MetaMessage.java Sun Jul 30 13:12:00 2006
@@ -19,35 +19,25 @@
 public class MetaMessage extends MidiMessage {
     public static final int META = 255;
     
-    private int type;
-
-    private byte[] data;
-
+    private int dsp; //displacement from begin of array that 
+                     //return by method getData() from begin
+                     //of array that contain data
+    
     public MetaMessage() {
-        super(new byte[] { -1, 0 });
-        data = new byte[0];
-        type = 0;
+        super(new byte[] {-1, 0});
     }
 
     protected MetaMessage(byte[] data) {
         super(data);
-        if (data.length >= 2) {
-            type = (int) (data[1] & 0xFF);
-        } else {
-            type = 0;
+        if (data == null) {
+            throw new NullPointerException();
         }
-        if (data.length > 3) {
+        if (super.length > 3) {
             int n = 3;
-            while (data[n - 1] < 0)
+            while ((n <= super.length) && (super.data[n - 1] < 0))
                 n++;
-            this.data = new byte[data.length - n];
-            for (int i = n; i < data.length; i++) {
-                this.data[i - n] = data[i];
-            }
-        } else {
-            this.data = new byte[0];
+            dsp = n;
         }
-
     }
 
     public Object clone() {
@@ -55,15 +45,26 @@
     }
 
     public byte[] getData() {
-        return data.clone();
+        if ((super.data != null) && (super.length > 3)) {
+            byte[] bt = new byte[super.length - dsp];
+            for (int i = dsp; i < super.length; i++) {
+                bt[i - dsp] = super.data[i];
+            }
+            return bt;
+        } else {
+            return new byte[0];
+        }
     }
 
     public int getType() {
-        return type;
+        if ((super.data != null) && (super.length >= 2)) {
+            return (int) (super.data[1] & 0xFF);
+        } else {
+            return 0;
+        }
     }
 
     public void setMessage(int type, byte[] data, int length) throws InvalidMidiDataException {
-        //FIXME
         if (type < 0 || type >= 128) {
             throw new InvalidMidiDataException("Invalid meta event with type " + type);
         }
@@ -76,7 +77,6 @@
                     throw new NullPointerException();
                 }
                 super.setMessage(new byte[] { -1, (byte) type, 0 }, 3);
-                this.data = new byte[0];
             } else {
                 int div = 128;
                 int n = 1;
@@ -105,15 +105,10 @@
                     }
                 }
                 super.setMessage(tdata, length + 2 + ln);
-                this.data = new byte[length];
-                if (length > 0) {
-                    for (int i = 0; i < length; i++)
-                        this.data[i] = data[i];
-                }
+                dsp = ln + 2;
             }
         } catch (InvalidMidiDataException e) {
             throw e;
         }
-        this.type = type;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiMessage.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiMessage.java?rev=426930&r1=426929&r2=426930&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiMessage.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/MidiMessage.java Sun Jul 30 13:12:00 2006
@@ -17,19 +17,17 @@
 package javax.sound.midi;
 
 public abstract class MidiMessage implements Cloneable {
-    private int status;
 
     protected byte[] data;
 
     protected int length;
 
     protected MidiMessage(byte[] data) {
-        if (data == null || data.length == 0) {
-            data = null;
+        if (data == null) {
+            length = 0;
         } else {
             length = data.length;
-            status = (int) (data[0] & 0xFF);
-            this.data = data.clone();
+            this.data = data;
         }
     }
 
@@ -40,34 +38,31 @@
     }
 
     public byte[] getMessage() {
+        if (data == null) {
+            throw new NullPointerException();
+        }
         return data.clone();
     }
 
     public int getStatus() {
-        return status;
+        if ((data == null) || (length == 0)) {
+            return 0;
+        } else {
+            return (int) (data[0] & 0xFF);
+        }
     }
 
     protected void setMessage(byte[] data, int length) throws InvalidMidiDataException {
-        //FIXME
-        /**
-         * this method should throw out IndexOutOfBoundsException when 
-         * I use negative length
-         */
-        if (length < 0)
-            throw new IndexOutOfBoundsException();
-
-        byte[] tdata = new byte[length];
-        if (length == 0 && data != null) {
-            status = 0;
-        } else {
+        if ((length < 0) || (length > data.length)) {
+            throw new IndexOutOfBoundsException("length out of bounds: " + length);
+        }
+
+        this.data = new byte[length];
+        if (length != 0) {
             for (int i = 0; i < length; i++) {
-                tdata[i] = data[i];
+                this.data[i] = data[i];
             }
-            status = (int) (data[0] & 0xFF);
-            this.length = length;
         }
         this.length = length;
-        this.data = tdata;
-
     }
 }

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=426930&r1=426929&r2=426930&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 Sun Jul 30 13:12:00 2006
@@ -58,45 +58,12 @@
 
     public static final int TUNE_REQUEST = 246;
 
-    private int data1;
-
-    private int data2;
-
-    private int channel;
-
-    private int command;
-
     public ShortMessage() {
-        super(new byte[] { -112, 64, 127 });
-        data1 = 64;
-        data2 = 127;
-        channel = 0;
-        command = 144;
+        super(new byte[] {-112, 64, 127});
     }
 
     protected ShortMessage(byte[] data) {
         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() {
@@ -104,19 +71,45 @@
     }
 
     public int getChannel() {
-        return channel;
+        /*
+         * channel change from 0 up to 15
+         */
+        if ((data == null) || (data.length == 0)) {
+            return 0;
+        } else {
+            return ((int) (data[0] & 0xFF)) % 16;
+        }
     }
 
     public int getCommand() {
-        return command;
+       /*
+        * command should be divisible by 16 without rest 
+        */
+        if ((data == null) || (data.length == 0)) {
+            return 0;
+        } else {
+            return ((int) (data[0] & 0xFF)) - getChannel();
+        }
     }
 
     public int getData1() {
-        return data1;
+        if ((data == null) || (data.length == 0)) {
+            return 0;
+        } else if (data.length < 2) {
+            return 0;
+        } else {
+            return (int) (data[1] & 0xFF);
+        }
     }
 
     public int getData2() {
-        return data2;
+        if ((data == null) || (data.length == 0)) {
+            return 0;
+        } else if (data.length < 3) {
+            return 0;
+        } else {
+            return (int) (data[2] & 0xFF);
+        }
     }
 
     protected final int getDataLength(int status)
@@ -132,10 +125,13 @@
          * 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;
+         * 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);
@@ -171,20 +167,13 @@
     }
 
     public void setMessage(int status) throws InvalidMidiDataException {
-        /**
+        /*
          * 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;
+        super.setMessage(new byte[] {(byte) status}, 1);
     }
 
     public void setMessage(int status, int data1, int data2)
@@ -197,26 +186,16 @@
          * 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;
+        super.setMessage(new byte[] {(byte) status}, 1);
     }
 
     public void setMessage(int command, int channel, int data1, int data2)
             throws InvalidMidiDataException {
         // FIXME
-        /**
+        /*
          * value of variable command is more or equals 128 and less or equals
          * 239
          */
@@ -225,46 +204,33 @@
              * when this exception throw out, the value of variable command
              * should be the hexadecimal number
              */
-            throw new InvalidMidiDataException("command out of range: "
-                    + command);
+            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);
+            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)) {
+        if ((getDataLength(command) >= 1) && ((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()
-         */
+        int tcom = command - (command % 16);
         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;
+            super.setMessage(new byte[] {(byte) (tcom + channel), (byte) data1}, 2);
+        } else {
+            super.setMessage(new byte[] {(byte) (tcom + channel), (byte) data1, 
+                    (byte) data2}, 3);
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MetaMessageTest.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/MetaMessageTest.java?rev=426930&r1=426929&r2=426930&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MetaMessageTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MetaMessageTest.java Sun Jul 30 13:12:00 2006
@@ -42,8 +42,7 @@
         try {
             meta = new MetaMessage1(null);
             fail("NullPointerException expected");
-        } catch (NullPointerException e) {
-        }
+        } catch (NullPointerException e) {}
 
         assertEquals(2, meta.getLength());
         assertEquals(255, meta.getStatus());
@@ -53,7 +52,8 @@
         assertEquals(0, meta.getMessage()[1]);
         assertEquals(0, meta.getData().length);
 
-        MetaMessage1 meta3 = new MetaMessage1(new byte[] { -87, 19, 4 });
+        byte[] bt = new byte[] {-87, 19, 4};
+        MetaMessage1 meta3 = new MetaMessage1(bt);
         assertEquals(3, meta3.getLength());
         assertEquals(169, meta3.getStatus());
         assertEquals(19, meta3.getType());
@@ -62,8 +62,22 @@
         assertEquals(19, meta3.getMessage()[1]);
         assertEquals(4, meta3.getMessage()[2]);
         assertEquals(0, meta3.getData().length);
+        bt[0] = 10;
+        bt[1] = 20;
+        bt[2] = 30;
+        /**
+         * values change!!!
+         */
+        assertEquals( meta3.getStatus(), 10 );
+        assertEquals( meta3.getType(), 20 );
+        assertEquals( meta3.getMessage().length, 3 );
+        assertEquals( meta3.getMessage()[0], 10 );
+        assertEquals( meta3.getMessage()[1], 20 );
+        assertEquals( meta3.getMessage()[2], 30 );
+        assertEquals( meta3.getData().length, 0 );
 
-        MetaMessage1 meta1 = new MetaMessage1(new byte[] { 17, -9, 23, 45, 56 });
+        bt = new byte[] {17, -9, 23, 45, 56};
+        MetaMessage1 meta1 = new MetaMessage1(bt);
         assertEquals(5, meta1.getLength());
         assertEquals(17, meta1.getStatus());
         assertEquals(247, meta1.getType());
@@ -76,6 +90,50 @@
         assertEquals(2, meta1.getData().length);
         assertEquals(45, meta1.getData()[0]);
         assertEquals(56, meta1.getData()[1]);
+        bt[0] = 98;
+        bt[2] = -56;
+        bt[3] = -16;
+        bt[4] = -3;
+        /**
+         * values change, but the begin of array that
+         * return by method getData() doesn't displace!!!
+         */
+        assertEquals( meta1.getLength(), 5 );
+        assertEquals( meta1.getStatus(), 98 );
+        assertEquals( meta1.getType(), 247 );
+        assertEquals( meta1.getMessage().length, 5 );
+        assertEquals( meta1.getMessage()[0], 98 );
+        assertEquals( meta1.getMessage()[1], -9 );
+        assertEquals( meta1.getMessage()[2], -56 );
+        assertEquals( meta1.getMessage()[3], -16 );
+        assertEquals( meta1.getMessage()[4], -3 );
+        assertEquals( 2, meta1.getData().length ); //!!!
+        assertEquals( meta1.getData()[0], -16 );   //!!! 
+        assertEquals( meta1.getData()[1], -3 );    //!!!
+        byte[] nb = meta1.getData();
+        nb[0] = 1;
+        nb[1] = 2;
+        /**
+         * and here values don't change...
+         */
+        assertEquals( meta1.getData()[0], -16 );
+        assertEquals( meta1.getData()[1], -3 );
+        
+        bt = new byte[] {17, -9, -23, -45, -56};
+        MetaMessage1 meta4 = new MetaMessage1(bt);
+        assertEquals(5, meta4.getLength());
+        assertEquals(17, meta4.getStatus());
+        assertEquals(247, meta4.getType());
+        assertEquals(5, meta4.getMessage().length);
+        assertEquals(17, meta4.getMessage()[0]);
+        assertEquals(-9, meta4.getMessage()[1]);
+        assertEquals(-23, meta4.getMessage()[2]);
+        assertEquals(-45, meta4.getMessage()[3]);
+        assertEquals(-56, meta4.getMessage()[4]);
+        try {
+            assertEquals(0, meta4.getData().length);
+            fail("NegativeArraySizeException expected");
+        } catch (NegativeArraySizeException e) {}
 
         meta.setMessage(10, new byte[100000], 16385);
 
@@ -160,11 +218,12 @@
         assertEquals(meta.getMessage()[3], -128);
         assertEquals(meta.getMessage()[4], 1);
 
-        meta.setMessage(10, new byte[] { 1, 2, 3, 4 }, 4);
+        byte[] bt = new byte[] { 1, 2, 3, 4 };
+        meta.setMessage(10, bt, 4);
         assertEquals(meta.getLength(), 7);
         assertEquals(meta.getStatus(), 255);
         assertEquals(meta.getType(), 10);
-        assertEquals(meta.getData().length, 4);
+        assertEquals(4, meta.getData().length);
         assertEquals(meta.getData()[0], 1);
         assertEquals(meta.getData()[1], 2);
         assertEquals(meta.getData()[2], 3);
@@ -177,6 +236,29 @@
         assertEquals(meta.getMessage()[4], 2);
         assertEquals(meta.getMessage()[5], 3);
         assertEquals(meta.getMessage()[6], 4);
+        bt[0] = 0;
+        bt[1] = 1;
+        bt[2] = 2;
+        bt[3] = 3;
+        /**
+         * values don't change
+         */
+        assertEquals( meta.getLength(), 7 );
+        assertEquals( meta.getStatus(), 255 );
+        assertEquals( meta.getType(), 10 );
+        assertEquals( meta.getData().length, 4 );
+        assertEquals( meta.getData()[0], 1 );
+        assertEquals( meta.getData()[1], 2 );
+        assertEquals( meta.getData()[2], 3 );
+        assertEquals( meta.getData()[3], 4 );
+        assertEquals( meta.getMessage().length, 7 );
+        assertEquals( meta.getMessage()[0], -1 );
+        assertEquals( meta.getMessage()[1], 10 );
+        assertEquals( meta.getMessage()[2], 4 );
+        assertEquals( meta.getMessage()[3], 1 );
+        assertEquals( meta.getMessage()[4], 2 );
+        assertEquals( meta.getMessage()[5], 3 );
+        assertEquals( meta.getMessage()[6], 4 );
 
         meta.setMessage(12, null, 0);
 
@@ -190,19 +272,17 @@
         assertEquals(meta.getMessage()[2], 0);
 
         /**
-         * I will testing this condition after throw out exception;
+         * I will testing following condition after throw out exception;
          * it must be the same after it 
          */
         try {
             meta.setMessage(10, new byte[] { 1, 2, 3, 4 }, 4);
-        } catch (InvalidMidiDataException e) {
-        }
+        } catch (InvalidMidiDataException e) {}
 
         try {
             meta.setMessage(12, new byte[0], 9);
             fail("InvalidMidiDataException expected");
-        } catch (InvalidMidiDataException e) {
-        }
+        } catch (InvalidMidiDataException e) {}
         assertEquals(meta.getLength(), 7);
         assertEquals(meta.getStatus(), 255);
         assertEquals(meta.getType(), 10);
@@ -223,8 +303,7 @@
         try {
             meta.setMessage(12, null, 9);
             fail("NullPointerException expected");
-        } catch (NullPointerException e) {
-        }
+        } catch (NullPointerException e) {}
         assertEquals(meta.getLength(), 7);
         assertEquals(meta.getStatus(), 255);
         assertEquals(meta.getType(), 10);
@@ -245,8 +324,7 @@
         try {
             meta.setMessage(12, null, -9);
             fail("InvalidMidiDataException expected");
-        } catch (InvalidMidiDataException e) {
-        }
+        } catch (InvalidMidiDataException e) {}
         assertEquals(meta.getLength(), 7);
         assertEquals(meta.getStatus(), 255);
         assertEquals(meta.getType(), 10);
@@ -275,26 +353,22 @@
         try {
             meta.setMessage(10, new byte[] { 1, 2, 3 }, 4);
             fail("InvalidMidiDataException expected");
-        } catch (InvalidMidiDataException e) {
-        }
+        } catch (InvalidMidiDataException e) {}
 
         try {
             meta.setMessage(10, new byte[] { 1, 2, 3 }, -5);
             fail("InvalidMidiDataException expected");
-        } catch (InvalidMidiDataException e) {
-        }
+        } catch (InvalidMidiDataException e) {}
 
         try {
             meta.setMessage(-1, new byte[] { 1, 2, 3 }, 3);
             fail("InvalidMidiDataException expected");
-        } catch (InvalidMidiDataException e) {
-        }
+        } catch (InvalidMidiDataException e) {}
 
         try {
             meta.setMessage(128, new byte[] { 1, 2, 3 }, 3);
             fail("InvalidMidiDataException expected");
-        } catch (InvalidMidiDataException e) {
-        }
+        } catch (InvalidMidiDataException e) {}
 
         meta.setMessage(10, new byte[] { 1, 2, 3, 4 }, 4);
 
@@ -350,9 +424,15 @@
         MetaMessage meta = new MetaMessage();
         assertEquals(meta.getType(), 0);
 
-        MetaMessage1 meta2 = new MetaMessage1(new byte[] { 9, -4, 34, 18 });
+        byte[] bt = new byte[] { 9, -4, 34, 18 };
+        MetaMessage1 meta2 = new MetaMessage1(bt);
         assertEquals(meta2.getType(), 252);
-
+        bt[1] = 5;
+        /**
+         * value change
+         */
+        assertEquals(5, meta2.getType());
+        
         meta.setMessage(10, new byte[] { 1, 2, 3, 4 }, 4);
         assertEquals(meta.getType(), 10);
 
@@ -368,20 +448,40 @@
         MetaMessage meta = new MetaMessage();
         assertEquals(0, meta.getData().length);
 
-        MetaMessage1 meta1 = new MetaMessage1(new byte[] { 18, 43, 27, -90, 4 });
+        byte[] bt = new byte[] { 18, 43, 27, -90, 4 };
+        MetaMessage1 meta1 = new MetaMessage1(bt);
         assertEquals(2, meta1.getData().length);
         assertEquals(-90, meta1.getData()[0]);
         assertEquals(4, meta1.getData()[1]);
+        bt[3] = 67;
+        bt[4] = -16;
+        /**
+         * values change
+         */
+        assertEquals(67, meta1.getData()[0]);
+        assertEquals(-16, meta1.getData()[1]);
 
         MetaMessage1 meta2 = new MetaMessage1(new byte[] { 18, 43, 27 });
         assertEquals(0, meta2.getData().length);
 
-        meta.setMessage(10, new byte[] { 1, 2, 3, 4 }, 4);
+        bt = new byte[] { 1, 2, 3, 4 };
+        meta.setMessage(10, bt, 4);
         assertEquals(4, meta.getData().length);
         assertEquals(1, meta.getData()[0]);
         assertEquals(2, meta.getData()[1]);
         assertEquals(3, meta.getData()[2]);
         assertEquals(4, meta.getData()[3]);
+        bt[0] = 34;
+        bt[1] = -17;
+        bt[2] = 90;
+        bt[3] = -6;
+        /**
+         * values don't change
+         */
+        assertEquals(1, meta.getData()[0]);
+        assertEquals(2, meta.getData()[1]);
+        assertEquals(3, meta.getData()[2]);
+        assertEquals(4, meta.getData()[3]);
 
         meta.setMessage(12, null, 0);
         assertNotNull(meta.getData());
@@ -463,6 +563,36 @@
                 assertEquals(meta.getMessage()[i], tmeta.getMessage()[i]);
             }
         }
+    }
+    
+    public void test_clone4() throws Exception {
+        byte[] bt = new byte[] {1, 2, 3, 4};
+        MetaMessage1 meta = new MetaMessage1(bt);
+        assertTrue(meta.clone() != meta);
+        
+        MetaMessage tmeta;
+        tmeta = (MetaMessage) meta.clone();
+        bt[0] = 34;
+        bt[1] = 15;
+        bt[2] = 89;
+        bt[3] = 1;
+        assertEquals(meta.getLength(), tmeta.getLength());
+        assertEquals(meta.getMessage().length, tmeta.getMessage().length);
+        assertEquals(meta.getData().length, tmeta.getData().length);
+        /**
+         * 'real' MetaMessage change, but 'clone' not
+         */
+        assertEquals(1, meta.getData()[0]);
+        assertEquals(34, meta.getMessage()[0]);
+        assertEquals(15, meta.getMessage()[1]);
+        assertEquals(89, meta.getMessage()[2]);
+        assertEquals(1, meta.getMessage()[3]);
+        
+        assertEquals(4, tmeta.getData()[0]);
+        assertEquals(1, tmeta.getMessage()[0]);
+        assertEquals(2, tmeta.getMessage()[1]);
+        assertEquals(3, tmeta.getMessage()[2]);
+        assertEquals(4, tmeta.getMessage()[3]);
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiMessageTest.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/MidiMessageTest.java?rev=426930&r1=426929&r2=426930&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiMessageTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/MidiMessageTest.java Sun Jul 30 13:12:00 2006
@@ -21,213 +21,243 @@
 import javax.sound.midi.InvalidMidiDataException;
 import javax.sound.midi.MidiMessage;
 
-
-public class MidiMessageTest extends TestCase
-{   
+public class MidiMessageTest extends TestCase {
     /**
      * test constructor of class MidiMessage
      *
      */
-    public void test_constructor_MidiMessage()
-    {
-        MidiMessage1 midi = new MidiMessage1( new byte[] { 1, 2, 3, -5 } );
-        assertTrue( midi.getLength() == 4 );
-        assertTrue( midi.getStatus() == 1 );
-        assertTrue( midi.getMessage().length == 4 );
-        assertTrue( midi.getMessage()[0] == 1 ); 
-        assertTrue( midi.getMessage()[1] == 2 );
-        assertTrue( midi.getMessage()[2] == 3 );
-        assertTrue( midi.getMessage()[3] == -5 );
-        
-        MidiMessage1 midi1 = new MidiMessage1( new byte[] { 0, -2 } );
-        assertTrue( midi1.getLength() == 2 );
-        assertTrue( midi1.getStatus() == 0 );
-        assertTrue( midi1.getMessage().length == 2 );
-        assertTrue( midi1.getMessage()[0] == 0 ); 
-        assertTrue( midi1.getMessage()[1] == -2 );
-        
-        MidiMessage1 midi2 = new MidiMessage1( new byte[] { -1, 87, 19 } );
-        assertTrue( midi2.getLength() == 3 );
-        assertTrue( midi2.getStatus() == 255 );
-        assertTrue( midi2.getMessage().length == 3 );
-        assertTrue( midi2.getMessage()[0] == -1 );
-        assertTrue( midi2.getMessage()[1] == 87 );
-        assertTrue( midi2.getMessage()[2] == 19 );
-        
-        MidiMessage1 midi3 = new MidiMessage1( null );
-        assertTrue( midi3.getLength() == 0 );
-        assertTrue( midi3.getStatus() == 0 );
+    public void test_constructor_MidiMessage() {
+        MidiMessage1 midi = new MidiMessage1(new byte[] { 1, 2, 3, -5 });
+        assertTrue(midi.getLength() == 4);
+        assertTrue(midi.getStatus() == 1);
+        assertTrue(midi.getMessage().length == 4);
+        assertTrue(midi.getMessage()[0] == 1);
+        assertTrue(midi.getMessage()[1] == 2);
+        assertTrue(midi.getMessage()[2] == 3);
+        assertTrue(midi.getMessage()[3] == -5);
+
+        MidiMessage1 midi1 = new MidiMessage1(new byte[] { 0, -2 });
+        assertTrue(midi1.getLength() == 2);
+        assertTrue(midi1.getStatus() == 0);
+        assertTrue(midi1.getMessage().length == 2);
+        assertTrue(midi1.getMessage()[0] == 0);
+        assertTrue(midi1.getMessage()[1] == -2);
+
+        byte[] bt = new byte[] { -1, 87, 19 };
+        MidiMessage1 midi2 = new MidiMessage1(bt);
+        assertTrue(midi2.getLength() == 3);
+        assertTrue(midi2.getStatus() == 255);
+        assertTrue(midi2.getMessage().length == 3);
+        assertTrue(midi2.getMessage()[0] == -1);
+        assertTrue(midi2.getMessage()[1] == 87);
+        assertTrue(midi2.getMessage()[2] == 19);
+        bt[0] = 45;
+        bt[1] = 16;
+        bt[2] = -29;
+        /**
+         * values change
+         */
+        assertEquals(3, midi2.getLength());
+        assertEquals(45, midi2.getStatus());
+        assertEquals(3, midi2.getMessage().length);
+        assertEquals(45, midi2.getMessage()[0]);
+        assertEquals(16, midi2.getMessage()[1]);
+        assertEquals(-29, midi2.getMessage()[2]);
+        
+
+        MidiMessage1 midi3 = new MidiMessage1(null);
+        assertTrue(midi3.getLength() == 0);
+        assertTrue(midi3.getStatus() == 0);
         try {
             midi3.getMessage();
-            fail( "NullPointerExcepiton expect" );
-        } catch( NullPointerException e ) { }
+            fail("No NPE");
+        } catch(NullPointerException e) {
+        }
         
+        MidiMessage1 midi4 = new MidiMessage1(new byte[0]);
+        assertEquals(0, midi4.getLength());
+        assertEquals(0, midi4.getStatus());
+        assertEquals(0, midi4.getMessage().length);
+
     }
-    
+
     /**
      * test method getMessage() of class MidiMessage
      *
      */
-    public void test_getMessage()
-    {
-        MidiMessage1 midi = new MidiMessage1( new byte[] { 1, 2, 3 } );
-        assertTrue( midi.getMessage()[0] == 1 );
-        assertTrue( midi.getMessage()[1] == 2 );
-        assertTrue( midi.getMessage()[2] == 3 );
-        
-        MidiMessage1 midi1 = new MidiMessage1( new byte[] { 1 } );
-        assertTrue( midi1.getMessage()[0] == 1 );
-        try {
-            int i = midi1.getMessage()[1];
-            fail( "IndexOutOfBoundsException expected" );
-        } catch( IndexOutOfBoundsException e ) { };
-        
-        MidiMessage1 midi2 = new MidiMessage1( null );
-        try {
-            int i = midi2.getMessage()[0];
-            fail( "NullPointerException expected" );
-        } catch( NullPointerException e ) { }
-        
-        try {
-            midi2.setMessage( new byte[] { 90, 84 } , 2 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi2.getMessage().length == 2 );
-        assertTrue( midi2.getMessage()[0] == 90 );
-        assertTrue( midi2.getMessage()[1] == 84 );
-        
-        try {
-            midi1.setMessage( new byte[] { -54, 84, -9 } , 1 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi1.getMessage().length == 1 );
-        assertTrue( midi1.getMessage()[0] == -54 );
-        
-        try {
-            midi.setMessage( new byte[] { -90, -7, 4 } , 0 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi.getMessage().length == 0 );
+    public void test_getMessage() throws Exception {
+        byte[] bt = new byte[] {1, 2, 3};
+        MidiMessage1 midi = new MidiMessage1(bt);
+        assertTrue(midi.getMessage()[0] == 1);
+        assertTrue(midi.getMessage()[1] == 2);
+        assertTrue(midi.getMessage()[2] == 3);
+        bt[0] = 76;
+        bt[1] = 13;
+        bt[2] = -5;
+        /**
+         * values change
+         */
+        assertEquals(76, midi.getMessage()[0]);
+        assertEquals(13, midi.getMessage()[1]);
+        assertEquals(-5, midi.getMessage()[2]);
+
+        MidiMessage1 midi1 = new MidiMessage1(new byte[] {1});
+        assertTrue(midi1.getMessage()[0] == 1);
+
+        MidiMessage1 midi2 = new MidiMessage1(null);
         try {
-            int i = midi.getMessage()[0];
-            fail( "ArrayIndexOutOfBoundsException expected" );
-        } catch( ArrayIndexOutOfBoundsException e ) { };
-        
+            midi2.getMessage();
+            fail("No NPE");
+        } catch(NullPointerException e) {
+        }
+
+        midi2.setMessage(new byte[] { 90, 84 }, 2);
+        assertTrue(midi2.getMessage().length == 2);
+        assertTrue(midi2.getMessage()[0] == 90);
+        assertTrue(midi2.getMessage()[1] == 84);
+        byte[] nb = midi2.getMessage();
+        nb[0] = 1;
+        nb[1] = 2;
+        /**
+         * values don't change
+         */
+        assertEquals(90, midi2.getMessage()[0]);
+        assertEquals(84, midi2.getMessage()[1]);
+
+        midi1.setMessage(new byte[] { -54, 84, -9 }, 1);
+        assertTrue(midi1.getMessage().length == 1);
+        assertTrue(midi1.getMessage()[0] == -54);
+
+        midi.setMessage(new byte[] { -90, -7, 4 }, 0);
+        assertTrue(midi.getMessage().length == 0);
     }
-    
+
     /**
      * test method getStatus() of class MidiMessage
      *
      */
-    public void test_getStatus()
-    {
-        MidiMessage1 midi = new MidiMessage1( new byte[] { 1, 2, 3 } );
-        assertTrue( midi.getStatus() == 1 );
-        
-        MidiMessage1 midi1 = new MidiMessage1( new byte[] { -91, 2, 3 } );
-        assertTrue( midi1.getStatus() == 165 );
-        
-        MidiMessage1 midi2 = new MidiMessage1( new byte[] { 1 } );
-        assertTrue( midi2.getStatus() == 1 );
-        
-        MidiMessage1 midi3 = new MidiMessage1( null );
-        assertTrue( midi3.getStatus() == 0 );
-        
-        try {
-            midi2.setMessage( new byte[] { 90, 84 } , 2 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi2.getStatus() == 90 );
-        
-        try {
-            midi1.setMessage( new byte[] { -54, 84, -9 } , 1 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi1.getStatus() == 202 );
-        
-        try {
-            midi.setMessage( new byte[] { -90, -7, 4 } , 0 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi.getStatus() == 0 );
+    public void test_getStatus() throws Exception {
+        byte[] bt = new byte[] {1, 2, 3};
+        MidiMessage1 midi = new MidiMessage1(bt);
+        assertTrue(midi.getStatus() == 1);
+        bt[0] = -1;
+        /**
+         * value change
+         */
+        assertEquals(255, midi.getStatus());
+
+        MidiMessage1 midi1 = new MidiMessage1(new byte[] { -91, 2, 3 });
+        assertTrue(midi1.getStatus() == 165);
+
+        MidiMessage1 midi2 = new MidiMessage1(new byte[] { 1 });
+        assertTrue(midi2.getStatus() == 1);
+
+        MidiMessage1 midi3 = new MidiMessage1(null);
+        assertTrue(midi3.getStatus() == 0);
+
+        bt = new byte[] {90, 84};
+        midi2.setMessage(bt, 2);
+        assertEquals(90, midi2.getStatus());
+        bt[0] = 35;
+        /*
+         * value don't change
+         */
+        assertEquals(90, midi2.getStatus());
+
+        midi1.setMessage(new byte[] {-54, 84, -9}, 1);
+        assertTrue(midi1.getStatus() == 202);
+
+        midi.setMessage(new byte[] { -90, -7, 4 }, 0);
+        assertTrue(midi.getStatus() == 0);
     }
-    
+
     /**
      * test method getLength() of class MidiMessage
      *
      */
-    public void test_getLength()
-    {
-        MidiMessage1 midi = new MidiMessage1( new byte[] { 1, 2, 3 } );
-        assertTrue( midi.getLength() == 3 );
-        
-        MidiMessage1 midi1 = new MidiMessage1( null );
-        assertTrue( midi1.getLength() == 0 );
-        
-        MidiMessage1 midi2 = new MidiMessage1( new byte[] { -71, 2, 3, -90 } );
-        assertTrue( midi2.getLength() == 4 );
-        
-        try {
-            midi2.setMessage( new byte[] { 90, 84 } , 2 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi2.getLength() == 2 );
-        
-        try {
-            midi1.setMessage( new byte[] { 90, 84, -9 } , 2 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi1.getLength() == 2 );
-        
-        try {
-            midi.setMessage( new byte[] { -90, -7, 4 } , 0 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi.getLength() == 0 );
+    public void test_getLength() throws Exception {
+        MidiMessage1 midi = new MidiMessage1(new byte[] {1, 2, 3});
+        assertTrue(midi.getLength() == 3);
+
+        MidiMessage1 midi1 = new MidiMessage1(null);
+        assertTrue(midi1.getLength() == 0);
+
+        MidiMessage1 midi2 = new MidiMessage1(new byte[] {-71, 2, 3, -90});
+        assertTrue(midi2.getLength() == 4);
+
+        midi2.setMessage(new byte[] {90, 84}, 2);
+        assertTrue(midi2.getLength() == 2);
+
+        midi1.setMessage(new byte[] { 90, 84, -9 }, 2);
+        assertTrue(midi1.getLength() == 2);
+
+        midi.setMessage(new byte[] { -90, -7, 4 }, 0);
+        assertTrue(midi.getLength() == 0);
     }
-    
+
     /**
      * test method setMessage( byte[], int ) of class MidiMessage
      *
      */
-    public void test_setMessage()
-    {
-        MidiMessage1 midi = new MidiMessage1( new byte[] { 18, 34, 48, -56, 12 } );
-        MidiMessage1 midi1 = new MidiMessage1( new byte[] { 18 } );
-        MidiMessage1 midi2 = new MidiMessage1( null );
-        try {
-            midi2.setMessage( new byte[] { 90, 84 } , 2 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi2.getMessage().length == 2 );
-        assertTrue( midi2.getMessage()[0] == 90 );
-        assertTrue( midi2.getMessage()[1] == 84 );
+    public void test_setMessage() throws Exception {
+        MidiMessage1 midi = new MidiMessage1(new byte[] {18, 34, 48, -56, 12});
+        MidiMessage1 midi1 = new MidiMessage1(new byte[] {18});
+        MidiMessage1 midi2 = new MidiMessage1(null);
+        
+        byte[] bt = new byte[] {90, 84};
+        midi2.setMessage(bt, 2);
+        assertEquals(2, midi2.getMessage().length);
+        assertEquals(90, midi2.getMessage()[0]);
+        assertEquals(84, midi2.getMessage()[1]);
+        bt[0] = 34;
+        bt[1] = -5;
+        /*
+         * values don't change
+         */
+        assertEquals(90, midi2.getMessage()[0]);
+        assertEquals(84, midi2.getMessage()[1]);
+
+        midi1.setMessage(new byte[] { -54, 84, -9 }, 1);
+        assertTrue(midi1.getMessage().length == 1);
+        assertTrue(midi1.getMessage()[0] == -54);
+
+        midi.setMessage(new byte[] { -90, -7, 4 }, 0);
+        assertTrue(midi.getMessage().length == 0);
         
         try {
-            midi1.setMessage( new byte[] { -54, 84, -9 } , 1 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi1.getMessage().length == 1 );
-        assertTrue( midi1.getMessage()[0] == -54 );
+            midi1.setMessage(new byte[] { -54, 84, -9 }, 5);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {}
         
         try {
-            midi.setMessage( new byte[] { -90, -7, 4 } , 0 );
-        } catch( InvalidMidiDataException e ) { };
-        assertTrue( midi.getMessage().length == 0 );
+            midi1.setMessage(null, -2);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {}
+        
         try {
-            int i = midi.getMessage()[0];
-            fail( "ArrayIndexOutOfBoundsException expected" );
-        } catch( ArrayIndexOutOfBoundsException e ) { };
+            midi1.setMessage(null, 0);
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {}
+        
     }
+
     /**
      * Subsidiary class in order to testing constructor
      * and method setMessage( byte[], int ) of class Instrument, 
      * because its declared as protected
      */
-    static class MidiMessage1 extends MidiMessage
-    {
-        MidiMessage1( byte[] data )
-        {
-            super( data );
+    static class MidiMessage1 extends MidiMessage {
+        MidiMessage1(byte[] data) {
+            super(data);
         }
-        public Object clone()
-        {
+
+        public Object clone() {
             return null;
         }
-        
-        public void setMessage( byte[] data, int length ) 
-                throws InvalidMidiDataException
-        {   
-            super.setMessage( data, length );
+
+        public void setMessage(byte[] data, int length)
+                throws InvalidMidiDataException {
+            super.setMessage(data, length);
         }
     }
 }

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=426930&r1=426929&r2=426930&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 Sun Jul 30 13:12:00 2006
@@ -32,25 +32,24 @@
      *
      */
     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);
+        assertEquals(254, ShortMessage.ACTIVE_SENSING);
+        assertEquals(208, ShortMessage.CHANNEL_PRESSURE);
+        assertEquals(251, ShortMessage.CONTINUE);
+        assertEquals(176, ShortMessage.CONTROL_CHANGE);
+        assertEquals(247, ShortMessage.END_OF_EXCLUSIVE);
+        assertEquals(241, ShortMessage.MIDI_TIME_CODE);
+        assertEquals(128, ShortMessage.NOTE_OFF);
+        assertEquals(144, ShortMessage.NOTE_ON);
+        assertEquals(224, ShortMessage.PITCH_BEND);
+        assertEquals(160, ShortMessage.POLY_PRESSURE);
+        assertEquals(192, ShortMessage.PROGRAM_CHANGE);
+        assertEquals(242, ShortMessage.SONG_POSITION_POINTER);
+        assertEquals(243, ShortMessage.SONG_SELECT);
+        assertEquals(250, ShortMessage.START);
+        assertEquals(252, ShortMessage.STOP);
+        assertEquals(255, ShortMessage.SYSTEM_RESET);
+        assertEquals(248, ShortMessage.TIMING_CLOCK);
+        assertEquals(246, ShortMessage.TUNE_REQUEST);
     }
 
     /**
@@ -70,8 +69,8 @@
         assertEquals(64, message.getMessage()[1]);
         assertEquals(127, message.getMessage()[2]);
 
-        ShortMessage1 message1 = new ShortMessage1(new byte[] { -95, -5, 9, 56,
-                -18 });
+        byte[] bt = new byte[] { -95, -5, 9, 56, -18 };
+        ShortMessage1 message1 = new ShortMessage1(bt);
         assertEquals(1, message1.getChannel());
         assertEquals(160, message1.getCommand());
         assertEquals(251, message1.getData1());
@@ -84,6 +83,25 @@
         assertEquals(9, message1.getMessage()[2]);
         assertEquals(56, message1.getMessage()[3]);
         assertEquals(-18, message1.getMessage()[4]);
+        bt[0] = 1;
+        bt[1] = 2;
+        bt[2] = 3;
+        bt[3] = 4;
+        bt[4] = 5;
+        /*
+         * values change
+         */
+        assertEquals(1, message1.getChannel());
+        assertEquals(0, message1.getCommand());
+        assertEquals(2, message1.getData1());
+        assertEquals(3, message1.getData2());
+        assertEquals(5, message1.getLength());
+        assertEquals(1, message1.getStatus());
+        assertEquals(1, message1.getMessage()[0]);
+        assertEquals(2, message1.getMessage()[1]);
+        assertEquals(3, message1.getMessage()[2]);
+        assertEquals(4, message1.getMessage()[3]);
+        assertEquals(5, message1.getMessage()[4]);
 
         ShortMessage1 message2 = new ShortMessage1(new byte[] { 95, 14 });
         assertEquals(15, message2.getChannel());
@@ -106,21 +124,31 @@
             fail("NullPointerException expected");
         } catch (NullPointerException e) {}
 
-        ShortMessage1 message4 = new ShortMessage1(new byte[] { 0 });
+        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());
+        assertEquals(1, message4.getMessage().length);
+        
+        ShortMessage1 message5 = new ShortMessage1(new byte[0]);
+        assertEquals(0, message5.getChannel());
+        assertEquals(0, message5.getCommand());
+        assertEquals(0, message5.getData1());
+        assertEquals(0, message5.getData2());
+        assertEquals(0, message5.getLength());
+        assertEquals(0, message5.getStatus());
+        assertEquals(0, message5.getMessage().length);
     }
 
     /**
-     * test method setMessage( int ) of class ShortMessage
+     * test method setMessage(int) of class ShortMessage
      */
-    public void test_setMessage1() {
+    public void test_setMessage1() throws Exception {
         ShortMessage1 message = new ShortMessage1();
-        /**
+        /*
          * value of variable status is more or equals 246 and
          * less or equals 255
          */
@@ -128,16 +156,14 @@
             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);
+        /*
          * channel change from 0 up to 15, and
          * channel + command == status, so
          * the value of command divisible by 16
@@ -152,12 +178,12 @@
     }
 
     /**
-     * test method setMessage( int, int, int ) of 
+     * test method setMessage(int, int, int) of 
      * class ShortMessage
      */
-    public void test_setMessage2() {
+    public void test_setMessage2() throws Exception {
         ShortMessage1 message = new ShortMessage1();
-        /**
+        /*
          * value of variable status is more or equals 246 and
          * less or equals 255
          */
@@ -169,10 +195,9 @@
             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);
+        /*
          * channel change from 0 up to 15, and
          * channel + command == status, so
          * the value of command divisible by 16.
@@ -187,12 +212,12 @@
     }
 
     /**
-     * test method setMessage( int, int, int ) of 
+     * test method setMessage(int, int, int, int) of 
      * class ShortMessage
      */
-    public void test_setMessage3() {
+    public void test_setMessage3() throws Exception {
         ShortMessage1 message = new ShortMessage1();
-        /**
+        /*
          * value of variable command is more or equals 128 and
          * less or equals 239
          */
@@ -205,7 +230,7 @@
             fail("InvalidMidiDataException expected");
         } catch (InvalidMidiDataException e) {}
 
-        /**
+        /*
          * value of variable channel is more or equals 0 and 
          * less or equals 15
          */
@@ -218,7 +243,7 @@
             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 223 the second data,
@@ -234,18 +259,17 @@
             message.setMessage(225, 8, 34, 456);
             fail("InvalidMidiDataException expected");
         } catch (InvalidMidiDataException e) {}
+        
+        /*
+         * it's all right
+         */
+        message.setMessage(200, 8, 34, 456);
 
-        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);
+        /*
          * channel change from 0 up to 15
          * command must to divisible by 16, and so it less or 
-         * equals parametr command
+         * equals parameter command
          * status is sum of channel and command
          */
         assertEquals(9, message.getChannel());
@@ -256,9 +280,7 @@
         assertEquals(201, message.getStatus());
         assertEquals(2, message.getMessage().length);
 
-        try {
-            message.setMessage(148, 9, 34, 56);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(148, 9, 34, 56);
         assertEquals(9, message.getChannel());
         assertEquals(144, message.getCommand());
         assertEquals(34, message.getData1());
@@ -272,29 +294,29 @@
      * test method getChannel() of class ShortMessage
      *
      */
-    public void test_getChannel() {
+    public void test_getChannel() throws Exception {
         ShortMessage message = new ShortMessage();
         assertEquals(0, message.getChannel());
 
-        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        byte[] bt = new byte[] {23, 16, 35};
+        ShortMessage1 message1 = new ShortMessage1(bt);
         assertEquals(7, message1.getChannel());
-
+        bt[0] = 15;
+        /*
+         * value change
+         */
+        assertEquals(15, message1.getChannel());
+        
         ShortMessage1 message2 = new ShortMessage1(null);
         assertEquals(0, message2.getChannel());
 
-        try {
-            message.setMessage(249);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(249);
         assertEquals(9, message.getChannel());
 
-        try {
-            message.setMessage(250, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(250, 14, 62);
         assertEquals(10, message.getChannel());
 
-        try {
-            message.setMessage(234, 15, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(234, 15, 14, 62);
         assertEquals(15, message.getChannel());
 
     }
@@ -303,29 +325,29 @@
      * test method getCommand() of class ShortMessage
      *
      */
-    public void test_getCommand() {
+    public void test_getCommand() throws Exception {
         ShortMessage message = new ShortMessage();
         assertEquals(144, message.getCommand());
 
-        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        byte[] bt = new byte[] {23, 16, 35};
+        ShortMessage1 message1 = new ShortMessage1(bt);
         assertEquals(16, message1.getCommand());
+        bt[0] = 4;
+        /*
+         * value change
+         */
+        assertEquals(0, message1.getCommand());
 
         ShortMessage1 message2 = new ShortMessage1(null);
         assertEquals(0, message2.getCommand());
 
-        try {
-            message.setMessage(249);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(249);
         assertEquals(240, message.getCommand());
 
-        try {
-            message.setMessage(250, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(250, 14, 62);
         assertEquals(240, message.getCommand());
 
-        try {
-            message.setMessage(234, 15, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(234, 15, 14, 62);
         assertEquals(224, message.getCommand());
     }
 
@@ -333,34 +355,26 @@
      * test method getLength() of class ShortMessage
      *
      */
-    public void test_getLength() {
+    public void test_getLength() throws Exception {
         ShortMessage message = new ShortMessage();
         assertEquals(3, message.getLength());
 
-        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        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) {}
+        message.setMessage(249);
         assertEquals(1, message.getLength());
 
-        try {
-            message.setMessage(250, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(250, 14, 62);
         assertEquals(1, message.getLength());
 
-        try {
-            message.setMessage(234, 15, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(234, 15, 14, 62);
         assertEquals(3, message.getLength());
 
-        try {
-            message.setMessage(214, 15, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(214, 15, 14, 62);
         assertEquals(2, message.getLength());
     }
 
@@ -368,29 +382,29 @@
      * test method getStatus() of class ShortMessage
      *
      */
-    public void test_getStatus() {
+    public void test_getStatus() throws Exception {
         ShortMessage message = new ShortMessage();
         assertEquals(144, message.getStatus());
 
-        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        byte[] bt = new byte[] {23, 16, 35};
+        ShortMessage1 message1 = new ShortMessage1(bt);
         assertEquals(23, message1.getStatus());
+        bt[0] = 84;
+        /*
+         * value change
+         */
+        assertEquals(84, message1.getStatus());
 
         ShortMessage1 message2 = new ShortMessage1(null);
         assertEquals(0, message2.getStatus());
 
-        try {
-            message.setMessage(249);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(249);
         assertEquals(249, message.getStatus());
 
-        try {
-            message.setMessage(250, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(250, 14, 62);
         assertEquals(250, message.getStatus());
 
-        try {
-            message.setMessage(234, 15, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(234, 15, 14, 62);
         assertEquals(239, message.getStatus());
     }
 
@@ -399,14 +413,22 @@
      * class ShortMessage
      *
      */
-    public void test_getData1_2() {
+    public void test_getData1_2() throws Exception {
         ShortMessage message = new ShortMessage();
         assertEquals(64, message.getData1());
         assertEquals(127, message.getData2());
 
-        ShortMessage1 message1 = new ShortMessage1(new byte[] { 23, 16, 35 });
+        byte[] bt = new byte[] { 23, 16, 35 };
+        ShortMessage1 message1 = new ShortMessage1(bt);
         assertEquals(16, message1.getData1());
         assertEquals(35, message1.getData2());
+        bt[1] = 84;
+        bt[2] = -16;
+        /*
+         * values change
+         */
+        assertEquals(84, message1.getData1());
+        assertEquals(240, message1.getData2());
 
         ShortMessage1 message11 = new ShortMessage1(new byte[] { 23, 16 });
         assertEquals(16, message11.getData1());
@@ -420,36 +442,32 @@
         assertEquals(0, message2.getData1());
         assertEquals(0, message2.getData2());
 
-        try {
-            message.setMessage(249);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(249);
         assertEquals(0, message.getData1());
         assertEquals(0, message.getData2());
 
-        try {
-            message.setMessage(250, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(250, 14, 62);
         assertEquals(0, message.getData1());
         assertEquals(0, message.getData2());
 
-        try {
-            message.setMessage(234, 15, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(234, 15, 14, 62);
         assertEquals(14, message.getData1());
         assertEquals(62, message.getData2());
 
-        try {
-            message.setMessage(198, 15, 14, 62);
-        } catch (InvalidMidiDataException e) {}
+        message.setMessage(198, 15, 14, 62);
         assertEquals(14, message.getData1());
         assertEquals(0, message.getData2());
+        
+        ShortMessage1 message15 = new ShortMessage1(new byte[] {-16, 16, 35});
+        assertEquals(16, message15.getData1());
+        assertEquals(35, message15.getData2());
     }
 
     /**
      * test method getDataLength() of class ShortMessage
      *
      */
-    public void test_getDataLentgth() {
+    public void test_getDataLentgth() throws Exception {
         ShortMessage1 message = new ShortMessage1();
 
         /*
@@ -512,41 +530,94 @@
             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) {}
+        assertEquals(2, message.getDataLength1(128));
+        assertEquals(1, message.getDataLength1(200));
+        assertEquals(2, message.getDataLength1(230));
+        assertEquals(1, message.getDataLength1(241));
+        assertEquals(2, message.getDataLength1(242));
+        assertEquals(1, message.getDataLength1(243));
+        assertEquals(0, message.getDataLength1(250));
+        assertEquals(2, message.getDataLength1(647));
     }
 
-    public void test_clone() {
+    /**
+     * tests method clone() of class ShortMessage
+     *
+     */
+    public void test_clone1() {
+        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]);
+            }
+        }
+    }
+    
+    public void test_clone2() {
+        byte[] bt = new byte[] {1, 2, 3, 4, 5};
+        ShortMessage1 message = new ShortMessage1(bt);
+        assertTrue(message.clone() != message);
+        
+        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]);
+            }
+        }
+        bt[0] = 10;
+        bt[1] = 20;
+        bt[2] = 30;
+        bt[3] = 40;
+        bt[4] = 50;
+        /*
+         * 'real' ShortMessage change, but 'clone' not
+         */
+        //'real'
+        assertEquals(10, message.getChannel());
+        assertEquals(0, message.getCommand());
+        assertEquals(20, message.getData1());
+        assertEquals(30, message.getData2());
+        assertEquals(10, message.getStatus());
+        assertEquals(10, message.getMessage()[0]);
+        assertEquals(20, message.getMessage()[1]);
+        assertEquals(30, message.getMessage()[2]);
+        assertEquals(40, message.getMessage()[3]);
+        assertEquals(50, message.getMessage()[4]);
+        //'clone'
+        assertEquals(1, tmessage.getChannel());
+        assertEquals(0, tmessage.getCommand());
+        assertEquals(2, tmessage.getData1());
+        assertEquals(3, tmessage.getData2());
+        assertEquals(1, tmessage.getStatus());
+        assertEquals(1, tmessage.getMessage()[0]);
+        assertEquals(2, tmessage.getMessage()[1]);
+        assertEquals(3, tmessage.getMessage()[2]);
+        assertEquals(4, tmessage.getMessage()[3]);
+        assertEquals(5, tmessage.getMessage()[4]);
+    }
+    
+    public void test_clone3() throws Exception {
         ShortMessage message = new ShortMessage();
+        message.setMessage(150, 14, 45, 60);
         assertTrue(message.clone() != message);
         assertEquals(message.clone().getClass(), message.getClass());
         ShortMessage tmessage;



Mime
View raw message