2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.liblldp;
10 import org.junit.Assert;
11 import org.junit.Test;
13 public class HexEncodeTest {
15 public void testbytesToHexString() {
16 byte[] bytes1 = { (byte) 0x01, (byte) 0x02, (byte) 0x03 };
17 String str1 = HexEncode.bytesToHexString(bytes1);
18 Assert.assertTrue(str1.equals("010203"));
20 byte[] bytes2 = { (byte) 0x11, (byte) 0x22, (byte) 0x33 };
21 String str2 = HexEncode.bytesToHexString(bytes2);
22 Assert.assertFalse(str2.equals("010203"));
27 public void testLongToHexString() {
28 long value1 = 12345678L;
29 String str1 = HexEncode.longToHexString(value1);
30 Assert.assertTrue(str1.equals("00:00:00:00:00:bc:61:4e"));
32 long value2 = 98765432L;
33 String str2 = HexEncode.longToHexString(value2);
34 Assert.assertFalse(str2.equals("00:44:33:22:11:bc:61:4e"));
39 public void testBytesFromHexString() {
40 String byteStr1 = "00:11:22:33:44:55";
41 byte byteArray1[] = HexEncode.bytesFromHexString(byteStr1);
43 Assert.assertTrue(byteArray1[0] == (byte) 0x0);
44 Assert.assertTrue(byteArray1[1] == (byte) 0x11);
45 Assert.assertTrue(byteArray1[2] == (byte) 0x22);
46 Assert.assertTrue(byteArray1[3] == (byte) 0x33);
47 Assert.assertTrue(byteArray1[4] == (byte) 0x44);
48 Assert.assertTrue(byteArray1[5] == (byte) 0x55);
50 String byteStr2 = "00:11:22:33:44:55";
51 byte byteArray2[] = HexEncode.bytesFromHexString(byteStr2);
53 Assert.assertFalse(byteArray2[0] == (byte) 0x55);
54 Assert.assertFalse(byteArray2[1] == (byte) 0x44);
55 Assert.assertFalse(byteArray2[2] == (byte) 0x33);
56 Assert.assertFalse(byteArray2[3] == (byte) 0x22);
57 Assert.assertFalse(byteArray2[4] == (byte) 0x11);
58 Assert.assertFalse(byteArray2[5] == (byte) 0x0);