summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-12-23 13:42:49 +0100
committerSven Gothel <[email protected]>2020-12-23 13:42:49 +0100
commit8d67207c94af1068b55f17f9c8350b1ca51d5144 (patch)
tree6fc5af6f24dd9109ac562f3f22a888f2adfb2016 /test
parentd7ccc4c6161df71dc7750b6ae25f58619dda4a1b (diff)
Convert unit test: cppunit -> catch2
Diffstat (limited to 'test')
-rw-r--r--test/direct_bt/CMakeLists.txt1
-rw-r--r--test/direct_bt/test_attpdu01.cpp35
-rw-r--r--test/direct_bt/test_btaddress01.cpp34
-rw-r--r--test/direct_bt/test_uuid.cpp106
-rw-r--r--test/ieee11073/CMakeLists.txt25
-rw-r--r--test/ieee11073/test_datatypes01.cpp65
-rw-r--r--test/ieee11073/test_ieee11073_01.cpp52
7 files changed, 143 insertions, 175 deletions
diff --git a/test/direct_bt/CMakeLists.txt b/test/direct_bt/CMakeLists.txt
index 4ec160cb..f20c0b70 100644
--- a/test/direct_bt/CMakeLists.txt
+++ b/test/direct_bt/CMakeLists.txt
@@ -1,5 +1,4 @@
include_directories(
- ${PROJECT_SOURCE_DIR}/include/cppunit
${PROJECT_SOURCE_DIR}/jaulib/include
${PROJECT_SOURCE_DIR}/api
)
diff --git a/test/direct_bt/test_attpdu01.cpp b/test/direct_bt/test_attpdu01.cpp
index 68abcd4c..69f0856e 100644
--- a/test/direct_bt/test_attpdu01.cpp
+++ b/test/direct_bt/test_attpdu01.cpp
@@ -3,7 +3,9 @@
#include <cinttypes>
#include <cstring>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <direct_bt/UUID.hpp>
// #include <direct_bt/BTAddress.hpp>
@@ -14,28 +16,17 @@
using namespace direct_bt;
-// Test examples.
-class Cppunit_tests: public Cppunit {
- void single_test() override {
- const uuid16_t uuid16 = uuid16_t(uuid16_t(0x1234));
- const AttReadByNTypeReq req(true /* group */, 1, 0xffff, uuid16);
+TEST_CASE( "ATT PDU Test 01", "[datatype][attpdu]" ) {
+ const uuid16_t uuid16 = uuid16_t(uuid16_t(0x1234));
+ const AttReadByNTypeReq req(true /* group */, 1, 0xffff, uuid16);
- std::shared_ptr<const uuid_t> uuid16_2 = req.getNType();
- CHECK(uuid16.getTypeSizeInt(), 2);
- CHECK(uuid16_2->getTypeSizeInt(), 2);
- CHECKT( 0 == memcmp(uuid16.data(), uuid16_2->data(), 2) )
- CHECKT( uuid16.toString() == uuid16_2->toString() );
+ std::shared_ptr<const uuid_t> uuid16_2 = req.getNType();
+ REQUIRE(uuid16.getTypeSizeInt() == 2);
+ REQUIRE(uuid16_2->getTypeSizeInt() == 2);
+ REQUIRE( 0 == memcmp(uuid16.data(), uuid16_2->data(), 2) );
+ REQUIRE( uuid16.toString() == uuid16_2->toString() );
- CHECK(req.getStartHandle(), 1);
- CHECK(req.getEndHandle(), 0xffff);
- }
-};
-
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
-
- Cppunit_tests test1;
- return test1.run();
+ REQUIRE(req.getStartHandle() == 1);
+ REQUIRE(req.getEndHandle() == 0xffff);
}
diff --git a/test/direct_bt/test_btaddress01.cpp b/test/direct_bt/test_btaddress01.cpp
index 0952511f..1bd2a7c7 100644
--- a/test/direct_bt/test_btaddress01.cpp
+++ b/test/direct_bt/test_btaddress01.cpp
@@ -3,7 +3,9 @@
#include <cinttypes>
#include <cstring>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <jau/basic_types.hpp>
#include <direct_bt/BTAddress.hpp>
@@ -11,27 +13,11 @@
using namespace direct_bt;
using namespace jau;
-// Test examples.
-class Cppunit_tests : public Cppunit {
- public:
- void single_test() override {
- {
- EUI48 mac01;
- PRINTM("EUI48 size: whole0 "+std::to_string(sizeof(EUI48)));
- PRINTM("EUI48 size: whole1 "+std::to_string(sizeof(mac01)));
- PRINTM("EUI48 size: data1 "+std::to_string(sizeof(mac01.b)));
- CHECKM("EUI48 struct and data size not matching", sizeof(EUI48), sizeof(mac01));
- CHECKM("EUI48 struct and data size not matching", sizeof(mac01), sizeof(mac01.b));
- }
-
- }
-};
-
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
-
- Cppunit_tests test1;
- return test1.run();
+TEST_CASE( "EUI48 Test 01", "[datatype][eui48]" ) {
+ EUI48 mac01;
+ INFO_STR("EUI48 size: whole0 "+std::to_string(sizeof(EUI48)));
+ INFO_STR("EUI48 size: whole1 "+std::to_string(sizeof(mac01)));
+ INFO_STR("EUI48 size: data1 "+std::to_string(sizeof(mac01.b)));
+ REQUIRE_MSG("EUI48 struct and data size match", sizeof(EUI48) == sizeof(mac01));
+ REQUIRE_MSG("EUI48 struct and data size match", sizeof(mac01) == sizeof(mac01.b));
}
-
diff --git a/test/direct_bt/test_uuid.cpp b/test/direct_bt/test_uuid.cpp
index dd933a0f..0ba8cc12 100644
--- a/test/direct_bt/test_uuid.cpp
+++ b/test/direct_bt/test_uuid.cpp
@@ -3,71 +3,59 @@
#include <cinttypes>
#include <cstring>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <direct_bt/UUID.hpp>
using namespace direct_bt;
-// Test examples.
-class Cppunit_tests : public Cppunit {
- public:
- void single_test() override {
-
- std::cout << "Hello COUT" << std::endl;
- std::cerr << "Hello CERR" << std::endl;
-
- uint8_t buffer[100];
- static uint8_t uuid128_bytes[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
-
- {
- const uuid128_t v01 = uuid128_t(uuid128_bytes, 0, true);
- CHECK(v01.getTypeSizeInt(), 16);
- CHECK(v01.getTypeSizeInt(), sizeof(v01.value));
- CHECK(v01.getTypeSizeInt(), sizeof(v01.value.data));
- CHECKT( 0 == memcmp(uuid128_bytes, v01.data(), 16) )
-
- put_uuid(buffer, 0, v01, true);
- std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID128_SZ, buffer, 0, true);
- CHECK(v02->getTypeSizeInt(), 16);
- CHECKT( 0 == memcmp(v01.data(), v02->data(), 16) )
- CHECKT( v01.toString() == v02->toString() );
- }
-
- {
- const uuid32_t v01 = uuid32_t(uuid32_t(0x12345678));
- CHECK(v01.getTypeSizeInt(), 4);
- CHECK(v01.getTypeSizeInt(), sizeof(v01.value));
- CHECK(0x12345678, v01.value);
-
- put_uuid(buffer, 0, v01, true);
- std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID32_SZ, buffer, 0, true);
- CHECK(v02->getTypeSizeInt(), 4);
- CHECKT( 0 == memcmp(v01.data(), v02->data(), 4) )
- CHECKT( v01.toString() == v02->toString() );
- }
-
- {
- const uuid16_t v01 = uuid16_t(uuid16_t(0x1234));
- CHECK(v01.getTypeSizeInt(), 2);
- CHECK(v01.getTypeSizeInt(), sizeof(v01.value));
- CHECK(0x1234, v01.value);
-
- put_uuid(buffer, 0, v01, true);
- std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID16_SZ, buffer, 0, true);
- CHECK(v02->getTypeSizeInt(), 2);
- CHECKT( 0 == memcmp(v01.data(), v02->data(), 2) )
- CHECKT( v01.toString() == v02->toString() );
- }
+TEST_CASE( "UUID Test 01", "[datatype][uuid]" ) {
+ std::cout << "Hello COUT" << std::endl;
+ std::cerr << "Hello CERR" << std::endl;
+
+ uint8_t buffer[100];
+ static uint8_t uuid128_bytes[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
+
+ {
+ const uuid128_t v01 = uuid128_t(uuid128_bytes, 0, true);
+ REQUIRE(v01.getTypeSizeInt() == 16);
+ REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
+ REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value.data));
+ REQUIRE( 0 == memcmp(uuid128_bytes, v01.data(), 16) );
+
+ put_uuid(buffer, 0, v01, true);
+ std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID128_SZ, buffer, 0, true);
+ REQUIRE(v02->getTypeSizeInt() == 16);
+ REQUIRE( 0 == memcmp(v01.data(), v02->data(), 16) );
+ REQUIRE( v01.toString() == v02->toString() );
}
-};
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
+ {
+ const uuid32_t v01 = uuid32_t(uuid32_t(0x12345678));
+ REQUIRE(v01.getTypeSizeInt() == 4);
+ REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
+ REQUIRE(0x12345678 == v01.value);
+
+ put_uuid(buffer, 0, v01, true);
+ std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID32_SZ, buffer, 0, true);
+ REQUIRE(v02->getTypeSizeInt() == 4);
+ REQUIRE( 0 == memcmp(v01.data(), v02->data(), 4) );
+ REQUIRE( v01.toString() == v02->toString() );
+ }
- Cppunit_tests test1;
- return test1.run();
+ {
+ const uuid16_t v01 = uuid16_t(uuid16_t(0x1234));
+ REQUIRE(v01.getTypeSizeInt() == 2);
+ REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
+ REQUIRE(0x1234 == v01.value);
+
+ put_uuid(buffer, 0, v01, true);
+ std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID16_SZ, buffer, 0, true);
+ REQUIRE(v02->getTypeSizeInt() == 2);
+ REQUIRE( 0 == memcmp(v01.data(), v02->data(), 2) );
+ REQUIRE( v01.toString() == v02->toString() );
+ }
}
-
diff --git a/test/ieee11073/CMakeLists.txt b/test/ieee11073/CMakeLists.txt
index 4c3b05de..2ba595ae 100644
--- a/test/ieee11073/CMakeLists.txt
+++ b/test/ieee11073/CMakeLists.txt
@@ -1,10 +1,27 @@
include_directories(
- ${PROJECT_SOURCE_DIR}/include/cppunit
+ ${PROJECT_SOURCE_DIR}/jaulib/include
${PROJECT_SOURCE_DIR}/api
)
-add_executable (test_datatypes01 test_datatypes01.cpp)
-target_link_libraries (test_datatypes01 direct_bt)
+# These examples use the standard separate compilation
+set( SOURCES_IDIOMATIC_EXAMPLES
+ test_ieee11073_01.cpp
+)
+
+string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}" )
+set( TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES} )
+
+foreach( name ${TARGETS_IDIOMATIC_EXAMPLES} )
+ add_executable(${name} ${name}.cpp)
+endforeach()
+
+set(ALL_EXAMPLE_TARGETS
+ ${TARGETS_IDIOMATIC_EXAMPLES}
+)
-add_test (NAME datatypes01 COMMAND test_datatypes01)
+foreach(name ${ALL_EXAMPLE_TARGETS})
+ target_link_libraries(${name} direct_bt catch2)
+ add_dependencies(${name} direct_bt catch2)
+ add_test (NAME ${name} COMMAND ${name})
+endforeach()
diff --git a/test/ieee11073/test_datatypes01.cpp b/test/ieee11073/test_datatypes01.cpp
deleted file mode 100644
index 10f03027..00000000
--- a/test/ieee11073/test_datatypes01.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include <iostream>
-#include <cassert>
-#include <cinttypes>
-#include <cstring>
-
-#include <cppunit.h>
-
-#include "ieee11073/DataTypes.hpp"
-
-using namespace ieee11073;
-
-// Test examples.
-class Cppunit_tests : public Cppunit {
- private:
- void test_float32_IEEE11073_to_IEEE754(const std::string msg, const uint32_t raw, const float expFloat) {
- const float has = FloatTypes::float32_IEEE11073_to_IEEE754(raw);
- PRINTM(msg+": has '"+std::to_string(has));
- PRINTM(msg+": exp '"+std::to_string(expFloat)+"', diff "+std::to_string(fabsf(has-expFloat)));
- CHECKD(msg, has, expFloat);
- }
-
- void test_AbsoluteTime_IEEE11073(const std::string msg, const uint8_t * data_le, const int size, const std::string expStr) {
- ieee11073::AbsoluteTime has(data_le, size);
- const std::string has_str = has.toString();
- PRINTM(msg+": has '"+has_str+"', len "+std::to_string(has_str.length()));
- PRINTM(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(has_str==expStr));
- CHECKM(msg, has_str.length(), expStr.length());
- CHECKTM(msg, has_str == expStr);
- }
-
- public:
- void single_test() override {
-
- {
- // 0x06 670100FF E40704040B1A00 00
- // 0x06 640100FF E40704040B2C00 00
-
- // 79 09 00 FE -> 24.25f
- test_float32_IEEE11073_to_IEEE754("IEEE11073-float01", 0xFE000979, 24.25f);
- // 670100FF -> 35.900002
- test_float32_IEEE11073_to_IEEE754("IEEE11073-float01", 0xFF000167, 35.900002f);
- // 640100FF -> 35.600002
- test_float32_IEEE11073_to_IEEE754("IEEE11073-float02", 0xFF000164, 35.600002f);
-
- {
- // E40704040B1A00 -> 2020-04-04 11:26:00
- const uint8_t input[] = { 0xE4, 0x07, 0x04, 0x04, 0x0B, 0x1A, 0x00 };
- test_AbsoluteTime_IEEE11073("IEEE11073 time01", input, 7, "2020-04-04 11:26:00");
- }
- {
- // E40704040B2C00 -> 2020-04-04 11:44:00
- const uint8_t input[] = { 0xE4, 0x07, 0x04, 0x04, 0x0B, 0x2C, 0x00 };
- test_AbsoluteTime_IEEE11073("IEEE11073 time02", input, 7, "2020-04-04 11:44:00");
- }
- }
- }
-};
-
-int main(int argc, char *argv[]) {
- (void) argc;
- (void) argv;
- Cppunit_tests test1;
- return test1.run();
-}
-
diff --git a/test/ieee11073/test_ieee11073_01.cpp b/test/ieee11073/test_ieee11073_01.cpp
new file mode 100644
index 00000000..707d4f51
--- /dev/null
+++ b/test/ieee11073/test_ieee11073_01.cpp
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <cassert>
+#include <cinttypes>
+#include <cstring>
+
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
+
+#include "ieee11073/DataTypes.hpp"
+
+using namespace ieee11073;
+
+static void test_float32_IEEE11073_to_IEEE754(const std::string msg, const uint32_t raw, const float expFloat) {
+ const float has = FloatTypes::float32_IEEE11073_to_IEEE754(raw);
+ INFO_STR(msg+": has '"+std::to_string(has));
+ INFO_STR(msg+": exp '"+std::to_string(expFloat)+"', diff "+std::to_string(fabsf(has-expFloat)));
+ REQUIRE_EPSI_MSG(msg, has, expFloat);
+}
+
+static void test_AbsoluteTime_IEEE11073(const std::string msg, const uint8_t * data_le, const int size, const std::string expStr) {
+ ieee11073::AbsoluteTime has(data_le, size);
+ const std::string has_str = has.toString();
+ INFO_STR(msg+": has '"+has_str+"', len "+std::to_string(has_str.length()));
+ INFO_STR(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(has_str==expStr));
+ REQUIRE_MSG(msg, has_str.length() == expStr.length());
+ REQUIRE_MSG(msg, has_str == expStr);
+}
+
+TEST_CASE( "Datatype IEEE11073 Test 01", "[datatype][IEEE11073]" ) {
+ // 0x06 670100FF E40704040B1A00 00
+ // 0x06 640100FF E40704040B2C00 00
+
+ // 79 09 00 FE -> 24.25f
+ test_float32_IEEE11073_to_IEEE754("IEEE11073-float01", 0xFE000979, 24.25f);
+ // 670100FF -> 35.900002
+ test_float32_IEEE11073_to_IEEE754("IEEE11073-float01", 0xFF000167, 35.900002f);
+ // 640100FF -> 35.600002
+ test_float32_IEEE11073_to_IEEE754("IEEE11073-float02", 0xFF000164, 35.600002f);
+
+ {
+ // E40704040B1A00 -> 2020-04-04 11:26:00
+ const uint8_t input[] = { 0xE4, 0x07, 0x04, 0x04, 0x0B, 0x1A, 0x00 };
+ test_AbsoluteTime_IEEE11073("IEEE11073 time01", input, 7, "2020-04-04 11:26:00");
+ }
+ {
+ // E40704040B2C00 -> 2020-04-04 11:44:00
+ const uint8_t input[] = { 0xE4, 0x07, 0x04, 0x04, 0x0B, 0x2C, 0x00 };
+ test_AbsoluteTime_IEEE11073("IEEE11073 time02", input, 7, "2020-04-04 11:44:00");
+ }
+}
+