From 04f275fea9186a75836b589022a9fa410aea7b02 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 14 Feb 2011 14:09:04 +0000 Subject: Added gcov (coverage measurement) in unittests. --- server/src/widgetvalue.cc | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'server/src/widgetvalue.cc') diff --git a/server/src/widgetvalue.cc b/server/src/widgetvalue.cc index 053eecc..3b68e8e 100644 --- a/server/src/widgetvalue.cc +++ b/server/src/widgetvalue.cc @@ -40,8 +40,10 @@ static bool getMapValue(Value &value, maps_t::iterator li = maps.begin(); while(li != maps.end()) { Map &_map = *li; - if(_map.attributes["name"] == map) { - luamap = _map.attributes["lua"]; + if(_map.attributes.find("name") != _map.attributes.end() && + _map.attributes["name"] == map) { + if(_map.attributes.find("lua") != _map.attributes.end()) + luamap = _map.attributes["lua"]; } li++; } @@ -145,8 +147,7 @@ bool getValue(Value &value, TEST_BEGIN; -pracro_debug_init(); -pracro_debug_parse("+all"); +debug_parse("+all"); time_t now = time(NULL); @@ -349,6 +350,39 @@ time_t now = time(NULL); TEST_EQUAL_STR(value.source, v.source, "Got the right source?"); } +{ + Conf::db_max_ttl = 1000; + Conf::pentominos_max_ttl = 500; + + Value value; + + attr_t attr; + attr["name"] = "foo"; + attr["value"] = "hello"; + attr["map"] = "bar"; + + maps_t maps; + Map m; + char tbuf[32]; sprintf(tbuf, "%ld", now - 1); + std::string val = "le valu"; + m.attributes["name"] = "bar"; + m.attributes["lua"] = "return '"+val+"', "+tbuf+", 'artefact'"; + maps.push_back(m); + LUAQueryMapper mapper; + + Values values; + Value v; + v.value = "world"; + v.source = "pracro"; + v.timestamp = now ; + values["foo"] = v; + + TEST_TRUE(getValue(value, attr, maps, mapper, values), "Got value?"); + TEST_EQUAL_STR(value.value, v.value, "Got the right value?"); + TEST_EQUAL_INT(value.timestamp, v.timestamp, "Got the right timestamp?"); + TEST_EQUAL_STR(value.source, v.source, "Got the right source?"); +} + TEST_END; #endif/*TEST_WIDGETVALUE*/ -- cgit v1.2.3