aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-08-25 21:22:34 +0200
committerSven Gothel <[email protected]>2021-08-25 21:22:34 +0200
commit80b3f83ff70c23e919f3e43f23860927b24f9654 (patch)
treee0884d2b5b92ab50c9f00eb376ff66889e328ddf /test
parent9feb4c030988912dc1702ef997ad65e2ed4ec425 (diff)
Fix EUI48Sub::scanEUI48Sub(..): Fail on missing expected colon, i.e. after each two digits
Diffstat (limited to 'test')
-rw-r--r--test/direct_bt/test_btaddress01.cpp24
-rw-r--r--test/java/test/org/direct_bt/TestEUI48.java22
2 files changed, 46 insertions, 0 deletions
diff --git a/test/direct_bt/test_btaddress01.cpp b/test/direct_bt/test_btaddress01.cpp
index afeeda9a..6cad6582 100644
--- a/test/direct_bt/test_btaddress01.cpp
+++ b/test/direct_bt/test_btaddress01.cpp
@@ -51,6 +51,21 @@ static void test_sub(const std::string& mac_str, const jau::darray<std::string>&
(void) indices;
}
+static void test_sub(const std::string& mac_sub_str_exp, const std::string& mac_sub_str, const bool expected_result) {
+ std::string errmsg;
+ EUI48Sub mac_sub;
+ const bool res = EUI48Sub::scanEUI48Sub(mac_sub_str, mac_sub, errmsg);
+ if( res ) {
+ printf("EUI48Sub mac_sub: '%s' -> '%s'\n", mac_sub_str.c_str(), mac_sub.toString().c_str());
+ if( expected_result ) {
+ REQUIRE(mac_sub_str_exp == mac_sub.toString());
+ }
+ } else {
+ printf("EUI48Sub mac_sub: '%s' -> Error '%s'\n", mac_sub_str.c_str(), errmsg.c_str());
+ }
+ REQUIRE( expected_result == res );
+}
+
TEST_CASE( "EUI48 Test 01", "[datatype][eui48]" ) {
EUI48 mac01;
INFO_STR("EUI48 size: whole0 "+std::to_string(sizeof(EUI48)));
@@ -74,4 +89,13 @@ TEST_CASE( "EUI48 Test 01", "[datatype][eui48]" ) {
const jau::darray<jau::snsize_t> mac03_sub_idxs = { 5, 4, 2, 2, 1, 1, 2, 0, 0, 0, 0, -1, 0};
test_sub(mac03_str, mac03_sub_strs, mac03_sub_idxs);
}
+ {
+ const std::string mac_sub_str = "C0:10:22:A0:10:00";
+ test_sub(mac_sub_str, mac_sub_str, true /* expected_result */);
+ }
+ {
+ const std::string mac_sub_str = "0600106";
+ const std::string dummy;
+ test_sub(dummy, mac_sub_str, false /* expected_result */);
+ }
}
diff --git a/test/java/test/org/direct_bt/TestEUI48.java b/test/java/test/org/direct_bt/TestEUI48.java
index e1dd54f0..93d3c40d 100644
--- a/test/java/test/org/direct_bt/TestEUI48.java
+++ b/test/java/test/org/direct_bt/TestEUI48.java
@@ -98,6 +98,20 @@ public class TestEUI48 extends JunitTracer {
}
}
}
+ static void test_sub(final String mac_sub_str_exp, final String mac_sub_str, final boolean expected_result) {
+ final StringBuilder errmsg = new StringBuilder();
+ final EUI48Sub mac_sub = new EUI48Sub ();
+ final boolean res = EUI48Sub.scanEUI48Sub(mac_sub_str, mac_sub, errmsg);
+ if( res ) {
+ System.out.printf("EUI48Sub mac_sub: '%s' -> '%s'\n", mac_sub_str, mac_sub.toString());
+ if( expected_result ) {
+ Assert.assertEquals(mac_sub_str_exp, mac_sub.toString());
+ }
+ } else {
+ System.out.printf("EUI48Sub mac_sub: '%s' -> Error '%s'\n", mac_sub_str, errmsg.toString());
+ }
+ Assert.assertEquals(expected_result, res);
+ }
@Test
public void test01_EUI48AndSub() {
@@ -116,6 +130,14 @@ public class TestEUI48 extends JunitTracer {
final Integer[] mac03_sub_idxs = { 5, 4, 2, 2, 1, 1, 2, 0, 0, 0, 0, -1, 0};
test_sub(mac03_str, Arrays.asList(mac03_sub_strs), Arrays.asList(mac03_sub_idxs));
}
+ {
+ final String mac_sub_str = "C0:10:22:A0:10:00";
+ test_sub(mac_sub_str, mac_sub_str, true /* expected_result */);
+ }
+ {
+ final String mac_sub_str = "0600106";
+ test_sub(null, mac_sub_str, false /* expected_result */);
+ }
}
public static void main(final String args[]) throws IOException {