blob: a927649ce8388d1a690e2c51e4b3ab3250989919 [file] [log] [blame]
chengfan8ea6a562016-11-26 16:37:02 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
chengfan8ea6a562016-11-26 16:37:02 +08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.teyang.utils.tunnel;
18
19import org.junit.Test;
20import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.IpAddress;
21
22import static org.junit.Assert.assertArrayEquals;
23import static org.junit.Assert.assertEquals;
24
25/**
26 * Test of the basic converter tools.
27 */
28public class BasicConverterTest {
29 private byte[] bytes1 = new byte[]{1, 1, 1, 1, 0, 0, 0, 0};
30 private byte[] bytes2 = new byte[]{2, 2, 2, 2, 0, 0, 0, 0};
31 private byte[] bytes3 = new byte[]{2, 0, 0, 0, 0, 0, 0, 0};
32 private IpAddress ip1 = IpAddress.fromString("1.1.1.1");
33 private IpAddress ip2 = IpAddress.fromString("2.2.2.2");
34 private long longNum1 = 16843009;
35 private long longNum2 = 33686018;
36 private static final String CVT_F = "Convert failed: ";
37
38
39 @Test
40 public void longToIp() throws Exception {
41 assertEquals(CVT_F + "longToIp", ip1, BasicConverter.longToIp(longNum1));
42 assertEquals(CVT_F + "longToIp", ip2, BasicConverter.longToIp(longNum2));
43 }
44
45 @Test
46 public void longToByte() throws Exception {
47 assertArrayEquals(CVT_F + "longToByte", bytes1,
48 BasicConverter.longToByte(longNum1));
49 assertArrayEquals(CVT_F + "longToByte", bytes2,
50 BasicConverter.longToByte(longNum2));
51 }
52
53 @Test
54 public void ipToLong() throws Exception {
55 assertEquals(CVT_F + "ipToLong", longNum1, BasicConverter.ipToLong(ip1));
56 assertEquals(CVT_F + "ipToLong", longNum2, BasicConverter.ipToLong(ip2));
57 }
58
59 @Test
60 public void bytesToLong() throws Exception {
61 assertEquals(CVT_F + "bytesToLong", longNum1,
62 BasicConverter.bytesToLong(bytes1));
63 assertEquals(CVT_F + "bytesToLong", longNum2,
64 BasicConverter.bytesToLong(bytes2));
65
66 assertEquals(CVT_F + "bytesToLong", 2,
67 BasicConverter.bytesToLong(bytes3));
68 }
69}