1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/tests/unit/mapping.cpp

101 lines
3.4 KiB
C++
Raw Permalink Normal View History

2017-03-25 21:23:48 +01:00
/** Unit tests for sample value mapping.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-03-25 21:23:48 +01:00
*********************************************************************************/
#include <criterion/criterion.h>
2018-03-26 12:50:15 +02:00
#include <villas/mapping.h>
#include <villas/node.h>
#include <villas/list.h>
#include <villas/utils.hpp>
2018-03-26 14:09:20 +02:00
#include <villas/signal.h>
2019-06-23 13:35:42 +02:00
using namespace villas;
// cppcheck-suppress syntaxError
Test(mapping, parse_nodes)
{
int ret;
struct mapping_entry m;
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "apple.ts.origin");
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "apple");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::TIMESTAMP);
cr_assert_eq(m.timestamp.type, MappingTimestampType::ORIGIN);
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "cherry.stats.owd.mean");
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "cherry");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::STATS);
2019-06-23 13:35:42 +02:00
cr_assert_eq(m.stats.metric, Stats::Metric::OWD);
cr_assert_eq(m.stats.type, Stats::Type::MEAN);
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "carrot.data[1-2]");
2018-03-26 14:09:20 +02:00
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "carrot");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::DATA);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.data.first, "1");
cr_assert_str_eq(m.data.last, "2");
2018-03-26 14:09:20 +02:00
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "carrot");
2018-03-26 14:09:20 +02:00
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "carrot");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::DATA);
2020-09-10 11:15:33 +02:00
cr_assert_eq(m.data.first, nullptr);
cr_assert_eq(m.data.last, nullptr);
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "carrot.data[sole]");
2017-03-25 21:23:48 +01:00
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "carrot");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::DATA);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.data.first, "sole");
cr_assert_eq(m.data.last, nullptr);
2017-03-25 21:23:48 +01:00
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "carrot.sole");
2017-03-25 21:23:48 +01:00
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "carrot");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::DATA);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.data.first, "sole");
cr_assert_eq(m.data.last, nullptr);
2017-03-25 21:23:48 +01:00
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "carrot.data.sole");
2017-03-25 21:23:48 +01:00
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "carrot");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::DATA);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.data.first, "sole");
cr_assert_eq(m.data.last, nullptr);
2017-09-02 22:01:52 +02:00
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "carrot.data[sole-mio]");
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "carrot");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::DATA);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.data.first, "sole");
cr_assert_str_eq(m.data.last, "mio");
2017-09-02 22:01:52 +02:00
2020-09-10 11:15:33 +02:00
ret = mapping_entry_parse_str(&m, "carrot[sole-mio]");
cr_assert_eq(ret, 0);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.node_name, "carrot");
2019-06-23 16:13:23 +02:00
cr_assert_eq(m.type, MappingType::DATA);
2020-09-10 11:15:33 +02:00
cr_assert_str_eq(m.data.first, "sole");
cr_assert_str_eq(m.data.last, "mio");
2017-09-02 22:01:52 +02:00
}