From 650fb016ce36cfda2e8073764196655ee6a50567 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 11 Jul 2015 14:30:14 +0200 Subject: o Adding a parser::finish() method that indicates that the stream is done and any possibly buffered data should be parsed and processed. --- sensor/test/CMakeLists.txt | 6 ++++-- sensor/test/SampleTest.cpp | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'sensor/test') 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(); + + auto parser = make_shared(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); } -- cgit v1.2.3