1 #include <unistd.h> // unlink
8 #include "stg/conffiles.h"
12 struct conffile_data {
15 typedef test_group<conffile_data> tg;
16 tg conffile_test_group("CONIGFILE tests group");
18 typedef tg::object testobject;
22 void testobject::test<1>()
24 set_test_name("Check read/write");
27 CONFIGFILE cf("/tmp/test.cf", true);
29 ensure_equals("Correct construction", cf.Error(), 0);
31 cf.WriteString("a", "a-string");
33 cf.WriteDouble("e", 2.718281828);
35 ensure_equals("Correct data flushing", cf.Flush(), 0);
39 CONFIGFILE cf("/tmp/test.cf");
41 ensure_equals("Correct construction (part 2)", cf.Error(), 0);
44 ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0);
46 ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0);
48 ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0);
50 ensure_equals("Correct 'a' value", svalue, "a-string");
51 ensure_equals("Correct 'b' value", ivalue, 0);
52 ensure("Correct 'e' value", dvalue != 0);
55 ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0);
60 void testobject::test<2>()
62 set_test_name("Check empty lines and comments");
65 std::ofstream f("/tmp/test.cf");
67 ensure("Correct construction (part 3)", static_cast<bool>(f));
70 << "a=a-string# a string\n"
78 CONFIGFILE cf("/tmp/test.cf");
80 ensure_equals("Correct construction (part 4)", cf.Error(), 0);
83 ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0);
85 ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0);
87 ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0);
89 ensure_equals("Correct 'a' value", svalue, "a-string");
90 ensure_equals("Correct 'b' value", ivalue, 0);
91 ensure("Correct 'e' value", dvalue != 0);
94 ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0);