X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/48ca7f876fa5f45a34bfd2d63f1804e5cb5e6a2b..8582d7dfe21e7225d4a715501d70c2649268228f:/tests/test_conffiles.cpp diff --git a/tests/test_conffiles.cpp b/tests/test_conffiles.cpp index 897148f5..688ad346 100644 --- a/tests/test_conffiles.cpp +++ b/tests/test_conffiles.cpp @@ -1,94 +1,89 @@ -#include // unlink +#define BOOST_TEST_MODULE STGConfFiles + +#include "stg/conffiles.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wparentheses" +#include +#pragma GCC diagnostic pop #include #include -#include +#include // unlink -#include "conffiles.h" +BOOST_AUTO_TEST_SUITE(ConfFiles) -namespace tut +BOOST_AUTO_TEST_CASE(ReadWrite) { - struct conffile_data { - }; + { + CONFIGFILE cf("/tmp/test.cf", true); + + BOOST_CHECK_EQUAL(cf.Error(), 0); - typedef test_group tg; - tg conffile_test_group("CONIGFILE tests group"); + cf.WriteString("a", "a-string"); + cf.WriteInt("b", 0); + cf.WriteDouble("e", 2.718281828); - typedef tg::object testobject; + BOOST_CHECK_EQUAL(cf.Flush(), 0); + } - template<> - template<> - void testobject::test<1>() { - set_test_name("Check read/write"); + CONFIGFILE cf("/tmp/test.cf"); - { - CONFIGFILE cf("/tmp/test.cf", true); + BOOST_CHECK_EQUAL(cf.Error(), 0); - ensure_equals("Correct construction", cf.Error(), 0); + std::string svalue; + BOOST_CHECK_EQUAL(cf.ReadString("a", &svalue, "a-default"), 0); + int ivalue; + BOOST_CHECK_EQUAL(cf.ReadInt("b", &ivalue, -1), 0); + double dvalue = 0; + BOOST_CHECK_EQUAL(cf.ReadDouble("e", &dvalue, 0), 0); - ensure_equals("Correct writing 'a' string", cf.WriteString("a", "a-string"), 0); - ensure_equals("Correct writing 'b' integer (0)", cf.WriteInt("b", 0), 0); - ensure_equals("Correct writing 'e' double (2.718281828)", cf.WriteDouble("e", 2.718281828), 0); - } + BOOST_CHECK_EQUAL(svalue, "a-string"); + BOOST_CHECK_EQUAL(ivalue, 0); + BOOST_CHECK(dvalue != 0); + } - { - CONFIGFILE cf("/tmp/test.cf"); + BOOST_CHECK_EQUAL(unlink("/tmp/test.cf"), 0); +} - ensure_equals("Correct construction (part 2)", cf.Error(), 0); - - std::string svalue; - ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0); - int ivalue; - ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0); - double dvalue = 0; - ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0); +BOOST_AUTO_TEST_CASE(EmptyLinesAndComments) +{ + { + std::ofstream f("/tmp/test.cf"); - ensure_equals("Correct 'a' value", svalue, "a-string"); - ensure_equals("Correct 'b' value", ivalue, 0); - ensure("Correct 'e' value", dvalue != 0); - } + BOOST_CHECK(static_cast(f)); - ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0); + f << "\n" + << "a=a-string# a string\n" + << " \n" + << "b=0\n" + << "#abc\n" + << "e=2.718281828\n"; } - template<> - template<> - void testobject::test<2>() { - set_test_name("Check empty lines and comments"); - - { - ofstream f("/tmp/test.cf"); - - ensure("Correct construction (part 3)", f); - - f << "\n" - << "a=a-string# a string\n" - << " \n" - << "b=0\n" - << "#abc\n" - << "e=2.718281828\n"; - } - - { - CONFIGFILE cf("/tmp/test.cf"); - - ensure_equals("Correct construction (part 4)", cf.Error(), 0); - - std::string svalue; - ensure_equals("Correct reading 'a' param as string", cf.ReadString("a", &svalue, "a-default"), 0); - int ivalue; - ensure_equals("Correct reading 'b' param as integer", cf.ReadInt("b", &ivalue, -1), 0); - double dvalue = 0; - ensure_equals("Correct reading 'e' param as double", cf.ReadDouble("e", &dvalue, 0), 0); - - ensure_equals("Correct 'a' value", svalue, "a-string"); - ensure_equals("Correct 'b' value", ivalue, 0); - ensure("Correct 'e' value", dvalue != 0); - } - - ensure_equals("Correct temporary file unlinking", unlink("/tmp/test.cf"), 0); + CONFIGFILE cf("/tmp/test.cf"); + + BOOST_CHECK_EQUAL(cf.Error(), 0); + + std::string svalue; + BOOST_CHECK_EQUAL(cf.ReadString("a", &svalue, "a-default"), 0); + int ivalue; + BOOST_CHECK_EQUAL(cf.ReadInt("b", &ivalue, -1), 0); + double dvalue = 0; + BOOST_CHECK_EQUAL(cf.ReadDouble("e", &dvalue, 0), 0); + + BOOST_CHECK_EQUAL(svalue, "a-string"); + BOOST_CHECK_EQUAL(ivalue, 0); + BOOST_CHECK(dvalue != 0); } + + BOOST_CHECK_EQUAL(unlink("/tmp/test.cf"), 0); } + +BOOST_AUTO_TEST_SUITE_END()