2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
18 package org.openflow.util;
20 import org.junit.Test;
22 import junit.framework.TestCase;
25 * Does hexstring conversion work?
27 * @author Rob Sherwood (rob.sherwood@stanford.edu)
31 public class HexStringTest extends TestCase {
34 public void testMarshalling() throws Exception {
35 String dpidStr = "00:00:00:23:20:2d:16:71";
36 long dpid = HexString.toLong(dpidStr);
37 String testStr = HexString.toHexString(dpid);
38 TestCase.assertEquals(dpidStr, testStr);
42 public void testToLong() {
43 String dpidStr = "3e:1f:01:fc:72:8c:63:31";
44 long valid = 0x3e1f01fc728c6331L;
45 long testLong = HexString.toLong(dpidStr);
46 TestCase.assertEquals(valid, testLong);
50 public void testToLongMSB() {
51 String dpidStr = "ca:7c:5e:d1:64:7a:95:9b";
52 long valid = -3856102927509056101L;
53 long testLong = HexString.toLong(dpidStr);
54 TestCase.assertEquals(valid, testLong);
58 public void testToLongError() {
59 String dpidStr = "09:08:07:06:05:04:03:02:01";
61 HexString.toLong(dpidStr);
62 fail("HexString.toLong() should have thrown a NumberFormatException");
64 catch (NumberFormatException expected) {
70 public void testToStringBytes() {
71 byte[] dpid = { 0, 0, 0, 0, 0, 0, 0, -1 };
72 String valid = "00:00:00:00:00:00:00:ff";
73 String testString = HexString.toHexString(dpid);
74 TestCase.assertEquals(valid, testString);
78 public void testFromHexStringError() {
79 String invalidStr = "00:00:00:00:00:00:ffff";
81 HexString.fromHexString(invalidStr);
82 fail("HexString.fromHexString() should have thrown a NumberFormatException");
84 catch (NumberFormatException expected) {