harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r426963 - in /incubator/harmony/enhanced/classlib/trunk/modules/sound/src: main/java/javax/sound/midi/SysexMessage.java test/java/org/apache/harmony/sound/tests/javax/sound/midi/SysexMessageTest.java
Date Sun, 30 Jul 2006 22:29:42 GMT
Author: ndbeyer
Date: Sun Jul 30 15:29:39 2006
New Revision: 426963

URL: http://svn.apache.org/viewvc?rev=426963&view=rev
Log:
Apply modified patch for HARMONY-1009: [classlib][sound] Class SysexMessage and test SysexMessageTest

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/SysexMessageTest.java
  (with props)
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/SysexMessage.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/SysexMessage.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/SysexMessage.java?rev=426963&r1=426962&r2=426963&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/SysexMessage.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/main/java/javax/sound/midi/SysexMessage.java
Sun Jul 30 15:29:39 2006
@@ -22,8 +22,7 @@
     public static final int SYSTEM_EXCLUSIVE = 240;
 
     public SysexMessage() {
-        //TODO
-        super(null);
+        super(new byte[] {-16, -9});
     }
 
     protected SysexMessage(byte[] data) {
@@ -31,20 +30,50 @@
     }
 
     public Object clone() {
-        //TODO
-        return null;
+        return new SysexMessage(this.getMessage());
     }
 
     public byte[] getData() {
-        //TODO
-        return null;
+        byte[] bt = new byte[super.length - 1];
+        for(int i = 1; i < super.length; i++) {
+            bt[i-1] = super.data[i];
+        }
+        return bt;
     }
 
     public void setMessage(byte[] data, int length) throws InvalidMidiDataException {
-        //TODO
+        //FIXME
+        /*
+         * if this exception throw out, the value of wrong status byte
+         * should be the hexadecimal value
+         */
+        if((((int) (data[0] & 0xFF)) != SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE) &&
+                (((int) (data[0] & 0xFF)) != SysexMessage.SYSTEM_EXCLUSIVE)) {
+            throw new InvalidMidiDataException("Invalid status byte for sysex message: "
+ 
+                    (int) (data[0] & 0xFF));
+        }
+        super.setMessage(data, length);
     }
 
     public void setMessage(int status, byte[] data, int length) throws InvalidMidiDataException
{
-        //TODO
+        //FIXME
+        /*
+         * if this exception throw out, the value of wrong status byte
+         * should be the hexadecimal value
+         */
+        if((status != SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE) &&
+                (status != SysexMessage.SYSTEM_EXCLUSIVE)) {
+            throw new InvalidMidiDataException("Invalid status byte for sysex message: "
+ 
+                    status);
+        }
+        if((length < 0) || (length > data.length)) {
+            throw new IndexOutOfBoundsException("length out of bounds: " + length);
+        }
+        byte[] bt = new byte[length + 1];
+        bt[0] = (byte) status;
+        for(int i = 0; i < length; i++) {
+            bt[i+1] = data[i];
+        }
+        super.setMessage(bt, length + 1);
     }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/SysexMessageTest.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/SysexMessageTest.java?rev=426963&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/SysexMessageTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/SysexMessageTest.java
Sun Jul 30 15:29:39 2006
@@ -0,0 +1,364 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.sound.tests.javax.sound.midi;
+
+import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.SysexMessage;
+
+import junit.framework.TestCase;
+
+public class SysexMessageTest extends TestCase {
+    public void test_constants() {
+        assertEquals(247, SysexMessage.SPECIAL_SYSTEM_EXCLUSIVE);
+        assertEquals(240, SysexMessage.SYSTEM_EXCLUSIVE);
+    }
+    
+    /**
+     * test constructors
+     *
+     */
+    public void test_constructors() {
+        SysexMessage1 message = new SysexMessage1();
+        assertEquals(2, message.getLength());
+        assertEquals(240, message.getStatus());
+        assertEquals(2, message.getMessage().length);
+        assertEquals(-16, message.getMessage()[0]);
+        assertEquals(-9, message.getMessage()[1]);
+        assertEquals(1, message.getData().length);
+        assertEquals(-9, message.getData()[0]);
+        
+        byte[] bt = new byte[] {16, 28, -43, 18, 54};
+        SysexMessage1 message1 = new SysexMessage1(bt);
+        assertEquals(5, message1.getLength());
+        assertEquals(16, message1.getStatus());
+        assertEquals(5, message1.getMessage().length);
+        assertEquals(16, message1.getMessage()[0]);
+        assertEquals(28, message1.getMessage()[1]);
+        assertEquals(-43, message1.getMessage()[2]);
+        assertEquals(18, message1.getMessage()[3]);
+        assertEquals(54, message1.getMessage()[4]);
+        assertEquals(4, message1.getData().length);
+        assertEquals(28, message1.getData()[0]);
+        assertEquals(-43, message1.getData()[1]);
+        assertEquals(18, message1.getData()[2]);
+        assertEquals(54, message1.getData()[3]);
+        bt[0] = 18;
+        bt[1] = 24;
+        bt[2] = 89;
+        bt[3] = -6;
+        bt[4] = -90;
+        /*
+         * values change
+         */
+        assertEquals(5, message1.getLength());
+        assertEquals(18, message1.getStatus());
+        assertEquals(5, message1.getMessage().length);
+        assertEquals(18, message1.getMessage()[0]);
+        assertEquals(24, message1.getMessage()[1]);
+        assertEquals(89, message1.getMessage()[2]);
+        assertEquals(-6, message1.getMessage()[3]);
+        assertEquals(-90, message1.getMessage()[4]);
+        assertEquals(4, message1.getData().length);
+        assertEquals(24, message1.getData()[0]);
+        assertEquals(89, message1.getData()[1]);
+        assertEquals(-6, message1.getData()[2]);
+        assertEquals(-90, message1.getData()[3]);
+        byte[] nb = message1.getData();
+        nb[0] = 34;
+        nb[1] = 8;
+        nb[2] = -4;
+        nb[3] = 3;
+        /*
+         * values don't change
+         */
+        assertEquals(24, message1.getData()[0]);
+        assertEquals(89, message1.getData()[1]);
+        assertEquals(-6, message1.getData()[2]);
+        assertEquals(-90, message1.getData()[3]);
+        
+        SysexMessage1 message2 = new SysexMessage1(new byte[0]);
+        assertEquals(0, message2.getLength());
+        assertEquals(0, message2.getStatus());
+        assertEquals(0, message2.getMessage().length);
+        try {
+            message2.getData();
+            fail("NegativeArraySizeException expected");
+        } catch (NegativeArraySizeException e) {}
+        
+        SysexMessage1 message3 = new SysexMessage1(null);
+        assertEquals(0, message3.getLength());
+        assertEquals(0, message3.getStatus());
+        try {
+            message3.getMessage();
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {}
+        try {
+            message3.getData();
+            fail("NegativeArraySizeException expected");
+        } catch (NegativeArraySizeException e) {}
+    }
+    
+    /**
+     * test method setMessage(byte[], int)
+     * 
+     */
+    public void test_setMessage1() throws Exception {
+        SysexMessage message = new SysexMessage();
+        
+        byte[] bt = new byte[] {-9, 18, -6, -9, 3};
+        message.setMessage(bt, 5);
+        assertEquals(5, message.getLength());
+        assertEquals(247, message.getStatus());
+        assertEquals(5, message.getMessage().length);
+        assertEquals(-9, message.getMessage()[0]);
+        assertEquals(18, message.getMessage()[1]);
+        assertEquals(-6, message.getMessage()[2]);
+        assertEquals(-9, message.getMessage()[3]);
+        assertEquals(3, message.getMessage()[4]);
+        assertEquals(4, message.getData().length);
+        assertEquals(18, message.getData()[0]);
+        assertEquals(-6, message.getData()[1]);
+        assertEquals(-9, message.getData()[2]);
+        assertEquals(3, message.getData()[3]);
+        bt[0] = 10;
+        bt[1] = 20;
+        bt[2] = 30;
+        bt[3] = 40;
+        bt[4] = 50;
+        /*
+         * values don't change
+         */
+        assertEquals(-9, message.getMessage()[0]);
+        assertEquals(18, message.getMessage()[1]);
+        assertEquals(-6, message.getMessage()[2]);
+        assertEquals(-9, message.getMessage()[3]);
+        assertEquals(3, message.getMessage()[4]);
+        assertEquals(18, message.getData()[0]);
+        assertEquals(-6, message.getData()[1]);
+        assertEquals(-9, message.getData()[2]);
+        assertEquals(3, message.getData()[3]);
+        
+        try {
+            message.setMessage(new byte[] {34}, 1);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+        /*
+         * it's all right!
+         */
+        message.setMessage(new byte[] {-9}, 1);
+        message.setMessage(new byte[] {-16}, 1);
+        
+        message.setMessage(new byte[] {-16, 34, 56}, 1);
+        assertEquals(1, message.getLength());
+        assertEquals(1, message.getMessage().length);
+        assertEquals(0, message.getData().length);
+        
+        try {
+            message.setMessage(new byte[] {-1, 34, 56}, 4);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+        try {
+            message.setMessage(new byte[] {-9, 34, 56}, 4);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {}
+        try {
+            message.setMessage(new byte[] {-9, 34, 56}, -1);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {}
+        
+        try {
+            message.setMessage(new byte[0], 0);
+            fail("ArrayIndexOutOfBoundsException expected");
+        } catch (ArrayIndexOutOfBoundsException e) {}
+        
+        try {
+            message.setMessage(null, 0);
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {}
+        
+        message.setMessage(new byte[] {-9, 3, 4}, 0);
+        assertEquals(0, message.getLength());
+        assertEquals(0, message.getStatus());
+        assertEquals(0, message.getMessage().length);
+        try {
+            message.getData();
+            fail("NegativeArraySizeException expected");
+        } catch (NegativeArraySizeException e) {}
+    }
+    
+    /**
+     * test method setMessage(int, byte[], int)
+     *
+     */
+    public void test_setMessage2() throws Exception {
+        SysexMessage message = new SysexMessage();
+        try {
+            message.setMessage(34, new byte[] {1, 2}, 2);
+            fail("InvalidMidiDataException expected");
+        } catch (InvalidMidiDataException e) {}
+        
+        /*
+         * it's all right
+         */
+        message.setMessage(240, new byte[] {1, 2}, 2);
+        message.setMessage(247, new byte[] {34, -42}, 2);
+        
+        assertEquals(3, message.getLength());
+        assertEquals(247, message.getStatus());
+        assertEquals(3, message.getMessage().length);
+        assertEquals(-9, message.getMessage()[0]);
+        assertEquals(34, message.getMessage()[1]);
+        assertEquals(-42, message.getMessage()[2]);
+        assertEquals(2, message.getData().length);
+        assertEquals(34, message.getData()[0]);
+        assertEquals(-42, message.getData()[1]);
+        
+        message.setMessage(240, new byte[] {12, 47, -9}, 1);
+        assertEquals(2, message.getLength());
+        assertEquals(240, message.getStatus());
+        assertEquals(2, message.getMessage().length);
+        assertEquals(-16, message.getMessage()[0]);
+        assertEquals(12, message.getMessage()[1]);
+        assertEquals(1, message.getData().length);
+        assertEquals(12, message.getData()[0]);
+        
+        message.setMessage(240, new byte[] {12, 4, 9}, 0);
+        assertEquals(1, message.getLength());
+        assertEquals(240, message.getStatus());
+        assertEquals(1, message.getMessage().length);
+        assertEquals(-16, message.getMessage()[0]);
+        assertEquals(0, message.getData().length);
+        
+        try {
+            message.setMessage(247, new byte[] {1, 2, 3}, 4);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {}
+        
+        try {
+            message.setMessage(247, new byte[] {1, 2, 3}, -1);
+            fail("IndexOutOfBoundsException expected");
+        } catch (IndexOutOfBoundsException e) {}
+        
+        message.setMessage(247, new byte[0], 0);
+        assertEquals(1, message.getLength());
+        assertEquals(247, message.getStatus());
+        assertEquals(1, message.getMessage().length);
+        assertEquals(-9, message.getMessage()[0]);
+        assertEquals(0, message.getData().length);
+        
+        try {
+            message.setMessage(247, null, 0);
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {}
+    }
+    
+    /**
+     * Test method clone() of class SysexMessage.
+     */
+    public void test_clone1() {
+        SysexMessage message = new SysexMessage();
+        assertTrue(message.clone() != message);
+        assertEquals(message.clone().getClass(), message.getClass());
+        SysexMessage tmessage;
+        tmessage = (SysexMessage) message.clone();
+        assertEquals(message.getLength(), tmessage.getLength());
+        assertEquals(message.getMessage().length, tmessage.getMessage().length);
+        assertEquals(message.getData().length, tmessage.getData().length);
+        if (message.getData().length != 0) {
+            for (int i = 0; i < message.getData().length; i++) {
+                assertEquals(message.getData()[i], tmessage.getData()[i]);
+            }
+        }
+        if (message.getMessage().length != 0) {
+            for (int i = 0; i < message.getMessage().length; i++) {
+                assertEquals(message.getMessage()[i], tmessage.getMessage()[i]);
+            }
+        }
+    }
+
+    /**
+     * Test method clone() of class SysexMessage.
+     */
+    public void test_clone2() throws Exception {
+        SysexMessage message = new SysexMessage();
+
+        message.setMessage(240, new byte[] { 23, 45, -90 }, 2);
+
+        assertTrue(message.clone() != message);
+        assertEquals(message.clone().getClass(), message.getClass());
+        SysexMessage tmessage;
+        tmessage = (SysexMessage) message.clone();
+        assertEquals(message.getLength(), tmessage.getLength());
+        assertEquals(message.getMessage().length, tmessage.getMessage().length);
+        assertEquals(message.getData().length, tmessage.getData().length);
+        if (message.getData().length != 0) {
+            for (int i = 0; i < message.getData().length; i++) {
+                assertEquals(message.getData()[i], tmessage.getData()[i]);
+            }
+        }
+        if (message.getMessage().length != 0) {
+            for (int i = 0; i < message.getMessage().length; i++) {
+                assertEquals(message.getMessage()[i], tmessage.getMessage()[i]);
+            }
+        }
+    }
+    
+    public void test_clone3() throws Exception {
+        byte[] bt = new byte[] {1, 2, 3, 4};
+        SysexMessage1 message = new SysexMessage1(bt);
+        assertTrue(message.clone() != message);
+        
+        SysexMessage tmessage;
+        tmessage = (SysexMessage) message.clone();
+        bt[0] = 34;
+        bt[1] = 15;
+        bt[2] = 89;
+        bt[3] = 1;
+        assertEquals(message.getLength(), tmessage.getLength());
+        assertEquals(message.getMessage().length, tmessage.getMessage().length);
+        assertEquals(message.getData().length, tmessage.getData().length);
+        /*
+         * 'real' SysexMessage change, but 'clone' not
+         */
+        //'real'
+        assertEquals(15, message.getData()[0]);
+        assertEquals(89, message.getData()[1]);
+        assertEquals(1, message.getData()[2]);
+        assertEquals(34, message.getMessage()[0]);
+        assertEquals(15, message.getMessage()[1]);
+        assertEquals(89, message.getMessage()[2]);
+        assertEquals(1, message.getMessage()[3]);
+        //'clone'
+        assertEquals(2, tmessage.getData()[0]);
+        assertEquals(3, tmessage.getData()[1]);
+        assertEquals(4, tmessage.getData()[2]);
+        assertEquals(1, tmessage.getMessage()[0]);
+        assertEquals(2, tmessage.getMessage()[1]);
+        assertEquals(3, tmessage.getMessage()[2]);
+        assertEquals(4, tmessage.getMessage()[3]);
+    }
+    
+    static class SysexMessage1 extends SysexMessage {
+        SysexMessage1() {
+            super();
+        }
+        
+        SysexMessage1(byte[] data) {
+            super(data);
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/sound/src/test/java/org/apache/harmony/sound/tests/javax/sound/midi/SysexMessageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message