14 const EUI48 mac(mac_str);
15 printf(
"Test EUI48 mac: '%s' -> '%s'\n", mac_str.c_str(), mac.
toString().c_str());
20 PRAGMA_DISABLE_WARNING_RESTRICT
22 jau::for_each_const(mac_sub_strs, [&byte_order, &i, &mac, &indices](
const std::string &mac_sub_str) {
24 printf(
"EUI48Sub mac02_sub: '%s' -> '%s'\n", mac_sub_str.c_str(), mac_sub.
toString().c_str());
27 std::string sub_str(mac_sub_str);
28 if( sub_str.size() == 0 ) {
30 }
else if( sub_str !=
":" ) {
31 if( sub_str.size() > 0 && sub_str[0] ==
':' ) {
32 sub_str = sub_str.substr(1, sub_str.size());
34 if( sub_str.size() > 0 && sub_str[sub_str.size()-1] ==
':' ) {
35 sub_str = sub_str.substr(0, sub_str.size()-1);
38 REQUIRE(sub_str == mac_sub.
toString());
41 REQUIRE( idx == indices.
at(i));
54static void test_sub02(
const std::string& mac_sub_str_exp,
const std::string& mac_sub_str,
const bool expected_result) {
57 const bool res = EUI48Sub::scanEUI48Sub(mac_sub_str, mac_sub, errmsg);
59 printf(
"EUI48Sub mac_sub: '%s' -> '%s'\n", mac_sub_str.c_str(), mac_sub.
toString().c_str());
60 if( expected_result ) {
61 REQUIRE(mac_sub_str_exp == mac_sub.
toString());
64 printf(
"EUI48Sub mac_sub: '%s' -> Error '%s'\n", mac_sub_str.c_str(), errmsg.c_str());
66 REQUIRE( expected_result == res );
74 REQUIRE_MSG(
"EUI48 struct and data size match",
sizeof(
EUI48) ==
sizeof(mac01));
75 REQUIRE_MSG(
"EUI48 struct and data size match",
sizeof(mac01) ==
sizeof(mac01.
b));
79 const std::string mac02_str =
"C0:10:22:A0:10:00";
80 const jau::darray<std::string> mac02_sub_strs = {
"C0",
"C0:10",
":10:22",
"10:22",
":10:22:",
"10:22:",
"10",
"10:00",
"00",
":",
"",
"00:10", mac02_str};
81 const jau::darray<jau::snsize_t> mac02_sub_idxs_le = { 5, 4, 3, 3, 3, 3, 1, 0, 0, 0, 0, -1, 0};
82 const jau::darray<jau::snsize_t> mac02_sub_idxs_be = { 0, 0, 1, 1, 1, 1, 4, 4, 5, 0, 0, -1, 0};
83 test_sub01(lb_endian_t::little, mac02_str, mac02_sub_strs, mac02_sub_idxs_le);
84 test_sub01(lb_endian_t::big, mac02_str, mac02_sub_strs, mac02_sub_idxs_be);
89 const std::string mac03_str =
"01:02:03:04:05:06";
90 const jau::darray<std::string> mac03_sub_strs = {
"01",
"01:02",
":03:04",
"03:04",
":04:05:",
"04:05:",
"04",
"05:06",
"06",
":",
"",
"06:05", mac03_str};
91 const jau::darray<jau::snsize_t> mac03_sub_idxs_le = { 5, 4, 2, 2, 1, 1, 2, 0, 0, 0, 0, -1, 0};
92 const jau::darray<jau::snsize_t> mac03_sub_idxs_be = { 0, 0, 2, 2, 3, 3, 3, 4, 5, 0, 0, -1, 0};
93 test_sub01(lb_endian_t::little, mac03_str, mac03_sub_strs, mac03_sub_idxs_le);
94 test_sub01(lb_endian_t::big, mac03_str, mac03_sub_strs, mac03_sub_idxs_be);
97 const std::string mac_sub_str =
"C0:10:22:A0:10:00";
101 const std::string mac_sub_str =
"0600106";
102 const std::string dummy;
106 EUI48 h(
"01:02:03:04:05:06");
109 REQUIRE(0 == h.
indexOf(n, lb_endian_t::big));
110 REQUIRE(4 == h.
indexOf(n, lb_endian_t::little));
113 EUI48 h(
"01:02:03:04:05:06");
116 REQUIRE(4 == h.
indexOf(n, lb_endian_t::big));
117 REQUIRE(0 == h.
indexOf(n, lb_endian_t::little));
#define REQUIRE_MSG(MSG,...)
Implementation of a dynamic linear array storage, aka vector.
const_reference at(size_type i) const
Like std::vector::at(size_type), immutable reference.
constexpr UnaryFunction for_each_const(T &data, UnaryFunction f, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
lb_endian_t
Simplified reduced endian type only covering little- and big-endian.
std::string to_string(const alphabet &v) noexcept
#define PRAGMA_DISABLE_WARNING_PUSH
#define PRAGMA_DISABLE_WARNING_POP
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
A 48 bit EUI-48 sub-identifier, see EUI48.
std::string toString() const noexcept
Returns the EUI48 sub-string representation with MSB first (lb_endian::big), less or equal 17 charact...
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
bool contains(const EUI48Sub &needle) const noexcept
jau::snsize_t indexOf(const EUI48Sub &needle, const lb_endian_t byte_order) const noexcept
std::string toString() const noexcept
static void test_sub01(const lb_endian_t byte_order, const std::string &mac_str, const jau::darray< std::string > &mac_sub_strs, const jau::darray< jau::snsize_t > &indices)
static void test_sub02(const std::string &mac_sub_str_exp, const std::string &mac_sub_str, const bool expected_result)
TEST_CASE("EUI48 Test 01", "[datatype][eui48]")
int printf(const char *format,...)
Operating Systems predefined macros.