aboutsummaryrefslogtreecommitdiff
path: root/sensor/test
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-11 14:30:14 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-11 14:30:14 +0200
commit650fb016ce36cfda2e8073764196655ee6a50567 (patch)
tree3889f4d25f5ee58286dd8a31e1bd7985845179ff /sensor/test
parent178a32835f3405399979b8635b88ce71c57f6cd6 (diff)
downloadble-toys-650fb016ce36cfda2e8073764196655ee6a50567.tar.gz
ble-toys-650fb016ce36cfda2e8073764196655ee6a50567.tar.bz2
ble-toys-650fb016ce36cfda2e8073764196655ee6a50567.tar.xz
ble-toys-650fb016ce36cfda2e8073764196655ee6a50567.zip
o Adding a parser::finish() method that indicates that the stream is done and any possibly buffered data should be parsed and processed.
Diffstat (limited to 'sensor/test')
-rw-r--r--sensor/test/CMakeLists.txt6
-rw-r--r--sensor/test/SampleTest.cpp33
2 files changed, 36 insertions, 3 deletions
diff --git a/sensor/test/CMakeLists.txt b/sensor/test/CMakeLists.txt
index 2e68532..5c2d527 100644
--- a/sensor/test/CMakeLists.txt
+++ b/sensor/test/CMakeLists.txt
@@ -4,6 +4,8 @@ find_package(Boost COMPONENTS log regex unit_test_framework REQUIRED)
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *Test.cpp)
add_definitions(-DBOOST_TEST_DYN_LINK)
+enable_testing()
+
foreach(testSrc ${TEST_SRCS})
get_filename_component(testName ${testSrc} NAME_WE)
@@ -21,6 +23,6 @@ foreach(testSrc ${TEST_SRCS})
#Finally add it to test execution -
#Notice the WORKING_DIRECTORY and COMMAND
add_test(NAME ${testName}
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testBin
- COMMAND ${CMAKE_BINARY_DIR}/testBin/${testName})
+ COMMAND ${testName})
+
endforeach(testSrc)
diff --git a/sensor/test/SampleTest.cpp b/sensor/test/SampleTest.cpp
index 9737d02..8479e75 100644
--- a/sensor/test/SampleTest.cpp
+++ b/sensor/test/SampleTest.cpp
@@ -20,6 +20,7 @@ BOOST_AUTO_TEST_CASE(key_value_parser) {
char data[] = "a=1, b=2, c=3\n";
auto buf = boost::asio::buffer(data, sizeof(data));
parser->process(buf);
+ parser->finish();
BOOST_CHECK_EQUAL(buffer->samples.size(), 1);
BOOST_CHECK_EQUAL(dict.size(), 3);
auto it = dict.begin();
@@ -41,9 +42,11 @@ BOOST_AUTO_TEST_CASE(key_value_parser2) {
char data[] = "now=1,sensor 1=0.000999999833333\n";
auto buf = boost::asio::buffer(data, sizeof(data));
parser->process(buf);
+ parser->finish();
+ BOOST_CHECK_EQUAL(dict.size(), 2);
BOOST_CHECK_EQUAL(buffer->samples.size(), 1);
+
SampleRecord& sample = buffer->samples[0];
- BOOST_CHECK_EQUAL(dict.size(), 2);
auto it = dict.begin();
BOOST_CHECK_EQUAL((*it)->name, "now");
BOOST_CHECK_EQUAL(!sample.at(*it).operator!(), true);
@@ -69,6 +72,7 @@ BOOST_AUTO_TEST_CASE(key_value_parser_with_custom_dict) {
char data[] = "a=1, b=2, c=3\n";
auto buf = boost::asio::buffer(data, sizeof(data));
parser->process(buf);
+ parser->finish();
BOOST_CHECK_EQUAL(buffer->samples.size(), 1);
BOOST_CHECK_EQUAL(dict.size(), 3);
auto it = dict.begin();
@@ -88,5 +92,32 @@ BOOST_AUTO_TEST_CASE(type_detection_key_value) {
char data[] = "a=1, b=2, c=3\n";
auto buf = boost::asio::buffer(data, sizeof(data));
parser->process(buf);
+ parser->finish();
+}
+
+BOOST_AUTO_TEST_CASE(key_value_parser_without_newline) {
+ KeyDictionary dict;
+
+ auto buffer = make_shared<VectorSampleOutputStream>();
+
+ auto parser = make_shared<KeyValueSampleStreamParser>(buffer, dict);
+
+ char data[] = "now=1,sensor=123";
+ auto buf = boost::asio::buffer(data, sizeof(data));
+ parser->process(buf);
+ parser->finish();
+ BOOST_CHECK_EQUAL(dict.size(), 2);
+ BOOST_CHECK_EQUAL(buffer->samples.size(), 1);
+
+ SampleRecord& sample = buffer->samples[0];
+ auto it = dict.begin();
+ BOOST_CHECK_EQUAL((*it)->name, "now");
+ BOOST_CHECK_EQUAL(!sample.at(*it).operator!(), true);
+ BOOST_CHECK_EQUAL(sample.at(*it).get(), "1");
+ BOOST_CHECK_EQUAL((*it++)->index, 0);
+ BOOST_CHECK_EQUAL((*it)->name, "sensor");
+ BOOST_CHECK_EQUAL(!sample.at(*it).operator!(), true);
+ BOOST_CHECK_EQUAL(sample.at(*it).get(), "123");
+ BOOST_CHECK_EQUAL((*it++)->index, 1);
}