# 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
-#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("../.."), "..");
}
+++ /dev/null
-
-#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)
-
-#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("../.."), "..");
}
-#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));
}