diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-20 08:35:51 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-20 08:35:51 +0100 |
commit | ffa313e80a27005405334db6491075442f6e1abd (patch) | |
tree | 23a48c91cfc0810afe88cc6104d0667516fbd4a9 /test | |
parent | af416f81b14a3bee682e300b165a6efdb9739d54 (diff) | |
download | ble-toys-master.tar.gz ble-toys-master.tar.bz2 ble-toys-master.tar.xz ble-toys-master.zip |
o Using more natural byte ordering in the code. No external effect.
o Using global ==, != and < operators instead of in-class operators for
better compatibility with STL.
ByteBuffer:
o Renaming setPosition() to setCursor().
Diffstat (limited to 'test')
-rw-r--r-- | test/ByteBufferTest.cpp | 10 | ||||
-rw-r--r-- | test/CMakeLists.txt | 19 | ||||
-rw-r--r-- | test/MacTest.cpp | 30 |
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); +} |