1 #define BOOST_TEST_MODULE STGConfFiles
3 #include "stg/conffiles.h"
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wold-style-cast"
7 #pragma GCC diagnostic ignored "-Wunused-parameter"
8 #pragma GCC diagnostic ignored "-Wsign-compare"
9 #pragma GCC diagnostic ignored "-Wparentheses"
10 #include <boost/test/unit_test.hpp>
11 #pragma GCC diagnostic pop
16 #include <unistd.h> // unlink
18 BOOST_AUTO_TEST_SUITE(ConfFiles)
20 BOOST_AUTO_TEST_CASE(ReadWrite)
23 CONFIGFILE cf("/tmp/test.cf", true);
25 BOOST_CHECK_EQUAL(cf.Error(), 0);
27 cf.WriteString("a", "a-string");
29 cf.WriteDouble("e", 2.718281828);
31 BOOST_CHECK_EQUAL(cf.Flush(), 0);
35 CONFIGFILE cf("/tmp/test.cf");
37 BOOST_CHECK_EQUAL(cf.Error(), 0);
40 BOOST_CHECK_EQUAL(cf.ReadString("a", &svalue, "a-default"), 0);
42 BOOST_CHECK_EQUAL(cf.ReadInt("b", &ivalue, -1), 0);
44 BOOST_CHECK_EQUAL(cf.ReadDouble("e", &dvalue, 0), 0);
46 BOOST_CHECK_EQUAL(svalue, "a-string");
47 BOOST_CHECK_EQUAL(ivalue, 0);
48 BOOST_CHECK(dvalue != 0);
51 BOOST_CHECK_EQUAL(unlink("/tmp/test.cf"), 0);
54 BOOST_AUTO_TEST_CASE(EmptyLinesAndComments)
57 std::ofstream f("/tmp/test.cf");
59 BOOST_CHECK(static_cast<bool>(f));
62 << "a=a-string# a string\n"
70 CONFIGFILE cf("/tmp/test.cf");
72 BOOST_CHECK_EQUAL(cf.Error(), 0);
75 BOOST_CHECK_EQUAL(cf.ReadString("a", &svalue, "a-default"), 0);
77 BOOST_CHECK_EQUAL(cf.ReadInt("b", &ivalue, -1), 0);
79 BOOST_CHECK_EQUAL(cf.ReadDouble("e", &dvalue, 0), 0);
81 BOOST_CHECK_EQUAL(svalue, "a-string");
82 BOOST_CHECK_EQUAL(ivalue, 0);
83 BOOST_CHECK(dvalue != 0);
86 BOOST_CHECK_EQUAL(unlink("/tmp/test.cf"), 0);
89 BOOST_AUTO_TEST_SUITE_END()