From aad1eaa291460509a5cf94092609ae22ebef5494 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 22 Mar 2015 16:57:09 +0100 Subject: o Renaming SoilMoistureIo to SensorSample, moving to its own library. --- sensor/test/SoilMoistureIoTest.cpp | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 sensor/test/SoilMoistureIoTest.cpp (limited to 'sensor/test') diff --git a/sensor/test/SoilMoistureIoTest.cpp b/sensor/test/SoilMoistureIoTest.cpp new file mode 100644 index 0000000..574885c --- /dev/null +++ b/sensor/test/SoilMoistureIoTest.cpp @@ -0,0 +1,48 @@ +#include "SensorSample.h" + +#define BOOST_TEST_MODULE "SoilMoistureIoTest" + +#include + +using namespace trygvis::soil_moisture; + +BOOST_AUTO_TEST_CASE(key_value_parser) { + KeyDictionary dict; + + auto buffer = make_shared(); + + auto parser = new KeyValueSampleStreamParser(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(key_value_parser_with_custom_dict) { + KeyDictionary dict; + + dict.indexOf("c"); + dict.indexOf("b"); + + auto buffer = make_shared(); + + auto parser = new KeyValueSampleStreamParser(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