10 #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());
111 _putenv_s(
"ENV_VAR_MULTIPLIER",
"2");
113 ::setenv(
"ENV_VAR_MULTIPLIER",
"2", 1);
117 "@define MAXSPEED 10\n" 118 "@define MAXOMEGA -30 \n" 123 "var4=$eval{5*MAXSPEED+MAXOMEGA}\n" 124 "var5 = $eval{ MAXSPEED - MAXOMEGA } \n" 125 "var6=$env{ENV_VAR_MULTIPLIER}\n" 126 "varstr1=MAXSPEED\n";
131 EXPECT_EQ(cfg.
read_int(
"test",
"var1", 0), 5);
132 EXPECT_EQ(cfg.
read_int(
"test",
"var2", 0), 10);
133 EXPECT_EQ(cfg.
read_int(
"test",
"var3", 0), -30);
134 EXPECT_NEAR(cfg.
read_double(
"test",
"var4", .0), 20.0, 1e-6);
135 EXPECT_NEAR(cfg.
read_double(
"test",
"var5", .0), 40.0, 1e-6);
136 EXPECT_NEAR(cfg.
read_double(
"test",
"var6", .0), 2.0, 1e-6);
This class implements a config file-like interface over a memory-stored string list.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
This class allows loading and storing values and vectors of different types from ".ini" files easily.
void getAllKeys(const std::string §ion, std::vector< std::string > &keys) const override
Returs a list with all the keys into a section.
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
std::string getTempFileName()
Returns the name of a proposed temporary file name.
mrpt::config::CConfigFile CConfigFile
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
GLsizei const GLchar ** string
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())
std::vector< string > names
void setContent(const std::vector< std::string > &stringList)
Changes the contents of the virtual "config file".
TEST(CConfigFileMemory, readwrite)
mrpt::config::CConfigFileMemory CConfigFileMemory
const std::string sampleCfgTxt
GLubyte GLubyte GLubyte a
const std::string expectedStr