diff --git a/src/test/java/seng302/server/TestMessage.java b/src/test/java/seng302/server/TestMessage.java index 8d8dfa46..6ba3a735 100644 --- a/src/test/java/seng302/server/TestMessage.java +++ b/src/test/java/seng302/server/TestMessage.java @@ -9,12 +9,11 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertTrue; public class TestMessage { private static int XML_MESSAGE_LEN = 14; - private static int RACE_STATUS_BASE_LEN = 24; - private static int BOAT_SUB_MESSAGE_LEN = 20; private static int CRC_LEN = 4; @@ -27,5 +26,31 @@ public class TestMessage { assertTrue(m.getSize() == (XML_MESSAGE_LEN + "12345".length())); } + @Test + public void testMessageBytesReverse(){ + byte[] bytes = {1,2,3,4,5}; + Message.reverse(bytes); + + int testValue = 1; + for (int i = 5; i > 0; i--){ + assertEquals((byte) testValue, bytes[i-1]); + testValue++; + } + } + + @Test + public void testIntToByteArray(){ + long originalValue = 0x5050; + long testValue = 0; + + byte[] bytes = Message.intToByteArray(originalValue, 6); + Message.reverse(bytes); + + for (int i = 0; i < bytes.length; i++){ + testValue += ((long) bytes[i] & 0xffL) << (8 * i); + } + + assertEquals(originalValue, testValue); + } }