From 5d6e4c971857b5e05d7c277e7eafcb9d64dbc6a7 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 17 Mar 2015 21:29:40 +0100 Subject: o An improved KeyDictionary. --- test/CMakeLists.txt | 5 ++++- test/SoilMoistureIoTest.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/SoilMoistureIoTest.cpp (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e9f217f..e8dc219 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(Boost COMPONENTS log unit_test_framework REQUIRED) +find_package(Boost COMPONENTS log regex unit_test_framework REQUIRED) # 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) @@ -18,6 +18,9 @@ foreach(testSrc ${TEST_SRCS}) target_link_libraries(${testName} pthread) target_link_libraries(${testName} ${Boost_LIBRARIES}) + include_directories("${PROJECT_SOURCE_DIR}/apps") + target_link_libraries(${testName} trygvis-apps) + #I like to move testing binaries into a testBin directory set_target_properties(${testName} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test) diff --git a/test/SoilMoistureIoTest.cpp b/test/SoilMoistureIoTest.cpp new file mode 100644 index 0000000..4a508b9 --- /dev/null +++ b/test/SoilMoistureIoTest.cpp @@ -0,0 +1,48 @@ +#include "SoilMoistureIo.h" + +#define BOOST_TEST_MODULE "SoilMoistureIoTest" + +#include + +using namespace trygvis::soil_moisture; + +BOOST_AUTO_TEST_CASE(csv_parser) { + KeyDictionary dict; + + auto buffer = make_shared(); + + auto parser = new CsvSampleParser(buffer, dict); + + char data[] = "a=1, b=2, c=3\n"; + parser->process(boost::asio::buffer(data, sizeof(data))); + BOOST_CHECK_EQUAL(buffer->samples.size(), 1); + BOOST_CHECK_EQUAL(dict.size(), 3); + auto it = dict.begin(); + BOOST_CHECK_EQUAL((*it)->name, "a"); + BOOST_CHECK_EQUAL((*it++)->index, 0); + BOOST_CHECK_EQUAL((*it)->name, "b"); + BOOST_CHECK_EQUAL((*it++)->index, 1); + BOOST_CHECK_EQUAL((*it)->name, "c"); + BOOST_CHECK_EQUAL((*it++)->index, 2); +} + +BOOST_AUTO_TEST_CASE(csv_parser_with_custom_dict) { + KeyDictionary dict; + + dict.indexOf("c"); + dict.indexOf("b"); + + auto buffer = make_shared(); + + auto parser = new CsvSampleParser(buffer, dict); + + char data[] = "a=1, b=2, c=3\n"; + parser->process(boost::asio::buffer(data, sizeof(data))); + BOOST_CHECK_EQUAL(buffer->samples.size(), 1); + BOOST_CHECK_EQUAL(dict.size(), 3); + auto it = dict.begin(); + BOOST_CHECK_EQUAL((*it)->name, "c"); + BOOST_CHECK_EQUAL((*it++)->index, 0); + BOOST_CHECK_EQUAL((*it)->name, "b"); + BOOST_CHECK_EQUAL((*it++)->index, 1); +} -- cgit v1.2.3