Go to the documentation of this file.
13 #include <gtest/gtest.h>
22 EXPECT_STREQ(
"final",
first.read_string(
a,
b,
b).c_str());
27 std::vector<std::string> sections;
29 second.
write(
"one",
"name",
"val");
30 second.
write(
"two",
"names",
"value");
32 EXPECT_EQ(2U, sections.size());
33 if (sections.size() == 2)
35 EXPECT_STREQ(
"one", sections[0].c_str());
36 EXPECT_STREQ(
"two", sections[1].c_str());
42 std::vector<std::string>
names;
44 third.
write(
"sec",
"name",
"val");
45 third.
write(
"sec",
"names",
"value");
47 EXPECT_EQ(2U,
names.size());
48 if (
names.size() == 2)
50 EXPECT_STREQ(
"name",
names[0].c_str());
51 EXPECT_STREQ(
"names",
names[1].c_str());
58 "# example config file from std::string\n"
66 EXPECT_EQ(cfg.
read_int(
"test",
"key_num", 0), 4);
73 "key_str = this is a \\\n"
74 "long value that can be \\\n"
75 "split into several lines \\\n"
76 "but read as a single line. \n";
79 "this is a long value that can be split into several lines but read as a "
96 f.open(tmpFile.c_str(), std::ofstream::out);
97 EXPECT_TRUE(f.is_open());
112 _putenv_s(
"ENV_VAR_MULTIPLIER",
"2");
114 ::setenv(
"ENV_VAR_MULTIPLIER",
"2", 1);
118 "@define MAXSPEED 10\n"
119 "@define MAXOMEGA -30 \n"
124 "var4=$eval{5*MAXSPEED+MAXOMEGA}\n"
125 "var5 = $eval{ MAXSPEED - MAXOMEGA } \n"
126 "var6=$env{ENV_VAR_MULTIPLIER}\n"
127 "varstr1=MAXSPEED\n";
132 EXPECT_EQ(cfg.
read_int(
"test",
"var1", 0), 5);
133 EXPECT_EQ(cfg.
read_int(
"test",
"var2", 0), 10);
134 EXPECT_EQ(cfg.
read_int(
"test",
"var3", 0), -30);
135 EXPECT_NEAR(cfg.
read_double(
"test",
"var4", .0), 20.0, 1e-6);
136 EXPECT_NEAR(cfg.
read_double(
"test",
"var5", .0), 40.0, 1e-6);
137 EXPECT_NEAR(cfg.
read_double(
"test",
"var6", .0), 2.0, 1e-6);
mrpt::config::CConfigFileMemory CConfigFileMemory
void getAllSections(std::vector< std::string > §ions) const override
Returns a list with all the section names.
void write(const std::string §ion, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
void getAllKeys(const std::string §ion, std::vector< std::string > &keys) const override
Returs a list with all the keys into a section.
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
mrpt::config::CConfigFile CConfigFile
std::string getTempFileName()
Returns the name of a proposed temporary file name.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
const std::string sampleCfgTxt
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
void setContent(const std::vector< std::string > &stringList)
Changes the contents of the virtual "config file".
std::vector< string > names
const std::string expectedStr
This class allows loading and storing values and vectors of different types from "....
GLsizei const GLchar ** string
This class implements a config file-like interface over a memory-stored string list.
TEST(CConfigFileMemory, readwrite)
GLubyte GLubyte GLubyte a
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |