diff options
author | Sven Gothel <[email protected]> | 2021-08-06 14:50:32 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-08-06 14:50:32 +0200 |
commit | 6fceb11db1063dd02b8804202bb08022f3c7b2ef (patch) | |
tree | dfa5143906b6d4d8bd64b632f3a25282f9fccf53 | |
parent | 02f8eadc05dcac3cc537882e04bd07d264e4dc1f (diff) |
Fix EUI48Sub Tests: An empty input string EUI48Sub results in a toString() ':', hinting its type.
-rw-r--r-- | test/direct_bt/test_btaddress01.cpp | 18 | ||||
-rw-r--r-- | test/java/test/org/direct_bt/TestEUI48.java | 18 |
2 files changed, 22 insertions, 14 deletions
diff --git a/test/direct_bt/test_btaddress01.cpp b/test/direct_bt/test_btaddress01.cpp index 1f4df2eb..afeeda9a 100644 --- a/test/direct_bt/test_btaddress01.cpp +++ b/test/direct_bt/test_btaddress01.cpp @@ -24,13 +24,17 @@ static void test_sub(const std::string& mac_str, const jau::darray<std::string>& jau::for_each_const(mac_sub_strs, [&i, &mac, &indices](const std::string &mac_sub_str) { const EUI48Sub mac_sub(mac_sub_str); printf("EUI48Sub mac02_sub: '%s' -> '%s'\n", mac_sub_str.c_str(), mac_sub.toString().c_str()); - // cut-off pre- and post-colon in test string - std::string sub_str = mac_sub_str; - if( sub_str.size() > 0 && sub_str[0] == ':' ) { - sub_str = sub_str.substr(1, sub_str.size()); - } - if( sub_str.size() > 0 && sub_str[sub_str.size()-1] == ':' ) { - sub_str = sub_str.substr(0, sub_str.size()-1); + // cut-off pre- and post-colon in test string, but leave single colon + std::string sub_str(mac_sub_str); + if( sub_str.size() == 0 ) { + sub_str = ":"; + } else if( sub_str != ":" ) { + if( sub_str.size() > 0 && sub_str[0] == ':' ) { + sub_str = sub_str.substr(1, sub_str.size()); + } + if( sub_str.size() > 0 && sub_str[sub_str.size()-1] == ':' ) { + sub_str = sub_str.substr(0, sub_str.size()-1); + } } REQUIRE(sub_str == mac_sub.toString()); diff --git a/test/java/test/org/direct_bt/TestEUI48.java b/test/java/test/org/direct_bt/TestEUI48.java index 89260e5e..e1dd54f0 100644 --- a/test/java/test/org/direct_bt/TestEUI48.java +++ b/test/java/test/org/direct_bt/TestEUI48.java @@ -75,13 +75,17 @@ public class TestEUI48 extends JunitTracer { final String mac_sub_str = iter.next(); final EUI48Sub mac_sub = new EUI48Sub(mac_sub_str); System.out.printf("EUI48Sub mac02_sub: '%s' -> '%s'\n", mac_sub_str, mac_sub.toString()); - // cut-off pre- and post-colon in test string - String sub_str = mac_sub_str; - if( sub_str.length() > 0 && sub_str.charAt(0) == ':' ) { - sub_str = sub_str.substring(1, sub_str.length()); - } - if( sub_str.length() > 0 && sub_str.charAt(sub_str.length()-1) == ':' ) { - sub_str = sub_str.substring(0, sub_str.length()-1); + // cut-off pre- and post-colon in test string, but leave single colon + String sub_str = new String(mac_sub_str); + if( sub_str.isEmpty() ) { + sub_str = ":"; + } else if( !sub_str.equals(":") ) { + if( sub_str.length() > 0 && sub_str.charAt(0) == ':' ) { + sub_str = sub_str.substring(1, sub_str.length()); + } + if( sub_str.length() > 0 && sub_str.charAt(sub_str.length()-1) == ':' ) { + sub_str = sub_str.substring(0, sub_str.length()-1); + } } Assert.assertEquals(sub_str, mac_sub.toString()); |