77 * http://www.apache.org/licenses/LICENSE-2.0
88 */
99package de .rub .nds .modifiablevariable .util ;
10+
1011import java .math .BigInteger ;
1112import static org .junit .Assert .assertArrayEquals ;
1213import static org .junit .Assert .assertEquals ;
1314import org .junit .Test ;
1415
1516/**
1617 * @author Juraj Somorovsky - juraj.somorovsky@rub.de
17- * @author Florian Pfützenreuter <Florian.Pfuetzenreuter@rub.de>
18+ * @author Florian Pfützenreuter <Florian.Pfuetzenreuter@rub.de>
1819 * @author Matthias Terlinde <matthias.terlinde@rub.de>
1920 */
2021public class ArrayConverterTest {
@@ -40,31 +41,32 @@ public void testLongToUint32Bytes() {
4041 public void testIntToBytes () {
4142 int toParse = 5717 ;
4243 byte [] result = ArrayConverter .intToBytes (toParse , 2 );
43- assertArrayEquals ("The conversion result of 5717 should be {0x16} {0x55}" , new byte []{ 0x16 , 0x55 }, result );
44+ assertArrayEquals ("The conversion result of 5717 should be {0x16} {0x55}" , new byte [] { 0x16 , 0x55 }, result );
4445 }
4546
4647 /**
4748 * Test of bytesToInt method, of class ArrayConverter.
4849 */
4950 @ Test
5051 public void testBytesToInt () {
51- byte [] toParse = {0x16 , 0x55 };
52+ byte [] toParse = { 0x16 , 0x55 };
5253 int expectedResult = 5717 ;
53- assertEquals ("The conversion result of {0x16, 0x55} should be 5717" , expectedResult , ArrayConverter .bytesToInt (toParse ));
54+ assertEquals ("The conversion result of {0x16, 0x55} should be 5717" , expectedResult ,
55+ ArrayConverter .bytesToInt (toParse ));
5456 }
5557
5658 /**
5759 * Test of bytesToLong method, of class ArrayConverter.
5860 */
5961 @ Test
6062 public void testBytesToLong () {
61- /** TODO get the casting correct.
62- long result = 571714867398058L;
63- byte[] toParse = {0x02, 0x07, (byte) 0xf8, (byte) 0xbd, (byte) 0x95, (byte) 0x85, (byte) 0xaa};
64- byte[] test = ArrayConverter.longToBytes(result, 7);
65- int a = 0;
66- //assertEquals(result, ArrayConverter.bytesToLong(toParse));
67- */
63+ /**
64+ * TODO get the casting correct. long result = 571714867398058L; byte[]
65+ * toParse = {0x02, 0x07, (byte) 0xf8, (byte) 0xbd, (byte) 0x95, (byte)
66+ * 0x85, ( byte) 0xaa}; byte [] test = ArrayConverter.longToBytes(result,
67+ * 7); int a = 0; //assertEquals(result,
68+ * ArrayConverter.bytesToLong(toParse));
69+ */
6870
6971 }
7072
@@ -73,17 +75,17 @@ public void testBytesToLong() {
7375 */
7476 @ Test
7577 public void testBytesToHexString_byteArr () {
76- byte [] toTest = new byte []{ 0x00 , 0x11 , 0x22 , 0x33 , 0x44 };
78+ byte [] toTest = new byte [] { 0x00 , 0x11 , 0x22 , 0x33 , 0x44 };
7779 assertEquals ("00 11 22 33 44" , ArrayConverter .bytesToHexString (toTest ));
78- toTest = new byte []{ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 };
80+ toTest = new byte [] { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 };
7981 assertEquals ("00 01 02 03 04 05 06 07 08" , ArrayConverter .bytesToHexString (toTest ));
80- toTest = new byte []{ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x10 };
82+ toTest = new byte [] { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x10 };
8183 assertEquals ("00 01 02 03 04 05 06 07 08 09 10" , ArrayConverter .bytesToHexString (toTest ));
82- toTest = new byte []{ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 ,
83- 0x07 ,};
84+ toTest = new byte [] { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 ,
85+ 0x07 , };
8486 assertEquals ("\n 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07" , ArrayConverter .bytesToHexString (toTest ));
85- toTest = new byte []{ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 ,
86- 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,};
87+ toTest = new byte [] { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 ,
88+ 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , };
8789 assertEquals (
8890 "\n 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07\n 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07" ,
8991 ArrayConverter .bytesToHexString (toTest ));
@@ -94,6 +96,14 @@ public void testBytesToHexString_byteArr() {
9496 */
9597 @ Test
9698 public void testBytesToHexString_byteArr_boolean () {
99+ byte [] toTest = new byte [] { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 ,
100+ 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 ,
101+ 0x06 , 0x07 };
102+ assertEquals ("00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07" ,
103+ ArrayConverter .bytesToHexString (toTest , false ));
104+ assertEquals (
105+ "\n 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07\n 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07" ,
106+ ArrayConverter .bytesToHexString (toTest , true ));
97107 }
98108
99109 /**
@@ -103,6 +113,18 @@ public void testBytesToHexString_byteArr_boolean() {
103113 public void testBytesToHexString_3args () {
104114 }
105115
116+ /**
117+ * Test ArrayConverter.bytesToRawHexString().
118+ */
119+ @ Test
120+ public void testBytesToRawHexString () {
121+ byte [] toTest = new byte [] { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 ,
122+ 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 ,
123+ 0x06 , 0x07 };
124+ assertEquals ("0001020304050607000102030405060700010203040506070001020304050607" ,
125+ ArrayConverter .bytesToRawHexString (toTest ));
126+ }
127+
106128 /**
107129 * Test of concatenate method, of class ArrayConverter.
108130 */
@@ -151,13 +173,13 @@ public void testConvertListToArray() {
151173 @ Test
152174 public void testHexStringToByteArray () {
153175 String hex = "01" ;
154- assertArrayEquals ("Testing simple one byte hex value" , new byte []{ 0x01 },
176+ assertArrayEquals ("Testing simple one byte hex value" , new byte [] { 0x01 },
155177 ArrayConverter .hexStringToByteArray (hex ));
156178 hex = "FF" ;
157- assertArrayEquals ("Testing one byte hex value > 0x7f" , new byte []{ (byte ) 0xff },
179+ assertArrayEquals ("Testing one byte hex value > 0x7f" , new byte [] { (byte ) 0xff },
158180 ArrayConverter .hexStringToByteArray (hex ));
159181 hex = "FFFFFF" ;
160- assertArrayEquals ("Testing one byte hex value > 0x7f" , new byte []{ (byte ) 0xff , (byte ) 0xff , (byte ) 0xff },
182+ assertArrayEquals ("Testing one byte hex value > 0x7f" , new byte [] { (byte ) 0xff , (byte ) 0xff , (byte ) 0xff },
161183 ArrayConverter .hexStringToByteArray (hex ));
162184 }
163185
@@ -167,7 +189,7 @@ public void testBigIntegerToNullPaddedByteArray() {
167189
168190 assertArrayEquals ("Check zero output size" , new byte [0 ],
169191 ArrayConverter .bigIntegerToNullPaddedByteArray (test , 0 ));
170- assertArrayEquals ("Check check output size smaller than input" , new byte []{ (byte ) 0xEC },
192+ assertArrayEquals ("Check check output size smaller than input" , new byte [] { (byte ) 0xEC },
171193 ArrayConverter .bigIntegerToNullPaddedByteArray (test , 1 ));
172194 assertArrayEquals ("Check output size bigger than input size" ,
173195 ArrayConverter .hexStringToByteArray ("0000000000000000000000001D42C86F7923DFEC" ),
0 commit comments