X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/da9b6f95cc1927507f2aeddd079528c7368025a1..7ef8de40e0bcdd931f5a400fd586fee3a1aaaeea:/tests/test_conffiles.cpp diff --git a/tests/test_conffiles.cpp b/tests/test_conffiles.cpp index ef63a7a1..688ad346 100644 --- a/tests/test_conffiles.cpp +++ b/tests/test_conffiles.cpp @@ -1,96 +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 "tut/tut.hpp" +#include // unlink -#include "stg/conffiles.h" +BOOST_AUTO_TEST_SUITE(ConfFiles) -namespace tut +BOOST_AUTO_TEST_CASE(ReadWrite) { - struct conffile_data { - }; + { + CONFIGFILE cf("/tmp/test.cf", true); - typedef test_group tg; - tg conffile_test_group("CONIGFILE tests group"); + BOOST_CHECK_EQUAL(cf.Error(), 0); - typedef tg::object testobject; + cf.WriteString("a", "a-string"); + cf.WriteInt("b", 0); + cf.WriteDouble("e", 2.718281828); - template<> - template<> - void testobject::test<1>() - { - set_test_name("Check read/write"); + BOOST_CHECK_EQUAL(cf.Flush(), 0); + } - { - CONFIGFILE cf("/tmp/test.cf", true); + { + CONFIGFILE cf("/tmp/test.cf"); - ensure_equals("Correct construction", cf.Error(), 0); + BOOST_CHECK_EQUAL(cf.Error(), 0); - cf.WriteString("a", "a-string"); - cf.WriteInt("b", 0); - cf.WriteDouble("e", 2.718281828); + 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 data flushing", cf.Flush(), 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"); - - { - std::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()