MRPT  1.9.9
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-2019, 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 
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 {
61  c.setContent(sampleCfgTxt);
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.
TEST(NodeletsTests, pub_sub_multithread_test)
const GLubyte * c
Definition: glext.h:6406
GLsizei const GLchar ** string
Definition: glext.h:4116
const std::string sampleCfgTxt



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019