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) {
37 EXPECT_STREQ(
"one", sections[0].c_str());
38 EXPECT_STREQ(
"two", sections[1].c_str());
46 third.
write(
"sec",
"name",
"val");
47 third.
write(
"sec",
"names",
"value");
49 EXPECT_EQ(2U, names.size());
50 if (names.size() == 2) {
51 EXPECT_STREQ(
"name", names[0].c_str());
52 EXPECT_STREQ(
"names", names[1].c_str());
59 "# example config file from std::string\n" 68 EXPECT_EQ(cfg.
read_int(
"test",
"key_num", 0), 4);
75 "key_str = this is a \\\n" 76 "long value that can be \\\n" 77 "split into several lines \\\n" 78 "but read as a single line. \n";
96 f.open(tmpFile.c_str(), std::ofstream::out);
97 EXPECT_TRUE(f.is_open());
111 "@define MAXSPEED 10\n" 112 "@define MAXOMEGA -30 \n" 117 "var4=$eval{5*MAXSPEED+MAXOMEGA}\n" 118 "var5 = $eval{ MAXSPEED - MAXOMEGA } \n" 119 "varstr1=MAXSPEED\n";
124 EXPECT_EQ(cfg.
read_int(
"test",
"var1", 0), 5);
125 EXPECT_EQ(cfg.
read_int(
"test",
"var2", 0), 10);
126 EXPECT_EQ(cfg.
read_int(
"test",
"var3", 0), -30);
127 EXPECT_NEAR(cfg.
read_double(
"test",
"var4", .0), 20.0, 1e-6);
128 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.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
void getAllSections(vector_string §ions) const MRPT_OVERRIDE
Returns a list with all the section names.
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 BASE_IMPEXP 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, const data_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
void getAllKeys(const std::string §ion, vector_string &keys) const MRPT_OVERRIDE
Returs a list with all the keys into a section.
TEST(CConfigFileMemory, readwrite)
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