Skip to content
Snippets Groups Projects
Commit 65b7ec18 authored by Joaquim Casals Buñuel's avatar Joaquim Casals Buñuel
Browse files

Fixed relative paths tests

parent 0cf8c5ca
No related branches found
No related tags found
1 merge request!260WIP: params autoconf
This commit is part of merge request !260. Comments created here will be created in the context of that merge request.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/wolf.h" #include "base/wolf.h"
// #include "sensor_odom_2D.cpp" // #include "sensor_odom_2D.cpp"
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include "parser_yaml.hpp" #include "base/yaml/parser_yaml.hpp"
#include "base/params_server.hpp" #include "base/params_server.hpp"
#include "../hello_wolf/capture_range_bearing.h" #include "../hello_wolf/capture_range_bearing.h"
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/wolf.h" #include "base/wolf.h"
// #include "sensor_odom_2D.cpp" // #include "sensor_odom_2D.cpp"
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include "parser_yaml.hpp" #include "base/yaml/parser_yaml.hpp"
#include "base/params_server.hpp" #include "base/params_server.hpp"
#include "../hello_wolf/capture_range_bearing.h" #include "../hello_wolf/capture_range_bearing.h"
......
...@@ -62,6 +62,8 @@ class parserYAML { ...@@ -62,6 +62,8 @@ class parserYAML {
vector<ParamsInitProcessor> _paramsProc; vector<ParamsInitProcessor> _paramsProc;
vector<string> _files; vector<string> _files;
string _file; string _file;
bool _relative_path;
string _path_root;
public: public:
parserYAML(){ parserYAML(){
_params = map<string, string>(); _params = map<string, string>();
...@@ -70,6 +72,8 @@ public: ...@@ -70,6 +72,8 @@ public:
_paramsProc = vector<ParamsInitProcessor>(); _paramsProc = vector<ParamsInitProcessor>();
_file = ""; _file = "";
_files = vector<string>(); _files = vector<string>();
_path_root = "";
_relative_path = false;
} }
parserYAML(string file){ parserYAML(string file){
_params = map<string, string>(); _params = map<string, string>();
...@@ -78,6 +82,18 @@ public: ...@@ -78,6 +82,18 @@ public:
_paramsProc = vector<ParamsInitProcessor>(); _paramsProc = vector<ParamsInitProcessor>();
_files = vector<string>(); _files = vector<string>();
_file = file; _file = file;
_path_root = "";
_relative_path = false;
}
parserYAML(string file, string path_root){
_params = map<string, string>();
_active_name = "";
_paramsSens = vector<ParamsInitSensor>();
_paramsProc = vector<ParamsInitProcessor>();
_files = vector<string>();
_file = file;
_path_root = path_root;
_relative_path = true;
} }
~parserYAML(){ ~parserYAML(){
// //
...@@ -104,16 +120,25 @@ string parserYAML::tagsToString(vector<std::string> &tags){ ...@@ -104,16 +120,25 @@ string parserYAML::tagsToString(vector<std::string> &tags){
return hdr; return hdr;
} }
void parserYAML::walkTree(string file){ void parserYAML::walkTree(string file){
YAML::Node n = YAML::LoadFile(file); YAML::Node n;
// cout << "RELATIVE? " << _relative_path << " path root " << _path_root << " file " << file << endl;
if(not _relative_path) n = YAML::LoadFile(file);
else n = YAML::LoadFile(_path_root + file);
vector<string> hdrs = vector<string>(); vector<string> hdrs = vector<string>();
walkTreeR(n, hdrs, ""); walkTreeR(n, hdrs, "");
} }
void parserYAML::walkTree(string file, vector<string>& tags){ void parserYAML::walkTree(string file, vector<string>& tags){
YAML::Node n = YAML::LoadFile(file); YAML::Node n;
// cout << "RELATIVE? " << _relative_path << " path root " << _path_root << " file " << file << endl;
if(not _relative_path) n = YAML::LoadFile(file);
else n = YAML::LoadFile(_path_root + file);
walkTreeR(n, tags, ""); walkTreeR(n, tags, "");
} }
void parserYAML::walkTree(string file, vector<string>& tags, string hdr){ void parserYAML::walkTree(string file, vector<string>& tags, string hdr){
YAML::Node n = YAML::LoadFile(file); YAML::Node n;
// cout << "RELATIVE? " << _relative_path << " path root " << _path_root << " file " << file << endl;
if(not _relative_path) n = YAML::LoadFile(file);
else n = YAML::LoadFile(_path_root + file);
walkTreeR(n, tags, hdr); walkTreeR(n, tags, hdr);
} }
void parserYAML::walkTreeR(YAML::Node n, vector<string>& tags, string hdr){ void parserYAML::walkTreeR(YAML::Node n, vector<string>& tags, string hdr){
...@@ -172,7 +197,10 @@ void parserYAML::updateActiveName(string tag){ ...@@ -172,7 +197,10 @@ void parserYAML::updateActiveName(string tag){
this->_active_name = tag; this->_active_name = tag;
} }
void parserYAML::parseFirstLevel(string file){ void parserYAML::parseFirstLevel(string file){
YAML::Node n = YAML::LoadFile(file); YAML::Node n;
// cout << "RELATIVE? " << _relative_path << " path root " << _path_root << " file " << file << endl;
if(not _relative_path) n = YAML::LoadFile(file);
else n = YAML::LoadFile(_path_root + file);
YAML::Node n_config = n["config"]; YAML::Node n_config = n["config"];
assert(n_config.Type() == YAML::NodeType::Map && "trying to parse config node but found a non-Map node"); assert(n_config.Type() == YAML::NodeType::Map && "trying to parse config node but found a non-Map node");
for(const auto& kv : n_config["sensors"]){ for(const auto& kv : n_config["sensors"]){
......
#include "utils_gtest.h" #include "utils_gtest.h"
#include "base/converter.h" #include "base/converter.h"
#include "base/wolf.h" #include "base/wolf.h"
#include "../hello_plugin/parser_yaml.hpp" #include "base/yaml/parser_yaml.hpp"
#include "base/params_server.hpp" #include "base/params_server.hpp"
using namespace std; using namespace std;
using namespace wolf; using namespace wolf;
parserYAML parse(string _file) std::string wolf_root = _WOLF_ROOT_DIR;
parserYAML parse(string _file, string _path_root)
{ {
parserYAML parser = parserYAML(_file); parserYAML parser = parserYAML(_file, _path_root);
parser.parse(); parser.parse();
return parser; return parser;
} }
TEST(ParamsServer, Default) TEST(ParamsServer, Default)
{ {
std::string wolf_root = _WOLF_ROOT_DIR; auto parser = parse("/test/params1.yaml", wolf_root);
auto parser = parse(wolf_root + "/test/params1.yaml");
auto params = parser.getParams(); auto params = parser.getParams();
paramsServer server = paramsServer(params, parser.sensorsSerialization(), parser.processorsSerialization()); paramsServer server = paramsServer(params, parser.sensorsSerialization(), parser.processorsSerialization());
EXPECT_EQ(server.getParam<double>("should_not_exist", "2.6"), 2.6); EXPECT_EQ(server.getParam<double>("should_not_exist", "2.6"), 2.6);
......
#include "utils_gtest.h" #include "utils_gtest.h"
#include "base/converter.h" #include "base/converter.h"
#include "base/wolf.h" #include "base/wolf.h"
#include "../hello_plugin/parser_yaml.hpp" #include "base/yaml/parser_yaml.hpp"
using namespace std; using namespace std;
using namespace wolf; using namespace wolf;
std::string wolf_root = _WOLF_ROOT_DIR; std::string wolf_root = _WOLF_ROOT_DIR;
parserYAML parse(string _file) parserYAML parse(string _file, string _path_root)
{ {
parserYAML parser = parserYAML(_file); parserYAML parser = parserYAML(_file, _path_root);
parser.parse(); parser.parse();
return parser; return parser;
} }
TEST(ParserYAML, RegularParse) TEST(ParserYAML, RegularParse)
{ {
cout << "WOOT " << wolf_root + "/test/params1.yaml" << endl; auto parser = parse("/test/params1.yaml", wolf_root);
auto parser = parse(wolf_root + "/test/params1.yaml");
auto params = parser.getParams(); auto params = parser.getParams();
// for(auto it : params) // for(auto it : params)
// cout << it.first << " %% " << it.second << endl; // cout << it.first << " %% " << it.second << endl;
...@@ -27,13 +26,13 @@ TEST(ParserYAML, RegularParse) ...@@ -27,13 +26,13 @@ TEST(ParserYAML, RegularParse)
} }
TEST(ParserYAML, ParseMap) TEST(ParserYAML, ParseMap)
{ {
auto parser = parse(wolf_root + "/test/params2.yaml"); auto parser = parse("/test/params2.yaml", wolf_root);
auto params = parser.getParams(); auto params = parser.getParams();
EXPECT_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) TEST(ParserYAML, JumpFile)
{ {
auto parser = parse(wolf_root + "/test/params3.yaml"); auto parser = parse("/test/params3.yaml", wolf_root);
auto params = parser.getParams(); auto params = parser.getParams();
EXPECT_EQ(params["my_proc_test/max_buff_length"], "100"); EXPECT_EQ(params["my_proc_test/max_buff_length"], "100");
EXPECT_EQ(params["my_proc_test/jump/voting_active"], "false"); EXPECT_EQ(params["my_proc_test/jump/voting_active"], "false");
......
...@@ -24,7 +24,7 @@ config: ...@@ -24,7 +24,7 @@ config:
type: "ODOM 2D" type: "ODOM 2D"
name: "my_proc_test" name: "my_proc_test"
sensorname: "odom" sensorname: "odom"
follow: "../test/params3.1.yaml" follow: "/test/params3.1.yaml"
files: files:
- "/home/jcasals/workspace/wip/wolf/lib/libsensor_odo.so" - "/home/jcasals/workspace/wip/wolf/lib/libsensor_odo.so"
- "/home/jcasals/workspace/wip/wolf/lib/librange_bearing.so" - "/home/jcasals/workspace/wip/wolf/lib/librange_bearing.so"
\ No newline at end of file
...@@ -24,8 +24,8 @@ config: ...@@ -24,8 +24,8 @@ config:
type: "ODOM 2D" type: "ODOM 2D"
name: "my_proc_test" name: "my_proc_test"
sensorname: "odom" sensorname: "odom"
follow: "../test/params3.1.yaml" follow: "/test/params3.1.yaml"
jump: "@../test/params3.1.yaml" jump: "@/test/params3.1.yaml"
files: files:
- "/home/jcasals/workspace/wip/wolf/lib/libsensor_odo.so" - "/home/jcasals/workspace/wip/wolf/lib/libsensor_odo.so"
- "/home/jcasals/workspace/wip/wolf/lib/librange_bearing.so" - "/home/jcasals/workspace/wip/wolf/lib/librange_bearing.so"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment