1 package org.umu.cops.stack;
3 import org.junit.Assert;
7 * Tests the public static COPSMsgParser methods
9 public class COPSMsgParserTest {
12 public void testCombineTwoBytesToOne() {
15 byte byte2 = (byte)15;
16 byte combined = (byte)((byte1) * 16 + (byte2));
18 System.out.println("Combined value =" + combined + " Hex value = " + Integer.toHexString(combined) );
23 public void testCombineAndSplitForAllValidCombinations() {
24 for (byte byte1 = 0; byte1 < 16; byte1++ ) {
25 for (byte byte2 = 0; byte2 < 16; byte2++ ) {
26 int combined = COPSMsgParser.combineNibbles(byte1, byte2);
27 System.out.println("byte1 = " + byte1 + " byte2 = " + byte2 + " Combined value =" + combined + " Hex value = " + Integer.toHexString(combined) );
29 Assert.assertTrue(combined >= 0 && combined < 256);
30 byte[] nibbles = COPSMsgParser.splitByteToNibbles((byte) combined);
32 Assert.assertEquals("Nibble 1 value = " + nibbles[0], byte1, nibbles[0]);
33 Assert.assertEquals("Nibble 2 value = " + nibbles[1], byte2, nibbles[1]);
38 @Test(expected = IllegalArgumentException.class)
39 public void testCombineByte1TooBig() {
40 COPSMsgParser.combineNibbles((byte)16, (byte)0);
43 @Test(expected = IllegalArgumentException.class)
44 public void testCombineByte2TooBig() {
45 COPSMsgParser.combineNibbles((byte)0, (byte)16);
48 @Test(expected = IllegalArgumentException.class)
49 public void testCombineByte1TooSmall() {
50 COPSMsgParser.combineNibbles((byte)-1, (byte)0);
53 @Test(expected = IllegalArgumentException.class)
54 public void testCombineByte2TooSmall() {
55 COPSMsgParser.combineNibbles((byte)0, (byte)-1);
58 // TODO - determine if tests for marshalling & un should be done with this class or implicitly via the COPSMsg objects