]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use boost unit test framework
authorArvin Schnell <aschnell@suse.de>
Thu, 23 Oct 2014 10:04:29 +0000 (12:04 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 23 Oct 2014 10:04:29 +0000 (12:04 +0200)
testsuite/Makefile.am
testsuite/basename1.cc
testsuite/common.h [deleted file]
testsuite/dirname1.cc
testsuite/sysconfig-get1.cc

index acacf399d2c9b50f5907a6904583f18697123d25..df6db5a14c3a4a141deb5bdaa32153496691a94e 100644 (file)
@@ -2,19 +2,15 @@
 # Makefile.am for snapper/testsuite
 #
 
-CXXFLAGS += -std=gnu++0x
-
 INCLUDES = -I$(top_srcdir)
 
-LDADD = ../snapper/libsnapper.la
+LDADD = ../snapper/libsnapper.la -lboost_unit_test_framework
 
 check_PROGRAMS = sysconfig-get1 dirname1 basename1
 
 TESTS = $(check_PROGRAMS)
 
-basename1_SOURCES = basename1.cc common.h
-dirname1_SOURCES = dirname1.cc common.h
-sysconfig_get1_SOURCES = sysconfig-get1.cc common.h
+AM_DEFAULT_SOURCE_EXT = .cc
 
 EXTRA_DIST = $(noinst_SCRIPTS) sysconfig-get1.txt
 
index baf30f3d3c84c207ebab89fa1c9746cef8b1ee97..861ea8b374c413a895f509ca8cb079fd1676a172 100644 (file)
@@ -1,21 +1,23 @@
 
-#include "common.h"
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE basename1
+
+#include <boost/test/unit_test.hpp>
 
 #include <snapper/AppUtil.h>
 
 using namespace snapper;
 
 
-int
-main()
+BOOST_AUTO_TEST_CASE(basename1)
 {
-    check_equal(basename("/hello/world"), string("world"));
-    check_equal(basename("hello/world"), string("world"));
-    check_equal(basename("/hello"), string("hello"));
-    check_equal(basename("hello"), string("hello"));
-    check_equal(basename("/"), string(""));
-    check_equal(basename(""), string(""));
-    check_equal(basename("."), string("."));
-    check_equal(basename(".."), string(".."));
-    check_equal(basename("../.."), string(".."));
+    BOOST_CHECK_EQUAL(basename("/hello/world"), "world");
+    BOOST_CHECK_EQUAL(basename("hello/world"), "world");
+    BOOST_CHECK_EQUAL(basename("/hello"), "hello");
+    BOOST_CHECK_EQUAL(basename("hello"), "hello");
+    BOOST_CHECK_EQUAL(basename("/"), "");
+    BOOST_CHECK_EQUAL(basename(""), "");
+    BOOST_CHECK_EQUAL(basename("."), ".");
+    BOOST_CHECK_EQUAL(basename(".."), "..");
+    BOOST_CHECK_EQUAL(basename("../.."), "..");
 }
diff --git a/testsuite/common.h b/testsuite/common.h
deleted file mode 100644 (file)
index e4cb4b8..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-
-#include <stdlib.h>
-
-#include <iostream>
-
-using namespace std;
-
-
-template <typename Type> void
-check_failure(const char* str, Type actual, Type expected, const char* file,
-             int line, const char* func)
-{
-    std::cerr << file << ":" << line << ": \"" << func << "\"" << std::endl;
-    std::cerr << "check \"" << str << "\"" << " failed. expected " << expected
-             << ", actual " << actual << "." << std::endl;
-
-    exit(EXIT_FAILURE);
-}
-
-
-#define check_true(expr)                                               \
-    do {                                                               \
-       bool actual = (expr);                                           \
-       if (!actual)                                                    \
-           check_failure(#expr, actual, true, __FILE__, __LINE__,      \
-                         __PRETTY_FUNCTION__);                         \
-    } while (0)
-
-
-#define check_zero(expr)                                               \
-    do {                                                               \
-       int actual = (expr);                                            \
-       if (actual != 0)                                                \
-           check_failure(#expr, actual, 0, __FILE__, __LINE__,         \
-                         __PRETTY_FUNCTION__);                         \
-    } while (0)
-
-
-#define check_equal(expr, expected)                                    \
-    do {                                                               \
-       typeof (expected) actual = (expr);                              \
-       if (actual != expected)                                         \
-           check_failure(#expr, actual, expected, __FILE__, __LINE__,  \
-                         __PRETTY_FUNCTION__);                         \
-    } while (0)
-
index 8ba0062dfcbf673792b1d7fbf5fca98e8482ab9b..6efebe6c9f4fee86f74934b6a38baf4afdec5898 100644 (file)
@@ -1,21 +1,23 @@
 
-#include "common.h"
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE dirname1
+
+#include <boost/test/unit_test.hpp>
 
 #include <snapper/AppUtil.h>
 
 using namespace snapper;
 
 
-int
-main()
+BOOST_AUTO_TEST_CASE(dirname1)
 {
-    check_equal(dirname("/hello/world"), string("/hello"));
-    check_equal(dirname("hello/world"), string("hello"));
-    check_equal(dirname("/hello"), string("/"));
-    check_equal(dirname("hello"), string("."));
-    check_equal(dirname("/"), string("/"));
-    check_equal(dirname(""), string("."));
-    check_equal(dirname("."), string("."));
-    check_equal(dirname(".."), string("."));
-    check_equal(dirname("../.."), string(".."));
+    BOOST_CHECK_EQUAL(dirname("/hello/world"), "/hello");
+    BOOST_CHECK_EQUAL(dirname("hello/world"), "hello");
+    BOOST_CHECK_EQUAL(dirname("/hello"), "/");
+    BOOST_CHECK_EQUAL(dirname("hello"), ".");
+    BOOST_CHECK_EQUAL(dirname("/"), "/");
+    BOOST_CHECK_EQUAL(dirname(""), ".");
+    BOOST_CHECK_EQUAL(dirname("."), ".");
+    BOOST_CHECK_EQUAL(dirname(".."), ".");
+    BOOST_CHECK_EQUAL(dirname("../.."), "..");
 }
index 3e29cd44112385d02e6d18ced07f1eb83dc21bbf..d0eaa4571754e8775b2847130aa0ca2477968b1c 100644 (file)
@@ -1,46 +1,45 @@
 
-#include <boost/algorithm/string.hpp>
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE sysconfig_get1
 
-#include "common.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/algorithm/string.hpp>
 
 #include <snapper/AsciiFile.h>
 
 using namespace snapper;
 
 
-int
-main()
+BOOST_AUTO_TEST_CASE(sysconfig_get1)
 {
     SysconfigFile s("sysconfig-get1.txt");
 
     string tmp_string;
 
-    check_true(s.getValue("S1", tmp_string));
-    check_equal(tmp_string, string("hello"));
+    BOOST_CHECK(s.getValue("S1", tmp_string));
+    BOOST_CHECK_EQUAL(tmp_string, "hello");
 
     bool tmp_bool;
 
-    check_true(s.getValue("B1", tmp_bool));
-    check_equal(tmp_bool, true);
+    BOOST_CHECK(s.getValue("B1", tmp_bool));
+    BOOST_CHECK_EQUAL(tmp_bool, true);
 
-    check_true(s.getValue("B2", tmp_bool));
-    check_equal(tmp_bool, false);
+    BOOST_CHECK(s.getValue("B2", tmp_bool));
+    BOOST_CHECK_EQUAL(tmp_bool, false);
 
     vector<string> tmp_vector;
 
-    check_true(s.getValue("V1", tmp_vector));
-    check_equal(boost::join(tmp_vector, "-"), string("one word"));
-
-    check_true(s.getValue("V2", tmp_vector));
-    check_equal(boost::join(tmp_vector, "-"), string("two-words"));
+    BOOST_CHECK(s.getValue("V1", tmp_vector));
+    BOOST_CHECK_EQUAL(boost::join(tmp_vector, "-"), "one word");
 
-    check_true(s.getValue("V3", tmp_vector));
-    check_equal(boost::join(tmp_vector, "-"), string("now-three-words"));
+    BOOST_CHECK(s.getValue("V2", tmp_vector));
+    BOOST_CHECK_EQUAL(boost::join(tmp_vector, "-"), "two-words");
 
-    check_true(s.getValue("V4", tmp_vector));
-    check_equal(boost::join(tmp_vector, "-"), string("c:\\io.sys"));
+    BOOST_CHECK(s.getValue("V3", tmp_vector));
+    BOOST_CHECK_EQUAL(boost::join(tmp_vector, "-"), "now-three-words");
 
-    check_true(!s.getValue("V5", tmp_vector));
+    BOOST_CHECK(s.getValue("V4", tmp_vector));
+    BOOST_CHECK_EQUAL(boost::join(tmp_vector, "-"), "c:\\io.sys");
 
-    exit(EXIT_SUCCESS);
+    BOOST_CHECK(!s.getValue("V5", tmp_vector));
 }