MRPT  2.0.2
yaml2config_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/config.h>
11 #if MRPT_HAS_YAMLCPP
12 
13 #include <gtest/gtest.h>
15 
16 // clang-format off
17 const auto sampleYamlTxt = std::string(R"xxx(
18 # example YAML config file from a std::string
19 unscoped_key1: 42
20 maps:
21  pointMaps: 1
22  gridMaps: 2
23 pointMap_00:
24  max_x: 10.0
25  min_x: -10.0
26 gridmap_00: {max_x: 25.0, min_x: -25.0}
27 gridmap_01:
28  foo1: 0
29  layerName: lidar
30 # end of YAMLexample
31 )xxx");
32 // clang-format on
33 
34 const std::string sampleCfgTxt =
35  "# example config file from std::string\n"
36  "[test]\n"
37  "key_num = 4\n"
38  "key_str = pepe\n";
39 
40 const std::string sampleCfgTxt_as_yaml_correct =
41  "test:\n"
42  " key_num: 4\n"
43  " key_str: pepe";
44 
45 TEST(yaml2ini, parse)
46 {
48  c.setContentFromYAML(sampleYamlTxt);
49 
50  // std::cout << "INI-liKe:\n" << c.getContent() << "\n";
51 
52  EXPECT_EQ(1, c.read_int("maps", "pointMaps", 0));
53  EXPECT_EQ(2, c.read_int("maps", "gridMaps", 0));
54  EXPECT_EQ(25.0, c.read_int("gridmap_00", "max_x", 0));
55  EXPECT_EQ(42, c.read_int("", "unscoped_key1", 0));
56 }
57 
58 TEST(ini2yaml, parse)
59 {
62 
63  // Note: we don't compare the exact strings since order of keys may vary (?)
64  EXPECT_EQ(sampleCfgTxt_as_yaml_correct.size(), c.getContentAsYAML().size());
65 }
66 
67 #endif // MRPT_HAS_YAMLCPP
This class implements a config file-like interface over a memory-stored string list.
int read_int(const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
TEST(ICP_SLAM_App, MapFromRawlog_PointMap)
void setContentFromYAML(const std::string &yaml_block)
Changes the contents of the virtual "config file" from a text block containing a YAML configuration t...
void setContent(const std::vector< std::string > &stringList)
Changes the contents of the virtual "config file".
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
std::string getContentAsYAML() const
Returns a text block representing the contents of the config file in YAML format. ...
const std::string sampleCfgTxt



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020