00001
00002
00003
00004
00005 #include <gtest/gtest.h>
00006
00007
00008 #include <dataspeed_can_usb/MacAddr.h>
00009 using namespace dataspeed_can_usb;
00010
00011
00012 TEST(MacAddr, constructors)
00013 {
00014 uint8_t data[] = {0x01,0x23,0x45,0x67,0x89,0xab};
00015 EXPECT_STRNE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xab).toString().c_str(), MacAddr().toString().c_str());
00016 EXPECT_STREQ(MacAddr(0x01,0x23,0x45,0x67,0x89,0xab).toString().c_str(), MacAddr(data).toString().c_str());
00017 }
00018
00019
00020 TEST(MacAddr, toString)
00021 {
00022
00023 EXPECT_STREQ("00:00:00:00:00:00", MacAddr().toString().c_str());
00024
00025
00026 EXPECT_STREQ("00:00:00:00:00:00", MacAddr(0x00,0x00,0x00,0x00,0x00,0x00).toString(true).c_str());
00027 EXPECT_STREQ("01:01:01:01:01:01", MacAddr(0x01,0x01,0x01,0x01,0x01,0x01).toString(true).c_str());
00028 EXPECT_STREQ("02:02:02:02:02:02", MacAddr(0x02,0x02,0x02,0x02,0x02,0x02).toString(true).c_str());
00029 EXPECT_STREQ("03:03:03:03:03:03", MacAddr(0x03,0x03,0x03,0x03,0x03,0x03).toString(true).c_str());
00030 EXPECT_STREQ("04:04:04:04:04:04", MacAddr(0x04,0x04,0x04,0x04,0x04,0x04).toString(true).c_str());
00031 EXPECT_STREQ("05:05:05:05:05:05", MacAddr(0x05,0x05,0x05,0x05,0x05,0x05).toString(true).c_str());
00032 EXPECT_STREQ("06:06:06:06:06:06", MacAddr(0x06,0x06,0x06,0x06,0x06,0x06).toString(true).c_str());
00033 EXPECT_STREQ("07:07:07:07:07:07", MacAddr(0x07,0x07,0x07,0x07,0x07,0x07).toString(true).c_str());
00034 EXPECT_STREQ("08:08:08:08:08:08", MacAddr(0x08,0x08,0x08,0x08,0x08,0x08).toString(true).c_str());
00035 EXPECT_STREQ("09:09:09:09:09:09", MacAddr(0x09,0x09,0x09,0x09,0x09,0x09).toString(true).c_str());
00036 EXPECT_STREQ("0A:0A:0A:0A:0A:0A", MacAddr(0x0A,0x0A,0x0A,0x0A,0x0A,0x0A).toString(true).c_str());
00037 EXPECT_STREQ("0B:0B:0B:0B:0B:0B", MacAddr(0x0B,0x0B,0x0B,0x0B,0x0B,0x0B).toString(true).c_str());
00038 EXPECT_STREQ("0C:0C:0C:0C:0C:0C", MacAddr(0x0C,0x0C,0x0C,0x0C,0x0C,0x0C).toString(true).c_str());
00039 EXPECT_STREQ("0D:0D:0D:0D:0D:0D", MacAddr(0x0D,0x0D,0x0D,0x0D,0x0D,0x0D).toString(true).c_str());
00040 EXPECT_STREQ("0E:0E:0E:0E:0E:0E", MacAddr(0x0E,0x0E,0x0E,0x0E,0x0E,0x0E).toString(true).c_str());
00041 EXPECT_STREQ("0F:0F:0F:0F:0F:0F", MacAddr(0x0F,0x0F,0x0F,0x0F,0x0F,0x0F).toString(true).c_str());
00042 EXPECT_STREQ("10:10:10:10:10:10", MacAddr(0x10,0x10,0x10,0x10,0x10,0x10).toString(true).c_str());
00043 EXPECT_STREQ("20:20:20:20:20:20", MacAddr(0x20,0x20,0x20,0x20,0x20,0x20).toString(true).c_str());
00044 EXPECT_STREQ("30:30:30:30:30:30", MacAddr(0x30,0x30,0x30,0x30,0x30,0x30).toString(true).c_str());
00045 EXPECT_STREQ("40:40:40:40:40:40", MacAddr(0x40,0x40,0x40,0x40,0x40,0x40).toString(true).c_str());
00046 EXPECT_STREQ("50:50:50:50:50:50", MacAddr(0x50,0x50,0x50,0x50,0x50,0x50).toString(true).c_str());
00047 EXPECT_STREQ("60:60:60:60:60:60", MacAddr(0x60,0x60,0x60,0x60,0x60,0x60).toString(true).c_str());
00048 EXPECT_STREQ("70:70:70:70:70:70", MacAddr(0x70,0x70,0x70,0x70,0x70,0x70).toString(true).c_str());
00049 EXPECT_STREQ("80:80:80:80:80:80", MacAddr(0x80,0x80,0x80,0x80,0x80,0x80).toString(true).c_str());
00050 EXPECT_STREQ("90:90:90:90:90:90", MacAddr(0x90,0x90,0x90,0x90,0x90,0x90).toString(true).c_str());
00051 EXPECT_STREQ("A0:A0:A0:A0:A0:A0", MacAddr(0xA0,0xA0,0xA0,0xA0,0xA0,0xA0).toString(true).c_str());
00052 EXPECT_STREQ("B0:B0:B0:B0:B0:B0", MacAddr(0xB0,0xB0,0xB0,0xB0,0xB0,0xB0).toString(true).c_str());
00053 EXPECT_STREQ("C0:C0:C0:C0:C0:C0", MacAddr(0xC0,0xC0,0xC0,0xC0,0xC0,0xC0).toString(true).c_str());
00054 EXPECT_STREQ("D0:D0:D0:D0:D0:D0", MacAddr(0xD0,0xD0,0xD0,0xD0,0xD0,0xD0).toString(true).c_str());
00055 EXPECT_STREQ("E0:E0:E0:E0:E0:E0", MacAddr(0xE0,0xE0,0xE0,0xE0,0xE0,0xE0).toString(true).c_str());
00056 EXPECT_STREQ("F0:F0:F0:F0:F0:F0", MacAddr(0xF0,0xF0,0xF0,0xF0,0xF0,0xF0).toString(true).c_str());
00057 EXPECT_STREQ("FF:FF:FF:FF:FF:FF", MacAddr(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF).toString(true).c_str());
00058
00059
00060 EXPECT_STREQ("00:00:00:00:00:00", MacAddr(0x00,0x00,0x00,0x00,0x00,0x00).toString(false).c_str());
00061 EXPECT_STREQ("01:01:01:01:01:01", MacAddr(0x01,0x01,0x01,0x01,0x01,0x01).toString(false).c_str());
00062 EXPECT_STREQ("02:02:02:02:02:02", MacAddr(0x02,0x02,0x02,0x02,0x02,0x02).toString(false).c_str());
00063 EXPECT_STREQ("03:03:03:03:03:03", MacAddr(0x03,0x03,0x03,0x03,0x03,0x03).toString(false).c_str());
00064 EXPECT_STREQ("04:04:04:04:04:04", MacAddr(0x04,0x04,0x04,0x04,0x04,0x04).toString(false).c_str());
00065 EXPECT_STREQ("05:05:05:05:05:05", MacAddr(0x05,0x05,0x05,0x05,0x05,0x05).toString(false).c_str());
00066 EXPECT_STREQ("06:06:06:06:06:06", MacAddr(0x06,0x06,0x06,0x06,0x06,0x06).toString(false).c_str());
00067 EXPECT_STREQ("07:07:07:07:07:07", MacAddr(0x07,0x07,0x07,0x07,0x07,0x07).toString(false).c_str());
00068 EXPECT_STREQ("08:08:08:08:08:08", MacAddr(0x08,0x08,0x08,0x08,0x08,0x08).toString(false).c_str());
00069 EXPECT_STREQ("09:09:09:09:09:09", MacAddr(0x09,0x09,0x09,0x09,0x09,0x09).toString(false).c_str());
00070 EXPECT_STREQ("0a:0a:0a:0a:0a:0a", MacAddr(0x0a,0x0a,0x0a,0x0a,0x0a,0x0a).toString(false).c_str());
00071 EXPECT_STREQ("0b:0b:0b:0b:0b:0b", MacAddr(0x0b,0x0b,0x0b,0x0b,0x0b,0x0b).toString(false).c_str());
00072 EXPECT_STREQ("0c:0c:0c:0c:0c:0c", MacAddr(0x0c,0x0c,0x0c,0x0c,0x0c,0x0c).toString(false).c_str());
00073 EXPECT_STREQ("0d:0d:0d:0d:0d:0d", MacAddr(0x0d,0x0d,0x0d,0x0d,0x0d,0x0d).toString(false).c_str());
00074 EXPECT_STREQ("0e:0e:0e:0e:0e:0e", MacAddr(0x0e,0x0e,0x0e,0x0e,0x0e,0x0e).toString(false).c_str());
00075 EXPECT_STREQ("0f:0f:0f:0f:0f:0f", MacAddr(0x0f,0x0f,0x0f,0x0f,0x0f,0x0f).toString(false).c_str());
00076 EXPECT_STREQ("10:10:10:10:10:10", MacAddr(0x10,0x10,0x10,0x10,0x10,0x10).toString(false).c_str());
00077 EXPECT_STREQ("20:20:20:20:20:20", MacAddr(0x20,0x20,0x20,0x20,0x20,0x20).toString(false).c_str());
00078 EXPECT_STREQ("30:30:30:30:30:30", MacAddr(0x30,0x30,0x30,0x30,0x30,0x30).toString(false).c_str());
00079 EXPECT_STREQ("40:40:40:40:40:40", MacAddr(0x40,0x40,0x40,0x40,0x40,0x40).toString(false).c_str());
00080 EXPECT_STREQ("50:50:50:50:50:50", MacAddr(0x50,0x50,0x50,0x50,0x50,0x50).toString(false).c_str());
00081 EXPECT_STREQ("60:60:60:60:60:60", MacAddr(0x60,0x60,0x60,0x60,0x60,0x60).toString(false).c_str());
00082 EXPECT_STREQ("70:70:70:70:70:70", MacAddr(0x70,0x70,0x70,0x70,0x70,0x70).toString(false).c_str());
00083 EXPECT_STREQ("80:80:80:80:80:80", MacAddr(0x80,0x80,0x80,0x80,0x80,0x80).toString(false).c_str());
00084 EXPECT_STREQ("90:90:90:90:90:90", MacAddr(0x90,0x90,0x90,0x90,0x90,0x90).toString(false).c_str());
00085 EXPECT_STREQ("a0:a0:a0:a0:a0:a0", MacAddr(0xa0,0xa0,0xa0,0xa0,0xa0,0xa0).toString(false).c_str());
00086 EXPECT_STREQ("b0:b0:b0:b0:b0:b0", MacAddr(0xb0,0xb0,0xb0,0xb0,0xb0,0xb0).toString(false).c_str());
00087 EXPECT_STREQ("c0:c0:c0:c0:c0:c0", MacAddr(0xc0,0xc0,0xc0,0xc0,0xc0,0xc0).toString(false).c_str());
00088 EXPECT_STREQ("d0:d0:d0:d0:d0:d0", MacAddr(0xd0,0xd0,0xd0,0xd0,0xd0,0xd0).toString(false).c_str());
00089 EXPECT_STREQ("e0:e0:e0:e0:e0:e0", MacAddr(0xe0,0xe0,0xe0,0xe0,0xe0,0xe0).toString(false).c_str());
00090 EXPECT_STREQ("f0:f0:f0:f0:f0:f0", MacAddr(0xf0,0xf0,0xf0,0xf0,0xf0,0xf0).toString(false).c_str());
00091 EXPECT_STREQ("ff:ff:ff:ff:ff:ff", MacAddr(0xff,0xff,0xff,0xff,0xff,0xff).toString(false).c_str());
00092 }
00093
00094
00095 TEST(MacAddr, match_other)
00096 {
00097
00098 EXPECT_FALSE(MacAddr(0x00,0x00,0x00,0x00,0x00,0x00).match(MacAddr(0x00,0x00,0x00,0x00,0x00,0x00)));
00099 EXPECT_FALSE(MacAddr(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF).match(MacAddr(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF)));
00100
00101
00102 EXPECT_TRUE (MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB)));
00103 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(MacAddr(0x00,0x23,0x45,0x67,0x89,0xAB)));
00104 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(MacAddr(0x01,0x20,0x45,0x67,0x89,0xAB)));
00105 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(MacAddr(0x01,0x23,0x40,0x67,0x89,0xAB)));
00106 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(MacAddr(0x01,0x23,0x45,0x60,0x89,0xAB)));
00107 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(MacAddr(0x01,0x23,0x45,0x67,0x80,0xAB)));
00108 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(MacAddr(0x01,0x23,0x45,0x67,0x89,0xA0)));
00109 EXPECT_TRUE (MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF)));
00110 EXPECT_FALSE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match(MacAddr(0x0A,0xBB,0xCC,0xDD,0xEE,0xFF)));
00111 EXPECT_FALSE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match(MacAddr(0xAA,0x0B,0xCC,0xDD,0xEE,0xFF)));
00112 EXPECT_FALSE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match(MacAddr(0xAA,0xBB,0x0C,0xDD,0xEE,0xFF)));
00113 EXPECT_FALSE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match(MacAddr(0xAA,0xBB,0xCC,0x0D,0xEE,0xFF)));
00114 EXPECT_FALSE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match(MacAddr(0xAA,0xBB,0xCC,0xDD,0x0E,0xFF)));
00115 EXPECT_FALSE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0x0F)));
00116 }
00117
00118
00119 TEST(MacAddr, match_string)
00120 {
00121
00122 EXPECT_FALSE(MacAddr(0x00,0x00,0x00,0x00,0x00,0x00).match("000000000000"));
00123 EXPECT_FALSE(MacAddr(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF).match("FFFFFFFFFFFF"));
00124 EXPECT_FALSE(MacAddr(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF).match("ffffffffffff"));
00125
00126
00127 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match(""));
00128 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match("0123456789A"));
00129 EXPECT_TRUE (MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match("0123456789AB"));
00130 EXPECT_FALSE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match("0123456789ABC"));
00131
00132
00133 EXPECT_TRUE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match("0123456789AB"));
00134 EXPECT_TRUE(MacAddr(0x01,0x23,0x45,0x67,0x89,0xAB).match("0123456789ab"));
00135 EXPECT_TRUE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match("aabbccddeeff"));
00136 EXPECT_TRUE(MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match("AABBCCDDEEFF"));
00137
00138
00139 EXPECT_TRUE (MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match("aa:bb:cc:dd:ee:ff"));
00140 EXPECT_FALSE(MacAddr(0x0A,0xBB,0xCC,0xDD,0xEE,0xFF).match("aa:bb:cc:dd:ee:ff"));
00141 EXPECT_TRUE (MacAddr(0xAA,0xBB,0xCC,0xDD,0xEE,0xFF).match("AA:BB:CC:DD:EE:FF"));
00142 EXPECT_FALSE(MacAddr(0x0A,0xBB,0xCC,0xDD,0xEE,0xFF).match("AA:BB:CC:DD:EE:FF"));
00143 }
00144
00145 int main(int argc, char **argv)
00146 {
00147 testing::InitGoogleTest(&argc, argv);
00148 return RUN_ALL_TESTS();
00149 }
00150