diff --git a/hello_plugin/parser_yaml.hpp b/hello_plugin/parser_yaml.hpp index ffe2adc5f5f5779dd91fd500ca9573d90564376a..b505b32ec35e72818bfd950f414c2262d4387b68 100644 --- a/hello_plugin/parser_yaml.hpp +++ b/hello_plugin/parser_yaml.hpp @@ -125,8 +125,8 @@ void parserYAML::walkTreeR(YAML::Node n, vector<string>& tags, string hdr){ // cout << "SUBSTR " << str.substr(1,str.size() - 1); walkTree(str.substr(1,str.size() - 1), tags, hdr); }else{ - std::copy(tags.begin(), tags.end(), std::ostream_iterator<string>(std::cout, "¬")); - cout << "«»" << n.Scalar() << endl; + // std::copy(tags.begin(), tags.end(), std::ostream_iterator<string>(std::cout, "¬")); + // cout << "«»" << n.Scalar() << endl; _params.insert(pair<string,string>(hdr, n.Scalar())); } break; @@ -140,7 +140,7 @@ void parserYAML::walkTreeR(YAML::Node n, vector<string>& tags, string hdr){ } case YAML::NodeType::Map : { for(const auto& kv : n){ - // If the key's value starts with a $ (i.e. $key) then its value is parsed as a literal map, + //If the key's value starts with a $ (i.e. $key) then its value is parsed as a literal map, //otherwise the parser recursively parses the map regex r("^\\$.*"); if(not regex_match(kv.first.as<string>(), r)){ diff --git a/test/gtest_parser_yaml.cpp b/test/gtest_parser_yaml.cpp index b25e7a4b30e303c3f76c4e7196e431d0a4bbd79b..caf037a97ccbf776dcf7042bb6ef06ad6435acd1 100644 --- a/test/gtest_parser_yaml.cpp +++ b/test/gtest_parser_yaml.cpp @@ -5,18 +5,35 @@ using namespace std; using namespace wolf; -TEST(ParserYAML, RegularParse) +parserYAML parse(string _file) { - string file = ""; - file = "../test/params1.yaml"; - parserYAML parser = parserYAML(file); + parserYAML parser = parserYAML(_file); parser.parse(); + return parser; +} + +TEST(ParserYAML, RegularParse) +{ + auto parser = parse("../test/params1.yaml"); auto params = parser.getParams(); - for(auto it : params) - cout << it.first << " %% " << it.second << endl; + // 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"); +} +TEST(ParserYAML, ParseMap) +{ + auto parser = parse("../test/params2.yaml"); + auto params = parser.getParams(); + ASSERT_EQ(params["processor1/mymap"], "[{k1:v1},{k2:v2},{k3:[v3,v4,v5]}]"); +} +TEST(ParserYAML, JumpFile) +{ + auto parser = parse("../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"); } - int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); diff --git a/test/params2.yaml b/test/params2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..30167145d3bf2c775ef497182de2e9a7022be0dd --- /dev/null +++ b/test/params2.yaml @@ -0,0 +1,33 @@ +config: + sensors: + - + type: "ODOM 2D" + name: "odom" + intrinsic: + k_disp_to_disp: 0.1 + k_rot_to_rot: 0.1 + extrinsic: + pos: [1,2,3] + - + type: "RANGE BEARING" + name: "rb" + processors: + - + type: "ODOM 2D" + name: "processor1" + sensorname: "odom" + $mymap: + k1: v1 + k2: v2 + k3: [v3,v4,v5] + - + type: "RANGE BEARING" + name: "rb_processor" + sensorname: "rb" + - + type: "ODOM 2D" + name: "my_proc_test" + sensorname: "odom" +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 new file mode 100644 index 0000000000000000000000000000000000000000..0d80a5802f5da772f59c29adf12257c8f79663d3 --- /dev/null +++ b/test/params3.1.yaml @@ -0,0 +1,8 @@ +cov_det: 100 +unmeasured_perturbation_std: 100 +angle_turned: 100 +dist_traveled: 100 +max_buff_length: 100 +max_time_span: 100 +time_tolerance: 100 +voting_active: false \ No newline at end of file diff --git a/test/params3.yaml b/test/params3.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ee07b011e7404d6a2d06571646b398a795db0498 --- /dev/null +++ b/test/params3.yaml @@ -0,0 +1,31 @@ +config: + sensors: + - + type: "ODOM 2D" + name: "odom" + intrinsic: + k_disp_to_disp: 0.1 + k_rot_to_rot: 0.1 + extrinsic: + pos: [1,2,3] + - + type: "RANGE BEARING" + name: "rb" + processors: + - + type: "ODOM 2D" + name: "processor1" + sensorname: "odom" + - + type: "RANGE BEARING" + name: "rb_processor" + sensorname: "rb" + - + type: "ODOM 2D" + name: "my_proc_test" + sensorname: "odom" + follow: "../test/params3.1.yaml" + jump: "@../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