aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ByteBufferTest.cpp10
-rw-r--r--test/CMakeLists.txt19
-rw-r--r--test/MacTest.cpp30
3 files changed, 49 insertions, 10 deletions
diff --git a/test/ByteBufferTest.cpp b/test/ByteBufferTest.cpp
index 9f26971..7af18ef 100644
--- a/test/ByteBufferTest.cpp
+++ b/test/ByteBufferTest.cpp
@@ -70,13 +70,13 @@ BOOST_AUTO_TEST_CASE(setCursor) {
BOOST_CHECK_EQUAL(buffer.read8(), 0);
checkBuffer(buffer, 1000, 1);
- buffer.setPosition(0);
+ buffer.setCursor(0);
checkBuffer(buffer, 1000, 0);
BOOST_CHECK_EQUAL(buffer.read8(), 0);
checkBuffer(buffer, 1000, 1);
- buffer.setPosition(9);
+ buffer.setCursor(9);
checkBuffer(buffer, 1000, 9);
}
@@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(ieee_11073_20601_float_1_0d) {
ByteBuffer buffer(b.bytes, b.capacity);
buffer.writeFLOAT(1.0);
- buffer.setPosition(0);
+ buffer.setCursor(0);
BOOST_CHECK_EQUAL(buffer.readFLOAT(), 1.0);
}
@@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(ieee_11073_20601_float_nan) {
BOOST_CHECK_EQUAL(std::isnan(stof("NaN")), true);
buffer.writeFLOAT(stof("NaN"));
- buffer.setPosition(0);
+ buffer.setCursor(0);
BOOST_CHECK_EQUAL(std::isnan(buffer.readFLOAT()), true);
}
@@ -120,7 +120,7 @@ void c(double input, uint32_t hx, double sigma = 0.00001) {
Bytes b(1000);
ByteBuffer buffer(b.bytes, b.capacity);
buffer.writeFLOAT(input);
- buffer.setPosition(0);
+ buffer.setCursor(0);
double output = buffer.readFLOAT();
stringstream str;
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 4671329..86f2b1b 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,7 +1,11 @@
find_package(Boost COMPONENTS log regex unit_test_framework REQUIRED QUIET)
+find_header_and_lib(LOG4CPLUS log4cplus/logger.h log4cplus REQUIRED QUIET)
# If we can change directory here add_definition and test-specific stuff could be moved to the test directory
-file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *Test.cpp)
+set(TEST_SRCS
+ ByteBufferTest.cpp
+ MacTest.cpp
+ UuidTest.cpp)
add_definitions(-DBOOST_TEST_DYN_LINK)
foreach(testSrc ${TEST_SRCS})
@@ -11,14 +15,19 @@ foreach(testSrc ${TEST_SRCS})
#Add compile target
add_executable(${testName} ${testSrc})
- include_directories("${PROJECT_SOURCE_DIR}/ble")
- include_directories("${PROJECT_SOURCE_DIR}/include")
+ target_include_directories(${testName} PUBLIC "${PROJECT_SOURCE_DIR}/ble")
+ target_include_directories(${testName} PUBLIC "${PROJECT_SOURCE_DIR}/include")
+
add_dependencies(${testName} ble)
target_link_libraries(${testName} ble)
+ target_link_libraries(${testName} bluetooth)
+
+ target_include_directories(${testName} PUBLIC "${PROJECT_SOURCE_DIR}/apps")
+
target_link_libraries(${testName} pthread)
target_link_libraries(${testName} ${Boost_LIBRARIES})
-
- include_directories("${PROJECT_SOURCE_DIR}/apps")
+ target_include_directories(${testName} PUBLIC "${LOG4CPLUS_INCLUDE_DIRECTORY}")
+ target_link_libraries(${testName} "${LOG4CPLUS_LIBRARY}")
#I like to move testing binaries into a testBin directory
set_target_properties(${testName} PROPERTIES
diff --git a/test/MacTest.cpp b/test/MacTest.cpp
new file mode 100644
index 0000000..7af1624
--- /dev/null
+++ b/test/MacTest.cpp
@@ -0,0 +1,30 @@
+#include "ble/Bluetooth.h"
+
+#define BOOST_TEST_MODULE "MacTest"
+
+#include <boost/test/unit_test.hpp>
+
+using trygvis::bluetooth::Mac;
+
+BOOST_AUTO_TEST_CASE(parseMac) {
+ auto mac = Mac::parseMac("11:22:33:44:55:FF");
+ uint8_t b1, b2, b3, b4, b5, b6;
+ mac.copy(b1, b2, b3, b4, b5, b6);
+ BOOST_CHECK_EQUAL(0x11, b1);
+ BOOST_CHECK_EQUAL(0x22, b2);
+ BOOST_CHECK_EQUAL(0x33, b3);
+ BOOST_CHECK_EQUAL(0x44, b4);
+ BOOST_CHECK_EQUAL(0x55, b5);
+ BOOST_CHECK_EQUAL(0xff, b6);
+ BOOST_CHECK_EQUAL("11:22:33:44:55:ff", mac.str());
+}
+
+BOOST_AUTO_TEST_CASE(equal) {
+ Mac a(0x11, 0x22, 0x33, 0x44, 0x55, 0xFF);
+ auto a2 = Mac::parseMac("11:22:33:44:55:FF");
+ BOOST_CHECK_EQUAL(a, a2);
+
+ Mac b(0x11, 0x22, 0x33, 0xff, 0x10, 0x02);
+
+ BOOST_CHECK_LT(a, b);
+}