13 #include <gtest/gtest.h> 25 EXPECT_STREQ(
"final",
first.read_string(
a,
b,
b).c_str());
32 second.
write(
"one",
"name",
"val");
33 second.
write(
"two",
"names",
"value");
35 EXPECT_EQ(2U, sections.size());
36 if (sections.size() == 2)
38 EXPECT_STREQ(
"one", sections[0].c_str());
39 EXPECT_STREQ(
"two", sections[1].c_str());
47 third.
write(
"sec",
"name",
"val");
48 third.
write(
"sec",
"names",
"value");
50 EXPECT_EQ(2U, names.size());
51 if (names.size() == 2)
53 EXPECT_STREQ(
"name", names[0].c_str());
54 EXPECT_STREQ(
"names", names[1].c_str());
61 "# example config file from std::string\n" 69 EXPECT_EQ(cfg.
read_int(
"test",
"key_num", 0), 4);
76 "key_str = this is a \\\n" 77 "long value that can be \\\n" 78 "split into several lines \\\n" 79 "but read as a single line. \n";
82 "this is a long value that can be split into several lines but read as a " 99 f.open(tmpFile.c_str(), std::ofstream::out);
100 EXPECT_TRUE(f.is_open());
114 "@define MAXSPEED 10\n" 115 "@define MAXOMEGA -30 \n" 120 "var4=$eval{5*MAXSPEED+MAXOMEGA}\n" 121 "var5 = $eval{ MAXSPEED - MAXOMEGA } \n" 122 "varstr1=MAXSPEED\n";
127 EXPECT_EQ(cfg.
read_int(
"test",
"var1", 0), 5);
128 EXPECT_EQ(cfg.
read_int(
"test",
"var2", 0), 10);
129 EXPECT_EQ(cfg.
read_int(
"test",
"var3", 0), -30);
130 EXPECT_NEAR(cfg.
read_double(
"test",
"var4", .0), 20.0, 1e-6);
131 EXPECT_NEAR(cfg.
read_double(
"test",
"var5", .0), 40.0, 1e-6);
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This class allows loading and storing values and vectors of different types from ".ini" files easily.
void getAllSections(vector_string §ions) const override
Returns a list with all the section names.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
This class implements a config file-like interface over a memory-stored string list.
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
std::vector< std::string > vector_string
A type for passing a vector of strings.
std::string getTempFileName()
Returns the name of a proposed temporary file name.
GLsizei const GLchar ** string
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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())
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
TEST(CConfigFileMemory, readwrite)
void getAllKeys(const std::string §ion, vector_string &keys) const override
Returs a list with all the keys into a section.
const std::string sampleCfgTxt
GLubyte GLubyte GLubyte a
void setContent(const utils::CStringList &stringList)
Changes the contents of the virtual "config file".
const std::string expectedStr