aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt5
-rw-r--r--test/SoilMoistureIoTest.cpp48
2 files changed, 52 insertions, 1 deletions
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 <boost/test/unit_test.hpp>
+
+using namespace trygvis::soil_moisture;
+
+BOOST_AUTO_TEST_CASE(csv_parser) {
+ KeyDictionary dict;
+
+ auto buffer = make_shared<VectorSampleOutputStream>();
+
+ 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<VectorSampleOutputStream>();
+
+ 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);
+}