]> git.stg.codes - stg.git/blobdiff - tests/test_conffiles.cpp
Build and test in both Debug and Release mode.
[stg.git] / tests / test_conffiles.cpp
index 5936ad36552456c5bbbdefb304e80596554405ed..688ad346a77f8eb580babb25bd0140d5941af777 100644 (file)
@@ -1,96 +1,89 @@
-#include <unistd.h> // 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 <boost/test/unit_test.hpp>
+#pragma GCC diagnostic pop
 
 #include <string>
 #include <fstream>
 
-#include "tut/tut.hpp"
+#include <unistd.h> // 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<conffile_data> 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<bool>(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)", static_cast<bool>(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()