* Test method setMessage( int, byte[], int ) of
* class MetaMessage with parameters and without its.
* Class was created using constructor MetaMessage()
*/
public void test_setMessage1() throws Exception {
MetaMessage meta = new MetaMessage();
try {
meta.setMessage(10, new byte[] { 1, 2, 3 }, 4);
fail("InvalidMidiDataException expected");
} catch (InvalidMidiDataException e) {
}
try {
meta.setMessage(10, new byte[] { 1, 2, 3 }, -5);
fail("InvalidMidiDataException expected");
} catch (InvalidMidiDataException e) {
}
try {
meta.setMessage(-1, new byte[] { 1, 2, 3 }, 3);
fail("InvalidMidiDataException expected");
} catch (InvalidMidiDataException e) {
}
try {
meta.setMessage(128, new byte[] { 1, 2, 3 }, 3);
fail("InvalidMidiDataException expected");
} catch (InvalidMidiDataException e) {
}
meta.setMessage(18, new byte[] { 1, 2, 3 }, 0);
assertEquals(3, meta.getLength());
assertEquals(3, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(18, meta.getMessage()[1]);
assertEquals(0, meta.getMessage()[2]);
assertEquals(0, meta.getData().length);
meta.setMessage(10, new byte[100000], 65535);
assertEquals(65540, meta.getLength());
assertEquals(65540, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(10, meta.getMessage()[1]);
assertEquals(-125, meta.getMessage()[2]);
assertEquals(-1, meta.getMessage()[3]);
assertEquals(127, meta.getMessage()[4]);
meta.setMessage(10, new byte[100000], 16385);
assertEquals(16390, meta.getLength());
assertEquals(16390, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(10, meta.getMessage()[1]);
assertEquals(-127, meta.getMessage()[2]);
assertEquals(-128, meta.getMessage()[3]);
assertEquals(1, meta.getMessage()[4]);
byte[] bt = new byte[] { 1, 2, 3, 4 };
meta.setMessage(10, bt, 4);
assertEquals(7, meta.getLength());
assertEquals(255, meta.getStatus());
assertEquals(10, meta.getType());
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]);
assertEquals(7, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(10, meta.getMessage()[1]);
assertEquals(4, meta.getMessage()[2]);
assertEquals(1, meta.getMessage()[3]);
assertEquals(2, meta.getMessage()[4]);
assertEquals(3, meta.getMessage()[5]);
assertEquals(4, meta.getMessage()[6]);
bt[0] = 0;
bt[1] = 1;
bt[2] = 2;
bt[3] = 3;
/**
* values don't change
*/
assertEquals(7, meta.getLength());
assertEquals(255, meta.getStatus());
assertEquals(10, meta.getType());
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]);
assertEquals(7, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(10, meta.getMessage()[1]);
assertEquals(4, meta.getMessage()[2]);
assertEquals(1, meta.getMessage()[3]);
assertEquals(2, meta.getMessage()[4]);
assertEquals(3, meta.getMessage()[5]);
assertEquals(4, meta.getMessage()[6]);
meta.setMessage(12, null, 0);
assertEquals(3, meta.getLength());
assertEquals(255, meta.getStatus());
assertEquals(12, meta.getType());
assertEquals(0, meta.getData().length);
assertEquals(3, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(12, meta.getMessage()[1]);
assertEquals(0, meta.getMessage()[2]);
/**
* 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) {}
try {
meta.setMessage(12, new byte[0], 9);
fail("InvalidMidiDataException expected");
} catch (InvalidMidiDataException e) {}
assertEquals(7, meta.getLength());
assertEquals(255, meta.getStatus());
assertEquals(10, meta.getType());
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]);
assertEquals(7, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(10, meta.getMessage()[1]);
assertEquals(4, meta.getMessage()[2]);
assertEquals(1, meta.getMessage()[3]);
assertEquals(2, meta.getMessage()[4]);
assertEquals(3, meta.getMessage()[5]);
assertEquals(4, meta.getMessage()[6]);
try {
meta.setMessage(12, null, 9);
fail("NullPointerException expected");
} catch (NullPointerException e) {}
assertEquals(7, meta.getLength());
assertEquals(255, meta.getStatus());
assertEquals(10, meta.getType());
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]);
assertEquals(7, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(10, meta.getMessage()[1]);
assertEquals(4, meta.getMessage()[2]);
assertEquals(1, meta.getMessage()[3]);
assertEquals(2, meta.getMessage()[4]);
assertEquals(3, meta.getMessage()[5]);
assertEquals(4, meta.getMessage()[6]);
try {
meta.setMessage(12, null, -9);
fail("InvalidMidiDataException expected");
} catch (InvalidMidiDataException e) {}
assertEquals(7, meta.getLength());
assertEquals(255, meta.getStatus());
assertEquals(10, meta.getType());
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]);
assertEquals(7, meta.getMessage().length);
assertEquals(-1, meta.getMessage()[0]);
assertEquals(10, meta.getMessage()[1]);
assertEquals(4, meta.getMessage()[2]);
assertEquals(1, meta.getMessage()[3]);
assertEquals(2, meta.getMessage()[4]);
assertEquals(3, meta.getMessage()[5]);
assertEquals(4, meta.getMessage()[6]);
}