From 0cf8c5cad6742a2c14b1672597450419700953b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20Casals=20Bu=C3=B1uel?= <jcasals@iri.upc.edu> Date: Fri, 15 Feb 2019 16:40:46 +0100 Subject: [PATCH] WIP tests not properly finding YAML files --- test/CMakeLists.txt | 4 ++++ test/gtest_param_server.cpp | 31 +++++++++++++++++++++++++++++++ test/gtest_parser_yaml.cpp | 20 ++++++++++++-------- test/params1.yaml | 2 +- test/params3.1.yaml | 2 +- 5 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 test/gtest_param_server.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c4e1ce8be..9a3910693 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -84,6 +84,10 @@ target_link_libraries(gtest_motion_buffer ${PROJECT_NAME}) wolf_add_gtest(gtest_pack_KF_buffer gtest_pack_KF_buffer.cpp) target_link_libraries(gtest_pack_KF_buffer ${PROJECT_NAME}) +# Parameters server +wolf_add_gtest(gtest_param_server gtest_param_server.cpp ${CMAKE_CURRENT_LIST_DIR}) +target_link_libraries(gtest_param_server ${PROJECT_NAME}) + # YAML parser wolf_add_gtest(gtest_parser_yaml gtest_parser_yaml.cpp) target_link_libraries(gtest_parser_yaml ${PROJECT_NAME}) diff --git a/test/gtest_param_server.cpp b/test/gtest_param_server.cpp new file mode 100644 index 000000000..4c85b1f77 --- /dev/null +++ b/test/gtest_param_server.cpp @@ -0,0 +1,31 @@ +#include "utils_gtest.h" +#include "base/converter.h" +#include "base/wolf.h" +#include "../hello_plugin/parser_yaml.hpp" +#include "base/params_server.hpp" + +using namespace std; +using namespace wolf; + +parserYAML parse(string _file) +{ + parserYAML parser = parserYAML(_file); + parser.parse(); + return parser; +} + +TEST(ParamsServer, Default) +{ + std::string wolf_root = _WOLF_ROOT_DIR; + auto parser = parse(wolf_root + "/test/params1.yaml"); + auto params = parser.getParams(); + paramsServer server = paramsServer(params, parser.sensorsSerialization(), parser.processorsSerialization()); + EXPECT_EQ(server.getParam<double>("should_not_exist", "2.6"), 2.6); + EXPECT_EQ(server.getParam<bool>("my_proc_test/voting_active", "true"), false); + EXPECT_NE(server.getParam<unsigned int>("my_proc_test/time_tolerance", "23"), 23); +} +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/gtest_parser_yaml.cpp b/test/gtest_parser_yaml.cpp index caf037a97..b7710b3ca 100644 --- a/test/gtest_parser_yaml.cpp +++ b/test/gtest_parser_yaml.cpp @@ -1,10 +1,13 @@ #include "utils_gtest.h" #include "base/converter.h" +#include "base/wolf.h" #include "../hello_plugin/parser_yaml.hpp" using namespace std; using namespace wolf; +std::string wolf_root = _WOLF_ROOT_DIR; + parserYAML parse(string _file) { parserYAML parser = parserYAML(_file); @@ -14,25 +17,26 @@ parserYAML parse(string _file) TEST(ParserYAML, RegularParse) { - auto parser = parse("../test/params1.yaml"); + cout << "WOOT " << wolf_root + "/test/params1.yaml" << endl; + auto parser = parse(wolf_root + "/test/params1.yaml"); auto params = parser.getParams(); // for(auto it : params) // cout << it.first << " %% " << it.second << endl; - ASSERT_EQ(params["odom/intrinsic/k_rot_to_rot"], "0.1"); - ASSERT_EQ(params["processor1/sensorname"], "odom"); + EXPECT_EQ(params["odom/intrinsic/k_rot_to_rot"], "0.1"); + EXPECT_EQ(params["processor1/sensorname"], "odom"); } TEST(ParserYAML, ParseMap) { - auto parser = parse("../test/params2.yaml"); + auto parser = parse(wolf_root + "/test/params2.yaml"); auto params = parser.getParams(); - ASSERT_EQ(params["processor1/mymap"], "[{k1:v1},{k2:v2},{k3:[v3,v4,v5]}]"); + EXPECT_EQ(params["processor1/mymap"], "[{k1:v1},{k2:v2},{k3:[v3,v4,v5]}]"); } TEST(ParserYAML, JumpFile) { - auto parser = parse("../test/params3.yaml"); + auto parser = parse(wolf_root + "/test/params3.yaml"); auto params = parser.getParams(); - ASSERT_EQ(params["my_proc_test/max_buff_length"], "100"); - ASSERT_EQ(params["my_proc_test/jump/voting_active"], "false"); + EXPECT_EQ(params["my_proc_test/max_buff_length"], "100"); + EXPECT_EQ(params["my_proc_test/jump/voting_active"], "false"); } int main(int argc, char **argv) { diff --git a/test/params1.yaml b/test/params1.yaml index db5fab3fa..9281f2ce9 100644 --- a/test/params1.yaml +++ b/test/params1.yaml @@ -24,7 +24,7 @@ config: type: "ODOM 2D" name: "my_proc_test" sensorname: "odom" - follow: "../hello_plugin/params_conf.yaml" + follow: "../test/params3.1.yaml" files: - "/home/jcasals/workspace/wip/wolf/lib/libsensor_odo.so" - "/home/jcasals/workspace/wip/wolf/lib/librange_bearing.so" \ No newline at end of file diff --git a/test/params3.1.yaml b/test/params3.1.yaml index 0d80a5802..bd9b495c8 100644 --- a/test/params3.1.yaml +++ b/test/params3.1.yaml @@ -5,4 +5,4 @@ dist_traveled: 100 max_buff_length: 100 max_time_span: 100 time_tolerance: 100 -voting_active: false \ No newline at end of file +voting_active: false \ No newline at end of file -- GitLab