31import java.io.IOException;
32import java.nio.ByteOrder;
33import java.util.Arrays;
34import java.util.Iterator;
37import org.jau.net.EUI48;
38import org.jau.net.EUI48Sub;
40import jau.test.junit.util.JunitTracer;
42import org.junit.Assert;
43import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 static void test_sub01(
final ByteOrder byte_order,
final String mac_str,
final List<String> mac_sub_strs,
final List<Integer> indices) {
54 final EUI48 mac =
new EUI48(mac_str);
56 System.out.printf(
"Test EUI48 mac: '%s' -> '%s'\n", mac_str, mac.toString());
57 Assert.assertEquals(mac_str, mac.toString());
60 for(
final Iterator<String> iter=mac_sub_strs.iterator(); iter.hasNext(); ++i) {
61 final String mac_sub_str = iter.next();
62 final EUI48Sub mac_sub =
new EUI48Sub(mac_sub_str);
63 System.out.printf(
"EUI48Sub mac02_sub: '%s' -> '%s'\n", mac_sub_str, mac_sub.toString());
65 String sub_str =
new String(mac_sub_str);
66 if( sub_str.isEmpty() ) {
68 }
else if( !sub_str.equals(
":") ) {
69 if( sub_str.length() > 0 && sub_str.charAt(0) ==
':' ) {
70 sub_str = sub_str.substring(1, sub_str.length());
72 if( sub_str.length() > 0 && sub_str.charAt(sub_str.length()-1) ==
':' ) {
73 sub_str = sub_str.substring(0, sub_str.length()-1);
76 Assert.assertEquals(sub_str, mac_sub.toString());
78 final int idx = mac.indexOf(mac_sub, byte_order);
79 Assert.assertEquals( idx, indices.get(i).intValue());
81 Assert.assertTrue( mac.contains(mac_sub) );
83 Assert.assertFalse( mac.contains(mac_sub) );
87 static void test_sub02(
final String mac_sub_str_exp,
final String mac_sub_str,
final boolean expected_result) {
88 final StringBuilder errmsg =
new StringBuilder();
89 final EUI48Sub mac_sub =
new EUI48Sub ();
90 final boolean res = EUI48Sub.scanEUI48Sub(mac_sub_str, mac_sub, errmsg);
92 System.out.printf(
"EUI48Sub mac_sub: '%s' -> '%s'\n", mac_sub_str, mac_sub.toString());
93 if( expected_result ) {
94 Assert.assertEquals(mac_sub_str_exp, mac_sub.toString());
97 System.out.printf(
"EUI48Sub mac_sub: '%s' -> Error '%s'\n", mac_sub_str, errmsg.toString());
99 Assert.assertEquals(expected_result, res);
106 final String mac02_str =
"C0:10:22:A0:10:00";
107 final String[] mac02_sub_strs = {
"C0",
"C0:10",
":10:22",
"10:22",
":10:22:",
"10:22:",
"10",
"10:00",
"00",
":",
"",
"00:10", mac02_str};
108 final Integer[] mac02_sub_idxs_le = { 5, 4, 3, 3, 3, 3, 1, 0, 0, 0, 0, -1, 0};
109 final Integer[] mac02_sub_idxs_be = { 0, 0, 1, 1, 1, 1, 4, 4, 5, 0, 0, -1, 0};
110 test_sub01(ByteOrder.LITTLE_ENDIAN, mac02_str, Arrays.asList(mac02_sub_strs), Arrays.asList(mac02_sub_idxs_le));
111 test_sub01(ByteOrder.BIG_ENDIAN, mac02_str, Arrays.asList(mac02_sub_strs), Arrays.asList(mac02_sub_idxs_be));
116 final String mac03_str =
"01:02:03:04:05:06";
117 final String[] mac03_sub_strs = {
"01",
"01:02",
":03:04",
"03:04",
":04:05:",
"04:05:",
"04",
"05:06",
"06",
":",
"",
"06:05", mac03_str};
118 final Integer[] mac03_sub_idxs_le = { 5, 4, 2, 2, 1, 1, 2, 0, 0, 0, 0, -1, 0};
119 final Integer[] mac03_sub_idxs_be = { 0, 0, 2, 2, 3, 3, 3, 4, 5, 0, 0, -1, 0};
120 test_sub01(ByteOrder.LITTLE_ENDIAN, mac03_str, Arrays.asList(mac03_sub_strs), Arrays.asList(mac03_sub_idxs_le));
121 test_sub01(ByteOrder.BIG_ENDIAN, mac03_str, Arrays.asList(mac03_sub_strs), Arrays.asList(mac03_sub_idxs_be));
124 final String mac_sub_str =
"C0:10:22:A0:10:00";
125 test_sub02(mac_sub_str, mac_sub_str,
true );
128 final String mac_sub_str =
"0600106";
129 test_sub02(
null, mac_sub_str,
false );
132 final EUI48 h =
new EUI48(
"01:02:03:04:05:06");
133 final EUI48Sub n =
new EUI48Sub(
"01:02");
134 Assert.assertEquals(0, h.indexOf(n, ByteOrder.BIG_ENDIAN));
135 Assert.assertEquals(4, h.indexOf(n, ByteOrder.LITTLE_ENDIAN));
138 final EUI48 h =
new EUI48(
"01:02:03:04:05:06");
139 final EUI48Sub n =
new EUI48Sub(
"05:06");
140 Assert.assertEquals(4, h.indexOf(n, ByteOrder.BIG_ENDIAN));
141 Assert.assertEquals(0, h.indexOf(n, ByteOrder.LITTLE_ENDIAN));
145 public static void main(
final String args[])
throws IOException {
146 final String tstname =
TestEUI48.class.getName();
147 org.junit.runner.JUnitCore.
main(tstname);
Test basic EUI48 functionality.
void test01_EUI48AndSub()
static void main(final String args[])