1 #include <unistd.h> // unlink
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 ensure_equals("Correct writing 'a' string", cf.WriteString("a", "a-string"), 0);
32 ensure_equals("Correct writing 'b' integer (0)", cf.WriteInt("b", 0), 0);
33 ensure_equals("Correct writing 'e' double (2.718281828)", cf.WriteDouble("e", 2.718281828), 0);
37 CONFIGFILE cf("/tmp/test.cf");
39 ensure_equals("Correct construction (part 2)", cf.Error(), 0);
42 ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0);
44 ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0);
46 ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0);
48 ensure_equals("Correct 'a' value", svalue, "a-string");
49 ensure_equals("Correct 'b' value", ivalue, 0);
50 ensure("Correct 'e' value", dvalue != 0);
53 ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0);
58 void testobject::test<2>()
60 set_test_name("Check empty lines and comments");
63 ofstream f("/tmp/test.cf");
65 ensure("Correct construction (part 3)", f);
68 << "a=a-string# a string\n"
76 CONFIGFILE cf("/tmp/test.cf");
78 ensure_equals("Correct construction (part 4)", cf.Error(), 0);
81 ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0);
83 ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0);
85 ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0);
87 ensure_equals("Correct 'a' value", svalue, "a-string");
88 ensure_equals("Correct 'b' value", ivalue, 0);
89 ensure("Correct 'e' value", dvalue != 0);
92 ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0);