summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2013-09-08 20:49:30 +0100
committerRoger Leigh <rleigh@debian.org>2013-09-08 20:49:30 +0100
commitf03585e22fe5fb1fe07e27de99418233e4081647 (patch)
treef18f360a25190234c201c7306c535a90f94e55d5
parent0d7ffd2e4778bdec29ab8e2fadb62f5ef793c5fa (diff)
parent90dda8b25a2a0914474e7fed26d155de9be7aae1 (diff)
downloadschroot-f03585e22fe5fb1fe07e27de99418233e4081647.tar.gz
Merge branch 'gtest'
-rw-r--r--.gitignore1
-rw-r--r--NEWS5
-rw-r--r--README13
-rw-r--r--configure.ac29
-rw-r--r--debian/changelog12
-rw-r--r--debian/control3
-rwxr-xr-xdebian/rules13
-rw-r--r--lib/test/Makefile.am2
-rw-r--r--lib/test/testmain.cc20
-rw-r--r--scripts/.gitignore2
-rw-r--r--scripts/global.mk4
-rw-r--r--test/.gitignore3
-rw-r--r--test/Makefile.am126
-rw-r--r--test/bin-common/option-action.cc168
-rw-r--r--test/sbuild/chroot/block-device.cc464
-rw-r--r--test/sbuild/chroot/btrfs-snapshot.cc456
-rw-r--r--test/sbuild/chroot/chroot.cc372
-rw-r--r--test/sbuild/chroot/chroot.h135
-rw-r--r--test/sbuild/chroot/config.cc281
-rw-r--r--test/sbuild/chroot/custom.cc211
-rw-r--r--test/sbuild/chroot/directory.cc546
-rw-r--r--test/sbuild/chroot/facet/userdata.cc205
-rw-r--r--test/sbuild/chroot/file.cc417
-rw-r--r--test/sbuild/chroot/loopback.cc518
-rw-r--r--test/sbuild/chroot/lvm-snapshot.cc403
-rw-r--r--test/sbuild/chroot/plain.cc165
-rw-r--r--test/sbuild/environment.cc555
-rw-r--r--test/sbuild/keyfile.cc405
-rw-r--r--test/sbuild/lock.cc228
-rw-r--r--test/sbuild/log.cc204
-rw-r--r--test/sbuild/nostream.cc25
-rw-r--r--test/sbuild/parse-value.cc139
-rw-r--r--test/sbuild/personality.cc164
-rw-r--r--test/sbuild/regex.cc107
-rw-r--r--test/sbuild/run-parts.cc138
-rw-r--r--test/sbuild/util.cc109
36 files changed, 2985 insertions, 3663 deletions
diff --git a/.gitignore b/.gitignore
index ac44c1d0..ce264ba8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,4 @@ build-stamp
ChangeLog
VERSION
.gdb_history
+test-suite.log
diff --git a/NEWS b/NEWS
index 17a0a5ba..3aab7ca4 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,11 @@ Full installation instructions are provided in the INSTALL file. The
README file also contains more specific notes regarding building and
configuration.
+* Major changes in 1.7.1:
+
+ 1) The unit tests now use Google Test (gtest) instead of the older and
+ less powerful CppUnit. See the README for how to build with gtest.
+
* Major changes in 1.7.0:
1) Support for disassociating networking in the chroot from the host
diff --git a/README b/README
index 478d543b..8567565b 100644
--- a/README
+++ b/README
@@ -32,6 +32,19 @@ gettext (0.16 or greater)
doxygen
po4a (>=0.40)
+To run the unit tests, you will optionally need:
+cmake
+gtest
+
+configure with GTEST_ROOT=/path/to/libgtest (it will be added as a
+linker -L option). On Debian systems, which don't provide a
+precompiled libgtest, build a version for the build with, for
+example:
+ mkdir gtest
+ cd gtest; \
+ CXX="g++ -std=c++11" cmake /usr/src/gtest ; \
+ make VERBOSE=1
+ ./configure CXX="g++ -std=c++11" GTEST_ROOT="$(pwd)/gtest"
Translation
-----------
diff --git a/configure.ac b/configure.ac
index d86d44b8..0d40a2d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,7 +85,7 @@ AC_SUBST([SBUILD_INTERFACE_AGE])
AC_SUBST([SBUILD_BINARY_AGE])
dnl Initialise automake stuff.
-AM_INIT_AUTOMAKE([1.10 gnu -Wno-portability subdir-objects check-news dist-xz no-dist-gzip tar-pax])
+AM_INIT_AUTOMAKE([1.10 gnu -Wno-portability subdir-objects check-news dist-xz no-dist-gzip tar-pax serial-tests])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
RELEASE_DATE='m4_esyscmd_s(date --date='m4_esyscmd_s([sed -ne '/^Release-Date:/{s/Release-Date:[[:space:]][[:space:]]*//p;q}' VERSION])' '+%s')'
RELEASE_DATE_S='m4_esyscmd_s([sed -ne '/^Release-Date:/{s/Release-Date:[[:space:]][[:space:]]*//p;q}' VERSION])'
@@ -260,8 +260,7 @@ if test -z "$LVCREATE" || test -z "$LVREMOVE"; then
fi
HAVE_BTRFS="yes"
AC_PATH_PROG([BTRFS], [btrfs], [], [$PATH:/sbin:/usr/sbin])
-AC_PATH_PROG([BTRFSCTL], [btrfsctl], [], [$PATH:/sbin:/usr/sbin])
-if test -z "$BTRFS" || test -z "$BTRFSCTL"; then
+if test -z "$BTRFS"; then
HAVE_BTRFS="no"
fi
HAVE_LOOPBACK="yes"
@@ -301,8 +300,28 @@ AC_DEFINE_UNQUOTED(SBUILD_HOST_CPU, ["$host_cpu"])
# Checks for libraries.
-AM_PATH_CPPUNIT([1.10.0], [HAVE_CPPUNIT=yes])
-AM_CONDITIONAL([USE_UNIT_TESTS], [test -n "$HAVE_CPPUNIT"])
+AC_MSG_CHECKING([for gtest])
+if test -d "$GTEST_ROOT"; then
+ LDFLAGS="$LDFLAGS -L$GTEST_ROOT"
+fi
+GTEST_LIBS="-lgtest"
+saved_CFLAGS="${CFLAGS}"
+saved_LIBS="${LIBS}"
+CXXFLAGS="${saved_CXXFLAGS} ${PTHREAD_CFLAGS}"
+LIBS="${saved_LIBS} ${GTEST_LIBS} ${PTHREAD_LIBS}"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <gtest/gtest.h>],
+ [testing::InitGoogleTest(static_cast<int*>(0), static_cast<char**>(0)); return RUN_ALL_TESTS();])],
+ [AC_MSG_RESULT([yes])
+ HAVE_GTEST=true],
+ [AC_MSG_RESULT([no])
+ AC_MSG_WARN([libgtest (Google Test) not found; this is optional, needed to run the unit tests])
+ GTEST_LIBS=""
+ HAVE_GTEST=""])
+CXXFLAGS="${saved_CXXFLAGS}"
+LIBS="${saved_LIBS}"
+AC_SUBST([GTEST_LIBS])
+
+AM_CONDITIONAL([USE_UNIT_TESTS], [test -n "$HAVE_GTEST"])
SCHROOT_CFLAGS=""
AC_SUBST([SCHROOT_CFLAGS])
diff --git a/debian/changelog b/debian/changelog
index 0a1d5d37..c9fe3fdf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+schroot (1.7.1-1) UNRELEASED; urgency=low
+
+ * New upstream development release.
+ * debian/control:
+ - Add cmake and gtest build dependencies.
+ - Drop cppunit from build dependencies.
+ * debian/rules:
+ - Build and configure gtest support.
+ - Drop BTRFSCTL, which is no longer used by configure.
+
+ -- Roger Leigh <rleigh@debian.org> Sat, 07 Sep 2013 23:24:40 +0100
+
schroot (1.7.0-1) experimental; urgency=low
* New upstream development release.
diff --git a/debian/control b/debian/control
index 5b5e1e5f..82ee1970 100644
--- a/debian/control
+++ b/debian/control
@@ -6,6 +6,7 @@ Uploaders: Roger Leigh <rleigh@debian.org>
Build-Depends:
debhelper (>= 9),
autotools-dev,
+ cmake,
pkg-config,
libpam0g-dev,
libboost-dev,
@@ -14,7 +15,7 @@ Build-Depends:
libboost-regex-dev,
libboost-filesystem-dev,
gettext,
- libcppunit-dev,
+ libgtest-dev,
groff-base,
po4a (>= 0.40)
Build-Depends-Indep:
diff --git a/debian/rules b/debian/rules
index 3330230d..d88422d2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -41,21 +41,28 @@ DH_INSTALL_FILES = $(basename $(wildcard debian/*.install.in))
override_dh_auto_configure: debian/build/config.status
-debian/build/config.status: configure
+debian/build/gtest/libgtest.a:
+ mkdir -p $(dir $@)
+ cd $(dir $@) ; \
+ CXX="g++ -std=c++11" cmake /usr/src/gtest ; \
+ make VERBOSE=1
+
+debian/build/config.status: configure debian/build/gtest/libgtest.a
dh_auto_configure -- \
--enable-dchroot --enable-dchroot-dsa \
--with-bash-completion-dir=/etc/bash_completion.d \
$(LVMSNAP_OPTIONS) $(BTRFSSNAP_OPTIONS) \
BTRFS=/sbin/btrfs \
- BTRFSCTL=/sbin/btrfsctl \
LVCREATE=/sbin/lvcreate \
LVREMOVE=/sbin/lvremove \
- CXX='g++ -std=gnu++11'
+ CXX='g++ -std=gnu++11' \
+ GTEST_ROOT="$(CURDIR)/debian/build/gtest"
dh_testdir
override_dh_auto_clean:
dh_auto_clean
rm -f $(DH_INSTALL_FILES)
+ rm -rf debian/build
rm -rf debian/install
override_dh_auto_build:
diff --git a/lib/test/Makefile.am b/lib/test/Makefile.am
index 8de09f20..4d87f1b4 100644
--- a/lib/test/Makefile.am
+++ b/lib/test/Makefile.am
@@ -22,5 +22,5 @@ endif
lib_test_libtest_la_SOURCES = \
lib/test/testmain.cc
-lib_test_libtest_la_LIBADD = $(top_builddir)/lib/sbuild/libsbuild.la $(CPPUNIT_LIBS)
+lib_test_libtest_la_LIBADD = $(top_builddir)/lib/sbuild/libsbuild.la $(GTEST_LIBS)
diff --git a/lib/test/testmain.cc b/lib/test/testmain.cc
index 97dd7b1f..efeb69f3 100644
--- a/lib/test/testmain.cc
+++ b/lib/test/testmain.cc
@@ -20,15 +20,11 @@
#include <sbuild/log.h>
-#include <cstdlib>
-
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-
-using namespace CppUnit;
+#include <gtest/gtest.h>
int
-main()
+main(int argc,
+ char *argv[])
{
#ifdef SBUILD_DEBUG
sbuild::debug_log_level = sbuild::DEBUG_NOTICE;
@@ -36,12 +32,6 @@ main()
sbuild::debug_log_level = sbuild::DEBUG_NONE;
#endif
- TextUi::TestRunner runner;
-
- TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
- runner.addTest(registry.makeTest());
-
- bool ok = runner.run();
-
- return (ok) ? EXIT_SUCCESS : EXIT_FAILURE;
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
}
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 28d37439..0707328a 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -7,3 +7,5 @@ ltmain.sh
missing
mkinstalldirs
po-notify
+compile
+test-driver
diff --git a/scripts/global.mk b/scripts/global.mk
index 76b28bbc..47c2d22f 100644
--- a/scripts/global.mk
+++ b/scripts/global.mk
@@ -16,6 +16,8 @@
#
#####################################################################
+DEFAULT_INCLUDES=
+
schroot_mountdir=$(localstatedir)/lib/$(PACKAGE)/mount
schroot_sessiondir=$(localstatedir)/lib/$(PACKAGE)/session
schroot_file_unpackdir=$(localstatedir)/lib/$(PACKAGE)/unpack
@@ -29,7 +31,7 @@ schroot_setupdatadir=$(pkgdatadir)/setup
SCHROOT_CONF=$(schroot_sysconfdir)/schroot.conf
# Global options for use in all Makefiles.
-AM_CXXFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/libexec -I$(top_srcdir)/bin $(LOCAL_CXXFLAGS) $(PTHREAD_CFLAGS) -pedantic -Wall -Wcast-align -Wwrite-strings -Wswitch-default -Wcast-qual -Wunused-variable -Wredundant-decls -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Wold-style-cast -Woverloaded-virtual -fstrict-aliasing
+AM_CXXFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/libexec -I$(top_srcdir)/bin $(LOCAL_CXXFLAGS) $(PTHREAD_CFLAGS) -pedantic -Wall -Wcast-align -Wwrite-strings -Wswitch-default -Wcast-qual -Wunused-variable -Wredundant-decls -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Wold-style-cast -Woverloaded-virtual -fstrict-aliasing
AM_LDFLAGS = $(LOCAL_LDFLAGS) $(PTHREAD_LIBS)
diff --git a/test/.gitignore b/test/.gitignore
index 8a4a875d..b2b8fab9 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -20,4 +20,5 @@ sbuild/regex
sbuild/run-parts
sbuild/util
bin-common/option-action
-
+*.log
+*.trs
diff --git a/test/Makefile.am b/test/Makefile.am
index 1c5b03ad..e60bc86e 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,56 +20,21 @@ if USE_UNIT_TESTS
noinst_PROGRAMS += \
test/sbuild/chroot/chroot \
- test/sbuild/chroot/plain \
- test/sbuild/chroot/custom \
- test/sbuild/chroot/file \
- test/sbuild/chroot/directory \
- test/sbuild/chroot/block-device \
- test/sbuild/chroot/loopback \
- test/sbuild/chroot/lvm-snapshot \
- test/sbuild/chroot/btrfs-snapshot \
test/sbuild/chroot/config \
- test/sbuild/chroot/facet/userdata \
- test/sbuild/environment \
+ test/sbuild/standard \
test/sbuild/keyfile \
test/sbuild/lock \
- test/sbuild/log \
- test/sbuild/nostream \
- test/sbuild/parse-value \
- test/sbuild/regex \
test/sbuild/run-parts \
- test/sbuild/util \
test/bin-common/option-action
-if BUILD_PERSONALITY
-noinst_PROGRAMS += \
- test/sbuild/personality
-personality_tests = test/sbuild/personality
-endif
-
-# sbuild-lock is excluded, because it is timing dependent and can fail
+# lock is excluded, because it is timing dependent and can fail
# randomly on slow or heavily-loaded systems.
TESTS = test/setup-test-data \
test/sbuild/chroot/chroot \
- test/sbuild/chroot/plain \
- test/sbuild/chroot/custom \
- test/sbuild/chroot/file \
- test/sbuild/chroot/directory \
- test/sbuild/chroot/block-device \
- test/sbuild/chroot/loopback \
- test/sbuild/chroot/lvm-snapshot \
- test/sbuild/chroot/btrfs-snapshot \
test/sbuild/chroot/config \
- test/sbuild/chroot/facet/userdata \
- test/sbuild/environment \
+ test/sbuild/standard \
test/sbuild/keyfile \
- test/sbuild/log \
- test/sbuild/nostream \
- test/sbuild/parse-value \
- $(personality_tests) \
test/sbuild/run-parts \
- test/sbuild/regex \
- test/sbuild/util \
test/bin-common/option-action \
test/cleanup-test-data
endif
@@ -94,61 +59,36 @@ test_sbuild_chroot_btrfssnap_sources = \
test/sbuild/chroot/btrfs-snapshot.cc
endif
+if BUILD_PERSONALITY
+test_sbuild_personality_sources = \
+ test/sbuild/personality.cc
+endif
test_sbuild_chroot_chroot_SOURCES = \
- test/sbuild/chroot/chroot.cc \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_chroot_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_plain_SOURCES = \
- test/sbuild/chroot/plain.cc \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_plain_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_custom_SOURCES = \
- test/sbuild/chroot/custom.cc \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_custom_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_file_SOURCES = \
- test/sbuild/chroot/file.cc \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_file_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_directory_SOURCES = \
- test/sbuild/chroot/directory.cc \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_directory_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_block_device_SOURCES = \
+ test/sbuild/chroot/chroot.h \
+ test/sbuild/chroot/chroot.cc \
+ test/sbuild/chroot/plain.cc \
+ test/sbuild/chroot/custom.cc \
+ test/sbuild/chroot/file.cc \
+ test/sbuild/chroot/directory.cc \
$(test_sbuild_chroot_blockdev_sources) \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_block_device_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_lvm_snapshot_SOURCES = \
$(test_sbuild_chroot_lvmsnap_sources) \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_lvm_snapshot_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_btrfs_snapshot_SOURCES = \
$(test_sbuild_chroot_btrfssnap_sources) \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_btrfs_snapshot_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_loopback_SOURCES = \
$(test_sbuild_chroot_loopback_sources) \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_loopback_LDADD = lib/test/libtest.la
-
-test_sbuild_chroot_facet_userdata_SOURCES = \
- test/sbuild/chroot/facet/userdata.cc \
- test/sbuild/chroot/chroot.h
-test_sbuild_chroot_facet_userdata_LDADD = lib/test/libtest.la
+ test/sbuild/chroot/facet/userdata.cc
+test_sbuild_chroot_chroot_LDADD = lib/test/libtest.la
test_sbuild_chroot_config_SOURCES = test/sbuild/chroot/config.cc
test_sbuild_chroot_config_LDADD = lib/test/libtest.la
-test_sbuild_environment_SOURCES = test/sbuild/environment.cc
-test_sbuild_environment_LDADD = lib/test/libtest.la
+test_sbuild_standard_SOURCES = \
+ test/sbuild/environment.cc \
+ test/sbuild/log.cc \
+ test/sbuild/nostream.cc \
+ test/sbuild/parse-value.cc \
+ $(test_sbuild_personality_sources) \
+ test/sbuild/regex.cc \
+ test/sbuild/util.cc
+test_sbuild_standard_LDADD = lib/test/libtest.la
test_sbuild_keyfile_SOURCES = test/sbuild/keyfile.cc
test_sbuild_keyfile_LDADD = lib/test/libtest.la
@@ -156,27 +96,9 @@ test_sbuild_keyfile_LDADD = lib/test/libtest.la
test_sbuild_lock_SOURCES = test/sbuild/lock.cc
test_sbuild_lock_LDADD = lib/test/libtest.la
-test_sbuild_log_SOURCES = test/sbuild/log.cc
-test_sbuild_log_LDADD = lib/test/libtest.la
-
-test_sbuild_nostream_SOURCES = test/sbuild/nostream.cc
-test_sbuild_nostream_LDADD = lib/test/libtest.la
-
-test_sbuild_parse_value_SOURCES = test/sbuild/parse-value.cc
-test_sbuild_parse_value_LDADD = lib/test/libtest.la
-
-test_sbuild_personality_SOURCES = test/sbuild/personality.cc
-test_sbuild_personality_LDADD = lib/test/libtest.la
-
-test_sbuild_regex_SOURCES = test/sbuild/regex.cc
-test_sbuild_regex_LDADD = lib/test/libtest.la
-
test_sbuild_run_parts_SOURCES = test/sbuild/run-parts.cc
test_sbuild_run_parts_LDADD = lib/test/libtest.la
-test_sbuild_util_SOURCES = test/sbuild/util.cc
-test_sbuild_util_LDADD = lib/test/libtest.la
-
test_bin_common_option_action_SOURCES = test/bin-common/option-action.cc
test_bin_common_option_action_LDADD = $(top_builddir)/lib/bin-common/libbin-common.la lib/test/libtest.la
diff --git a/test/bin-common/option-action.cc b/test/bin-common/option-action.cc
index 18e0c73c..4a0674e1 100644
--- a/test/bin-common/option-action.cc
+++ b/test/bin-common/option-action.cc
@@ -16,46 +16,29 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <bin-common/option-action.h>
#include <bin-common/options.h>
#include <iostream>
-#include <cppunit/extensions/HelperMacros.h>
-
using bin_common::option_action;
-using namespace CppUnit;
-class test_option_action : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_option_action);
- CPPUNIT_TEST(test_construction);
- CPPUNIT_TEST(test_default);
- CPPUNIT_TEST_EXCEPTION(test_default_fail, bin_common::options::error);
- CPPUNIT_TEST(test_current);
- CPPUNIT_TEST_EXCEPTION(test_current_fail, bin_common::options::error);
- CPPUNIT_TEST_EXCEPTION(test_current_fail_multipleset,
- bin_common::options::error);
- CPPUNIT_TEST(test_operators);
- CPPUNIT_TEST_EXCEPTION(test_operators_fail_multipleset,
- bin_common::options::error);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- option_action *action;
+class OptionAction : public ::testing::Test
+{
public:
- test_option_action():
- TestFixture(),
- action()
- {}
+ option_action *action;
- virtual ~test_option_action()
- {}
+ void SetUp()
+ {
+ action = new option_action;
+ }
- void setUp()
+ void TearDown()
{
- this->action = new option_action;
+ delete action;
}
static void
@@ -67,92 +50,77 @@ public:
act.add("info");
act.add("config");
}
+};
- void tearDown()
- {
- delete this->action;
- }
-
- void
- test_construction()
- {
- option_action act;
- }
-
- void
- test_default()
- {
- add_examples(*this->action);
- CPPUNIT_ASSERT(this->action->get_default() == "");
- CPPUNIT_ASSERT(this->action->get() == "");
+TEST_F(OptionAction, Construct)
+{
+ ASSERT_NO_THROW(option_action act);
+}
- this->action->set_default("info");
- CPPUNIT_ASSERT(this->action->get_default() == "info");
- CPPUNIT_ASSERT(this->action->get() == "info");
- }
+TEST_F(OptionAction, Default)
+{
+ add_examples(*action);
+ EXPECT_EQ(action->get_default(), "");
+ EXPECT_EQ(action->get(), "");
- void
- test_default_fail()
- {
- add_examples(*this->action);
+ action->set_default("info");
+ EXPECT_EQ(action->get_default(), "info");
+ EXPECT_EQ(action->get(), "info");
+}
- this->action->set_default("invalid");
- }
+TEST_F(OptionAction, DefaultFail)
+{
+ add_examples(*action);
- void
- test_current()
- {
- add_examples(*this->action);
+ ASSERT_THROW(action->set_default("invalid"), bin_common::options::error);
+}
- CPPUNIT_ASSERT(this->action->get_default() == "");
- CPPUNIT_ASSERT(this->action->get() == "");
- this->action->set_default("list");
+TEST_F(OptionAction, Current)
+{
+ add_examples(*action);
- CPPUNIT_ASSERT(this->action->get_default() == "list");
- CPPUNIT_ASSERT(this->action->get() == "list");
+ EXPECT_EQ(action->get_default(), "");
+ EXPECT_EQ(action->get(), "");
+ action->set_default("list");
- this->action->set("config");
- CPPUNIT_ASSERT(this->action->get_default() == "list");
- CPPUNIT_ASSERT(this->action->get() == "config");
- }
+ EXPECT_EQ(action->get_default(), "list");
+ EXPECT_EQ(action->get(), "list");
- void
- test_current_fail()
- {
- add_examples(*this->action);
+ action->set("config");
+ EXPECT_EQ(action->get_default(), "list");
+ EXPECT_EQ(action->get(), "config");
+}
- this->action->set("invalid");
- }
+TEST_F(OptionAction, CurrentFail)
+{
+ add_examples(*action);
- void
- test_current_fail_multipleset()
- {
- add_examples(*this->action);
+ ASSERT_THROW(action->set("invalid"), bin_common::options::error);
+}
- this->action->set("list");
- this->action->set("info");
- }
+TEST_F(OptionAction, CurrentFailMultipleSet)
+{
+ add_examples(*action);
- void
- test_operators()
- {
- add_examples(*this->action);
+ ASSERT_NO_THROW(action->set("list"));
+ ASSERT_THROW(action->set("info"), bin_common::options::error);
+}
- *this->action = "list";
- CPPUNIT_ASSERT(*this->action == "list");
- CPPUNIT_ASSERT(!(*this->action != "list"));
- CPPUNIT_ASSERT(*this->action != "invalid");
- CPPUNIT_ASSERT(!(*this->action == "invalid"));
- }
+TEST_F(OptionAction, Operators)
+{
+ add_examples(*action);
- void
- test_operators_fail_multipleset()
- {
- add_examples(*this->action);
+ *action = "list";
+ EXPECT_TRUE(*action == "list");
+ EXPECT_FALSE(*action !="list");
+ EXPECT_TRUE(*action != "invalid");
+ EXPECT_FALSE(*action == "invalid");
+}
- *this->action = "list";
- *this->action = "config";
- }
-};
+TEST_F(OptionAction, OperatorsFailMultipleSet)
+{
+ add_examples(*action);
-CPPUNIT_TEST_SUITE_REGISTRATION(test_option_action);
+ ASSERT_NO_THROW(*action = "list");
+ ASSERT_THROW(*action = "config", bin_common::options::error);
+}
diff --git a/test/sbuild/chroot/block-device.cc b/test/sbuild/chroot/block-device.cc
index 19ac7b06..ac4e95f5 100644
--- a/test/sbuild/chroot/block-device.cc
+++ b/test/sbuild/chroot/block-device.cc
@@ -28,95 +28,43 @@
#include <test/sbuild/chroot/chroot.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
using sbuild::_;
-class test_chroot_block_device : public test_chroot_base
+class ChrootBlockDevice : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_block_device);
- CPPUNIT_TEST(test_device);
- CPPUNIT_TEST(test_mount_options);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_env_session);
-#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_env_union);
- CPPUNIT_TEST(test_setup_env_session_union);
- CPPUNIT_TEST(test_setup_env_source_union);
-#endif // SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_setup_keyfile_session);
-#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_keyfile_union);
- CPPUNIT_TEST(test_setup_keyfile_session_union);
- CPPUNIT_TEST(test_setup_keyfile_source_union);
-#endif // SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_session_flags);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot_block_device():
- test_chroot_base("block-device")
+ ChrootBlockDevice():
+ ChrootBase("block-device")
{}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(session);
- CPPUNIT_ASSERT(!source);
- CPPUNIT_ASSERT(!session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_NE(session, nullptr);
+ ASSERT_EQ(source, nullptr);
+ ASSERT_EQ(session_source, nullptr);
#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_ASSERT(chroot_union);
- CPPUNIT_ASSERT(session_union);
- CPPUNIT_ASSERT(source_union);
- CPPUNIT_ASSERT(session_source_union);
+ ASSERT_NE(chroot_union, nullptr);
+ ASSERT_NE(session_union, nullptr);
+ ASSERT_NE(source_union, nullptr);
+ ASSERT_NE(session_source_union, nullptr);
#endif // SBUILD_FEATURE_UNION
}
virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
chroot->get_facet_strict<sbuild::chroot::facet::block_device>()->set_device("/dev/testdev");
sbuild::chroot::facet::mountable::ptr pmnt(chroot->get_facet<sbuild::chroot::facet::mountable>());
- CPPUNIT_ASSERT(pmnt);
+ ASSERT_NE(pmnt, nullptr);
pmnt->set_mount_options("-t jfs -o quota,rw");
pmnt->set_location("/squeeze");
}
- void
- test_device()
- {
- chroot->get_facet_strict<sbuild::chroot::facet::block_device>()->set_device("/dev/some/device");
- CPPUNIT_ASSERT(chroot->get_facet_strict<sbuild::chroot::facet::block_device>()->get_device() == "/dev/some/device");
- }
-
- void
- test_mount_options()
- {
- sbuild::chroot::facet::mountable::ptr pmnt(chroot->get_facet<sbuild::chroot::facet::mountable>());
- CPPUNIT_ASSERT(pmnt);
-
- pmnt->set_mount_options("-o opt1,opt2");
- CPPUNIT_ASSERT(pmnt->get_mount_options() == "-o opt1,opt2");
- pmnt->set_location("/squeeze");
- CPPUNIT_ASSERT(pmnt->get_location() == "/squeeze");
- }
-
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "block-device");
- }
-
void setup_env_gen(sbuild::environment& expected)
{
setup_env_chroot(expected);
@@ -129,216 +77,236 @@ public:
expected.add("CHROOT_MOUNT_OPTIONS", "-t jfs -o quota,rw");
}
- void test_setup_env()
+ void setup_keyfile_block(sbuild::keyfile &expected, std::string group)
{
- sbuild::environment expected;
- setup_env_gen(expected);
+ expected.set_value(group, "type", "block-device");
+ expected.set_value(group, "device", "/dev/testdev");
+ expected.set_value(group, "location", "/squeeze");
+ expected.set_value(group, "mount-options", "-t jfs -o quota,rw");
+ }
+};
+
+TEST_F(ChrootBlockDevice, Device)
+{
+ chroot->get_facet_strict<sbuild::chroot::facet::block_device>()->set_device("/dev/some/device");
+ ASSERT_EQ(chroot->get_facet_strict<sbuild::chroot::facet::block_device>()->get_device(),
+ "/dev/some/device");
+}
+
+TEST_F(ChrootBlockDevice, MountOptions)
+{
+ sbuild::chroot::facet::mountable::ptr pmnt(chroot->get_facet<sbuild::chroot::facet::mountable>());
+ ASSERT_NE(pmnt, nullptr);
+
+ pmnt->set_mount_options("-o opt1,opt2");
+ ASSERT_EQ(pmnt->get_mount_options(), "-o opt1,opt2");
+ pmnt->set_location("/squeeze");
+ ASSERT_EQ(pmnt->get_location(), "/squeeze");
+}
+
+TEST_F(ChrootBlockDevice, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "block-device");
+}
+
+TEST_F(ChrootBlockDevice, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
#ifdef SBUILD_FEATURE_UNION
- expected.add("CHROOT_UNION_TYPE", "none");
+ expected.add("CHROOT_UNION_TYPE", "none");
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_env(chroot, expected);
- }
+ ChrootBase::test_setup_env(chroot, expected);
+}
- void test_setup_env_session()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "false");
- expected.add("CHROOT_MOUNT_DEVICE", "/dev/testdev");
+TEST_F(ChrootBlockDevice, SetupEnvSession)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_MOUNT_DEVICE", "/dev/testdev");
#ifdef SBUILD_FEATURE_UNION
- expected.add("CHROOT_UNION_TYPE", "none");
+ expected.add("CHROOT_UNION_TYPE", "none");
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_env(session, expected);
- }
+ ChrootBase::test_setup_env(session, expected);
+}
#ifdef SBUILD_FEATURE_UNION
- void test_setup_env_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_SESSION_CLONE", "true");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
- expected.add("CHROOT_UNION_TYPE", "aufs");
- expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
- expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay");
- expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay");
-
- test_chroot_base::test_setup_env(chroot_union, expected);
- }
-
- void test_setup_env_session_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("SESSION_ID", "test-union-session-name");
- expected.add("CHROOT_ALIAS", "test-union-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "true");
- expected.add("CHROOT_MOUNT_DEVICE", "/dev/testdev");
- expected.add("CHROOT_UNION_TYPE", "aufs");
- expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
- expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay/test-union-session-name");
- expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay/test-union-session-name");
- test_chroot_base::test_setup_env(session_union, expected);
- }
-
- void test_setup_env_source_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
+TEST_F(ChrootBlockDevice, SetupEnvUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_SESSION_CLONE", "true");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_UNION_TYPE", "aufs");
+ expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
+ expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay");
+ expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay");
+
+ ChrootBase::test_setup_env(chroot_union, expected);
+}
+
+TEST_F(ChrootBlockDevice, SetupEnvSessionUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("SESSION_ID", "test-union-session-name");
+ expected.add("CHROOT_ALIAS", "test-union-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "true");
+ expected.add("CHROOT_MOUNT_DEVICE", "/dev/testdev");
+ expected.add("CHROOT_UNION_TYPE", "aufs");
+ expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
+ expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay/test-union-session-name");
+ expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay/test-union-session-name");
+ ChrootBase::test_setup_env(session_union, expected);
+}
+
+TEST_F(ChrootBlockDevice, SetupEnvSourceUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- expected.add("CHROOT_NAME", "test-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_NAME", "test-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
- test_chroot_base::test_setup_env(source_union, expected);
- }
+ ChrootBase::test_setup_env(source_union, expected);
+}
#endif // SBUILD_FEATURE_UNION
- void setup_keyfile_block(sbuild::keyfile &expected, std::string group)
- {
- expected.set_value(group, "type", "block-device");
- expected.set_value(group, "device", "/dev/testdev");
- expected.set_value(group, "location", "/squeeze");
- expected.set_value(group, "mount-options", "-t jfs -o quota,rw");
- }
-
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- std::string group = chroot->get_name();
- setup_keyfile_chroot(expected, group);
- setup_keyfile_block(expected, group);
+TEST_F(ChrootBlockDevice, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ std::string group = chroot->get_name();
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_block(expected, group);
#ifdef SBUILD_FEATURE_UNION
- setup_keyfile_union_unconfigured(expected, group);
+ setup_keyfile_union_unconfigured(expected, group);
#endif
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
+}
- void test_setup_keyfile_session()
- {
- sbuild::keyfile expected;
- const std::string group(session->get_name());
- setup_keyfile_session(expected, group);
- setup_keyfile_block(expected, group);
- expected.set_value(group, "name", "test-session-name");
- expected.set_value(group, "selected-name", "test-session-name");
- expected.set_value(group, "mount-device", "/dev/testdev");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
+TEST_F(ChrootBlockDevice, SetupKeyfileSession)
+{
+ sbuild::keyfile expected;
+ const std::string group(session->get_name());
+ setup_keyfile_session(expected, group);
+ setup_keyfile_block(expected, group);
+ expected.set_value(group, "name", "test-session-name");
+ expected.set_value(group, "selected-name", "test-session-name");
+ expected.set_value(group, "mount-device", "/dev/testdev");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
#ifdef SBUILD_FEATURE_UNION
- setup_keyfile_union_unconfigured(expected, group);
+ setup_keyfile_union_unconfigured(expected, group);
#endif
- test_chroot_base::test_setup_keyfile
- (session, expected, group);
- }
+ ChrootBase::test_setup_keyfile
+ (session, expected, group);
+}
#ifdef SBUILD_FEATURE_UNION
- void test_setup_keyfile_union()
- {
- sbuild::keyfile expected;
- const std::string group(chroot_union->get_name());
- setup_keyfile_union_configured(expected, group);
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source(expected, group);
- setup_keyfile_block(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (chroot_union, expected, group);
- }
-
- void test_setup_keyfile_session_union()
- {
- sbuild::keyfile expected;
- const std::string group(session_union->get_name());
- setup_keyfile_session(expected, group);
- setup_keyfile_block(expected, group);
- expected.set_value(group, "name", "test-union-session-name");
- expected.set_value(group, "selected-name", "test-union-session-name");
- expected.set_value(group, "mount-device", "/dev/testdev");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
- setup_keyfile_union_session(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (session_union, expected, group);
- }
-
- void test_setup_keyfile_source_union()
- {
- sbuild::keyfile expected;
- const std::string group(source_union->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source_clone(expected, group);
- setup_keyfile_block(expected, group);
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
-
- test_chroot_base::test_setup_keyfile
- (source_union, expected, group);
- }
+TEST_F(ChrootBlockDevice, SetupKeyfileUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(chroot_union->get_name());
+ setup_keyfile_union_configured(expected, group);
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source(expected, group);
+ setup_keyfile_block(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (chroot_union, expected, group);
+}
+
+TEST_F(ChrootBlockDevice, SetupKeyfileSessionUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(session_union->get_name());
+ setup_keyfile_session(expected, group);
+ setup_keyfile_block(expected, group);
+ expected.set_value(group, "name", "test-union-session-name");
+ expected.set_value(group, "selected-name", "test-union-session-name");
+ expected.set_value(group, "mount-device", "/dev/testdev");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
+ setup_keyfile_union_session(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (session_union, expected, group);
+}
+
+TEST_F(ChrootBlockDevice, SetupKeyfileSourceUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(source_union->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source_clone(expected, group);
+ setup_keyfile_block(expected, group);
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+
+ ChrootBase::test_setup_keyfile
+ (source_union, expected, group);
+}
#endif // SBUILD_FEATURE_UNION
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
+TEST_F(ChrootBlockDevice, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
- CPPUNIT_ASSERT(session->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_NOFLAGS);
+ ASSERT_EQ(session->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_NOFLAGS);
#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_ASSERT(chroot_union->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE |
- sbuild::chroot::facet::facet::SESSION_CLONE));
+ ASSERT_EQ(chroot_union->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE |
+ sbuild::chroot::facet::facet::SESSION_CLONE));
- CPPUNIT_ASSERT(session_union->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_PURGE);
+ ASSERT_EQ(session_union->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_PURGE);
- CPPUNIT_ASSERT(source_union->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
+ ASSERT_EQ(source_union->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
#endif // SBUILD_FEATURE_UNION
- }
-
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
-
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+}
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts());
- }
-
-};
+TEST_F(ChrootBlockDevice, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_block_device);
+TEST_F(ChrootBlockDevice, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootBlockDevice, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/chroot/btrfs-snapshot.cc b/test/sbuild/chroot/btrfs-snapshot.cc
index 1b2543de..212d4c1a 100644
--- a/test/sbuild/chroot/btrfs-snapshot.cc
+++ b/test/sbuild/chroot/btrfs-snapshot.cc
@@ -28,109 +28,33 @@
#include <algorithm>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
using sbuild::_;
-class test_chroot_btrfs_snapshot : public test_chroot_base
+class BtrfsSnapshot : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_btrfs_snapshot);
- CPPUNIT_TEST(test_source_subvolume);
- CPPUNIT_TEST(test_snapshot_directory);
- CPPUNIT_TEST(test_snapshot_name);
- CPPUNIT_TEST_EXCEPTION(test_source_subvolume_error, sbuild::chroot::chroot::error);
- CPPUNIT_TEST_EXCEPTION(test_snapshot_directory_error, sbuild::chroot::chroot::error);
- CPPUNIT_TEST_EXCEPTION(test_snapshot_name_error, sbuild::chroot::chroot::error);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_env_session);
- CPPUNIT_TEST(test_setup_env_source);
- CPPUNIT_TEST(test_setup_env_session_source);
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_setup_keyfile_session);
- CPPUNIT_TEST(test_setup_keyfile_source);
- CPPUNIT_TEST(test_setup_keyfile_session_source);
- CPPUNIT_TEST(test_session_flags);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot_btrfs_snapshot():
- test_chroot_base("btrfs-snapshot")
+ BtrfsSnapshot():
+ ChrootBase("btrfs-snapshot")
{}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(session);
- CPPUNIT_ASSERT(source);
- CPPUNIT_ASSERT(session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_NE(session, nullptr);
+ ASSERT_NE(source, nullptr);
+ ASSERT_NE(session_source, nullptr);
}
virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
bfac->set_source_subvolume("/srv/chroot/sid");
bfac->set_snapshot_directory("/srv/chroot/snapshot");
}
- void
- test_source_subvolume()
- {
- sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
- bfac->set_source_subvolume("/srv/chroot/chroot");
- CPPUNIT_ASSERT(bfac->get_source_subvolume() == "/srv/chroot/chroot");
- }
-
- void
- test_snapshot_directory()
- {
- sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
- bfac->set_snapshot_directory("/srv/chroot/snapshot2");
- CPPUNIT_ASSERT(bfac->get_snapshot_directory() == "/srv/chroot/snapshot2");
- }
-
- void
- test_snapshot_name()
- {
- sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
- bfac->set_snapshot_directory("/srv/chroot/snapshot2/test-session-id");
- CPPUNIT_ASSERT(bfac->get_snapshot_directory() == "/srv/chroot/snapshot2/test-session-id");
- }
-
- void
- test_source_subvolume_error()
- {
- sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
- bfac->set_source_subvolume("chroot/invalid");
- }
-
- void
- test_snapshot_directory_error()
- {
- sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
- bfac->set_snapshot_directory("chroot/invalid");
- }
-
- void
- test_snapshot_name_error()
- {
- sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
- bfac->set_snapshot_name("invalid");
- }
-
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "btrfs-snapshot");
- }
-
void setup_env_gen(sbuild::environment &expected)
{
setup_env_chroot(expected);
@@ -138,177 +62,219 @@ public:
expected.add("CHROOT_PATH", "/mnt/mount-location");
}
- void test_setup_env()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "btrfs-snapshot");
- expected.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", "/srv/chroot/sid");
- expected.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", "/srv/chroot/snapshot");
- expected.add("CHROOT_SESSION_CLONE", "true");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(chroot, expected);
- }
-
- void test_setup_env_session()
+ void setup_keyfile_btrfs(sbuild::keyfile &expected, std::string group)
{
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "btrfs-snapshot");
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", "/srv/chroot/sid");
- expected.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", "/srv/chroot/snapshot");
- expected.add("CHROOT_BTRFS_SNAPSHOT_NAME", "/srv/chroot/snapshot/test-session-name");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "true");
-
- test_chroot_base::test_setup_env(session, expected);
}
+};
- void test_setup_env_source()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "directory");
- expected.add("CHROOT_NAME", "test-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.add("CHROOT_DIRECTORY", "/srv/chroot/sid");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(source, expected);
- }
+TEST_F(BtrfsSnapshot, SourceSubvolume)
+{
+ sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
+ bfac->set_source_subvolume("/srv/chroot/chroot");
+ ASSERT_EQ(bfac->get_source_subvolume(), "/srv/chroot/chroot");
+}
- void test_setup_env_session_source()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "directory");
- expected.add("CHROOT_NAME", "test-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.add("CHROOT_DIRECTORY", "/srv/chroot/sid");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(source, expected);
- }
+TEST_F(BtrfsSnapshot, SnapshotDirectory)
+{
+ sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
+ bfac->set_snapshot_directory("/srv/chroot/snapshot2");
+ ASSERT_EQ(bfac->get_snapshot_directory(), "/srv/chroot/snapshot2");
+}
- void setup_keyfile_btrfs(sbuild::keyfile &expected, std::string group)
- {
- }
+TEST_F(BtrfsSnapshot, SnapshotName)
+{
+ sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
+ bfac->set_snapshot_directory("/srv/chroot/snapshot2/test-session-id");
+ ASSERT_EQ(bfac->get_snapshot_directory(), "/srv/chroot/snapshot2/test-session-id");
+}
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- std::string group = chroot->get_name();
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source(expected, group);
- setup_keyfile_btrfs(expected, group);
- expected.set_value(group, "type", "btrfs-snapshot");
- expected.set_value(group, "btrfs-source-subvolume", "/srv/chroot/sid");
- expected.set_value(group, "btrfs-snapshot-directory", "/srv/chroot/snapshot");
-
- test_chroot_base::test_setup_keyfile
- (chroot,expected, chroot->get_name());
- }
+TEST_F(BtrfsSnapshot, SourceSubvolumeFail)
+{
+ sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
+ ASSERT_THROW(bfac->set_source_subvolume("chroot/invalid"), sbuild::chroot::chroot::error);
+}
- void test_setup_keyfile_session()
- {
- sbuild::keyfile expected;
- const std::string group(session->get_name());
- setup_keyfile_session(expected, group);
- setup_keyfile_btrfs(expected, group);
- expected.set_value(group, "type", "btrfs-snapshot");
- expected.set_value(group, "name", "test-session-name");
- expected.set_value(group, "selected-name", "test-session-name");
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.set_value(group, "aliases", "");
- expected.set_value(group, "btrfs-snapshot-name", "/srv/chroot/snapshot/test-session-name");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
-
- test_chroot_base::test_setup_keyfile
- (session, expected, group);
- }
+TEST_F(BtrfsSnapshot, SnapshotDirectoryFail)
+{
+ sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
+ ASSERT_THROW(bfac->set_snapshot_directory("chroot/invalid"), sbuild::chroot::chroot::error);
+}
- void test_setup_keyfile_source()
- {
- sbuild::keyfile expected;
- const std::string group(source->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_btrfs(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.set_value(group, "aliases", "test-alias-1-source,test-alias-2-source");
- expected.set_value(group, "directory", "/srv/chroot/sid");
- setup_keyfile_source_clone(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (source, expected, group);
- }
+TEST_F(BtrfsSnapshot, SnapshotNameFail)
+{
+ sbuild::chroot::facet::btrfs_snapshot::ptr bfac = chroot->get_facet_strict<sbuild::chroot::facet::btrfs_snapshot>();
+ ASSERT_THROW(bfac->set_snapshot_name("invalid"), sbuild::chroot::chroot::error);
+}
- void test_setup_keyfile_session_source()
- {
- sbuild::keyfile expected;
- const std::string group(source->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_btrfs(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.set_value(group, "aliases", "test-alias-1-source,test-alias-2-source");
- expected.set_value(group, "directory", "/srv/chroot/sid");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_source_clone(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (session_source, expected, group);
- }
+TEST_F(BtrfsSnapshot, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "btrfs-snapshot");
+}
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE |
- sbuild::chroot::facet::facet::SESSION_CLONE));
-
- CPPUNIT_ASSERT(session->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_PURGE));
-
- /// @todo: Should return NOFLAGS? This depends upon if source
- /// chroots need transforming into sessions as well (which should
- /// probably happen and be tested for independently).
- CPPUNIT_ASSERT(source->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE));
- }
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+TEST_F(BtrfsSnapshot, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "btrfs-snapshot");
+ expected.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", "/srv/chroot/sid");
+ expected.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", "/srv/chroot/snapshot");
+ expected.add("CHROOT_SESSION_CLONE", "true");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(chroot, expected);
+}
+
+TEST_F(BtrfsSnapshot, SetupEnvSession)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "btrfs-snapshot");
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", "/srv/chroot/sid");
+ expected.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", "/srv/chroot/snapshot");
+ expected.add("CHROOT_BTRFS_SNAPSHOT_NAME", "/srv/chroot/snapshot/test-session-name");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "true");
+
+ ChrootBase::test_setup_env(session, expected);
+}
+
+TEST_F(BtrfsSnapshot, SetupEnvSource)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "directory");
+ expected.add("CHROOT_NAME", "test-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.add("CHROOT_DIRECTORY", "/srv/chroot/sid");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(source, expected);
+}
+
+TEST_F(BtrfsSnapshot, SetupEnvSessionSource)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "directory");
+ expected.add("CHROOT_NAME", "test-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.add("CHROOT_DIRECTORY", "/srv/chroot/sid");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(source, expected);
+}
+
+TEST_F(BtrfsSnapshot, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ std::string group = chroot->get_name();
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source(expected, group);
+ setup_keyfile_btrfs(expected, group);
+ expected.set_value(group, "type", "btrfs-snapshot");
+ expected.set_value(group, "btrfs-source-subvolume", "/srv/chroot/sid");
+ expected.set_value(group, "btrfs-snapshot-directory", "/srv/chroot/snapshot");
+
+ ChrootBase::test_setup_keyfile
+ (chroot,expected, chroot->get_name());
+}
+
+TEST_F(BtrfsSnapshot, SetupKeyfileSession)
+{
+ sbuild::keyfile expected;
+ const std::string group(session->get_name());
+ setup_keyfile_session(expected, group);
+ setup_keyfile_btrfs(expected, group);
+ expected.set_value(group, "type", "btrfs-snapshot");
+ expected.set_value(group, "name", "test-session-name");
+ expected.set_value(group, "selected-name", "test-session-name");
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.set_value(group, "aliases", "");
+ expected.set_value(group, "btrfs-snapshot-name", "/srv/chroot/snapshot/test-session-name");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+
+ ChrootBase::test_setup_keyfile
+ (session, expected, group);
+}
+
+TEST_F(BtrfsSnapshot, SetupKeyfileSource)
+{
+ sbuild::keyfile expected;
+ const std::string group(source->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_btrfs(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.set_value(group, "aliases", "test-alias-1-source,test-alias-2-source");
+ expected.set_value(group, "directory", "/srv/chroot/sid");
+ setup_keyfile_source_clone(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (source, expected, group);
+}
+
+TEST_F(BtrfsSnapshot, SetupKeyfileSessionSource)
+{
+ sbuild::keyfile expected;
+ const std::string group(source->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_btrfs(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.set_value(group, "aliases", "test-alias-1-source,test-alias-2-source");
+ expected.set_value(group, "directory", "/srv/chroot/sid");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_source_clone(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (session_source, expected, group);
+}
+
+TEST_F(BtrfsSnapshot, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE |
+ sbuild::chroot::facet::facet::SESSION_CLONE));
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+ ASSERT_EQ(session->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_PURGE));
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts());
- }
+ /// @todo: Should return NOFLAGS? This depends upon if source
+ /// chroots need transforming into sessions as well (which should
+ /// probably happen and be tested for independently).
+ ASSERT_EQ(source->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE));
+}
-};
+TEST_F(BtrfsSnapshot, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_btrfs_snapshot);
+TEST_F(BtrfsSnapshot, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(BtrfsSnapshot, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/chroot/chroot.cc b/test/sbuild/chroot/chroot.cc
index 28e4f9bc..575b7d28 100644
--- a/test/sbuild/chroot/chroot.cc
+++ b/test/sbuild/chroot/chroot.cc
@@ -16,6 +16,8 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <config.h>
#include <sbuild/chroot/chroot.h>
@@ -31,10 +33,6 @@
#include <algorithm>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
class test_chroot_facet : public sbuild::chroot::facet::facet,
public sbuild::chroot::facet::storage
{
@@ -121,238 +119,214 @@ namespace
}
-class test_chroot : public test_chroot_base
+class Chroot : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot);
- CPPUNIT_TEST(test_name);
- CPPUNIT_TEST(test_description);
- CPPUNIT_TEST(test_mount_location);
- CPPUNIT_TEST(test_groups);
- CPPUNIT_TEST(test_root_groups);
- CPPUNIT_TEST(test_aliases);
- CPPUNIT_TEST(test_environment_filter);
- CPPUNIT_TEST(test_active);
- CPPUNIT_TEST(test_script_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST(test_verbose);
- CPPUNIT_TEST(test_preserve_environment);
- CPPUNIT_TEST_EXCEPTION(test_verbose_error, sbuild::chroot::chroot::error);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_session_flags);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot():
- test_chroot_base("test")
- {
- }
-
- void test_name()
- {
- chroot->set_name("test-name-example");
- CPPUNIT_ASSERT(chroot->get_name() == "test-name-example");
- }
-
- void test_description()
- {
- chroot->set_description("test-description-example");
- CPPUNIT_ASSERT(chroot->get_description() == "test-description-example");
- }
-
- void test_mount_location()
+ Chroot():
+ ChrootBase("test")
{
- chroot->set_mount_location("/mnt/mount-location/example");
- CPPUNIT_ASSERT(chroot->get_mount_location() ==
- "/mnt/mount-location/example");
- }
-
- void test_groups()
- {
- sbuild::string_list groups;
- groups.push_back("schroot");
- groups.push_back("sbuild-users");
- groups.push_back("fred");
- groups.push_back("users");
-
- test_list(*chroot.get(),
- groups,
- &sbuild::chroot::chroot::get_groups,
- &sbuild::chroot::chroot::set_groups);
- }
-
- void test_root_groups()
- {
- sbuild::string_list groups;
- groups.push_back("schroot");
- groups.push_back("trusted");
- groups.push_back("root");
-
- test_list(*chroot.get(),
- groups,
- &sbuild::chroot::chroot::get_root_groups,
- &sbuild::chroot::chroot::set_root_groups);
}
+};
- void test_aliases()
- {
- sbuild::string_list aliases;
- aliases.push_back("alias1");
- aliases.push_back("alias2");
-
- test_list(*chroot.get(),
- aliases,
- &sbuild::chroot::chroot::get_aliases,
- &sbuild::chroot::chroot::set_aliases);
- }
+TEST_F(Chroot, Name)
+{
+ chroot->set_name("test-name-example");
+ ASSERT_EQ(chroot->get_name(), "test-name-example");
+}
- void test_environment_filter()
- {
- sbuild::regex r("foo|bar|baz");
+TEST_F(Chroot, Description)
+{
+ chroot->set_description("test-description-example");
+ ASSERT_EQ(chroot->get_description(), "test-description-example");
+}
- chroot->set_environment_filter(r);
+TEST_F(Chroot, MountLocation)
+{
+ chroot->set_mount_location("/mnt/mount-location/example");
+ ASSERT_EQ(chroot->get_mount_location(),
+ "/mnt/mount-location/example");
+}
- CPPUNIT_ASSERT(chroot->get_environment_filter().compare(r) == 0);
- }
+TEST_F(Chroot, Groups)
+{
+ sbuild::string_list groups;
+ groups.push_back("schroot");
+ groups.push_back("sbuild-users");
+ groups.push_back("fred");
+ groups.push_back("users");
+
+ test_list(*chroot.get(),
+ groups,
+ &sbuild::chroot::chroot::get_groups,
+ &sbuild::chroot::chroot::set_groups);
+}
- void test_active()
- {
- CPPUNIT_ASSERT(!chroot->get_facet<sbuild::chroot::facet::session>());
- }
+TEST_F(Chroot, RootGroups)
+{
+ sbuild::string_list groups;
+ groups.push_back("schroot");
+ groups.push_back("trusted");
+ groups.push_back("root");
+
+ test_list(*chroot.get(),
+ groups,
+ &sbuild::chroot::chroot::get_root_groups,
+ &sbuild::chroot::chroot::set_root_groups);
+}
- void test_script_config()
- {
- chroot->set_script_config("desktop/config");
+TEST_F(Chroot, Aliases)
+{
+ sbuild::string_list aliases;
+ aliases.push_back("alias1");
+ aliases.push_back("alias2");
+
+ test_list(*chroot.get(),
+ aliases,
+ &sbuild::chroot::chroot::get_aliases,
+ &sbuild::chroot::chroot::set_aliases);
+}
- {
- sbuild::keyfile expected;
- const std::string group(chroot->get_name());
- setup_keyfile_chroot(expected, group);
- expected.remove_key(group, "setup.config");
- expected.remove_key(group, "setup.copyfiles");
- expected.remove_key(group, "setup.fstab");
- expected.remove_key(group, "setup.nssdatabases");
- expected.set_value(group, "type", "test");
- expected.set_value(group, "profile", "");
- expected.set_value(group, "script-config", "desktop/config");
-
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
+TEST_F(Chroot, EnvironmentFilter)
+{
+ sbuild::regex r("foo|bar|baz");
- {
- sbuild::environment expected;
- setup_env_chroot(expected);
- expected.remove("CHROOT_PROFILE");
- expected.remove("CHROOT_PROFILE_DIR");
- expected.remove("SETUP_CONFIG");
- expected.remove("SETUP_COPYFILES");
- expected.remove("SETUP_FSTAB");
- expected.remove("SETUP_NSSDATABASES");
- expected.add("CHROOT_TYPE", "test");
- expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
- expected.add("CHROOT_PATH", "/mnt/mount-location");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
- expected.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(SCHROOT_SYSCONF_DIR) + "/desktop/config"));
-
- sbuild::environment observed;
- chroot->setup_env(observed);
-
- test_chroot_base::test_setup_env(observed, expected);
- }
- }
+ chroot->set_environment_filter(r);
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts() == true);
- }
+ ASSERT_EQ(chroot->get_environment_filter().compare(r), 0);
+}
- void test_verbose()
- {
- CPPUNIT_ASSERT(chroot->get_verbosity() == sbuild::chroot::chroot::VERBOSITY_QUIET);
- chroot->set_verbosity(sbuild::chroot::chroot::VERBOSITY_VERBOSE);
- CPPUNIT_ASSERT(chroot->get_verbosity() == sbuild::chroot::chroot::VERBOSITY_VERBOSE);
- CPPUNIT_ASSERT(std::string(chroot->get_verbosity_string()) == "verbose");
- chroot->set_verbosity("normal");
- CPPUNIT_ASSERT(chroot->get_verbosity() == sbuild::chroot::chroot::VERBOSITY_NORMAL);
- CPPUNIT_ASSERT(std::string(chroot->get_verbosity_string()) == "normal");
- }
+TEST_F(Chroot, Active)
+{
+ ASSERT_EQ(chroot->get_facet<sbuild::chroot::facet::session>(), nullptr);
+}
- void test_preserve_environment()
- {
- CPPUNIT_ASSERT(chroot->get_preserve_environment() == false);
- chroot->set_preserve_environment(true);
- CPPUNIT_ASSERT(chroot->get_preserve_environment() == true);
- chroot->set_preserve_environment(false);
- CPPUNIT_ASSERT(chroot->get_preserve_environment() == false);
- }
+TEST_F(Chroot, ScriptConfig)
+{
+ chroot->set_script_config("desktop/config");
- void test_verbose_error()
{
- chroot->set_verbosity("invalid");
- }
+ sbuild::keyfile expected;
+ const std::string group(chroot->get_name());
+ setup_keyfile_chroot(expected, group);
+ expected.remove_key(group, "setup.config");
+ expected.remove_key(group, "setup.copyfiles");
+ expected.remove_key(group, "setup.fstab");
+ expected.remove_key(group, "setup.nssdatabases");
+ expected.set_value(group, "type", "test");
+ expected.set_value(group, "profile", "");
+ expected.set_value(group, "script-config", "desktop/config");
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "test");
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
}
- void test_setup_env()
{
sbuild::environment expected;
setup_env_chroot(expected);
+ expected.remove("CHROOT_PROFILE");
+ expected.remove("CHROOT_PROFILE_DIR");
+ expected.remove("SETUP_CONFIG");
+ expected.remove("SETUP_COPYFILES");
+ expected.remove("SETUP_FSTAB");
+ expected.remove("SETUP_NSSDATABASES");
expected.add("CHROOT_TYPE", "test");
expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
expected.add("CHROOT_PATH", "/mnt/mount-location");
expected.add("CHROOT_SESSION_CLONE", "false");
expected.add("CHROOT_SESSION_CREATE", "true");
expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(SCHROOT_SYSCONF_DIR) + "/desktop/config"));
sbuild::environment observed;
chroot->setup_env(observed);
- test_chroot_base::test_setup_env(observed, expected);
+ ChrootBase::test_setup_env(observed, expected);
}
+}
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- std::string group = chroot->get_name();
- setup_keyfile_chroot(expected, group);
- expected.set_value(group, "type", "test");
+TEST_F(Chroot, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
+TEST_F(Chroot, Verbose)
+{
+ ASSERT_EQ(chroot->get_verbosity(), sbuild::chroot::chroot::VERBOSITY_QUIET);
+ chroot->set_verbosity(sbuild::chroot::chroot::VERBOSITY_VERBOSE);
+ ASSERT_EQ(chroot->get_verbosity(), sbuild::chroot::chroot::VERBOSITY_VERBOSE);
+ ASSERT_EQ(std::string(chroot->get_verbosity_string()), "verbose");
+ chroot->set_verbosity("normal");
+ ASSERT_EQ(chroot->get_verbosity(), sbuild::chroot::chroot::VERBOSITY_NORMAL);
+ ASSERT_EQ(std::string(chroot->get_verbosity_string()), "normal");
+}
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
- }
+TEST_F(Chroot, PreserveEnvironment)
+{
+ ASSERT_FALSE(chroot->get_preserve_environment());
+ chroot->set_preserve_environment(true);
+ ASSERT_TRUE(chroot->get_preserve_environment());
+ chroot->set_preserve_environment(false);
+ ASSERT_FALSE(chroot->get_preserve_environment());
+}
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+TEST_F(Chroot, VerboseError)
+{
+ EXPECT_THROW(chroot->set_verbosity("invalid"), sbuild::chroot::chroot::error);
+}
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
-};
+TEST_F(Chroot, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "test");
+}
+
+TEST_F(Chroot, SetupEnvironment)
+{
+ sbuild::environment expected;
+ setup_env_chroot(expected);
+ expected.add("CHROOT_TYPE", "test");
+ expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
+ expected.add("CHROOT_PATH", "/mnt/mount-location");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ sbuild::environment observed;
+ chroot->setup_env(observed);
+
+ ChrootBase::test_setup_env(observed, expected);
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot);
+TEST_F(Chroot, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ std::string group = chroot->get_name();
+ setup_keyfile_chroot(expected, group);
+ expected.set_value(group, "type", "test");
+
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
+}
+
+TEST_F(Chroot, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
+}
+
+TEST_F(Chroot, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(Chroot, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
diff --git a/test/sbuild/chroot/chroot.h b/test/sbuild/chroot/chroot.h
index 03c731a4..3b8bd908 100644
--- a/test/sbuild/chroot/chroot.h
+++ b/test/sbuild/chroot/chroot.h
@@ -19,6 +19,8 @@
#ifndef TEST_SBUILD_CHROOT_H
#define TEST_SBUILD_CHROOT_H
+#include <gtest/gtest.h>
+
#include <sbuild/config.h>
#include <sbuild/chroot/chroot.h>
#ifdef SBUILD_FEATURE_PERSONALITY
@@ -43,12 +45,9 @@
#include <iostream>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
using sbuild::_;
-class test_chroot_base : public TestFixture
+class ChrootBase : public ::testing::Test
{
protected:
std::string type;
@@ -65,8 +64,7 @@ protected:
std::string abs_testdata_dir;
public:
- test_chroot_base(const std::string& type):
- TestFixture(),
+ ChrootBase(const std::string& type):
type(type),
chroot(),
session(),
@@ -84,108 +82,108 @@ public:
abs_testdata_dir.append("/" TESTDATADIR);
}
- virtual ~test_chroot_base()
+ virtual ~ChrootBase()
{}
- void setUp()
+ void SetUp()
{
// Create new chroot
- this->chroot = sbuild::chroot::chroot::create(type);
- CPPUNIT_ASSERT(this->chroot);
- CPPUNIT_ASSERT(!(static_cast<bool>(this->chroot->get_facet<sbuild::chroot::facet::session>())));
+ chroot = sbuild::chroot::chroot::create(type);
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_FALSE(static_cast<bool>(chroot->get_facet<sbuild::chroot::facet::session>()));
- setup_chroot_props(this->chroot);
+ setup_chroot_props(chroot);
- CPPUNIT_ASSERT(this->chroot->get_name().length());
+ ASSERT_GT(chroot->get_name().length(), 0);
// Create new source chroot.
sbuild::chroot::facet::session_clonable::const_ptr psess
- (this->chroot->get_facet<sbuild::chroot::facet::session_clonable>());
+ (chroot->get_facet<sbuild::chroot::facet::session_clonable>());
if (psess)
{
- this->session = this->chroot->clone_session("test-session-name",
+ session = chroot->clone_session("test-session-name",
"test-session-name",
"user1",
false);
- if (this->session)
+ if (session)
{
- CPPUNIT_ASSERT(this->session->get_facet<sbuild::chroot::facet::session>());
+ ASSERT_NE(session->get_facet<sbuild::chroot::facet::session>(), nullptr);
}
}
sbuild::chroot::facet::source_clonable::const_ptr psrc
- (this->chroot->get_facet<sbuild::chroot::facet::source_clonable>());
+ (chroot->get_facet<sbuild::chroot::facet::source_clonable>());
if (psrc)
- this->source = this->chroot->clone_source();
- if (this->source)
+ source = chroot->clone_source();
+ if (source)
{
sbuild::chroot::facet::source_clonable::const_ptr pfsrcc
- (this->source->get_facet<sbuild::chroot::facet::source_clonable>());
- CPPUNIT_ASSERT(!pfsrcc);
+ (source->get_facet<sbuild::chroot::facet::source_clonable>());
+ ASSERT_EQ(pfsrcc, nullptr);
sbuild::chroot::facet::source::const_ptr pfsrc
- (this->source->get_facet<sbuild::chroot::facet::source>());
- CPPUNIT_ASSERT(pfsrc);
+ (source->get_facet<sbuild::chroot::facet::source>());
+ ASSERT_NE(pfsrc, nullptr);
}
if (source)
{
sbuild::chroot::facet::session_clonable::const_ptr psess_src
- (this->source->get_facet<sbuild::chroot::facet::session_clonable>());
+ (source->get_facet<sbuild::chroot::facet::session_clonable>());
if (psess_src)
{
- this->session_source = this->source->clone_session("test-session-name",
+ session_source = source->clone_session("test-session-name",
"test-session-name",
"user1",
false);
- if (this->session_source)
+ if (session_source)
{
- CPPUNIT_ASSERT(this->session_source->get_facet<sbuild::chroot::facet::session>());
+ ASSERT_NE(session_source->get_facet<sbuild::chroot::facet::session>(), nullptr);
}
}
}
#ifdef SBUILD_FEATURE_UNION
- this->chroot_union = sbuild::chroot::chroot::create(type);
+ chroot_union = sbuild::chroot::chroot::create(type);
sbuild::chroot::facet::fsunion::ptr un =
- this->chroot_union->get_facet<sbuild::chroot::facet::fsunion>();
+ chroot_union->get_facet<sbuild::chroot::facet::fsunion>();
if (!un)
{
- this->chroot_union.reset();
+ chroot_union.reset();
}
else
{
un->set_union_type("aufs");
- setup_chroot_props(this->chroot_union);
- CPPUNIT_ASSERT(!(this->chroot_union->get_facet<sbuild::chroot::facet::session>()));
- CPPUNIT_ASSERT(this->chroot_union->get_name().length());
+ setup_chroot_props(chroot_union);
+ ASSERT_EQ(chroot_union->get_facet<sbuild::chroot::facet::session>(), nullptr);
+ ASSERT_GT(chroot_union->get_name().length(), 0);
un->set_union_overlay_directory("/overlay");
un->set_union_underlay_directory("/underlay");
un->set_union_mount_options("union-mount-options");
- this->session_union =
- this->chroot_union->clone_session("test-union-session-name",
+ session_union =
+ chroot_union->clone_session("test-union-session-name",
"test-union-session-name",
"user1",
false);
- this->source_union = chroot_union->clone_source();
+ source_union = chroot_union->clone_source();
sbuild::chroot::facet::session_clonable::const_ptr puni_sess_src
- (this->source_union->get_facet<sbuild::chroot::facet::session_clonable>());
+ (source_union->get_facet<sbuild::chroot::facet::session_clonable>());
if (puni_sess_src)
{
- this->session_source_union = this->source_union->clone_session("test-session-name",
+ session_source_union = source_union->clone_session("test-session-name",
"test-session-name",
"user1",
false);
}
- CPPUNIT_ASSERT(this->session_union);
- CPPUNIT_ASSERT(this->session_union->get_facet<sbuild::chroot::facet::session>());
- CPPUNIT_ASSERT(this->source_union);
- CPPUNIT_ASSERT(this->session_source_union);
- CPPUNIT_ASSERT(this->session_source_union->get_facet<sbuild::chroot::facet::session>());
+ ASSERT_NE(session_union, nullptr);
+ ASSERT_NE(session_union->get_facet<sbuild::chroot::facet::session>(), nullptr);
+ ASSERT_NE(source_union, nullptr);
+ ASSERT_NE(session_source_union, nullptr);
+ ASSERT_NE(session_source_union->get_facet<sbuild::chroot::facet::session>(), nullptr);
}
#endif // SBUILD_FEATURE_UNION
@@ -240,9 +238,18 @@ public:
}
}
- void tearDown()
+ void TearDown()
{
- this->chroot = sbuild::chroot::chroot::ptr();
+ chroot = sbuild::chroot::chroot::ptr();
+ session = sbuild::chroot::chroot::ptr();
+ source = sbuild::chroot::chroot::ptr();
+ session_source = sbuild::chroot::chroot::ptr();
+#ifdef SBUILD_FEATURE_UNION
+ chroot_union = sbuild::chroot::chroot::ptr();
+ session_union = sbuild::chroot::chroot::ptr();
+ source_union = sbuild::chroot::chroot::ptr();
+ session_source_union = sbuild::chroot::chroot::ptr();
+#endif // SBUILD_FEATURE_UNION
}
void setup_env_chroot (sbuild::environment& env)
@@ -386,8 +393,8 @@ public:
void test_setup_env(const sbuild::environment& observed_environment,
const sbuild::environment& expected_environment)
{
- CPPUNIT_ASSERT(observed_environment.size() != 0);
- CPPUNIT_ASSERT(expected_environment.size() != 0);
+ ASSERT_GT(observed_environment.size(), 0);
+ ASSERT_GT(expected_environment.size(), 0);
std::set<std::string> expected;
for (const auto& env : expected_environment)
@@ -411,7 +418,7 @@ public:
<< env << "=" << value << std::endl;
}
}
- CPPUNIT_ASSERT(missing.empty());
+ ASSERT_TRUE(missing.empty());
sbuild::string_list extra;
set_difference(found.begin(), found.end(),
@@ -427,19 +434,19 @@ public:
<< env << "=" << value << std::endl;
}
}
- CPPUNIT_ASSERT(extra.empty());
+ ASSERT_TRUE(extra.empty());
for (const auto& env : expected_environment)
{
std::string checkval;
- CPPUNIT_ASSERT(observed_environment.get(env.first, checkval) == true);
+ ASSERT_TRUE(observed_environment.get(env.first, checkval));
if (checkval != env.second)
std::cout << "Environment error (" << env.first << "): "
<< checkval << " [observed] != "
<< env.second << " [expected]"
<< std::endl;
- CPPUNIT_ASSERT(checkval == env.second);
+ ASSERT_EQ(checkval, env.second);
}
}
@@ -449,7 +456,7 @@ public:
sbuild::environment observed_environment;
chroot->setup_env(observed_environment);
- CPPUNIT_ASSERT(observed_environment.size() != 0);
+ ASSERT_GT(observed_environment.size(), 0);
test_setup_env(observed_environment, expected_environment);
}
@@ -459,8 +466,8 @@ public:
const sbuild::keyfile& expected_keyfile,
const std::string& expected_group)
{
- CPPUNIT_ASSERT(observed_keyfile.get_keys(observed_group).size() != 0);
- CPPUNIT_ASSERT(expected_keyfile.get_keys(expected_group).size() != 0);
+ ASSERT_GT(observed_keyfile.get_keys(observed_group).size(), 0);
+ ASSERT_GT(expected_keyfile.get_keys(expected_group).size(), 0);
sbuild::string_list expected_keys =
@@ -485,7 +492,7 @@ public:
<< key << "=" << value << std::endl;
}
}
- CPPUNIT_ASSERT(missing.empty());
+ ASSERT_TRUE(missing.empty());
sbuild::string_list extra;
set_difference(observed.begin(), observed.end(),
@@ -501,24 +508,24 @@ public:
<< key << "=" << value << std::endl;
}
}
- CPPUNIT_ASSERT(extra.empty());
+ ASSERT_TRUE(extra.empty());
for (const auto& key : expected_keys)
{
std::string expected_val;
- CPPUNIT_ASSERT(expected_keyfile.get_value(expected_group,
- key, expected_val) == true);
+ ASSERT_TRUE(expected_keyfile.get_value(expected_group,
+ key, expected_val));
std::string observed_val;
- CPPUNIT_ASSERT(observed_keyfile.get_value(observed_group,
- key, observed_val) == true);
+ ASSERT_TRUE(observed_keyfile.get_value(observed_group,
+ key, observed_val));
if (expected_val != observed_val)
std::cout << "Keyfile error (" << key << "): "
<< observed_val << " [observed] != "
<< expected_val << " [expected]"
<< std::endl;
- CPPUNIT_ASSERT(expected_val == observed_val);
+ ASSERT_EQ(expected_val, observed_val);
}
}
@@ -566,8 +573,8 @@ void test_list(T& itype,
std::cout << "Missing list item: " << item << std::endl;
}
// Ensure the test is working.
- CPPUNIT_ASSERT(missing.empty());
- CPPUNIT_ASSERT(set_items.size() == list.size());
+ ASSERT_TRUE(missing.empty());
+ ASSERT_EQ(set_items.size(), list.size());
}
#endif /* TEST_SBUILD_CHROOT_H */
diff --git a/test/sbuild/chroot/config.cc b/test/sbuild/chroot/config.cc
index 5f9b93aa..b58bd323 100644
--- a/test/sbuild/chroot/config.cc
+++ b/test/sbuild/chroot/config.cc
@@ -16,6 +16,8 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/chroot/config.h>
#include <sbuild/nostream.h>
@@ -23,188 +25,161 @@
#include <sstream>
#include <vector>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_config : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_config);
- CPPUNIT_TEST(test_construction_file);
- CPPUNIT_TEST(test_construction_dir);
- CPPUNIT_TEST_EXCEPTION(test_construction_fail, sbuild::error_base);
- CPPUNIT_TEST(test_add_file);
- CPPUNIT_TEST(test_add_dir);
- CPPUNIT_TEST_EXCEPTION(test_add_fail, sbuild::error_base);
- CPPUNIT_TEST(test_get_chroots);
- CPPUNIT_TEST(test_find_chroot);
- CPPUNIT_TEST(test_find_alias);
- CPPUNIT_TEST(test_get_chroot_list);
- CPPUNIT_TEST(test_get_alias_list);
- CPPUNIT_TEST(test_validate_chroots);
- CPPUNIT_TEST_EXCEPTION(test_validate_chroots_fail, sbuild::error_base);
- CPPUNIT_TEST_EXCEPTION(test_config_fail, sbuild::error_base);
- CPPUNIT_TEST(test_config_deprecated);
- CPPUNIT_TEST(test_config_valid);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
- sbuild::chroot::config *cf;
-
+class ChrootConfig : public ::testing::Test
+{
public:
- test_config():
- TestFixture(),
- cf()
- {}
+ sbuild::chroot::config *cf;
- virtual ~test_config()
+ ChrootConfig():
+ cf(nullptr)
{}
- void setUp()
- {
- this->cf = new sbuild::chroot::config("chroot", TESTDATADIR "/config.ex1");
- }
-
- void tearDown()
- {
- delete this->cf;
- }
-
- void test_construction_file()
+ void SetUp()
{
- sbuild::chroot::config c("chroot", TESTDATADIR "/config.ex1");
+ cf = new sbuild::chroot::config("chroot", TESTDATADIR "/config.ex1");
+ ASSERT_NE(cf, nullptr);
}
- void test_construction_dir()
+ void TearDown()
{
- sbuild::chroot::config c("chroot", TESTDATADIR "/config.ex2");
- }
-
- void test_construction_fail()
- {
- sbuild::chroot::config c("chroot", TESTDATADIR "/config.nonexistent");
+ if (cf)
+ delete cf;
+ cf = nullptr;
}
+};
- void test_construction_fail_wrong()
- {
- sbuild::chroot::config c("chroot", TESTDATADIR "/config.ex3");
- }
+TEST_F(ChrootConfig, ConstructFile)
+{
+ ASSERT_NO_THROW(sbuild::chroot::config c("chroot", TESTDATADIR "/config.ex1"));
+}
- void test_add_file()
- {
- sbuild::chroot::config c;
- c.add("chroot", TESTDATADIR "/config.ex1");
- }
+TEST_F(ChrootConfig, ConstructDirectory)
+{
+ ASSERT_NO_THROW(sbuild::chroot::config c("chroot", TESTDATADIR "/config.ex2"));
+}
- void test_add_dir()
- {
- sbuild::chroot::config c;
- c.add("chroot", TESTDATADIR "/config.ex2");
- }
+TEST_F(ChrootConfig, ConstructFailNonexistent)
+{
+ ASSERT_THROW(sbuild::chroot::config c("chroot", TESTDATADIR "/config.nonexistent"), sbuild::error_base);
+}
- void test_add_fail()
- {
- sbuild::chroot::config c;
- c.add("chroot", TESTDATADIR "/config.nonexistent");
- }
+TEST_F(ChrootConfig, ConstructFailInvalid)
+{
+ ASSERT_THROW(sbuild::chroot::config c("chroot", TESTDATADIR "/config.ex3"), sbuild::error_base);
+}
- void test_get_chroots()
- {
- CPPUNIT_ASSERT(this->cf->get_chroots("chroot").size() == 4);
- }
+TEST_F(ChrootConfig, AddFile)
+{
+ sbuild::chroot::config c;
+ c.add("chroot", TESTDATADIR "/config.ex1");
+}
- void test_find_chroot()
- {
- sbuild::chroot::chroot::ptr chroot;
+TEST_F(ChrootConfig, AddDirectory)
+{
+ sbuild::chroot::config c;
+ c.add("chroot", TESTDATADIR "/config.ex2");
+}
- chroot = this->cf->find_chroot("chroot", "sid");
- CPPUNIT_ASSERT((chroot));
- CPPUNIT_ASSERT(chroot->get_name() == "sid");
+TEST_F(ChrootConfig, AddFail)
+{
+ sbuild::chroot::config c;
+ ASSERT_THROW(c.add("chroot", TESTDATADIR "/config.nonexistent"), sbuild::error_base);
+}
- chroot = this->cf->find_chroot("chroot", "stable");
- CPPUNIT_ASSERT((!chroot));
+TEST_F(ChrootConfig, GetChroots)
+{
+ EXPECT_EQ(cf->get_chroots("chroot").size(), 4);
+}
- chroot = this->cf->find_chroot("chroot", "invalid");
- CPPUNIT_ASSERT((!chroot));
- }
+TEST_F(ChrootConfig, FindChroot)
+{
+ sbuild::chroot::chroot::ptr chroot;
- void test_find_alias()
- {
- sbuild::chroot::chroot::ptr chroot;
+ EXPECT_NO_THROW(chroot = cf->find_chroot("chroot", "sid"));
+ EXPECT_NE(chroot, nullptr);
+ EXPECT_EQ(chroot->get_name(), "sid");
- chroot = this->cf->find_alias("chroot", "sid");
- CPPUNIT_ASSERT((chroot));
- CPPUNIT_ASSERT(chroot->get_name() == "sid");
+ EXPECT_NO_THROW(chroot = cf->find_chroot("chroot", "stable"));
+ EXPECT_EQ(chroot, nullptr);
- chroot = this->cf->find_alias("chroot", "stable");
- CPPUNIT_ASSERT((chroot));
- CPPUNIT_ASSERT(chroot->get_name() == "sarge");
+ EXPECT_NO_THROW(chroot = cf->find_chroot("chroot", "invalid"));
+ EXPECT_EQ(chroot, nullptr);
+}
- chroot = this->cf->find_alias("chroot", "invalid");
- CPPUNIT_ASSERT((!chroot));
- }
+TEST_F(ChrootConfig, FindAlias)
+{
+ sbuild::chroot::chroot::ptr chroot;
- void test_get_chroot_list()
- {
- sbuild::string_list chroots = this->cf->get_chroot_list("chroot");
- CPPUNIT_ASSERT(chroots.size() == 4);
- CPPUNIT_ASSERT(chroots[0] == "chroot:experimental");
- CPPUNIT_ASSERT(chroots[1] == "chroot:sarge");
- CPPUNIT_ASSERT(chroots[2] == "chroot:sid");
- CPPUNIT_ASSERT(chroots[3] == "chroot:sid-local");
- }
+ chroot = cf->find_alias("chroot", "sid");
+ EXPECT_NE(chroot, nullptr);
+ EXPECT_EQ(chroot->get_name(), "sid");
- void test_get_alias_list()
- {
- sbuild::string_list chroots = this->cf->get_alias_list("chroot");
- CPPUNIT_ASSERT(chroots.size() == 7);
- CPPUNIT_ASSERT(chroots[0] == "chroot:default");
- CPPUNIT_ASSERT(chroots[1] == "chroot:experimental");
- CPPUNIT_ASSERT(chroots[2] == "chroot:sarge");
- CPPUNIT_ASSERT(chroots[3] == "chroot:sid");
- CPPUNIT_ASSERT(chroots[4] == "chroot:sid-local");
- CPPUNIT_ASSERT(chroots[5] == "chroot:stable");
- CPPUNIT_ASSERT(chroots[6] == "chroot:unstable");
- }
+ chroot = cf->find_alias("chroot", "stable");
+ EXPECT_NE(chroot, nullptr);
+ EXPECT_EQ(chroot->get_name(), "sarge");
- void test_validate_chroots()
- {
- sbuild::string_list chroots;
- chroots.push_back("default");
- chroots.push_back("sarge");
- chroots.push_back("unstable");
+ chroot = cf->find_alias("chroot", "invalid");
+ EXPECT_EQ(chroot, nullptr);
+}
- sbuild::chroot::config::chroot_map m = this->cf->validate_chroots("chroot", chroots);
- assert(m.size() == 3);
- }
+TEST_F(ChrootConfig, GetChrootList)
+{
+ sbuild::string_list chroots = cf->get_chroot_list("chroot");
+ EXPECT_EQ(chroots.size(), 4);
+ EXPECT_EQ(chroots[0], "chroot:experimental");
+ EXPECT_EQ(chroots[1], "chroot:sarge");
+ EXPECT_EQ(chroots[2], "chroot:sid");
+ EXPECT_EQ(chroots[3], "chroot:sid-local");
+}
+
+TEST_F(ChrootConfig, GetAliasList)
+{
+ sbuild::string_list chroots = cf->get_alias_list("chroot");
+ EXPECT_EQ(chroots.size(), 7);
+ EXPECT_EQ(chroots[0], "chroot:default");
+ EXPECT_EQ(chroots[1], "chroot:experimental");
+ EXPECT_EQ(chroots[2], "chroot:sarge");
+ EXPECT_EQ(chroots[3], "chroot:sid");
+ EXPECT_EQ(chroots[4], "chroot:sid-local");
+ EXPECT_EQ(chroots[5], "chroot:stable");
+ EXPECT_EQ(chroots[6], "chroot:unstable");
+}
+
+TEST_F(ChrootConfig, ValidateChroots)
+{
+ sbuild::string_list chroots;
+ chroots.push_back("default");
+ chroots.push_back("sarge");
+ chroots.push_back("unstable");
- void test_validate_chroots_fail()
- {
- sbuild::string_list chroots;
- chroots.push_back("default");
- chroots.push_back("invalid");
- chroots.push_back("invalid2");
- chroots.push_back("sarge");
- chroots.push_back("unstable");
-
- this->cf->validate_chroots("chroot", chroots);
- }
+ sbuild::chroot::config::chroot_map m = cf->validate_chroots("chroot", chroots);
+ EXPECT_EQ(m.size(), 3);
+}
- void test_config_fail()
- {
- sbuild::chroot::config c("chroot", TESTDATADIR "/config-directory-fail.ex");
- }
+TEST_F(ChrootConfig, ValidateChrootsFail)
+{
+ sbuild::string_list chroots;
+ chroots.push_back("default");
+ chroots.push_back("invalid");
+ chroots.push_back("invalid2");
+ chroots.push_back("sarge");
+ chroots.push_back("unstable");
- void test_config_deprecated()
- {
- sbuild::chroot::config c("chroot", TESTDATADIR "/config-directory-deprecated.ex");
- }
+ EXPECT_THROW(cf->validate_chroots("chroot", chroots), sbuild::error_base);
+}
- void test_config_valid()
- {
- sbuild::chroot::config c("chroot", TESTDATADIR "/config-directory-valid.ex");
- }
+TEST_F(ChrootConfig, ConfigFail)
+{
+ EXPECT_THROW(sbuild::chroot::config c("chroot", TESTDATADIR "/config-directory-fail.ex"),
+ sbuild::error_base);
+}
-};
+TEST_F(ChrootConfig, ConfigDeprecated)
+{
+ EXPECT_NO_THROW(sbuild::chroot::config c("chroot", TESTDATADIR "/config-directory-deprecated.ex"));
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_config);
+TEST_F(ChrootConfig, ConfigValid)
+{
+ EXPECT_NO_THROW(sbuild::chroot::config c("chroot", TESTDATADIR "/config-directory-valid.ex"));
+}
diff --git a/test/sbuild/chroot/custom.cc b/test/sbuild/chroot/custom.cc
index a5b462ba..801ec832 100644
--- a/test/sbuild/chroot/custom.cc
+++ b/test/sbuild/chroot/custom.cc
@@ -30,62 +30,32 @@
#include <algorithm>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_chroot_custom : public test_chroot_base
+class ChrootCustom : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_custom);
- CPPUNIT_TEST(test_directory);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_session_flags1);
- CPPUNIT_TEST(test_session_flags2);
- CPPUNIT_TEST(test_session_flags3);
- CPPUNIT_TEST(test_session_flags4);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot_custom():
- test_chroot_base("custom")
+ ChrootCustom():
+ ChrootBase("custom")
{}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(session);
- CPPUNIT_ASSERT(!source);
- CPPUNIT_ASSERT(!session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_NE(session, nullptr);
+ ASSERT_EQ(source, nullptr);
+ ASSERT_EQ(session_source, nullptr);
}
virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
sbuild::chroot::facet::userdata::ptr userdata = chroot->get_facet<sbuild::chroot::facet::userdata>();
- CPPUNIT_ASSERT(userdata);
+ ASSERT_NE(userdata, nullptr);
userdata->set_data("custom.directory", "/srv/chroots/sid");
userdata->set_data("custom.options", "foobar");
}
- void
- test_directory()
- {
- CPPUNIT_ASSERT(chroot->get_path() == "/mnt/mount-location");
- CPPUNIT_ASSERT(chroot->get_mount_location() == "/mnt/mount-location");
- }
-
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "custom");
- }
-
void setup_env_gen(sbuild::environment& expected)
{
setup_env_chroot(expected);
@@ -99,98 +69,107 @@ public:
expected.add("CUSTOM_DIRECTORY", "/srv/chroots/sid");
expected.add("CUSTOM_OPTIONS", "foobar");
}
+};
- void test_setup_env()
+TEST_F(ChrootCustom, Directory)
{
- sbuild::environment expected;
- setup_env_gen(expected);
-
- test_chroot_base::test_setup_env(chroot, expected);
+ ASSERT_EQ(chroot->get_path(), "/mnt/mount-location");
+ ASSERT_EQ(chroot->get_mount_location(), "/mnt/mount-location");
}
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- std::string group = chroot->get_name();
- setup_keyfile_chroot(expected, group);
- expected.set_value(group, "type", "custom");
- expected.set_value(group, "custom-session-purgeable", "false");
- expected.set_value(group, "custom.directory", "/srv/chroots/sid");
- expected.set_value(group, "custom.options", "foobar");
-
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
+TEST_F(ChrootCustom, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "custom");
+}
- void test_session_flags1()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
- CPPUNIT_ASSERT(chroot->get_facet<sbuild::chroot::facet::session_clonable>());
- CPPUNIT_ASSERT(!chroot->get_facet<sbuild::chroot::facet::source_clonable>());
- }
+TEST_F(ChrootCustom, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- void test_session_flags2()
- {
- sbuild::chroot::facet::custom::ptr custp = chroot->get_facet_strict<sbuild::chroot::facet::custom>();
- custp->set_session_cloneable(false);
+ ChrootBase::test_setup_env(chroot, expected);
+}
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_NOFLAGS);
+TEST_F(ChrootCustom, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ std::string group = chroot->get_name();
+ setup_keyfile_chroot(expected, group);
+ expected.set_value(group, "type", "custom");
+ expected.set_value(group, "custom-session-purgeable", "false");
+ expected.set_value(group, "custom.directory", "/srv/chroots/sid");
+ expected.set_value(group, "custom.options", "foobar");
+
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
+}
+
+TEST_F(ChrootCustom, SessionFlags1)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
- CPPUNIT_ASSERT(!chroot->get_facet<sbuild::chroot::facet::session_clonable>());
- CPPUNIT_ASSERT(!chroot->get_facet<sbuild::chroot::facet::source_clonable>());
- }
+ ASSERT_NE(chroot->get_facet<sbuild::chroot::facet::session_clonable>(), nullptr);
+ ASSERT_EQ(chroot->get_facet<sbuild::chroot::facet::source_clonable>(), nullptr);
+}
- void test_session_flags3()
- {
- sbuild::chroot::facet::custom::ptr custp = chroot->get_facet_strict<sbuild::chroot::facet::custom>();
- custp->set_source_cloneable(true);
+TEST_F(ChrootCustom, SessionFlags2)
+{
+ sbuild::chroot::facet::custom::ptr custp = chroot->get_facet_strict<sbuild::chroot::facet::custom>();
+ custp->set_session_cloneable(false);
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE|sbuild::chroot::facet::facet::SESSION_CLONE));
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_NOFLAGS);
- CPPUNIT_ASSERT(chroot->get_facet<sbuild::chroot::facet::session_clonable>());
- CPPUNIT_ASSERT(chroot->get_facet<sbuild::chroot::facet::source_clonable>());
- }
+ ASSERT_EQ(chroot->get_facet<sbuild::chroot::facet::session_clonable>(), nullptr);
+ ASSERT_EQ(chroot->get_facet<sbuild::chroot::facet::source_clonable>(), nullptr);
+}
- void test_session_flags4()
- {
- sbuild::chroot::facet::custom::ptr custp = chroot->get_facet_strict<sbuild::chroot::facet::custom>();
- custp->set_session_cloneable(false);
- custp->set_source_cloneable(true);
+TEST_F(ChrootCustom, SessionFlags3)
+{
+ sbuild::chroot::facet::custom::ptr custp = chroot->get_facet_strict<sbuild::chroot::facet::custom>();
+ custp->set_source_cloneable(true);
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CLONE);
+ ASSERT_EQ(chroot->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE|sbuild::chroot::facet::facet::SESSION_CLONE));
- CPPUNIT_ASSERT(!chroot->get_facet<sbuild::chroot::facet::session_clonable>());
- CPPUNIT_ASSERT(chroot->get_facet<sbuild::chroot::facet::source_clonable>());
- }
+ ASSERT_NE(chroot->get_facet<sbuild::chroot::facet::session_clonable>(), nullptr);
+ ASSERT_NE(chroot->get_facet<sbuild::chroot::facet::source_clonable>(), nullptr);
+}
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+TEST_F(ChrootCustom, SessionFlags4)
+{
+ sbuild::chroot::facet::custom::ptr custp = chroot->get_facet_strict<sbuild::chroot::facet::custom>();
+ custp->set_session_cloneable(false);
+ custp->set_source_cloneable(true);
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CLONE);
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts());
- }
+ ASSERT_EQ(chroot->get_facet<sbuild::chroot::facet::session_clonable>(), nullptr);
+ ASSERT_NE(chroot->get_facet<sbuild::chroot::facet::source_clonable>(), nullptr);
+}
-};
+TEST_F(ChrootCustom, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_custom);
+TEST_F(ChrootCustom, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootCustom, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/chroot/directory.cc b/test/sbuild/chroot/directory.cc
index 9f6e4253..fccabb43 100644
--- a/test/sbuild/chroot/directory.cc
+++ b/test/sbuild/chroot/directory.cc
@@ -27,86 +27,40 @@
#include <algorithm>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
using sbuild::_;
-class test_chroot_directory : public test_chroot_base
+class ChrootDirectory : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_directory);
- CPPUNIT_TEST(test_directory);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_env_session);
-#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_env_union);
- CPPUNIT_TEST(test_setup_env_session_union);
- CPPUNIT_TEST(test_setup_env_source_union);
- CPPUNIT_TEST(test_setup_env_session_source_union);
-#endif // SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_setup_keyfile_session);
- CPPUNIT_TEST(test_setup_keyfile_root_session);
-#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_keyfile_union);
- CPPUNIT_TEST(test_setup_keyfile_session_union);
- CPPUNIT_TEST(test_setup_keyfile_source_union);
- CPPUNIT_TEST(test_setup_keyfile_session_source_union);
-#endif // SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_session_flags);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot_directory():
- test_chroot_base("directory")
+ ChrootDirectory():
+ ChrootBase("directory")
{}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(session);
- CPPUNIT_ASSERT(!source);
- CPPUNIT_ASSERT(!session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_NE(session, nullptr);
+ ASSERT_EQ(source, nullptr);
+ ASSERT_EQ(session_source, nullptr);
#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_ASSERT(chroot_union);
- CPPUNIT_ASSERT(session_union);
- CPPUNIT_ASSERT(source_union);
- CPPUNIT_ASSERT(session_source_union);
+ ASSERT_NE(chroot_union, nullptr);
+ ASSERT_NE(session_union, nullptr);
+ ASSERT_NE(source_union, nullptr);
+ ASSERT_NE(session_source_union, nullptr);
#endif
}
virtual void setup_chroot_props (sbuild::chroot::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
sbuild::chroot::facet::directory::ptr dirfac = chroot->get_facet<sbuild::chroot::facet::directory>();
- CPPUNIT_ASSERT(dirfac);
+ ASSERT_NE(dirfac, nullptr);
dirfac->set_directory("/srv/chroot/example-chroot");
}
- void
- test_directory()
- {
- sbuild::chroot::facet::directory::ptr dirfac = chroot->get_facet<sbuild::chroot::facet::directory>();
- CPPUNIT_ASSERT(dirfac);
- dirfac->set_directory("/mnt/chroot/example");
- CPPUNIT_ASSERT(chroot->get_mount_location() == "/mnt/mount-location");
- CPPUNIT_ASSERT(dirfac->get_directory() == "/mnt/chroot/example");
- CPPUNIT_ASSERT(chroot->get_path() == "/mnt/mount-location");
- }
-
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "directory");
- }
-
void setup_env_gen(sbuild::environment& expected)
{
setup_env_chroot(expected);
@@ -116,279 +70,275 @@ public:
expected.add("CHROOT_DIRECTORY", "/srv/chroot/example-chroot");
expected.add("CHROOT_PATH", "/mnt/mount-location");
}
+};
- void test_setup_env()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
+TEST_F(ChrootDirectory, Directory)
+{
+ sbuild::chroot::facet::directory::ptr dirfac = chroot->get_facet<sbuild::chroot::facet::directory>();
+ ASSERT_NE(dirfac, nullptr);
+ dirfac->set_directory("/mnt/chroot/example");
+ ASSERT_EQ(chroot->get_mount_location(), "/mnt/mount-location");
+ ASSERT_EQ(dirfac->get_directory(), "/mnt/chroot/example");
+ ASSERT_EQ(chroot->get_path(), "/mnt/mount-location");
+}
+
+TEST_F(ChrootDirectory, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "directory");
+}
+
+TEST_F(ChrootDirectory, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
#ifdef SBUILD_FEATURE_UNION
- expected.add("CHROOT_UNION_TYPE", "none");
+ expected.add("CHROOT_UNION_TYPE", "none");
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_env(chroot, expected);
- }
+ ChrootBase::test_setup_env(chroot, expected);
+}
- void test_setup_env_session()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
-
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "false");
+TEST_F(ChrootDirectory, SetupEnvSession)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "false");
#ifdef SBUILD_FEATURE_UNION
- expected.add("CHROOT_UNION_TYPE", "none");
+ expected.add("CHROOT_UNION_TYPE", "none");
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_env(session, expected);
- }
+ ChrootBase::test_setup_env(session, expected);
+}
#ifdef SBUILD_FEATURE_UNION
- void test_setup_env_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
-
- expected.add("CHROOT_SESSION_CLONE", "true");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
- expected.add("CHROOT_UNION_TYPE", "aufs");
- expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
- expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay");
- expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay");
-
- test_chroot_base::test_setup_env(chroot_union, expected);
- }
-
- void test_setup_env_session_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
-
- expected.add("SESSION_ID", "test-union-session-name");
- expected.add("CHROOT_ALIAS", "test-union-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "true");
- expected.add("CHROOT_UNION_TYPE", "aufs");
- expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
- expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay/test-union-session-name");
- expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay/test-union-session-name");
-
- test_chroot_base::test_setup_env(session_union, expected);
- }
-
- void test_setup_env_source_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
-
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(source_union, expected);
- }
+TEST_F(ChrootDirectory, SetupEnvUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+
+ expected.add("SESSION_ID", "test-union-session-name");
+ expected.add("CHROOT_ALIAS", "test-union-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "true");
+ expected.add("CHROOT_UNION_TYPE", "aufs");
+ expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
+ expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay/test-union-session-name");
+ expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay/test-union-session-name");
+
+ ChrootBase::test_setup_env(session_union, expected);
+}
+
+TEST_F(ChrootDirectory, SetupEnvSourceUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- void test_setup_env_session_source_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "false");
+ ChrootBase::test_setup_env(source_union, expected);
+}
- test_chroot_base::test_setup_env(session_source_union, expected);
- }
+TEST_F(ChrootDirectory, SetupEnvSessionSourceUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(session_source_union, expected);
+}
#endif // SBUILD_FEATURE_UNION
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- const std::string group(chroot->get_name());
- setup_keyfile_chroot(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
+TEST_F(ChrootDirectory, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ const std::string group(chroot->get_name());
+ setup_keyfile_chroot(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
#ifdef SBUILD_FEATURE_UNION
- setup_keyfile_union_unconfigured(expected, group);
+ setup_keyfile_union_unconfigured(expected, group);
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
+}
- void test_setup_keyfile_session()
- {
- sbuild::keyfile expected;
- const std::string group(session->get_name());
- setup_keyfile_session(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "name", "test-session-name");
- expected.set_value(group, "selected-name", "test-session-name");
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
+TEST_F(ChrootDirectory, SetupKeyfileSession)
+{
+ sbuild::keyfile expected;
+ const std::string group(session->get_name());
+ setup_keyfile_session(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "name", "test-session-name");
+ expected.set_value(group, "selected-name", "test-session-name");
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
#ifdef SBUILD_FEATURE_UNION
- setup_keyfile_union_unconfigured(expected, group);
+ setup_keyfile_union_unconfigured(expected, group);
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_keyfile
- (session, expected, group);
- }
+ ChrootBase::test_setup_keyfile
+ (session, expected, group);
+}
- // Note, this test is unique to the directory chroot but is
- // applicable to all.
- void test_setup_keyfile_root_session()
- {
- // Create session owned by user in root-users.
- this->session = this->chroot->clone_session("test-session-name",
- "test-session-name",
- "user3",
- true);
- if (this->session)
- {
- CPPUNIT_ASSERT(this->session->get_facet<sbuild::chroot::facet::session>());
- }
-
- sbuild::keyfile expected;
- const std::string group(session->get_name());
- setup_keyfile_session(expected, group);
- expected.set_value(group, "users", "");
- expected.set_value(group, "root-users", "user3");
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "name", "test-session-name");
- expected.set_value(group, "selected-name", "test-session-name");
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
+// Note, this test is unique to the directory chroot but is
+// applicable to all.
+TEST_F(ChrootDirectory, SetupKeyfileRootSession)
+{
+ // Create session owned by user in root-users.
+ this->session = this->chroot->clone_session("test-session-name",
+ "test-session-name",
+ "user3",
+ true);
+ if (this->session)
+ {
+ ASSERT_NE(this->session->get_facet<sbuild::chroot::facet::session>(), nullptr);
+ }
+
+ sbuild::keyfile expected;
+ const std::string group(session->get_name());
+ setup_keyfile_session(expected, group);
+ expected.set_value(group, "users", "");
+ expected.set_value(group, "root-users", "user3");
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "name", "test-session-name");
+ expected.set_value(group, "selected-name", "test-session-name");
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
#ifdef SBUILD_FEATURE_UNION
- setup_keyfile_union_unconfigured(expected, group);
+ setup_keyfile_union_unconfigured(expected, group);
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_keyfile
- (session, expected, group);
- }
+ ChrootBase::test_setup_keyfile
+ (session, expected, group);
+}
#ifdef SBUILD_FEATURE_UNION
- void test_setup_keyfile_union()
- {
- sbuild::keyfile expected;
- const std::string group(chroot_union->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
- setup_keyfile_union_configured(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (chroot_union, expected, group);
- }
-
- void test_setup_keyfile_session_union()
- {
- sbuild::keyfile expected;
- const std::string group(session_union->get_name());
- setup_keyfile_session(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "name", "test-union-session-name");
- expected.set_value(group, "selected-name", "test-union-session-name");
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
- setup_keyfile_union_session(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (session_union, expected, group);
- }
-
- void test_setup_keyfile_source_union()
- {
- sbuild::keyfile expected;
- const std::string group(source_union->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source_clone(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
-
- test_chroot_base::test_setup_keyfile
- (source_union, expected, group);
- }
-
- void test_setup_keyfile_session_source_union()
- {
- sbuild::keyfile expected;
- const std::string group(source_union->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source_clone(expected, group);
- expected.set_value(group, "type", "directory");
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_source_clone(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (session_source_union, expected, group);
- }
+TEST_F(ChrootDirectory, SetupKeyfileUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(chroot_union->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
+ setup_keyfile_union_configured(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (chroot_union, expected, group);
+}
+
+TEST_F(ChrootDirectory, SetupKeyfileSessionUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(session_union->get_name());
+ setup_keyfile_session(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "name", "test-union-session-name");
+ expected.set_value(group, "selected-name", "test-union-session-name");
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
+ setup_keyfile_union_session(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (session_union, expected, group);
+}
+
+TEST_F(ChrootDirectory, SetupKeyfileSourceUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(source_union->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source_clone(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
+
+ ChrootBase::test_setup_keyfile
+ (source_union, expected, group);
+}
+
+TEST_F(ChrootDirectory, SetupKeyfileSessionSourceUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(source_union->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source_clone(expected, group);
+ expected.set_value(group, "type", "directory");
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_source_clone(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (session_source_union, expected, group);
+}
#endif // SBUILD_FEATURE_UNION
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
+TEST_F(ChrootDirectory, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
- CPPUNIT_ASSERT(session->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_NOFLAGS);
+ ASSERT_EQ(session->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_NOFLAGS);
#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_ASSERT(chroot_union->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE |
- sbuild::chroot::facet::facet::SESSION_CLONE));
+ ASSERT_EQ(chroot_union->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE |
+ sbuild::chroot::facet::facet::SESSION_CLONE));
- CPPUNIT_ASSERT(session_union->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_PURGE);
+ ASSERT_EQ(session_union->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_PURGE);
- CPPUNIT_ASSERT(source_union->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
+ ASSERT_EQ(source_union->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
#endif // SBUILD_FEATURE_UNION
- }
+}
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
-
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
-
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts());
- }
-
-};
+TEST_F(ChrootDirectory, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_directory);
+TEST_F(ChrootDirectory, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootDirectory, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/chroot/facet/userdata.cc b/test/sbuild/chroot/facet/userdata.cc
index 7cd4662f..c7baa229 100644
--- a/test/sbuild/chroot/facet/userdata.cc
+++ b/test/sbuild/chroot/facet/userdata.cc
@@ -16,49 +16,37 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <config.h>
#include <sbuild/chroot/facet/directory.h>
#include <sbuild/chroot/facet/userdata.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
using sbuild::_;
-class test_chroot_facet_userdata : public TestFixture
+class Userdata : public ::testing::Test
{
- CPPUNIT_TEST_SUITE(test_chroot_facet_userdata);
- CPPUNIT_TEST(test_data_set);
- CPPUNIT_TEST_EXCEPTION(test_data_fail1, sbuild::chroot::facet::userdata::error);
- CPPUNIT_TEST_EXCEPTION(test_data_fail2, sbuild::chroot::facet::userdata::error);
- CPPUNIT_TEST_EXCEPTION(test_data_fail3, sbuild::chroot::facet::userdata::error);
- CPPUNIT_TEST_EXCEPTION(test_data_fail4, sbuild::chroot::facet::userdata::error);
- CPPUNIT_TEST(test_user_set);
- CPPUNIT_TEST_EXCEPTION(test_user_fail1, sbuild::chroot::facet::userdata::error);
- CPPUNIT_TEST_EXCEPTION(test_user_fail2, sbuild::chroot::facet::userdata::error);
- CPPUNIT_TEST(test_root_set);
- CPPUNIT_TEST_EXCEPTION(test_root_fail, sbuild::chroot::facet::userdata::error);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot_facet_userdata():
+ sbuild::chroot::chroot::ptr chroot;
+ sbuild::chroot::facet::userdata::ptr userdata;
+
+ Userdata():
chroot(),
userdata()
{}
- void setUp()
+ void SetUp()
{
chroot = sbuild::chroot::chroot::create("directory");
- CPPUNIT_ASSERT(chroot);
+ ASSERT_NE(chroot, nullptr);
sbuild::chroot::facet::directory::ptr dirfac = chroot->get_facet<sbuild::chroot::facet::directory>();
- CPPUNIT_ASSERT(dirfac);
+ ASSERT_NE(dirfac, nullptr);
dirfac->set_directory("/chroots/test");
userdata = chroot->get_facet<sbuild::chroot::facet::userdata>();
- CPPUNIT_ASSERT(userdata);
+ ASSERT_NE(userdata, nullptr);
sbuild::string_set userkeys;
userkeys.insert("sbuild.resolver");
@@ -70,108 +58,109 @@ public:
userdata->set_root_modifiable_keys(rootkeys);
}
- void tearDown()
+ void TearDown()
{
this->chroot = sbuild::chroot::chroot::ptr();
this->userdata = sbuild::chroot::facet::userdata::ptr();
}
+};
- void test_data_set()
- {
- userdata->set_data("custom.test1", "testval");
- userdata->set_data("sbuild.resolver", "apt");
- userdata->set_data("setup.fstab", "custom/fstab");
+TEST_F(Userdata, Set)
+{
+ userdata->set_data("custom.test1", "testval");
+ userdata->set_data("sbuild.resolver", "apt");
+ userdata->set_data("setup.fstab", "custom/fstab");
- std::string t1;
- CPPUNIT_ASSERT(userdata->get_data("custom.test1", t1));
- CPPUNIT_ASSERT(t1 == "testval");
+ std::string t1;
+ ASSERT_TRUE(userdata->get_data("custom.test1", t1));
+ ASSERT_EQ(t1, "testval");
- std::string t2;
- CPPUNIT_ASSERT(userdata->get_data("sbuild.resolver", t2));
- CPPUNIT_ASSERT(t2 == "apt");
+ std::string t2;
+ ASSERT_TRUE(userdata->get_data("sbuild.resolver", t2));
+ ASSERT_EQ(t2, "apt");
- std::string t3;
- CPPUNIT_ASSERT(userdata->get_data("setup.fstab", t3));
- CPPUNIT_ASSERT(t3 == "custom/fstab");
+ std::string t3;
+ ASSERT_TRUE(userdata->get_data("setup.fstab", t3));
+ ASSERT_EQ(t3, "custom/fstab");
- std::string t4("invalid");
- CPPUNIT_ASSERT(!userdata->get_data("invalidkey", t4));
- CPPUNIT_ASSERT(t4 == "invalid");
- }
+ std::string t4("invalid");
+ ASSERT_TRUE(!userdata->get_data("invalidkey", t4));
+ ASSERT_EQ(t4, "invalid");
+}
- void test_data_fail1()
- {
- userdata->set_data("custom", "testval");
- }
-
- void test_data_fail2()
- {
- userdata->set_data("custom.key.set", "testval1");
- userdata->set_data("custom.key_set", "testval2");
- }
+TEST_F(Userdata, SetFail1)
+{
+ EXPECT_THROW(userdata->set_data("custom", "testval"),
+ sbuild::chroot::facet::userdata::error);
+}
- void test_data_fail3()
- {
- userdata->set_data("setup-data-dir", "testval3");
- }
+TEST_F(Userdata, SetFail2)
+{
+ EXPECT_NO_THROW(userdata->set_data("custom.key.set", "testval1"));
+ EXPECT_THROW(userdata->set_data("custom.key_set", "testval2"),
+ sbuild::chroot::facet::userdata::error);
+}
- void test_data_fail4()
- {
- userdata->set_data("setup.data.dir", "testval4");
- }
+TEST_F(Userdata, SetFail3)
+{
+ EXPECT_THROW(userdata->set_data("setup-data-dir", "testval3"),
+ sbuild::chroot::facet::userdata::error);
+}
- void test_user_set()
- {
- sbuild::string_map d;
- d.insert(std::make_pair("sbuild.resolver", "aptitude"));
- userdata->set_user_data(d);
+TEST_F(Userdata, SetFail4)
+{
+ EXPECT_THROW(userdata->set_data("setup.data.dir", "testval4"),
+ sbuild::chroot::facet::userdata::error);
+}
- std::string t1;
- CPPUNIT_ASSERT(userdata->get_data("sbuild.resolver", t1));
- CPPUNIT_ASSERT(t1 == "aptitude");
- }
+TEST_F(Userdata, UserSet)
+{
+ sbuild::string_map d;
+ d.insert(std::make_pair("sbuild.resolver", "aptitude"));
+ userdata->set_user_data(d);
- void test_user_fail1()
- {
- sbuild::string_map d;
- d.insert(std::make_pair("sbuild.apt-update", "true"));
- userdata->set_user_data(d);
- }
+ std::string t1;
+ ASSERT_TRUE(userdata->get_data("sbuild.resolver", t1));
+ ASSERT_EQ(t1, "aptitude");
+}
- void test_user_fail2()
- {
- // Use root key.
- sbuild::string_map d;
- d.insert(std::make_pair("debian.apt-update", "false"));
- userdata->set_user_data(d);
- }
+TEST_F(Userdata, UserSetFail1)
+{
+ sbuild::string_map d;
+ d.insert(std::make_pair("sbuild.apt-update", "true"));
+ EXPECT_THROW(userdata->set_user_data(d),
+ sbuild::chroot::facet::userdata::error);
+}
- void test_root_set()
- {
- sbuild::string_map d;
- d.insert(std::make_pair("sbuild.resolver", "aptitude"));
- d.insert(std::make_pair("debian.apt-update", "false"));
- userdata->set_root_data(d);
-
- std::string t1;
- CPPUNIT_ASSERT(userdata->get_data("sbuild.resolver", t1));
- CPPUNIT_ASSERT(t1 == "aptitude");
-
- std::string t2;
- CPPUNIT_ASSERT(userdata->get_data("debian.apt-update", t2));
- CPPUNIT_ASSERT(t2 == "false");
- }
+TEST_F(Userdata, UserSetFail2)
+{
+ // Use root key.
+ sbuild::string_map d;
+ d.insert(std::make_pair("debian.apt-update", "false"));
+ EXPECT_THROW(userdata->set_user_data(d),
+ sbuild::chroot::facet::userdata::error);
+}
+
+TEST_F(Userdata, RootSet)
+{
+ sbuild::string_map d;
+ d.insert(std::make_pair("sbuild.resolver", "aptitude"));
+ d.insert(std::make_pair("debian.apt-update", "false"));
+ userdata->set_root_data(d);
- void test_root_fail()
- {
- sbuild::string_map d;
- d.insert(std::make_pair("invalid.key", "testv"));
- userdata->set_root_data(d);
- }
+ std::string t1;
+ ASSERT_TRUE(userdata->get_data("sbuild.resolver", t1));
+ ASSERT_EQ(t1, "aptitude");
-private:
- sbuild::chroot::chroot::ptr chroot;
- sbuild::chroot::facet::userdata::ptr userdata;
-};
+ std::string t2;
+ ASSERT_TRUE(userdata->get_data("debian.apt-update", t2));
+ ASSERT_EQ(t2, "false");
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_facet_userdata);
+TEST_F(Userdata, RootSetFail)
+{
+ sbuild::string_map d;
+ d.insert(std::make_pair("invalid.key", "testv"));
+ EXPECT_THROW(userdata->set_root_data(d),
+ sbuild::chroot::facet::userdata::error);
+}
diff --git a/test/sbuild/chroot/file.cc b/test/sbuild/chroot/file.cc
index 20bda45f..07f694b2 100644
--- a/test/sbuild/chroot/file.cc
+++ b/test/sbuild/chroot/file.cc
@@ -27,108 +27,39 @@
#include <algorithm>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
using sbuild::_;
-class test_chroot_file : public test_chroot_base
+class ChrootFile : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_file);
- CPPUNIT_TEST(test_file);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_location);
- CPPUNIT_TEST_EXCEPTION(test_location_invalid, sbuild::chroot::chroot::error);
- CPPUNIT_TEST(test_repack);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_env_session);
- CPPUNIT_TEST(test_setup_env_source);
- CPPUNIT_TEST(test_setup_env_session_source);
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_setup_keyfile_session);
- CPPUNIT_TEST(test_setup_keyfile_source);
- CPPUNIT_TEST(test_setup_keyfile_session_source);
- CPPUNIT_TEST(test_session_flags);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot_file():
- test_chroot_base("file")
+ ChrootFile():
+ ChrootBase("file")
{}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(session);
- CPPUNIT_ASSERT(source);
- CPPUNIT_ASSERT(session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_NE(session, nullptr);
+ ASSERT_NE(source, nullptr);
+ ASSERT_NE(session_source, nullptr);
#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_ASSERT(!chroot_union);
- CPPUNIT_ASSERT(!session_union);
- CPPUNIT_ASSERT(!source_union);
- CPPUNIT_ASSERT(!session_source_union);
+ ASSERT_EQ(chroot_union, nullptr);
+ ASSERT_EQ(session_union, nullptr);
+ ASSERT_EQ(source_union, nullptr);
+ ASSERT_EQ(session_source_union, nullptr);
#endif // SBUILD_FEATURE_UNION
}
virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
sbuild::chroot::facet::file::ptr filefac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
filefac->set_filename("/srv/chroot/example.tar.bz2");
filefac->set_location("/sid");
}
- void
- test_file()
- {
- sbuild::chroot::facet::file::ptr filefac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
- filefac->set_filename("/srv/chroot-images/unstable.tar.gz");
- CPPUNIT_ASSERT(filefac->get_filename() == "/srv/chroot-images/unstable.tar.gz");
- }
-
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "file");
- }
-
- void test_location()
- {
- sbuild::chroot::facet::file::ptr filefac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
-
- filefac->set_location("");
- CPPUNIT_ASSERT(filefac->get_location() == "");
- CPPUNIT_ASSERT(filefac->get_path() == chroot->get_mount_location());
-
- filefac->set_location("/test");
- CPPUNIT_ASSERT(filefac->get_location() == "/test");
- CPPUNIT_ASSERT(filefac->get_path() == "/mnt/mount-location/test");
- }
-
- void test_location_invalid()
- {
- sbuild::chroot::facet::file::ptr filefac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
-
- filefac->set_location("invalid");
- }
-
- void test_repack()
- {
- sbuild::chroot::facet::file::ptr filechrootfac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
- sbuild::chroot::facet::file::ptr filesessionfac = session->get_facet_strict<sbuild::chroot::facet::file>();
- sbuild::chroot::facet::file::ptr filesourcefac = source->get_facet_strict<sbuild::chroot::facet::file>();
-
-
- CPPUNIT_ASSERT(filechrootfac->get_file_repack() == false);
- CPPUNIT_ASSERT(filesessionfac->get_file_repack() == false);
- CPPUNIT_ASSERT(filesourcefac->get_file_repack() == true);
- }
-
void setup_env_gen(sbuild::environment &expected)
{
setup_env_chroot(expected);
@@ -143,62 +74,7 @@ public:
expected.add("CHROOT_SESSION_CREATE", "true");
expected.add("CHROOT_SESSION_PURGE", "false");
- test_chroot_base::test_setup_env(chroot, expected);
- }
-
- void test_setup_env()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_FILE_REPACK", "false");
- expected.add("CHROOT_SESSION_CLONE", "true");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(chroot, expected);
- }
-
- void test_setup_env_session()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_FILE_REPACK", "false");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "true");
-
- test_chroot_base::test_setup_env(session, expected);
- }
-
- void test_setup_env_source()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.add("CHROOT_FILE_REPACK", "true");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(source, expected);
- }
-
- void test_setup_env_session_source()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
- expected.add("CHROOT_FILE_REPACK", "true");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "true");
-
- test_chroot_base::test_setup_env(session_source, expected);
+ ChrootBase::test_setup_env(chroot, expected);
}
void setup_keyfile_file(sbuild::keyfile &expected, const std::string group)
@@ -207,99 +83,194 @@ public:
expected.set_value(group, "file", "/srv/chroot/example.tar.bz2");
expected.set_value(group, "location", "/sid");
}
+};
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- const std::string group(chroot->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source(expected, group);
- setup_keyfile_file(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
+TEST_F(ChrootFile, Filename)
+{
+ sbuild::chroot::facet::file::ptr filefac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
+ filefac->set_filename("/srv/chroot-images/unstable.tar.gz");
+ ASSERT_EQ(filefac->get_filename(), "/srv/chroot-images/unstable.tar.gz");
+}
- void test_setup_keyfile_session()
- {
- sbuild::keyfile expected;
- const std::string group(session->get_name());
- setup_keyfile_session(expected, group);
- setup_keyfile_file(expected, group);
- expected.set_value(group, "name", "test-session-name");
- expected.set_value(group, "selected-name", "test-session-name");
- expected.set_value(group, "file-repack", "false");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (session, expected, group);
- }
+TEST_F(ChrootFile, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "file");
+}
- void test_setup_keyfile_source()
- {
- sbuild::keyfile expected;
- const std::string group(source->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source_clone(expected, group);
- setup_keyfile_file(expected, group);
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
-
- test_chroot_base::test_setup_keyfile
- (source, expected, group);
- }
+TEST_F(ChrootFile, Location)
+{
+ sbuild::chroot::facet::file::ptr filefac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
- void test_setup_keyfile_session_source()
- {
- sbuild::keyfile expected;
- const std::string group(source->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_file(expected, group);
- setup_keyfile_session_source_clone(expected, group);
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
- expected.set_value(group, "file-repack", "true");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
-
- test_chroot_base::test_setup_keyfile
- (session_source, expected, group);
- }
+ filefac->set_location("");
+ ASSERT_EQ(filefac->get_location(), "");
+ ASSERT_EQ(filefac->get_path(), chroot->get_mount_location());
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE |
- sbuild::chroot::facet::facet::SESSION_CLONE));
+ filefac->set_location("/test");
+ ASSERT_EQ(filefac->get_location(), "/test");
+ ASSERT_EQ(filefac->get_path(), "/mnt/mount-location/test");
+}
- CPPUNIT_ASSERT(session->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_PURGE);
+TEST_F(ChrootFile, LocationInvalid)
+{
+ sbuild::chroot::facet::file::ptr filefac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
- CPPUNIT_ASSERT(source->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
- }
+ ASSERT_THROW(filefac->set_location("invalid"), sbuild::chroot::chroot::error);
+}
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+TEST_F(ChrootFile, Repack)
+{
+ sbuild::chroot::facet::file::ptr filechrootfac = chroot->get_facet_strict<sbuild::chroot::facet::file>();
+ sbuild::chroot::facet::file::ptr filesessionfac = session->get_facet_strict<sbuild::chroot::facet::file>();
+ sbuild::chroot::facet::file::ptr filesourcefac = source->get_facet_strict<sbuild::chroot::facet::file>();
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+ ASSERT_FALSE(filechrootfac->get_file_repack());
+ ASSERT_FALSE(filesessionfac->get_file_repack());
+ ASSERT_TRUE(filesourcefac->get_file_repack());
+}
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts());
- }
+TEST_F(ChrootFile, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_FILE_REPACK", "false");
+ expected.add("CHROOT_SESSION_CLONE", "true");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
-};
+ ChrootBase::test_setup_env(chroot, expected);
+}
+
+TEST_F(ChrootFile, SetupEnvSession)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_FILE_REPACK", "false");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "true");
+
+ ChrootBase::test_setup_env(session, expected);
+}
+
+TEST_F(ChrootFile, SetupSource)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.add("CHROOT_FILE_REPACK", "true");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(source, expected);
+}
+
+TEST_F(ChrootFile, SetupEnvSessionSource)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
+ expected.add("CHROOT_FILE_REPACK", "true");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "true");
+
+ ChrootBase::test_setup_env(session_source, expected);
+}
+
+TEST_F(ChrootFile, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ const std::string group(chroot->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source(expected, group);
+ setup_keyfile_file(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_file);
+TEST_F(ChrootFile, SetupKeyfileSession)
+{
+ sbuild::keyfile expected;
+ const std::string group(session->get_name());
+ setup_keyfile_session(expected, group);
+ setup_keyfile_file(expected, group);
+ expected.set_value(group, "name", "test-session-name");
+ expected.set_value(group, "selected-name", "test-session-name");
+ expected.set_value(group, "file-repack", "false");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (session, expected, group);
+}
+
+TEST_F(ChrootFile, SetupKeyfileSource)
+{
+ sbuild::keyfile expected;
+ const std::string group(source->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source_clone(expected, group);
+ setup_keyfile_file(expected, group);
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+
+ ChrootBase::test_setup_keyfile
+ (source, expected, group);
+}
+
+TEST_F(ChrootFile, SetupKeyfileSessionSource)
+{
+ sbuild::keyfile expected;
+ const std::string group(source->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_file(expected, group);
+ setup_keyfile_session_source_clone(expected, group);
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
+ expected.set_value(group, "file-repack", "true");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+
+ ChrootBase::test_setup_keyfile
+ (session_source, expected, group);
+}
+
+TEST_F(ChrootFile, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE |
+ sbuild::chroot::facet::facet::SESSION_CLONE));
+
+ ASSERT_EQ(session->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_PURGE);
+
+ ASSERT_EQ(source->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
+}
+
+TEST_F(ChrootFile, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootFile, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootFile, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/chroot/loopback.cc b/test/sbuild/chroot/loopback.cc
index 96f5e09e..73c464ae 100644
--- a/test/sbuild/chroot/loopback.cc
+++ b/test/sbuild/chroot/loopback.cc
@@ -30,100 +30,52 @@
#include <test/sbuild/chroot/chroot.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
using sbuild::_;
-class test_chroot_loopback : public test_chroot_base
+class ChrootLoopback : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_loopback);
- CPPUNIT_TEST(test_file);
- CPPUNIT_TEST(test_mount_options);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_env_session);
-#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_env_union);
- CPPUNIT_TEST(test_setup_env_session_union);
- CPPUNIT_TEST(test_setup_env_source_union);
- CPPUNIT_TEST(test_setup_env_session_source_union);
-#endif // SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_setup_keyfile_session);
-#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_setup_keyfile_union);
- CPPUNIT_TEST(test_setup_keyfile_session_union);
- CPPUNIT_TEST(test_setup_keyfile_source_union);
- CPPUNIT_TEST(test_setup_keyfile_session_source_union);
-#endif // SBUILD_FEATURE_UNION
- CPPUNIT_TEST(test_session_flags);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
+public:
std::string loopback_file;
-public:
- test_chroot_loopback():
- test_chroot_base("loopback"),
+ ChrootLoopback():
+ ChrootBase("loopback"),
loopback_file()
{
loopback_file = abs_testdata_dir;
loopback_file.append("/loopback-file");
}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(session);
- CPPUNIT_ASSERT(!source);
- CPPUNIT_ASSERT(!session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_NE(session, nullptr);
+ ASSERT_EQ(source, nullptr);
+ ASSERT_EQ(session_source, nullptr);
#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_ASSERT(chroot_union);
- CPPUNIT_ASSERT(session_union);
- CPPUNIT_ASSERT(source_union);
- CPPUNIT_ASSERT(session_source_union);
+ ASSERT_NE(chroot_union, nullptr);
+ ASSERT_NE(session_union, nullptr);
+ ASSERT_NE(source_union, nullptr);
+ ASSERT_NE(session_source_union, nullptr);
#endif // SBUILD_FEATURE_UNION
}
virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
sbuild::chroot::facet::loopback::ptr loop = chroot->get_facet_strict<sbuild::chroot::facet::loopback>();
- CPPUNIT_ASSERT(loop);
+ ASSERT_NE(loop, nullptr);
loop->set_filename(loopback_file);
sbuild::chroot::facet::mountable::ptr pmnt(chroot->get_facet<sbuild::chroot::facet::mountable>());
- CPPUNIT_ASSERT(pmnt);
+ ASSERT_NE(pmnt, nullptr);
pmnt->set_mount_options("-t jfs -o quota,rw");
pmnt->set_location("/squeeze");
}
- void
- test_file()
- {
- sbuild::chroot::facet::loopback::ptr loop = chroot->get_facet_strict<sbuild::chroot::facet::loopback>();
- CPPUNIT_ASSERT(loop);
- loop->set_filename("/dev/some/file");
- CPPUNIT_ASSERT(loop->get_filename() == "/dev/some/file");
- }
-
- void
- test_mount_options()
- {
- sbuild::chroot::facet::mountable::ptr pmnt(chroot->get_facet<sbuild::chroot::facet::mountable>());
- CPPUNIT_ASSERT(pmnt);
- pmnt->set_mount_options("-o opt1,opt2");
- CPPUNIT_ASSERT(pmnt->get_mount_options() == "-o opt1,opt2");
- }
-
void setup_env_gen(sbuild::environment& expected)
{
setup_env_chroot(expected);
@@ -136,254 +88,268 @@ public:
expected.add("CHROOT_MOUNT_OPTIONS", "-t jfs -o quota,rw");
}
- void test_setup_env()
+ void setup_keyfile_loop(sbuild::keyfile &expected, std::string group)
{
- sbuild::environment expected;
- setup_env_gen(expected);
+ expected.set_value(group, "type", "loopback");
+ expected.set_value(group, "file", loopback_file);
+ expected.set_value(group, "location", "/squeeze");
+ expected.set_value(group, "mount-options", "-t jfs -o quota,rw");
+ }
+};
+
+TEST_F(ChrootLoopback, File)
+{
+ sbuild::chroot::facet::loopback::ptr loop = chroot->get_facet_strict<sbuild::chroot::facet::loopback>();
+ ASSERT_NE(loop, nullptr);
+ loop->set_filename("/dev/some/file");
+ ASSERT_EQ(loop->get_filename(), "/dev/some/file");
+}
+
+TEST_F(ChrootLoopback, MountOptions)
+{
+ sbuild::chroot::facet::mountable::ptr pmnt(chroot->get_facet<sbuild::chroot::facet::mountable>());
+ ASSERT_NE(pmnt, nullptr);
+ pmnt->set_mount_options("-o opt1,opt2");
+ ASSERT_EQ(pmnt->get_mount_options(), "-o opt1,opt2");
+}
+
+TEST_F(ChrootLoopback, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
#ifdef SBUILD_FEATURE_UNION
- expected.add("CHROOT_UNION_TYPE", "none");
+ expected.add("CHROOT_UNION_TYPE", "none");
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_env(chroot, expected);
- }
+ ChrootBase::test_setup_env(chroot, expected);
+}
- void test_setup_env_session()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
+TEST_F(ChrootLoopback, SetupEnvSession)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "false");
- expected.add("CHROOT_MOUNT_DEVICE", loopback_file);
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_MOUNT_DEVICE", loopback_file);
#ifdef SBUILD_FEATURE_UNION
- expected.add("CHROOT_UNION_TYPE", "none");
+ expected.add("CHROOT_UNION_TYPE", "none");
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_env(session, expected);
- }
+ ChrootBase::test_setup_env(session, expected);
+}
#ifdef SBUILD_FEATURE_UNION
- void test_setup_env_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
-
- expected.add("CHROOT_SESSION_CLONE", "true");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
- expected.add("CHROOT_UNION_TYPE", "aufs");
- expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
- expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay");
- expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay");
-
- test_chroot_base::test_setup_env(chroot_union, expected);
- }
+TEST_F(ChrootLoopback, SetupEnvUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- void test_setup_env_session_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
-
- expected.add("SESSION_ID", "test-union-session-name");
- expected.add("CHROOT_ALIAS", "test-union-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "true");
- expected.add("CHROOT_MOUNT_DEVICE", loopback_file);
- expected.add("CHROOT_UNION_TYPE", "aufs");
- expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
- expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay/test-union-session-name");
- expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay/test-union-session-name");
- test_chroot_base::test_setup_env(session_union, expected);
- }
+ expected.add("CHROOT_SESSION_CLONE", "true");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+ expected.add("CHROOT_UNION_TYPE", "aufs");
+ expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
+ expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay");
+ expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay");
- void test_setup_env_source_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
+ ChrootBase::test_setup_env(chroot_union, expected);
+}
- expected.add("CHROOT_NAME", "test-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
+TEST_F(ChrootLoopback, SetupEnvSessionUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+
+ expected.add("SESSION_ID", "test-union-session-name");
+ expected.add("CHROOT_ALIAS", "test-union-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "true");
+ expected.add("CHROOT_MOUNT_DEVICE", loopback_file);
+ expected.add("CHROOT_UNION_TYPE", "aufs");
+ expected.add("CHROOT_UNION_MOUNT_OPTIONS", "union-mount-options");
+ expected.add("CHROOT_UNION_OVERLAY_DIRECTORY", "/overlay/test-union-session-name");
+ expected.add("CHROOT_UNION_UNDERLAY_DIRECTORY", "/underlay/test-union-session-name");
+ ChrootBase::test_setup_env(session_union, expected);
+}
+
+TEST_F(ChrootLoopback, SetupEnvSourceUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
- test_chroot_base::test_setup_env(source_union, expected);
- }
+ expected.add("CHROOT_NAME", "test-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
- void test_setup_env_session_source_union()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
-
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_NAME", "test-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
- expected.add("CHROOT_MOUNT_DEVICE", loopback_file);
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(session_source_union, expected);
- }
+ ChrootBase::test_setup_env(source_union, expected);
+}
+
+TEST_F(ChrootLoopback, SetupEnvSessionSourceUnion)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_NAME", "test-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
+ expected.add("CHROOT_MOUNT_DEVICE", loopback_file);
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(session_source_union, expected);
+}
#endif // SBUILD_FEATURE_UNION
- void setup_keyfile_loop(sbuild::keyfile &expected, std::string group)
- {
- expected.set_value(group, "type", "loopback");
- expected.set_value(group, "file", loopback_file);
- expected.set_value(group, "location", "/squeeze");
- expected.set_value(group, "mount-options", "-t jfs -o quota,rw");
- }
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- const std::string group(chroot->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_loop(expected, group);
+TEST_F(ChrootLoopback, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ const std::string group(chroot->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_loop(expected, group);
#ifdef SBUILD_FEATURE_UNION
- setup_keyfile_union_unconfigured(expected, group);
+ setup_keyfile_union_unconfigured(expected, group);
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
+}
- void test_setup_keyfile_session()
- {
- sbuild::keyfile expected;
- const std::string group(session->get_name());
- setup_keyfile_session(expected, group);
- setup_keyfile_loop(expected, group);
- expected.set_value(group, "name", "test-session-name");
- expected.set_value(group, "selected-name", "test-session-name");
- expected.set_value(group, "mount-device", loopback_file);
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
+TEST_F(ChrootLoopback, SetupKeyfileSession)
+{
+ sbuild::keyfile expected;
+ const std::string group(session->get_name());
+ setup_keyfile_session(expected, group);
+ setup_keyfile_loop(expected, group);
+ expected.set_value(group, "name", "test-session-name");
+ expected.set_value(group, "selected-name", "test-session-name");
+ expected.set_value(group, "mount-device", loopback_file);
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
#ifdef SBUILD_FEATURE_UNION
- setup_keyfile_union_unconfigured(expected, group);
+ setup_keyfile_union_unconfigured(expected, group);
#endif // SBUILD_FEATURE_UNION
- test_chroot_base::test_setup_keyfile
- (session, expected, group);
- }
+ ChrootBase::test_setup_keyfile
+ (session, expected, group);
+}
#ifdef SBUILD_FEATURE_UNION
- void test_setup_keyfile_union()
- {
- sbuild::keyfile expected;
- const std::string group(chroot_union->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source(expected, group);
- setup_keyfile_loop(expected, group);
- setup_keyfile_union_configured(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (chroot_union, expected, group);
- }
-
- void test_setup_keyfile_session_union()
- {
- sbuild::keyfile expected;
- const std::string group(session_union->get_name());
- setup_keyfile_session(expected, group);
- setup_keyfile_loop(expected, group);
- expected.set_value(group, "name", "test-union-session-name");
- expected.set_value(group, "selected-name", "test-union-session-name");
- expected.set_value(group, "mount-device", loopback_file);
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_clone(expected, group);
- setup_keyfile_union_session(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (session_union, expected, group);
- }
-
- void test_setup_keyfile_source_union()
- {
- sbuild::keyfile expected;
- const std::string group(source_union->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source_clone(expected, group);
- setup_keyfile_loop(expected, group);
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
-
- test_chroot_base::test_setup_keyfile
- (source_union, expected, group);
- }
-
- void test_setup_keyfile_session_source_union()
- {
- sbuild::keyfile expected;
- const std::string group(source_union->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_session_source_clone(expected, group);
- setup_keyfile_loop(expected, group);
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
- expected.set_value(group, "mount-device", loopback_file);
- expected.set_value(group, "mount-location", "/mnt/mount-location");
-
- test_chroot_base::test_setup_keyfile
- (session_source_union, expected, group);
- }
+TEST_F(ChrootLoopback, SetupKeyfileUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(chroot_union->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source(expected, group);
+ setup_keyfile_loop(expected, group);
+ setup_keyfile_union_configured(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (chroot_union, expected, group);
+}
+
+TEST_F(ChrootLoopback, SetupKeyfileSessionUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(session_union->get_name());
+ setup_keyfile_session(expected, group);
+ setup_keyfile_loop(expected, group);
+ expected.set_value(group, "name", "test-union-session-name");
+ expected.set_value(group, "selected-name", "test-union-session-name");
+ expected.set_value(group, "mount-device", loopback_file);
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_clone(expected, group);
+ setup_keyfile_union_session(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (session_union, expected, group);
+}
+
+TEST_F(ChrootLoopback, SetupKeyfileSourceUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(source_union->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source_clone(expected, group);
+ setup_keyfile_loop(expected, group);
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+
+ ChrootBase::test_setup_keyfile
+ (source_union, expected, group);
+}
+
+TEST_F(ChrootLoopback, SetupKeyfileSessionSourceUnion)
+{
+ sbuild::keyfile expected;
+ const std::string group(source_union->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_session_source_clone(expected, group);
+ setup_keyfile_loop(expected, group);
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
+ expected.set_value(group, "mount-device", loopback_file);
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+
+ ChrootBase::test_setup_keyfile
+ (session_source_union, expected, group);
+}
#endif // SBUILD_FEATURE_UNION
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
+TEST_F(ChrootLoopback, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
- CPPUNIT_ASSERT(session->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_NOFLAGS);
+ ASSERT_EQ(session->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_NOFLAGS);
#ifdef SBUILD_FEATURE_UNION
- CPPUNIT_ASSERT(chroot_union->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE |
- sbuild::chroot::facet::facet::SESSION_CLONE));
+ ASSERT_EQ(chroot_union->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE |
+ sbuild::chroot::facet::facet::SESSION_CLONE));
- CPPUNIT_ASSERT(session_union->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_PURGE);
+ ASSERT_EQ(session_union->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_PURGE);
- CPPUNIT_ASSERT(source_union->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_CREATE);
+ ASSERT_EQ(source_union->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_CREATE);
#endif // SBUILD_FEATURE_UNION
- }
-
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
-
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+}
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts());
- }
-
-};
+TEST_F(ChrootLoopback, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_loopback);
+TEST_F(ChrootLoopback, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootLoopback, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/chroot/lvm-snapshot.cc b/test/sbuild/chroot/lvm-snapshot.cc
index e66f56be..658f17f7 100644
--- a/test/sbuild/chroot/lvm-snapshot.cc
+++ b/test/sbuild/chroot/lvm-snapshot.cc
@@ -29,49 +29,27 @@
#include <algorithm>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
using sbuild::_;
-class test_chroot_lvm_snapshot : public test_chroot_base
+class ChrootLVMSnapshot : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_lvm_snapshot);
- CPPUNIT_TEST(test_snapshot_device);
- CPPUNIT_TEST(test_snapshot_options);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_env_session);
- CPPUNIT_TEST(test_setup_env_source);
- CPPUNIT_TEST(test_setup_env_session_source);
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_setup_keyfile_session);
- CPPUNIT_TEST(test_setup_keyfile_source);
- CPPUNIT_TEST(test_setup_keyfile_session_source);
- CPPUNIT_TEST(test_session_flags);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
-
public:
- test_chroot_lvm_snapshot():
- test_chroot_base("lvm-snapshot")
+ ChrootLVMSnapshot():
+ ChrootBase("lvm-snapshot")
{}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(session);
- CPPUNIT_ASSERT(source);
- CPPUNIT_ASSERT(session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_NE(session, nullptr);
+ ASSERT_NE(source, nullptr);
+ ASSERT_NE(session_source, nullptr);
}
virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
sbuild::chroot::facet::lvm_snapshot::ptr psnap(chroot->get_facet_strict<sbuild::chroot::facet::lvm_snapshot>());
@@ -79,34 +57,13 @@ public:
psnap->set_snapshot_options("--size 1G");
sbuild::chroot::facet::mountable::ptr pmnt(chroot->get_facet<sbuild::chroot::facet::mountable>());
- CPPUNIT_ASSERT(pmnt);
+ ASSERT_NE(pmnt, nullptr);
pmnt->set_mount_options("-t jfs -o quota,rw");
pmnt->set_location("/squeeze");
//c->set_snapshot_device("/dev/volgroup/snaptestdev");
}
- void
- test_snapshot_device()
- {
- sbuild::chroot::facet::lvm_snapshot::ptr psnap(chroot->get_facet_strict<sbuild::chroot::facet::lvm_snapshot>());
- psnap->set_snapshot_device("/dev/volgroup/some/snapshot/device");
- CPPUNIT_ASSERT(psnap->get_snapshot_device() == "/dev/volgroup/some/snapshot/device");
- }
-
- void
- test_snapshot_options()
- {
- sbuild::chroot::facet::lvm_snapshot::ptr psnap(chroot->get_facet_strict<sbuild::chroot::facet::lvm_snapshot>());
- psnap->set_snapshot_options("-o opt1,opt2");
- CPPUNIT_ASSERT(psnap->get_snapshot_options() == "-o opt1,opt2");
- }
-
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "lvm-snapshot");
- }
-
void setup_env_gen(sbuild::environment &expected)
{
setup_env_chroot(expected);
@@ -117,178 +74,194 @@ public:
expected.add("CHROOT_MOUNT_OPTIONS", "-t jfs -o quota,rw");
}
- void test_setup_env()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "lvm-snapshot");
- expected.add("CHROOT_LVM_SNAPSHOT_OPTIONS", "--size 1G");
- expected.add("CHROOT_SESSION_CLONE", "true");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(chroot, expected);
- }
-
- void test_setup_env_session()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "lvm-snapshot");
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.add("CHROOT_MOUNT_DEVICE", "/dev/volgroup/test-session-name");
- expected.add("CHROOT_LVM_SNAPSHOT_NAME", "test-session-name");
- expected.add("CHROOT_LVM_SNAPSHOT_DEVICE", "/dev/volgroup/test-session-name");
- expected.add("CHROOT_LVM_SNAPSHOT_OPTIONS", "--size 1G");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "true");
-
- test_chroot_base::test_setup_env(session, expected);
- }
-
- void test_setup_env_source()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "block-device");
- expected.add("CHROOT_NAME", "test-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "true");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(source, expected);
- }
-
- void test_setup_env_session_source()
- {
- sbuild::environment expected;
- setup_env_gen(expected);
- expected.add("CHROOT_TYPE", "block-device");
- expected.add("CHROOT_NAME", "test-name");
- expected.add("SESSION_ID", "test-session-name");
- expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
- expected.add("CHROOT_ALIAS", "test-session-name");
- expected.add("CHROOT_MOUNT_DEVICE", "/dev/volgroup/testdev");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(session_source, expected);
- }
-
void setup_keyfile_lvm(sbuild::keyfile &expected, std::string group)
{
expected.set_value(group, "device", "/dev/volgroup/testdev");
expected.set_value(group, "location", "/squeeze");
expected.set_value(group, "mount-options", "-t jfs -o quota,rw");
}
+};
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- std::string group = chroot->get_name();
- setup_keyfile_chroot(expected, group);
- setup_keyfile_source(expected, group);
- setup_keyfile_lvm(expected, group);
- expected.set_value(group, "type", "lvm-snapshot");
- expected.set_value(group, "lvm-snapshot-options", "--size 1G");
-
- test_chroot_base::test_setup_keyfile
- (chroot,expected, chroot->get_name());
- }
-
- void test_setup_keyfile_session()
- {
- sbuild::keyfile expected;
- const std::string group(session->get_name());
- setup_keyfile_session(expected, group);
- setup_keyfile_lvm(expected, group);
- expected.set_value(group, "type", "lvm-snapshot");
- expected.set_value(group, "name", "test-session-name");
- expected.set_value(group, "selected-name", "test-session-name");
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(session chroot)"));
- expected.set_value(group, "aliases", "");
- expected.set_value(group, "lvm-snapshot-device", "/dev/volgroup/test-session-name");
- expected.set_value(group, "mount-device", "/dev/volgroup/test-session-name");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
-
- test_chroot_base::test_setup_keyfile
- (session, expected, group);
- }
-
- void test_setup_keyfile_source()
- {
- sbuild::keyfile expected;
- const std::string group(source->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_lvm(expected, group);
- expected.set_value(group, "type", "block-device");
- expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
- expected.set_value(group, "aliases", "test-name-source,test-alias-1-source,test-alias-2-source");
- setup_keyfile_source_clone(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (source, expected, group);
- }
+TEST_F(ChrootLVMSnapshot, SnapshotDevice)
+{
+ sbuild::chroot::facet::lvm_snapshot::ptr psnap(chroot->get_facet_strict<sbuild::chroot::facet::lvm_snapshot>());
+ psnap->set_snapshot_device("/dev/volgroup/some/snapshot/device");
+ ASSERT_EQ(psnap->get_snapshot_device(), "/dev/volgroup/some/snapshot/device");
+}
- void test_setup_keyfile_session_source()
- {
- sbuild::keyfile expected;
- const std::string group(source->get_name());
- setup_keyfile_chroot(expected, group);
- setup_keyfile_lvm(expected, group);
- expected.set_value(group, "type", "block-device");
- expected.set_value(group, "mount-device", "/dev/volgroup/testdev");
- expected.set_value(group, "mount-location", "/mnt/mount-location");
- setup_keyfile_session_source_clone(expected, group);
-
- test_chroot_base::test_setup_keyfile
- (session_source, expected, group);
- }
+TEST_F(ChrootLVMSnapshot, SnapshotOptions)
+{
+ sbuild::chroot::facet::lvm_snapshot::ptr psnap(chroot->get_facet_strict<sbuild::chroot::facet::lvm_snapshot>());
+ psnap->set_snapshot_options("-o opt1,opt2");
+ ASSERT_EQ(psnap->get_snapshot_options(), "-o opt1,opt2");
+}
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE |
- sbuild::chroot::facet::facet::SESSION_CLONE));
-
- CPPUNIT_ASSERT(session->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_PURGE));
-
- /// @todo: Should return NOFLAGS? This depends upon if source
- /// chroots need transforming into sessions as well (which should
- /// probably happen and be tested for independently).
- CPPUNIT_ASSERT(source->get_session_flags() ==
- (sbuild::chroot::facet::facet::SESSION_CREATE));
- }
+TEST_F(ChrootLVMSnapshot, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "lvm-snapshot");
+}
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+TEST_F(ChrootLVMSnapshot, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "lvm-snapshot");
+ expected.add("CHROOT_LVM_SNAPSHOT_OPTIONS", "--size 1G");
+ expected.add("CHROOT_SESSION_CLONE", "true");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(chroot, expected);
+}
+
+TEST_F(ChrootLVMSnapshot, SetupEnvSession)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "lvm-snapshot");
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.add("CHROOT_MOUNT_DEVICE", "/dev/volgroup/test-session-name");
+ expected.add("CHROOT_LVM_SNAPSHOT_NAME", "test-session-name");
+ expected.add("CHROOT_LVM_SNAPSHOT_DEVICE", "/dev/volgroup/test-session-name");
+ expected.add("CHROOT_LVM_SNAPSHOT_OPTIONS", "--size 1G");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "true");
+
+ ChrootBase::test_setup_env(session, expected);
+}
+
+TEST_F(ChrootLVMSnapshot, SetupEnvSource)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "block-device");
+ expected.add("CHROOT_NAME", "test-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "true");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(source, expected);
+}
+
+TEST_F(ChrootLVMSnapshot, SetupEnvSessionSource)
+{
+ sbuild::environment expected;
+ setup_env_gen(expected);
+ expected.add("CHROOT_TYPE", "block-device");
+ expected.add("CHROOT_NAME", "test-name");
+ expected.add("SESSION_ID", "test-session-name");
+ expected.add("CHROOT_DESCRIPTION", chroot->get_description() + ' ' + _("(source chroot) (session chroot)"));
+ expected.add("CHROOT_ALIAS", "test-session-name");
+ expected.add("CHROOT_MOUNT_DEVICE", "/dev/volgroup/testdev");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(session_source, expected);
+}
+
+TEST_F(ChrootLVMSnapshot, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ std::string group = chroot->get_name();
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_source(expected, group);
+ setup_keyfile_lvm(expected, group);
+ expected.set_value(group, "type", "lvm-snapshot");
+ expected.set_value(group, "lvm-snapshot-options", "--size 1G");
+
+ ChrootBase::test_setup_keyfile
+ (chroot,expected, chroot->get_name());
+}
+
+TEST_F(ChrootLVMSnapshot, SetupKeyfileSession)
+{
+ sbuild::keyfile expected;
+ const std::string group(session->get_name());
+ setup_keyfile_session(expected, group);
+ setup_keyfile_lvm(expected, group);
+ expected.set_value(group, "type", "lvm-snapshot");
+ expected.set_value(group, "name", "test-session-name");
+ expected.set_value(group, "selected-name", "test-session-name");
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(session chroot)"));
+ expected.set_value(group, "aliases", "");
+ expected.set_value(group, "lvm-snapshot-device", "/dev/volgroup/test-session-name");
+ expected.set_value(group, "mount-device", "/dev/volgroup/test-session-name");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+
+ ChrootBase::test_setup_keyfile
+ (session, expected, group);
+}
+
+TEST_F(ChrootLVMSnapshot, SetupKeyfileSource)
+{
+ sbuild::keyfile expected;
+ const std::string group(source->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_lvm(expected, group);
+ expected.set_value(group, "type", "block-device");
+ expected.set_value(group, "description", chroot->get_description() + ' ' + _("(source chroot)"));
+ expected.set_value(group, "aliases", "test-name-source,test-alias-1-source,test-alias-2-source");
+ setup_keyfile_source_clone(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (source, expected, group);
+}
+
+TEST_F(ChrootLVMSnapshot, SetupKeyfileSessionSource)
+{
+ sbuild::keyfile expected;
+ const std::string group(source->get_name());
+ setup_keyfile_chroot(expected, group);
+ setup_keyfile_lvm(expected, group);
+ expected.set_value(group, "type", "block-device");
+ expected.set_value(group, "mount-device", "/dev/volgroup/testdev");
+ expected.set_value(group, "mount-location", "/mnt/mount-location");
+ setup_keyfile_session_source_clone(expected, group);
+
+ ChrootBase::test_setup_keyfile
+ (session_source, expected, group);
+}
+
+TEST_F(ChrootLVMSnapshot, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE |
+ sbuild::chroot::facet::facet::SESSION_CLONE));
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+ ASSERT_EQ(session->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_PURGE));
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts());
- }
+ /// @todo: Should return NOFLAGS? This depends upon if source
+ /// chroots need transforming into sessions as well (which should
+ /// probably happen and be tested for independently).
+ ASSERT_EQ(source->get_session_flags(),
+ (sbuild::chroot::facet::facet::SESSION_CREATE));
+}
-};
+TEST_F(ChrootLVMSnapshot, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_lvm_snapshot);
+TEST_F(ChrootLVMSnapshot, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootLVMSnapshot, RunSetupScripts)
+{
+ ASSERT_TRUE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/chroot/plain.cc b/test/sbuild/chroot/plain.cc
index f7ceb928..c1e270c6 100644
--- a/test/sbuild/chroot/plain.cc
+++ b/test/sbuild/chroot/plain.cc
@@ -27,116 +27,99 @@
#include <algorithm>
#include <set>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_chroot_plain : public test_chroot_base
+class ChrootPlain : public ChrootBase
{
- CPPUNIT_TEST_SUITE(test_chroot_plain);
- CPPUNIT_TEST(test_directory);
- CPPUNIT_TEST(test_chroot_type);
- CPPUNIT_TEST(test_setup_env);
- CPPUNIT_TEST(test_setup_keyfile);
- CPPUNIT_TEST(test_print_details);
- CPPUNIT_TEST(test_print_config);
- CPPUNIT_TEST(test_run_setup_scripts);
- CPPUNIT_TEST_SUITE_END();
public:
- test_chroot_plain():
- test_chroot_base("plain")
+ ChrootPlain():
+ ChrootBase("plain")
{}
- void setUp()
+ void SetUp()
{
- test_chroot_base::setUp();
- CPPUNIT_ASSERT(chroot);
- CPPUNIT_ASSERT(!session);
- CPPUNIT_ASSERT(!source);
- CPPUNIT_ASSERT(!session_source);
+ ChrootBase::SetUp();
+ ASSERT_NE(chroot, nullptr);
+ ASSERT_EQ(session, nullptr);
+ ASSERT_EQ(source, nullptr);
+ ASSERT_EQ(session_source, nullptr);
}
virtual void setup_chroot_props (sbuild::chroot::chroot::ptr& chroot)
{
- test_chroot_base::setup_chroot_props(chroot);
+ ChrootBase::setup_chroot_props(chroot);
chroot->set_mount_location("");
sbuild::chroot::facet::plain::ptr plfac = chroot->get_facet<sbuild::chroot::facet::plain>();
plfac->set_directory("/srv/chroot/example-chroot");
}
+};
- void
- test_directory()
- {
- sbuild::chroot::facet::plain::ptr plfac = chroot->get_facet<sbuild::chroot::facet::plain>();
- plfac->set_directory("/mnt/mount-location/example");
- CPPUNIT_ASSERT(plfac->get_directory() == "/mnt/mount-location/example");
- CPPUNIT_ASSERT(chroot->get_path() == "/mnt/mount-location/example");
- CPPUNIT_ASSERT(chroot->get_mount_location() == "");
- }
-
- void test_chroot_type()
- {
- CPPUNIT_ASSERT(chroot->get_chroot_type() == "plain");
- }
-
- void test_setup_env()
- {
- sbuild::environment expected;
- setup_env_chroot(expected);
- expected.add("CHROOT_TYPE", "plain");
- expected.add("CHROOT_DIRECTORY", "/srv/chroot/example-chroot");
- expected.add("CHROOT_PATH", "/srv/chroot/example-chroot");
- expected.add("CHROOT_SESSION_CLONE", "false");
- expected.add("CHROOT_SESSION_CREATE", "false");
- expected.add("CHROOT_SESSION_PURGE", "false");
-
- test_chroot_base::test_setup_env(chroot, expected);
- }
-
- void test_setup_keyfile()
- {
- sbuild::keyfile expected;
- std::string group = chroot->get_name();
- setup_keyfile_chroot(expected, group);
- expected.set_value(group, "type", "plain");
- expected.set_value(group, "directory", "/srv/chroot/example-chroot");
-
- test_chroot_base::test_setup_keyfile
- (chroot, expected, group);
- }
-
- void test_session_flags()
- {
- CPPUNIT_ASSERT(chroot->get_session_flags() ==
- sbuild::chroot::facet::facet::SESSION_NOFLAGS);
- }
+TEST_F(ChrootPlain, Directory)
+{
+ sbuild::chroot::facet::plain::ptr plfac = chroot->get_facet<sbuild::chroot::facet::plain>();
+ plfac->set_directory("/mnt/mount-location/example");
+ ASSERT_EQ(plfac->get_directory(), "/mnt/mount-location/example");
+ ASSERT_EQ(chroot->get_path(), "/mnt/mount-location/example");
+ ASSERT_EQ(chroot->get_mount_location(), "");
+}
+
+TEST_F(ChrootPlain, Type)
+{
+ ASSERT_EQ(chroot->get_chroot_type(), "plain");
+}
- void test_print_details()
- {
- std::ostringstream os;
- os << chroot;
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+TEST_F(ChrootPlain, SetupEnv)
+{
+ sbuild::environment expected;
+ setup_env_chroot(expected);
+ expected.add("CHROOT_TYPE", "plain");
+ expected.add("CHROOT_DIRECTORY", "/srv/chroot/example-chroot");
+ expected.add("CHROOT_PATH", "/srv/chroot/example-chroot");
+ expected.add("CHROOT_SESSION_CLONE", "false");
+ expected.add("CHROOT_SESSION_CREATE", "false");
+ expected.add("CHROOT_SESSION_PURGE", "false");
+
+ ChrootBase::test_setup_env(chroot, expected);
+}
+
+TEST_F(ChrootPlain, SetupKeyfile)
+{
+ sbuild::keyfile expected;
+ std::string group = chroot->get_name();
+ setup_keyfile_chroot(expected, group);
+ expected.set_value(group, "type", "plain");
+ expected.set_value(group, "directory", "/srv/chroot/example-chroot");
- void test_print_config()
- {
- std::ostringstream os;
- sbuild::keyfile config;
- config << chroot;
- os << sbuild::keyfile_writer(config);
- // TODO: Compare output.
- CPPUNIT_ASSERT(!os.str().empty());
- }
+ ChrootBase::test_setup_keyfile
+ (chroot, expected, group);
+}
- void test_run_setup_scripts()
- {
- CPPUNIT_ASSERT(!chroot->get_run_setup_scripts());
- }
+TEST_F(ChrootPlain, SessionFlags)
+{
+ ASSERT_EQ(chroot->get_session_flags(),
+ sbuild::chroot::facet::facet::SESSION_NOFLAGS);
+}
-};
+TEST_F(ChrootPlain, PrintDetails)
+{
+ std::ostringstream os;
+ os << chroot;
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_plain);
+TEST_F(ChrootPlain, PrintConfig)
+{
+ std::ostringstream os;
+ sbuild::keyfile config;
+ config << chroot;
+ os << sbuild::keyfile_writer(config);
+ // TODO: Compare output.
+ ASSERT_FALSE(os.str().empty());
+}
+
+TEST_F(ChrootPlain, RunSetupScripts)
+{
+ ASSERT_FALSE(chroot->get_run_setup_scripts());
+}
diff --git a/test/sbuild/environment.cc b/test/sbuild/environment.cc
index 9ec079ff..e93b20ed 100644
--- a/test/sbuild/environment.cc
+++ b/test/sbuild/environment.cc
@@ -16,368 +16,309 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/environment.h>
#include <sbuild/util.h>
#include <iostream>
#include <sstream>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-class test_environment : public TestFixture
+class Environment : public ::testing::Test
{
- CPPUNIT_TEST_SUITE(test_environment);
- CPPUNIT_TEST(test_construction);
- CPPUNIT_TEST(test_add_strv);
- CPPUNIT_TEST(test_add_env);
- CPPUNIT_TEST(test_add_value);
- CPPUNIT_TEST(test_add_string_pair);
- CPPUNIT_TEST(test_add_template);
- CPPUNIT_TEST(test_add_string);
- CPPUNIT_TEST(test_add_empty_implicit_remove);
- CPPUNIT_TEST(test_remove_strv);
- CPPUNIT_TEST(test_remove_env);
- CPPUNIT_TEST(test_remove_value);
- CPPUNIT_TEST(test_remove_string);
- CPPUNIT_TEST(test_get_value);
- CPPUNIT_TEST(test_get_strv);
- CPPUNIT_TEST(test_operator_plus);
- CPPUNIT_TEST(test_operator_plus_equals);
- CPPUNIT_TEST(test_operator_minus);
- CPPUNIT_TEST(test_operator_minus_equals);
- CPPUNIT_TEST(test_add_filter);
- CPPUNIT_TEST(test_filter);
- CPPUNIT_TEST(test_output);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
+public:
sbuild::environment *env;
sbuild::environment *half_env;
-public:
- test_environment():
- TestFixture(),
- env()
- {}
-
- virtual ~test_environment()
- {}
-
- void setUp()
+ void SetUp()
{
- this->env = new sbuild::environment;
- this->env->add(std::make_pair("TERM", "wy50"));
- this->env->add(std::make_pair("SHELL", "/bin/sh"));
- this->env->add(std::make_pair("USER", "root"));
- this->env->add(std::make_pair("COLUMNS", "80"));
-
- this->half_env = new sbuild::environment;
- this->half_env->add(std::make_pair("TERM", "wy50"));
- this->half_env->add(std::make_pair("USER", "root"));
+ env = new sbuild::environment;
+ env->add(std::make_pair("TERM", "wy50"));
+ env->add(std::make_pair("SHELL", "/bin/sh"));
+ env->add(std::make_pair("USER", "root"));
+ env->add(std::make_pair("COLUMNS", "80"));
+
+ half_env = new sbuild::environment;
+ half_env->add(std::make_pair("TERM", "wy50"));
+ half_env->add(std::make_pair("USER", "root"));
}
- static void add_examples(sbuild::environment& env)
+ void TearDown()
{
- sbuild::environment::size_type size = env.size();
- env.add(std::make_pair("TERM", "wy50"));
- env.add(std::make_pair("SHELL", "/bin/sh"));
- env.add(std::make_pair("USER", "root"));
- env.add(std::make_pair("COLUMNS", "80"));
- CPPUNIT_ASSERT(env.size() == size + 4);
+ delete env;
+ delete half_env;
}
+};
- static void add_simple_examples(sbuild::environment& env)
- {
- sbuild::environment::size_type size = env.size();
- env.add(std::make_pair("TERM", "wy50"));
- env.add(std::make_pair("USER", "root"));
- CPPUNIT_ASSERT(env.size() == size + 2);
- }
-
- void tearDown()
- {
- delete this->env;
- delete this->half_env;
- }
-
- void
- test_construction()
- {
- const char *items[] = {"TERM=wy50", "SHELL=/bin/sh",
- "USER=root", "COLUMNS=80", 0};
- sbuild::environment e(const_cast<char **>(&items[0]));
-
- CPPUNIT_ASSERT(e.size() == 4);
-
- CPPUNIT_ASSERT(e == *this->env);
- }
- void
- test_add_strv()
- {
- const char *items[] = {"TERM=wy50", "SHELL=/bin/sh",
+TEST_F(Environment, Construction)
+{
+ const char *items[] = {"TERM=wy50", "SHELL=/bin/sh",
"USER=root", "COLUMNS=80", 0};
- sbuild::environment e;
- e.add(const_cast<char **>(&items[0]));
-
- CPPUNIT_ASSERT(e.size() == 4);
+ sbuild::environment e(const_cast<char **>(&items[0]));
- CPPUNIT_ASSERT(e == *this->env);
- }
+ ASSERT_EQ(e.size(), 4);
+ ASSERT_EQ(e, *env);
+}
- void
- test_add_env()
- {
- sbuild::environment e;
- e.add(*this->env);
+TEST_F(Environment, AddStrv)
+{
+ const char *items[] = {"TERM=wy50", "SHELL=/bin/sh",
+ "USER=root", "COLUMNS=80", 0};
+ sbuild::environment e;
+ e.add(const_cast<char **>(&items[0]));
- CPPUNIT_ASSERT(e == *this->env);
- }
+ ASSERT_EQ(e.size(),4);
+ ASSERT_EQ(e, *env);
+}
- void
- test_add_value()
- {
- sbuild::environment e;
- e.add(sbuild::environment::value_type("TERM", "wy50"));
- e.add(sbuild::environment::value_type("SHELL", "/bin/sh"));
- e.add(sbuild::environment::value_type("USER", "root"));
- e.add(sbuild::environment::value_type("COLUMNS", "80"));
+TEST_F(Environment, AddEnvironment)
+{
+ sbuild::environment e;
+ e.add(*env);
- CPPUNIT_ASSERT(e == *this->env);
- }
+ ASSERT_EQ(e, *env);
+}
- void
- test_add_string_pair()
- {
- sbuild::environment e;
- e.add("TERM", "wy50");
- e.add("SHELL", "/bin/sh");
- e.add("USER", "root");
- e.add("COLUMNS", "80");
+TEST_F(Environment, AddValue)
+{
+ sbuild::environment e;
+ e.add(sbuild::environment::value_type("TERM", "wy50"));
+ e.add(sbuild::environment::value_type("SHELL", "/bin/sh"));
+ e.add(sbuild::environment::value_type("USER", "root"));
+ e.add(sbuild::environment::value_type("COLUMNS", "80"));
- CPPUNIT_ASSERT(e == *this->env);
- }
+ ASSERT_EQ(e, *env);
+}
- void
- test_add_template()
- {
- sbuild::environment e;
- e.add("TERM", "wy50");
- e.add("SHELL", "/bin/sh");
- e.add("USER", std::string("root"));
- e.add("COLUMNS", 80);
+TEST_F(Environment, AddStringPair)
+{
+ sbuild::environment e;
+ e.add("TERM", "wy50");
+ e.add("SHELL", "/bin/sh");
+ e.add("USER", "root");
+ e.add("COLUMNS", "80");
- CPPUNIT_ASSERT(e == *this->env);
- }
+ ASSERT_EQ(e, *env);
+}
- void
- test_add_string()
- {
- sbuild::environment e;
- e.add("TERM=wy50");
- e.add("SHELL=/bin/sh");
- e.add("USER=root");
- e.add("COLUMNS=80");
-
- CPPUNIT_ASSERT(e == *this->env);
- }
+TEST_F(Environment, AddTemplate)
+{
+ sbuild::environment e;
+ e.add("TERM", "wy50");
+ e.add("SHELL", "/bin/sh");
+ e.add("USER", std::string("root"));
+ e.add("COLUMNS", 80);
- void
- test_add_empty_implicit_remove()
- {
- sbuild::environment e;
- e.add("TERM=wy50");
- e.add("USER=root");
+ ASSERT_EQ(e, *env);
+}
- this->env->add("COLUMNS=");
- this->env->add(sbuild::environment::value_type("SHELL", ""));
+TEST_F(Environment, AddString)
+{
+ sbuild::environment e;
+ e.add("TERM=wy50");
+ e.add("SHELL=/bin/sh");
+ e.add("USER=root");
+ e.add("COLUMNS=80");
- CPPUNIT_ASSERT(this->env->size() == 2);
- CPPUNIT_ASSERT(e == *this->env);
- }
+ ASSERT_EQ(e, *env);
+}
- void
- test_remove_strv()
- {
- const char *items[] = {"SHELL=/bin/bash",
- "COLUMNS=160", 0};
- this->env->remove(const_cast<char **>(&items[0]));
+TEST_F(Environment, AddEmptyWithImplicitRemove)
+{
+ sbuild::environment e;
+ e.add("TERM=wy50");
+ e.add("USER=root");
- CPPUNIT_ASSERT(this->env->size() == 2);
- CPPUNIT_ASSERT(*this->env == *this->half_env);
- }
+ env->add("COLUMNS=");
+ env->add(sbuild::environment::value_type("SHELL", ""));
- void
- test_remove_env()
- {
- sbuild::environment e;
- e.add("SHELL=/bin/bash");
- e.add("COLUMNS=160");
+ ASSERT_EQ(env->size(), 2);
+ ASSERT_EQ(e, *env);
+}
- this->env->remove(e);
+TEST_F(Environment, RemoveStrv)
+{
+ const char *items[] = {"SHELL=/bin/bash",
+ "COLUMNS=160", 0};
+ env->remove(const_cast<char **>(&items[0]));
- CPPUNIT_ASSERT(*this->env == *this->half_env);
- }
+ ASSERT_EQ(env->size(), 2);
+ ASSERT_EQ(*env, *half_env);
+}
- void
- test_remove_value()
- {
- this->env->remove(sbuild::environment::value_type("SHELL", "/bin/bash"));
- this->env->remove(sbuild::environment::value_type("COLUMNS", "160"));
+TEST_F(Environment, RemoveEnvironment)
+{
+ sbuild::environment e;
+ e.add("SHELL=/bin/bash");
+ e.add("COLUMNS=160");
- CPPUNIT_ASSERT(*this->env == *this->half_env);
- }
+ env->remove(e);
- void
- test_remove_string()
- {
- this->env->remove("SHELL=/bin/bash");
- this->env->remove("COLUMNS=160");
+ ASSERT_EQ(*env, *half_env);
+}
- CPPUNIT_ASSERT(*this->env == *this->half_env);
- }
+TEST_F(Environment, RemoveValue)
+{
+ env->remove(sbuild::environment::value_type("SHELL", "/bin/bash"));
+ env->remove(sbuild::environment::value_type("COLUMNS", "160"));
- void test_get_value()
- {
- std::string value;
- CPPUNIT_ASSERT(this->env->get("TERM", value) && value == "wy50");
- CPPUNIT_ASSERT(this->env->get("SHELL", value) && value == "/bin/sh");
- CPPUNIT_ASSERT(this->env->get("USER", value) && value == "root");
- CPPUNIT_ASSERT(this->env->get("COLUMNS", value) && value == "80");
- // Check failure doesn't overwrite value.
- CPPUNIT_ASSERT(!this->env->get("MUSTFAIL", value) && value == "80");
-
- // Check getting templated types.
- int tval;
- CPPUNIT_ASSERT(this->env->get("COLUMNS", tval) && tval == 80);
- }
+ ASSERT_EQ(*env, *half_env);
+}
- void test_get_strv()
- {
- char **strv = this->env->get_strv();
+TEST_F(Environment, RemoveString)
+{
+ env->remove("SHELL=/bin/bash");
+ env->remove("COLUMNS=160");
- int size = 0;
- for (char **ev = strv; ev != 0 && *ev != 0; ++ev, ++size);
+ ASSERT_EQ(*env, *half_env);
+}
- CPPUNIT_ASSERT(size == 4);
- CPPUNIT_ASSERT(std::string(strv[0]) == "COLUMNS=80");
- CPPUNIT_ASSERT(std::string(strv[1]) == "SHELL=/bin/sh");
- CPPUNIT_ASSERT(std::string(strv[2]) == "TERM=wy50");
- CPPUNIT_ASSERT(std::string(strv[3]) == "USER=root");
+TEST_F(Environment, GetValue)
+{
+ std::string value;
+ ASSERT_TRUE(env->get("TERM", value));
+ ASSERT_EQ(value,"wy50");
+ ASSERT_TRUE(env->get("SHELL", value));
+ ASSERT_EQ(value, "/bin/sh");
+ ASSERT_TRUE(env->get("USER", value));
+ ASSERT_EQ(value,"root");
+ ASSERT_TRUE(env->get("COLUMNS", value));
+ ASSERT_EQ(value, "80");
+ // Check failure doesn't overwrite value.
+ ASSERT_FALSE(env->get("MUSTFAIL", value));
+ ASSERT_EQ(value, "80");
+
+ // Check getting templated types.
+ int tval;
+ ASSERT_TRUE(env->get("COLUMNS", tval));
+ ASSERT_EQ(tval, 80);
+}
+
+TEST_F(Environment, GetStrv)
+{
+ char **strv = env->get_strv();
- sbuild::strv_delete(strv);
- }
+ int size = 0;
+ for (char **ev = strv; ev != 0 && *ev != 0; ++ev, ++size);
- void test_operator_plus()
- {
- sbuild::environment e;
- e.add("SHELL=/bin/sh");
- e.add("COLUMNS=80");
-
- sbuild::environment result;
- result = *this->half_env + e;
- CPPUNIT_ASSERT(result == *this->env);
-
- sbuild::environment e2;
- e2 = *this->half_env + "SHELL=/bin/sh";
- e2 = e2 + sbuild::environment::value_type("COLUMNS", "80");
- CPPUNIT_ASSERT(e2 == *this->env);
- }
+ ASSERT_EQ(size, 4);
+ ASSERT_EQ(std::string(strv[0]), "COLUMNS=80");
+ ASSERT_EQ(std::string(strv[1]), "SHELL=/bin/sh");
+ ASSERT_EQ(std::string(strv[2]), "TERM=wy50");
+ ASSERT_EQ(std::string(strv[3]), "USER=root");
- void test_operator_plus_equals()
- {
- sbuild::environment e;
- e.add("SHELL=/bin/sh");
- e.add("COLUMNS=80");
-
- sbuild::environment result(*this->half_env);
- result += e;
- CPPUNIT_ASSERT(result == *this->env);
-
- sbuild::environment e2(*this->half_env);
- e2 += "SHELL=/bin/sh";
- // TODO: Why does calling direct fail?
- sbuild::environment::value_type val("COLUMNS", "80");
- e2 += val;
- CPPUNIT_ASSERT(e2 == *this->env);
- }
+ sbuild::strv_delete(strv);
+}
- void test_operator_minus()
- {
- sbuild::environment e;
- e.add("SHELL=/bin/sh");
- e.add("COLUMNS=80");
-
- sbuild::environment result;
- result = *this->env - e;
- CPPUNIT_ASSERT(result == *this->half_env);
-
- sbuild::environment e2;
- e2 = *this->env - "SHELL=/bin/sh";
- e2 = e2 - sbuild::environment::value_type("COLUMNS", "80");
- CPPUNIT_ASSERT(e2 == *this->half_env);
- }
-
- void test_operator_minus_equals()
- {
- sbuild::environment e;
- e.add("SHELL=/bin/sh");
- e.add("COLUMNS=80");
-
- sbuild::environment result(*this->env);
- result -= e;
- CPPUNIT_ASSERT(result == *this->half_env);
-
- sbuild::environment e2(*this->env);
- e2 -= "SHELL=/bin/sh";
- // TODO: Why does calling direct fail?
- sbuild::environment::value_type val("COLUMNS", "80");
- e2 -= val;
- CPPUNIT_ASSERT(e2 == *this->half_env);
- }
+TEST_F(Environment, OperatorPlus)
+{
+ sbuild::environment e;
+ e.add("SHELL=/bin/sh");
+ e.add("COLUMNS=80");
- void test_add_filter()
- {
- sbuild::regex f("^FOO|BAR$");
+ sbuild::environment result;
+ result = *half_env + e;
+ ASSERT_EQ(result, *env);
- sbuild::environment e;
- e.set_filter(f);
+ sbuild::environment e2;
+ e2 = *half_env + "SHELL=/bin/sh";
+ e2 = e2 + sbuild::environment::value_type("COLUMNS", "80");
+ ASSERT_EQ(e2, *env);
+}
- CPPUNIT_ASSERT(f.compare(e.get_filter()) == 0);
- }
+TEST_F(Environment, OperatorPlusEquals)
+{
+ sbuild::environment e;
+ e.add("SHELL=/bin/sh");
+ e.add("COLUMNS=80");
+
+ sbuild::environment result(*half_env);
+ result += e;
+ ASSERT_EQ(result, *env);
+
+ sbuild::environment e2(*half_env);
+ e2 += "SHELL=/bin/sh";
+ // TODO: Why does calling direct fail?
+ sbuild::environment::value_type val("COLUMNS", "80");
+ e2 += val;
+ ASSERT_EQ(e2, *env);
+}
+
+TEST_F(Environment, OperatorMinus)
+{
+ sbuild::environment e;
+ e.add("SHELL=/bin/sh");
+ e.add("COLUMNS=80");
- void test_filter()
- {
- sbuild::regex f("^FOO|BAR$");
+ sbuild::environment result;
+ result = *env - e;
+ ASSERT_EQ(result, *half_env);
- sbuild::environment e;
- e.set_filter(f);
+ sbuild::environment e2;
+ e2 = *env - "SHELL=/bin/sh";
+ e2 = e2 - sbuild::environment::value_type("COLUMNS", "80");
+ ASSERT_EQ(e2, *half_env);
+}
- e.add("FOO=bar");
- e.add("BAR=baz");
- e.add("BAZ=bat");
- e.add("BAT=bah");
+TEST_F(Environment, OperatorMinusEquals)
+{
+ sbuild::environment e;
+ e.add("SHELL=/bin/sh");
+ e.add("COLUMNS=80");
+
+ sbuild::environment result(*env);
+ result -= e;
+ ASSERT_EQ(result, *half_env);
+
+ sbuild::environment e2(*env);
+ e2 -= "SHELL=/bin/sh";
+ // TODO: Why does calling direct fail?
+ sbuild::environment::value_type val("COLUMNS", "80");
+ e2 -= val;
+ ASSERT_EQ(e2, *half_env);
+}
+
+TEST_F(Environment, AddFilter)
+{
+ sbuild::regex f("^FOO|BAR$");
- std::string value;
- CPPUNIT_ASSERT(e.get("FOO", value) == false);
- CPPUNIT_ASSERT(e.get("BAR", value) == false);
- CPPUNIT_ASSERT(e.get("BAZ", value) && value == "bat");
- CPPUNIT_ASSERT(e.get("BAT", value) && value == "bah");
- }
+ sbuild::environment e;
+ e.set_filter(f);
- void test_output()
- {
- std::ostringstream os;
- os << *this->env;
-
- CPPUNIT_ASSERT(os.str() ==
- "COLUMNS=80\n"
- "SHELL=/bin/sh\n"
- "TERM=wy50\n"
- "USER=root\n");
- }
-};
+ ASSERT_EQ(f.compare(e.get_filter()), 0);
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_environment);
+TEST_F(Environment, Filter)
+{
+ sbuild::regex f("^FOO|BAR$");
+
+ sbuild::environment e;
+ e.set_filter(f);
+
+ e.add("FOO=bar");
+ e.add("BAR=baz");
+ e.add("BAZ=bat");
+ e.add("BAT=bah");
+
+ std::string value;
+ ASSERT_FALSE(e.get("FOO", value));
+ ASSERT_FALSE(e.get("BAR", value));
+ ASSERT_TRUE(e.get("BAZ", value));
+ ASSERT_EQ(value, "bat");
+ ASSERT_TRUE(e.get("BAT", value));
+ ASSERT_EQ(value, "bah");
+}
+
+TEST_F(Environment, StreamOutput)
+{
+ std::ostringstream os;
+ os << *env;
+
+ ASSERT_EQ(os.str(),
+ "COLUMNS=80\n"
+ "SHELL=/bin/sh\n"
+ "TERM=wy50\n"
+ "USER=root\n");
+}
diff --git a/test/sbuild/keyfile.cc b/test/sbuild/keyfile.cc
index b69812b2..e820e61f 100644
--- a/test/sbuild/keyfile.cc
+++ b/test/sbuild/keyfile.cc
@@ -16,6 +16,8 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/keyfile.h>
#include <sbuild/keyfile-reader.h>
#include <sbuild/keyfile-writer.h>
@@ -24,43 +26,13 @@
#include <sstream>
#include <vector>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_keyfile : public TestFixture
+class Keyfile : public ::testing::Test
{
- CPPUNIT_TEST_SUITE(test_keyfile);
- CPPUNIT_TEST(test_construction_file);
- CPPUNIT_TEST(test_construction_stream);
- CPPUNIT_TEST_EXCEPTION(test_construction_fail, sbuild::keyfile::error);
- CPPUNIT_TEST(test_get_groups);
- CPPUNIT_TEST(test_get_keys);
- CPPUNIT_TEST(test_get_value);
- CPPUNIT_TEST(test_get_value_fail);
- CPPUNIT_TEST(test_get_list_value);
- CPPUNIT_TEST(test_get_list_value_fail);
- CPPUNIT_TEST(test_get_line);
- CPPUNIT_TEST(test_set_value);
- CPPUNIT_TEST(test_set_list_value);
- CPPUNIT_TEST(test_remove_group);
- CPPUNIT_TEST(test_remove_key);
- CPPUNIT_TEST(test_output);
- CPPUNIT_TEST_SUITE_END();
-
protected:
sbuild::keyfile *kf;
public:
- test_keyfile():
- TestFixture(),
- kf()
- {}
-
- virtual ~test_keyfile()
- {}
-
- void setUp()
+ void SetUp()
{
std::istringstream is("# Comment\n"
"[group1]\n"
@@ -75,222 +47,211 @@ public:
"name=Mary King\n"
"age=43\n"
"photo=mary.jpeg\n");
- this->kf = new sbuild::keyfile;
- sbuild::keyfile_reader kp(*this->kf);
+ kf = new sbuild::keyfile;
+ sbuild::keyfile_reader kp(*kf);
is >> kp;
}
- void tearDown()
- {
- delete this->kf;
- }
-
- void
- test_construction_file()
- {
- sbuild::keyfile k;
- sbuild::keyfile_reader(k, TESTDATADIR "/keyfile.ex1");
- }
-
- void
- test_construction_stream()
- {
- std::ifstream strm(TESTDATADIR "/keyfile.ex1");
- CPPUNIT_ASSERT(strm);
- sbuild::keyfile k;
- sbuild::keyfile_reader(k, strm);
- }
-
- void
- test_construction_fail()
+ void TearDown()
{
- sbuild::keyfile k;
- sbuild::keyfile_reader(k, TESTDATADIR "/nonexistent-keyfile-will-throw-exception");
+ delete kf;
}
+};
- void test_get_groups()
- {
- sbuild::string_list l = this->kf->get_groups();
- CPPUNIT_ASSERT(l.size() == 2);
- CPPUNIT_ASSERT(l[0] == "group1");
- CPPUNIT_ASSERT(l[1] == "group2");
+TEST_F(Keyfile, ConstructFile)
+{
+ sbuild::keyfile k;
+ ASSERT_NO_THROW(sbuild::keyfile_reader(k, TESTDATADIR "/keyfile.ex1"));
+}
- CPPUNIT_ASSERT(this->kf->has_group("group1") == true);
- CPPUNIT_ASSERT(this->kf->has_group("nonexistent") == false);
- }
+TEST_F(Keyfile, ConstructStream)
+{
+ std::ifstream strm(TESTDATADIR "/keyfile.ex1");
+ ASSERT_TRUE(strm);
+ sbuild::keyfile k;
+ ASSERT_NO_THROW(sbuild::keyfile_reader(k, strm));
+}
- void test_get_keys()
- {
- sbuild::string_list l = this->kf->get_keys("group2");
- CPPUNIT_ASSERT(l.size() == 3);
- CPPUNIT_ASSERT(l[0] == "age");
- CPPUNIT_ASSERT(l[1] == "name");
- CPPUNIT_ASSERT(l[2] == "photo");
-
- CPPUNIT_ASSERT(this->kf->has_key("group2", "name") == true);
- CPPUNIT_ASSERT(this->kf->has_key("nonexistent", "name") == false);
- CPPUNIT_ASSERT(this->kf->has_key("group1", "nonexistent") == false);
- }
+TEST_F(Keyfile, ConstructFail)
+{
+ sbuild::keyfile k;
+ ASSERT_THROW(sbuild::keyfile_reader(k, TESTDATADIR "/nonexistent-keyfile-will-throw-exception"),
+ sbuild::keyfile::error);
+}
- void test_get_value()
- {
- std::string sval;
- int ival;
-
- CPPUNIT_ASSERT(this->kf->get_value("group2", "name", sval) == true);
- CPPUNIT_ASSERT(sval == "Mary King");
- CPPUNIT_ASSERT(this->kf->get_value("group2", "age", ival) == true);
- CPPUNIT_ASSERT(ival == 43);
-
- // Check failure does not alter value.
- ival = 11;
- CPPUNIT_ASSERT(this->kf->get_value("group2", "nonexistent", ival) == false);
- CPPUNIT_ASSERT(ival == 11);
- }
+TEST_F(Keyfile, GetGroups)
+{
+ sbuild::string_list l = kf->get_groups();
+ ASSERT_EQ(l.size(),2);
+ ASSERT_EQ(l[0], "group1");
+ ASSERT_EQ(l[1], "group2");
- void test_get_value_fail()
- {
- bool bval = false;
+ ASSERT_TRUE(kf->has_group("group1"));
+ ASSERT_FALSE(kf->has_group("nonexistent"));
+}
- // Expect a warning here.
- CPPUNIT_ASSERT(this->kf->get_value("group2", "age", bval) == false);
- CPPUNIT_ASSERT(bval == false);
- }
+TEST_F(Keyfile, GetKeys)
+{
+ sbuild::string_list l = kf->get_keys("group2");
+ ASSERT_EQ(l.size(), 3);
+ ASSERT_EQ(l[0], "age");
+ ASSERT_EQ(l[1], "name");
+ ASSERT_EQ(l[2], "photo");
+
+ ASSERT_TRUE(kf->has_key("group2", "name"));
+ ASSERT_FALSE(kf->has_key("nonexistent", "name"));
+ ASSERT_FALSE(kf->has_key("group1", "nonexistent"));
+}
+
+TEST_F(Keyfile, GetValue)
+{
+ std::string sval;
+ int ival;
- void test_get_list_value()
- {
- std::vector<int> expected;
- expected.push_back(1);
- expected.push_back(2);
- expected.push_back(3);
- expected.push_back(4);
- expected.push_back(5);
- expected.push_back(6);
-
- std::vector<int> found;
- CPPUNIT_ASSERT(this->kf->get_list_value("group1", "numbers", found) == true);
- CPPUNIT_ASSERT(found == expected);
- }
+ ASSERT_TRUE(kf->get_value("group2", "name", sval));
+ ASSERT_EQ(sval, "Mary King");
+ ASSERT_TRUE(kf->get_value("group2", "age", ival));
+ ASSERT_EQ(ival, 43);
- void test_get_list_value_fail()
- {
- std::vector<int> expected;
- expected.push_back(1);
- expected.push_back(2);
- expected.push_back(3);
- expected.push_back(4);
- expected.push_back(5);
- expected.push_back(6);
-
- std::vector<bool> found;
-
- // Expect a warning here.
- CPPUNIT_ASSERT(this->kf->get_list_value("group1", "numbers", found) == false);
- CPPUNIT_ASSERT(found.size() == 1); // 1 converts to bool.
- }
+ // Check failure does not alter value.
+ ival = 11;
+ ASSERT_FALSE(kf->get_value("group2", "nonexistent", ival));
+ ASSERT_EQ(ival, 11);
+}
- // TODO: Test priority.
- // TODO: Test comments, when available.
+TEST_F(Keyfile, GetValueFail)
+{
+ bool bval = false;
- void test_get_line()
- {
- CPPUNIT_ASSERT(this->kf->get_line("group2") == 10);
- CPPUNIT_ASSERT(this->kf->get_line("group1", "age") == 4);
- CPPUNIT_ASSERT(this->kf->get_line("group2", "name") == 11);
- }
+ // Expect a warning here.
+ ASSERT_FALSE(kf->get_value("group2", "age", bval));
+ ASSERT_FALSE(bval);
+}
- void test_set_value()
- {
- this->kf->set_value("group1", "name", "Adam Smith");
- this->kf->set_value("group1", "age", 27);
- this->kf->set_value("group1", "interests", "Ice Hockey,GNU/Linux");
- this->kf->set_value("newgroup", "newitem", 89);
-
- std::string result;
- int number = 0;
- CPPUNIT_ASSERT(this->kf->get_value("group1", "name", result) == true);
- CPPUNIT_ASSERT(result == "Adam Smith");
- CPPUNIT_ASSERT(this->kf->get_value("group1", "age", number) == true);
- CPPUNIT_ASSERT(number == 27);
- CPPUNIT_ASSERT(this->kf->get_value("group1", "interests", result) == true);
- CPPUNIT_ASSERT(result == "Ice Hockey,GNU/Linux");
- CPPUNIT_ASSERT(this->kf->get_value("newgroup", "newitem", number) == true);
- CPPUNIT_ASSERT(number == 89);
- }
+TEST_F(Keyfile, GetListValue)
+{
+ std::vector<int> expected;
+ expected.push_back(1);
+ expected.push_back(2);
+ expected.push_back(3);
+ expected.push_back(4);
+ expected.push_back(5);
+ expected.push_back(6);
+
+ std::vector<int> found;
+ ASSERT_TRUE(kf->get_list_value("group1", "numbers", found));
+ ASSERT_EQ(found, expected);
+}
+
+TEST_F(Keyfile, GetListValueFail)
+{
+ std::vector<int> expected;
+ expected.push_back(1);
+ expected.push_back(2);
+ expected.push_back(3);
+ expected.push_back(4);
+ expected.push_back(5);
+ expected.push_back(6);
- void test_set_list_value()
- {
- std::vector<int> expected;
- expected.push_back(1);
- expected.push_back(2);
- expected.push_back(3);
- expected.push_back(4);
- expected.push_back(5);
- expected.push_back(6);
-
- std::vector<int> found;
-
- this->kf->set_list_value("listgroup", "numbers2",
- expected.begin(), expected.end());
- CPPUNIT_ASSERT(this->kf->get_list_value("listgroup", "numbers2", found) == true);
- CPPUNIT_ASSERT(found == expected);
- }
+ std::vector<bool> found;
- void test_remove_group()
- {
- CPPUNIT_ASSERT(this->kf->get_groups().size() == 2);
+ // Expect a warning here.
+ ASSERT_FALSE(kf->get_list_value("group1", "numbers", found));
+ ASSERT_EQ(found.size(), 1); // 1 converts to bool.
+}
- this->kf->set_value("newgroup", "newitem", 89);
+// TODO: Test priority.
+// TODO: Test comments, when available.
- CPPUNIT_ASSERT(this->kf->get_groups().size() == 3);
+TEST_F(Keyfile, GetLine)
+{
+ ASSERT_EQ(kf->get_line("group2"), 10);
+ ASSERT_EQ(kf->get_line("group1", "age"), 4);
+ ASSERT_EQ(kf->get_line("group2", "name"), 11);
+}
- this->kf->remove_group("group1");
+TEST_F(Keyfile, SetValue)
+{
+ kf->set_value("group1", "name", "Adam Smith");
+ kf->set_value("group1", "age", 27);
+ kf->set_value("group1", "interests", "Ice Hockey,GNU/Linux");
+ kf->set_value("newgroup", "newitem", 89);
+
+ std::string result;
+ int number = 0;
+ ASSERT_TRUE(kf->get_value("group1", "name", result));
+ ASSERT_EQ(result, "Adam Smith");
+ ASSERT_TRUE(kf->get_value("group1", "age", number));
+ ASSERT_EQ(number, 27);
+ ASSERT_TRUE(kf->get_value("group1", "interests", result));
+ ASSERT_EQ(result, "Ice Hockey,GNU/Linux");
+ ASSERT_TRUE(kf->get_value("newgroup", "newitem", number));
+ ASSERT_EQ(number, 89);
+}
+
+TEST_F(Keyfile, SetListValue)
+{
+ std::vector<int> expected;
+ expected.push_back(1);
+ expected.push_back(2);
+ expected.push_back(3);
+ expected.push_back(4);
+ expected.push_back(5);
+ expected.push_back(6);
+
+ std::vector<int> found;
+
+ kf->set_list_value("listgroup", "numbers2",
+ expected.begin(), expected.end());
+ ASSERT_TRUE(kf->get_list_value("listgroup", "numbers2", found));
+ ASSERT_EQ(found, expected);
+}
+
+TEST_F(Keyfile, RemoveGroup)
+{
+ ASSERT_EQ(kf->get_groups().size(), 2);
- sbuild::string_list l = this->kf->get_groups();
- CPPUNIT_ASSERT(l.size() == 2);
- CPPUNIT_ASSERT(l[0] == "group2");
- CPPUNIT_ASSERT(l[1] == "newgroup");
- }
+ kf->set_value("newgroup", "newitem", 89);
- void test_remove_key()
- {
- CPPUNIT_ASSERT(this->kf->get_keys("group2").size() == 3);
+ ASSERT_EQ(kf->get_groups().size(), 3);
- this->kf->remove_key("group2", "photo");
+ kf->remove_group("group1");
- sbuild::string_list l = this->kf->get_keys("group2");
- CPPUNIT_ASSERT(l.size() == 2);
- CPPUNIT_ASSERT(l[0] == "age");
- CPPUNIT_ASSERT(l[1] == "name");
- }
+ sbuild::string_list l = kf->get_groups();
+ ASSERT_EQ(l.size(), 2);
+ ASSERT_EQ(l[0], "group2");
+ ASSERT_EQ(l[1], "newgroup");
+}
-#include <iostream>
+TEST_F(Keyfile, RemoveKey)
+{
+ ASSERT_EQ(kf->get_keys("group2").size(), 3);
- void test_output()
- {
- // TODO: Add comments, when available.
- std::ostringstream os;
-
- std::cerr << sbuild::keyfile_writer(*this->kf);
-
- os << sbuild::keyfile_writer(*this->kf);
-
- CPPUNIT_ASSERT(os.str() ==
- "# Comment\n"
- "[group1]\n"
- "age=32\n"
- "name=Fred Walker\n"
- "# Test item comment\n"
- "#\n"
- "# spanning multiple lines\n"
- "numbers=1,2,3,4,5,6\n"
- "\n"
- "[group2]\n"
- "age=43\n"
- "name=Mary King\n"
- "photo=mary.jpeg\n");
- }
+ kf->remove_key("group2", "photo");
-};
+ sbuild::string_list l = kf->get_keys("group2");
+ ASSERT_EQ(l.size(), 2);
+ ASSERT_EQ(l[0], "age");
+ ASSERT_EQ(l[1], "name");
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_keyfile);
+TEST_F(Keyfile, StreamOutput)
+{
+ std::ostringstream os;
+ os << sbuild::keyfile_writer(*kf);
+
+ ASSERT_EQ(os.str(),
+ "# Comment\n"
+ "[group1]\n"
+ "age=32\n"
+ "name=Fred Walker\n"
+ "# Test item comment\n"
+ "#\n"
+ "# spanning multiple lines\n"
+ "numbers=1,2,3,4,5,6\n"
+ "\n"
+ "[group2]\n"
+ "age=43\n"
+ "name=Mary King\n"
+ "photo=mary.jpeg\n");
+}
diff --git a/test/sbuild/lock.cc b/test/sbuild/lock.cc
index 21d03b2c..3078796e 100644
--- a/test/sbuild/lock.cc
+++ b/test/sbuild/lock.cc
@@ -16,6 +16,8 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/lock.h>
#include <iostream>
@@ -24,31 +26,29 @@
#include <sys/wait.h>
#include <unistd.h>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
+class FileLockParameters
+{
+public:
+ sbuild::lock::type initial;
+ sbuild::lock::type establish;
+ bool willthrow;
+
+ FileLockParameters(sbuild::lock::type initial,
+ sbuild::lock::type establish,
+ bool willthrow):
+ initial(initial),
+ establish(establish),
+ willthrow(willthrow)
+ {}
+};
-class test_file_lock : public TestFixture
+class FileLock : public ::testing::TestWithParam<FileLockParameters>
{
- CPPUNIT_TEST_SUITE(test_file_lock);
- CPPUNIT_TEST(test_none_none_lock);
- CPPUNIT_TEST(test_none_shr_lock);
- CPPUNIT_TEST(test_none_excl_lock);
- CPPUNIT_TEST(test_shr_none_lock);
- CPPUNIT_TEST(test_shr_shr_lock);
- CPPUNIT_TEST_EXCEPTION(test_shr_excl_lock, sbuild::lock::error);
- CPPUNIT_TEST(test_excl_none_lock);
- CPPUNIT_TEST_EXCEPTION(test_excl_shr_lock, sbuild::lock::error);
- CPPUNIT_TEST_EXCEPTION(test_excl_excl_lock, sbuild::lock::error);
- CPPUNIT_TEST_SUITE_END();
-
-protected:
+public:
int fd;
sbuild::file_lock *lck;
-public:
- test_file_lock():
- TestFixture(),
+ FileLock():
fd(-1),
lck(0)
{
@@ -56,127 +56,97 @@ public:
unlink(TESTDATADIR "/filelock.ex1");
}
- virtual ~test_file_lock()
+ virtual ~FileLock()
{}
- void setUp()
+ void SetUp()
{
- this->fd = open(TESTDATADIR "/filelock.ex1", O_RDWR|O_EXCL|O_CREAT, 0600);
- CPPUNIT_ASSERT(this->fd >= 0);
+ fd = open(TESTDATADIR "/filelock.ex1", O_RDWR|O_EXCL|O_CREAT, 0600);
+ ASSERT_GE(fd, 0);
- ssize_t wsize = write(this->fd,
+ ssize_t wsize = write(fd,
"This file exists in order to test "
"sbuild::file_lock locking.\n", 61);
- CPPUNIT_ASSERT(wsize == 61);
+ ASSERT_EQ(wsize, 61);
- this->lck = new sbuild::file_lock(this->fd);
- CPPUNIT_ASSERT(lck != 0);
+ lck = new sbuild::file_lock(fd);
+ ASSERT_NE(lck, nullptr);
}
- void tearDown()
+ void TearDown()
{
- CPPUNIT_ASSERT(lck != 0);
- this->lck->unset_lock();
- delete this->lck;
+ ASSERT_NE(lck, nullptr);
+ lck->unset_lock();
+ delete lck;
- CPPUNIT_ASSERT(close(this->fd) == 0);
- CPPUNIT_ASSERT(unlink(TESTDATADIR "/filelock.ex1") == 0);
+ ASSERT_EQ(close(fd), 0);
+ ASSERT_EQ(unlink(TESTDATADIR "/filelock.ex1"), 0);
}
+};
- void test(sbuild::lock::type initial,
- sbuild::lock::type establish)
- {
- this->lck->unset_lock();
- int pid = fork();
- CPPUNIT_ASSERT(pid >= 0);
- if (pid == 0)
- {
- try
- {
- this->lck->set_lock(initial, 1);
- // Note: can cause unexpected success if < 4. Set to 8 to
- // allow for slow or heavily-loaded machines.
- sleep(4);
- this->lck->unset_lock();
- }
- catch (const std::exception& e)
- {
- try
- {
- this->lck->unset_lock();
- }
- catch (const std::exception& ignore)
- {
- }
- std::cerr << "Child fail: " << e.what() << std::endl;
+TEST_P(FileLock, Locking)
+{
+ const FileLockParameters& params = GetParam();
+
+ lck->unset_lock();
+ int pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ {
+ try
+ {
+ lck->set_lock(params.initial, 1);
+ // Note: can cause unexpected success if < 4. Set to 8 to
+ // allow for slow or heavily-loaded machines.
+ sleep(4);
+ lck->unset_lock();
+ }
+ catch (const std::exception& e)
+ {
+ try
+ {
+ lck->unset_lock();
+ }
+ catch (const std::exception& ignore)
+ {
+ }
+ std::cerr << "Child fail: " << e.what() << std::endl;
_exit(EXIT_FAILURE);
- }
- _exit(EXIT_SUCCESS);
- }
- else
- {
- try
- {
- sleep(2);
- this->lck->set_lock(establish, 1);
-
- int status;
- CPPUNIT_ASSERT(waitpid(pid, &status, 0) >= 0);
- CPPUNIT_ASSERT(WIFEXITED(status) && WEXITSTATUS(status) == 0);
- }
- catch (const std::exception& e)
- {
- int status;
- waitpid(pid, &status, 0);
- throw;
- }
- }
- }
-
- void test_none_none_lock()
- {
- test(sbuild::lock::LOCK_NONE, sbuild::lock::LOCK_NONE);
- }
-
- void test_none_shr_lock()
- {
- test(sbuild::lock::LOCK_NONE, sbuild::lock::LOCK_SHARED);
- }
-
- void test_none_excl_lock()
- {
- test(sbuild::lock::LOCK_NONE, sbuild::lock::LOCK_EXCLUSIVE);
- }
-
- void test_shr_none_lock()
- {
- test(sbuild::lock::LOCK_SHARED, sbuild::lock::LOCK_NONE);
- }
-
- void test_shr_shr_lock()
- {
- test(sbuild::lock::LOCK_SHARED, sbuild::lock::LOCK_SHARED);
- }
-
- void test_shr_excl_lock()
- {
- test(sbuild::lock::LOCK_SHARED, sbuild::lock::LOCK_EXCLUSIVE);
- }
-
- void test_excl_none_lock()
- {
- test(sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_NONE);
- }
-
- void test_excl_shr_lock()
- {
- test(sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_SHARED);
- }
-
- void test_excl_excl_lock()
+ }
+ _exit(EXIT_SUCCESS);
+ }
+ else
+ {
+ try
+ {
+ sleep(2);
+ lck->set_lock(params.establish, 1);
+
+ int status;
+ ASSERT_GE(waitpid(pid, &status, 0), 0);
+ ASSERT_EQ(WIFEXITED(status) && WEXITSTATUS(status), 0);
+ ASSERT_FALSE(params.willthrow);
+ }
+ catch (const std::exception& e)
+ {
+ int status;
+ waitpid(pid, &status, 0);
+ ASSERT_TRUE(params.willthrow);
+ }
+ }
+}
+
+FileLockParameters params[] =
{
- test(sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_EXCLUSIVE);
- }
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_file_lock);
+ FileLockParameters(sbuild::lock::LOCK_NONE, sbuild::lock::LOCK_NONE, false),
+ FileLockParameters(sbuild::lock::LOCK_NONE, sbuild::lock::LOCK_SHARED, false),
+ FileLockParameters(sbuild::lock::LOCK_NONE, sbuild::lock::LOCK_EXCLUSIVE, false),
+ FileLockParameters(sbuild::lock::LOCK_SHARED, sbuild::lock::LOCK_NONE, false),
+ FileLockParameters(sbuild::lock::LOCK_SHARED, sbuild::lock::LOCK_SHARED, false),
+ FileLockParameters(sbuild::lock::LOCK_SHARED, sbuild::lock::LOCK_EXCLUSIVE, true),
+ FileLockParameters(sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_NONE, false),
+ FileLockParameters(sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_SHARED, true),
+ FileLockParameters(sbuild::lock::LOCK_EXCLUSIVE, sbuild::lock::LOCK_EXCLUSIVE, true)
+ };
+
+INSTANTIATE_TEST_CASE_P(LockVariants, FileLock, ::testing::ValuesIn(params));
diff --git a/test/sbuild/log.cc b/test/sbuild/log.cc
index 26a89125..0d74b2f1 100644
--- a/test/sbuild/log.cc
+++ b/test/sbuild/log.cc
@@ -16,144 +16,126 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/log.h>
#include <iostream>
#include <ios>
#include <sstream>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_log : public TestFixture
+class Log : public ::testing::Test
{
- CPPUNIT_TEST_SUITE(test_log);
- CPPUNIT_TEST(test_info);
- CPPUNIT_TEST(test_warning);
- CPPUNIT_TEST(test_error);
- CPPUNIT_TEST(test_debug_none);
- CPPUNIT_TEST(test_debug_notice);
- CPPUNIT_TEST(test_debug_info);
- CPPUNIT_TEST(test_debug_warning);
- CPPUNIT_TEST(test_debug_critical);
- CPPUNIT_TEST_SUITE_END();
-
+public:
std::streambuf *saved;
std::stringbuf *monitor;
-public:
- test_log()
- {}
-
- void setUp()
+ void SetUp()
{
- this->monitor = new std::stringbuf();
- this->saved = std::cerr.std::ios::rdbuf(this->monitor);
+ monitor = new std::stringbuf();
+ saved = std::cerr.std::ios::rdbuf(monitor);
}
- void tearDown()
+ void TearDown()
{
- std::cerr.std::ios::rdbuf(this->saved);
- delete this->monitor;
- }
-
- void test_info()
- {
- sbuild::log_info() << "Discard me please";
- CPPUNIT_ASSERT(this->monitor->str() == "I: Discard me please");
- }
-
- void test_warning()
- {
- sbuild::log_warning() << "Discard me please";
- CPPUNIT_ASSERT(this->monitor->str() == "W: Discard me please");
- }
-
- void test_error()
- {
- sbuild::log_error() << "Discard me please";
- CPPUNIT_ASSERT(this->monitor->str() == "E: Discard me please");
+ std::cerr.std::ios::rdbuf(saved);
+ delete monitor;
}
std::string
debug(sbuild::debug_level level,
const std::string& msg)
{
- this->monitor->str("");
+ monitor->str("");
sbuild::log_debug(level) << msg;
- return this->monitor->str();
+ return monitor->str();
}
+};
- void test_debug_none()
- {
- sbuild::debug_log_level = sbuild::DEBUG_NONE;
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NONE, "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NOTICE, "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_INFO, "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_WARNING, "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_CRITICAL, "Discard me") == "");
- }
+TEST_F(Log, Info)
+{
+ sbuild::log_info() << "Discard me please";
+ ASSERT_EQ(monitor->str(), "I: Discard me please");
+}
- void test_debug_notice()
- {
- sbuild::debug_log_level = sbuild::DEBUG_NOTICE;
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NONE,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NOTICE,
- "Discard me") == "D(1): Discard me");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_INFO,
- "Discard me") == "D(2): Discard me");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_WARNING,
- "Discard me") == "D(3): Discard me");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_CRITICAL,
- "Discard me") == "D(4): Discard me");
- }
+TEST_F(Log, Warning)
+{
+ sbuild::log_warning() << "Discard me please";
+ ASSERT_EQ(monitor->str(), "W: Discard me please");
+}
- void test_debug_info()
- {
- sbuild::debug_log_level = sbuild::DEBUG_INFO;
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NONE,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NOTICE,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_INFO,
- "Discard me") == "D(2): Discard me");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_WARNING,
- "Discard me") == "D(3): Discard me");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_CRITICAL,
- "Discard me") == "D(4): Discard me");
- }
+TEST_F(Log, Error)
+{
+ sbuild::log_error() << "Discard me please";
+ ASSERT_EQ(monitor->str(), "E: Discard me please");
+}
- void test_debug_warning()
- {
- sbuild::debug_log_level = sbuild::DEBUG_WARNING;
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NONE,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NOTICE,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_INFO,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_WARNING,
- "Discard me") == "D(3): Discard me");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_CRITICAL,
- "Discard me") == "D(4): Discard me");
+TEST_F(Log, DebugNone)
+{
+ sbuild::debug_log_level = sbuild::DEBUG_NONE;
+ ASSERT_EQ(debug(sbuild::DEBUG_NONE, "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_NOTICE, "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_INFO, "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_WARNING, "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_CRITICAL, "Discard me"), "");
+}
+
+TEST_F(Log, DebugNotice)
+{
+ sbuild::debug_log_level = sbuild::DEBUG_NOTICE;
+ ASSERT_EQ(debug(sbuild::DEBUG_NONE,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_NOTICE,
+ "Discard me"), "D(1): Discard me");
+ ASSERT_EQ(debug(sbuild::DEBUG_INFO,
+ "Discard me"), "D(2): Discard me");
+ ASSERT_EQ(debug(sbuild::DEBUG_WARNING,
+ "Discard me"), "D(3): Discard me");
+ ASSERT_EQ(debug(sbuild::DEBUG_CRITICAL,
+ "Discard me"), "D(4): Discard me");
+}
+
+TEST_F(Log, DebugInfo)
+{
+ sbuild::debug_log_level = sbuild::DEBUG_INFO;
+ ASSERT_EQ(debug(sbuild::DEBUG_NONE,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_NOTICE,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_INFO,
+ "Discard me"), "D(2): Discard me");
+ ASSERT_EQ(debug(sbuild::DEBUG_WARNING,
+ "Discard me"), "D(3): Discard me");
+ ASSERT_EQ(debug(sbuild::DEBUG_CRITICAL,
+ "Discard me"), "D(4): Discard me");
}
- void test_debug_critical()
- {
- sbuild::debug_log_level = sbuild::DEBUG_CRITICAL;
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NONE,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_NOTICE,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_INFO,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_WARNING,
- "Discard me") == "");
- CPPUNIT_ASSERT(debug(sbuild::DEBUG_CRITICAL,
- "Discard me") == "D(4): Discard me");
+TEST_F(Log, DebugWarning)
+{
+ sbuild::debug_log_level = sbuild::DEBUG_WARNING;
+ ASSERT_EQ(debug(sbuild::DEBUG_NONE,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_NOTICE,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_INFO,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_WARNING,
+ "Discard me"), "D(3): Discard me");
+ ASSERT_EQ(debug(sbuild::DEBUG_CRITICAL,
+ "Discard me"), "D(4): Discard me");
}
-};
-CPPUNIT_TEST_SUITE_REGISTRATION(test_log);
+TEST_F(Log, DebugCritical)
+{
+ sbuild::debug_log_level = sbuild::DEBUG_CRITICAL;
+ ASSERT_EQ(debug(sbuild::DEBUG_NONE,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_NOTICE,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_INFO,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_WARNING,
+ "Discard me"), "");
+ ASSERT_EQ(debug(sbuild::DEBUG_CRITICAL,
+ "Discard me"), "D(4): Discard me");
+}
diff --git a/test/sbuild/nostream.cc b/test/sbuild/nostream.cc
index a97e5479..593d9c1c 100644
--- a/test/sbuild/nostream.cc
+++ b/test/sbuild/nostream.cc
@@ -16,28 +16,13 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/nostream.h>
#include <cstdlib>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_nostream : public TestCase
+TEST(NullOstream, Discard)
{
- CPPUNIT_TEST_SUITE(test_nostream);
- CPPUNIT_TEST(test_stream);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- test_nostream()
- {}
-
- void test_stream()
- {
- sbuild::cnull << "Discard";
- }
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_nostream);
+ sbuild::cnull << "Discard";
+}
diff --git a/test/sbuild/parse-value.cc b/test/sbuild/parse-value.cc
index a5f2c8d5..928bfc2a 100644
--- a/test/sbuild/parse-value.cc
+++ b/test/sbuild/parse-value.cc
@@ -16,101 +16,62 @@
*
*********************************************************************/
-#include <sbuild/parse-value.h>
-
-#include <cppunit/extensions/HelperMacros.h>
+#include <gtest/gtest.h>
-using namespace CppUnit;
+#include <sbuild/parse-value.h>
-class test_parse_value : public TestCase
+TEST(ParseValue, Bool)
{
- CPPUNIT_TEST_SUITE(test_parse_value);
- CPPUNIT_TEST(test_bool);
- CPPUNIT_TEST(test_bool_fail);
- CPPUNIT_TEST(test_int);
- CPPUNIT_TEST(test_int_fail);
- CPPUNIT_TEST(test_string);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- test_parse_value()
- {}
-
- void test_bool()
- {
- bool result;
-
- result = false;
- sbuild::parse_value("true", result);
- CPPUNIT_ASSERT(result == true);
- result = false;
- sbuild::parse_value("yes", result);
- CPPUNIT_ASSERT(result == true);
- result = false;
- sbuild::parse_value("1", result);
- CPPUNIT_ASSERT(result == true);
-
- result = true;
- sbuild::parse_value("false", result);
- CPPUNIT_ASSERT(result == false);
- result = true;
- sbuild::parse_value("no", result);
- CPPUNIT_ASSERT(result == false);
- result = true;
- sbuild::parse_value("0", result);
- CPPUNIT_ASSERT(result == false);
- }
-
- void test_bool_fail()
- {
- bool result = true;
-
- try
- {
- sbuild::parse_value("invalid", result);
- }
- catch (const sbuild::parse_value_error& e)
- {
- // Exception thown, and original value unmodified.
- CPPUNIT_ASSERT(result == true);
- return;
- }
- // Should never be reached
- CPPUNIT_ASSERT(false);
- }
+ bool result;
+
+ result = false;
+ sbuild::parse_value("true", result);
+ EXPECT_TRUE(result);
+ result = false;
+ sbuild::parse_value("yes", result);
+ EXPECT_TRUE(result);
+ result = false;
+ sbuild::parse_value("1", result);
+ EXPECT_TRUE(result);
+
+ result = true;
+ sbuild::parse_value("false", result);
+ EXPECT_FALSE(result);
+ result = true;
+ sbuild::parse_value("no", result);
+ EXPECT_FALSE(result);
+ result = true;
+ sbuild::parse_value("0", result);
+ EXPECT_FALSE(result);
+}
+
+TEST(ParseValue, BoolFail)
+{
+ bool result = true;
- void test_int()
- {
- int result = 0;
- sbuild::parse_value("23", result);
- CPPUNIT_ASSERT(result == 23);
- }
+ EXPECT_THROW(sbuild::parse_value("invalid", result), sbuild::parse_value_error);
+ EXPECT_TRUE(result);
+}
- void test_int_fail()
- {
- int result = 22;
+TEST(ParseValue, Int)
+{
+ int result = 0;
+ sbuild::parse_value("23", result);
+ EXPECT_EQ(result, 23);
+}
- try
- {
- sbuild::parse_value("invalid", result);
- }
- catch (const sbuild::parse_value_error& e)
- {
- // Exception thown, and original value unmodified.
- CPPUNIT_ASSERT(result == 22);
- return;
- }
- // Should never be reached
- CPPUNIT_ASSERT(false);
- }
+TEST(ParseValue, IntFail)
+{
+ int result = 22;
- void test_string()
- {
- std::string result;
+ EXPECT_THROW(sbuild::parse_value("invalid", result), sbuild::parse_value_error);
+ EXPECT_EQ(result, 22);
+}
- sbuild::parse_value("test string", result);
- CPPUNIT_ASSERT(result == "test string");
- }
-};
+TEST(ParseValue, String)
+{
+ std::string result;
-CPPUNIT_TEST_SUITE_REGISTRATION(test_parse_value);
+ sbuild::parse_value("test string", result);
+ EXPECT_EQ(result, "test string");
+}
diff --git a/test/sbuild/personality.cc b/test/sbuild/personality.cc
index 651c9f7e..aa5a6110 100644
--- a/test/sbuild/personality.cc
+++ b/test/sbuild/personality.cc
@@ -16,125 +16,79 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/personality.h>
#include <iostream>
#include <sstream>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_personality : public TestCase
+TEST(Personality, Construct1)
{
- CPPUNIT_TEST_SUITE(test_personality);
- CPPUNIT_TEST(test_construction);
- CPPUNIT_TEST_EXCEPTION(test_construction_fail, sbuild::personality::error);
- CPPUNIT_TEST(test_output);
- CPPUNIT_TEST(test_input);
- CPPUNIT_TEST_EXCEPTION(test_input_fail, sbuild::personality::error);
- CPPUNIT_TEST(test_set);
- CPPUNIT_TEST_EXCEPTION(test_set_fail, sbuild::personality::error);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- test_personality()
- {}
-
- virtual ~test_personality()
- {}
+ sbuild::personality p;
+ ASSERT_EQ(p.get_name(), "undefined");
+}
- void
- test_construction()
- {
- sbuild::personality p1;
- CPPUNIT_ASSERT(p1.get_name() == "undefined");
-
-#if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__)
- sbuild::personality p4("linux");
- CPPUNIT_ASSERT(p4.get_name() == "linux");
-#endif
- }
-
- void
- test_construction_fail()
- {
- sbuild::personality p3("invalid_personality");
- }
-
- void
- test_output()
- {
-#if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__)
- sbuild::personality p4("linux");
-#else
- sbuild::personality p4;
-#endif
+TEST(Personality, Construct2)
+{
+ sbuild::personality p("linux");
+ ASSERT_EQ(p.get_name(), "linux");
+}
- std::ostringstream ps4;
- ps4 << p4;
+TEST(Personality, Construct3)
+{
+ ASSERT_THROW(sbuild::personality p("invalid_personality"), sbuild::personality::error);
+}
-#if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__)
- CPPUNIT_ASSERT(ps4.str() == "linux");
-#else
- CPPUNIT_ASSERT(ps4.str() == "undefined");
-#endif
- }
+TEST(Personality, StreamOutput)
+{
+ sbuild::personality p("linux");
- void
- test_input()
- {
- sbuild::personality p2;
- std::istringstream ps2("undefined");
- ps2 >> p2;
- CPPUNIT_ASSERT(p2.get_name() == "undefined");
+ std::ostringstream os;
+ os << p;
- sbuild::personality p4;
-#if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__)
- std::istringstream ps4("linux");
-#else
- std::istringstream ps4("undefined");
-#endif
- ps4 >> p4;
-#if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__)
- CPPUNIT_ASSERT(p4.get_name() == "linux");
-#else
- CPPUNIT_ASSERT(p4.get_name() == "undefined");
-#endif
- }
+ ASSERT_EQ(os.str(), "linux");
+}
- void
- test_input_fail()
- {
- sbuild::personality p3;
- std::istringstream ps3("invalid_personality");
- ps3 >> p3;
- }
+TEST(Personality, StreamInput1)
+{
+ sbuild::personality p;
+ std::istringstream is("undefined");
+ ASSERT_NO_THROW(is >> p);
+ ASSERT_EQ(p.get_name(), "undefined");
+}
- void
- test_set()
- {
- sbuild::personality p2;
- p2.set_name("undefined");
- CPPUNIT_ASSERT(p2.get_name() == "undefined");
+TEST(Personality, StreamInput2)
+{
+ sbuild::personality p;
+ std::istringstream is("linux");
+ ASSERT_NO_THROW(is >> p);
+ ASSERT_EQ(p.get_name(), "linux");
+}
- sbuild::personality p4;
-#if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__)
- p4.set_name("linux");
- CPPUNIT_ASSERT(p4.get_name() == "linux");
-#else
- p4.set_name("undefined");
- CPPUNIT_ASSERT(p4.get_name() == "undefined");
-#endif
- }
+TEST(Personality, StreamInput3)
+{
+ sbuild::personality p;
+ std::istringstream is("invalid_personality");
+ ASSERT_THROW(is >> p, sbuild::personality::error);
+}
- void
- test_set_fail()
- {
- sbuild::personality p3;
- p3.set_name("invalid_personality");
- }
+TEST(Personality, Set1)
+{
+ sbuild::personality p;
+ p.set_name("undefined");
+ ASSERT_EQ(p.get_name(), "undefined");
+}
-};
+TEST(Personality, Set2)
+{
+ sbuild::personality p;
+ p.set_name("linux");
+ ASSERT_EQ(p.get_name(), "linux");
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_personality);
+TEST(Personality, Set3)
+{
+ sbuild::personality p;
+ ASSERT_THROW(p.set_name("invalid_personality"), sbuild::personality::error);
+}
diff --git a/test/sbuild/regex.cc b/test/sbuild/regex.cc
index dcd46aff..e2e38e42 100644
--- a/test/sbuild/regex.cc
+++ b/test/sbuild/regex.cc
@@ -16,85 +16,52 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/regex.h>
#include <iostream>
#include <sstream>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_regex : public TestCase
+TEST(Regex, Construct)
{
- CPPUNIT_TEST_SUITE(test_regex);
- CPPUNIT_TEST(test_construction);
- CPPUNIT_TEST_EXCEPTION(test_construction_fail, std::regex_error);
- CPPUNIT_TEST(test_output);
- CPPUNIT_TEST(test_input);
- CPPUNIT_TEST(test_match);
- CPPUNIT_TEST_EXCEPTION(test_input_fail, std::regex_error);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- test_regex()
- {}
-
- virtual ~test_regex()
- {}
-
- void
- test_construction()
- {
- sbuild::regex r1;
-
- sbuild::regex r2("foo");
+ EXPECT_NO_THROW(sbuild::regex r1);
- std::string p("foo|bar$");
- sbuild::regex r3(p);
- }
+ EXPECT_NO_THROW(sbuild::regex r2("foo"));
- void
- test_construction_fail()
- {
- sbuild::regex r("[foo");
- }
+ std::string p("foo|bar$");
+ EXPECT_NO_THROW(sbuild::regex r3(p));
- void
- test_output()
- {
- sbuild::regex r("foo");
- std::ostringstream o;
- o << r;
- CPPUNIT_ASSERT(r.str() == "foo");
- CPPUNIT_ASSERT(o.str() == "foo");
- }
+ EXPECT_THROW(sbuild::regex r("[foo"), std::regex_error);
+}
- void
- test_input()
- {
- sbuild::regex r;
- std::istringstream i("foo");
- i >> r;
- std::cerr << "str='" << r.str() << "'" << std::endl;
- CPPUNIT_ASSERT(r.str() == "foo");
- }
-
- void
- test_match()
- {
- sbuild::regex r("^[^:/,.][^:/,]*$");
- sbuild::regex_search("foobar", r);
- }
-
- void
- test_input_fail()
- {
- sbuild::regex r;
- std::istringstream i("([[invalid_regex");
- i >> r;
- }
+TEST(Regex, StreamOutput)
+{
+ sbuild::regex r("foo");
+ std::ostringstream o;
+ o << r;
+ ASSERT_EQ(r.str(),"foo");
+ ASSERT_EQ(o.str(),"foo");
+}
+
+TEST(Regex, StreamInput)
+{
+ sbuild::regex r;
+ std::istringstream i("foo");
+ i >> r;
+ ASSERT_EQ(r.str(),"foo");
+}
-};
+TEST(Regex, Match)
+{
+ sbuild::regex r("^[^:/,.][^:/,]*$");
+ ASSERT_TRUE(sbuild::regex_search("foobar", r));
+ ASSERT_FALSE(sbuild::regex_search(":fail:", r));
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_regex);
+TEST(Regex, StreamInputFail)
+{
+ sbuild::regex r;
+ std::istringstream i("([[invalid_regex");
+ EXPECT_THROW(i >> r, std::regex_error);
+}
diff --git a/test/sbuild/run-parts.cc b/test/sbuild/run-parts.cc
index 225fc56f..397977bc 100644
--- a/test/sbuild/run-parts.cc
+++ b/test/sbuild/run-parts.cc
@@ -16,6 +16,8 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/nostream.h>
#include <sbuild/run-parts.h>
#include <sbuild/util.h>
@@ -25,108 +27,84 @@
#include <boost/filesystem/operations.hpp>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_run_parts : public TestFixture
+class RunParts : public ::testing::Test
{
- CPPUNIT_TEST_SUITE(test_run_parts);
- CPPUNIT_TEST(test_construction);
- CPPUNIT_TEST_EXCEPTION(test_construction_fail, boost::filesystem::filesystem_error);
- CPPUNIT_TEST(test_run);
- CPPUNIT_TEST(test_run2);
- CPPUNIT_TEST(test_run3);
- CPPUNIT_TEST_SUITE_END();
-
+public:
std::streambuf *saved;
sbuild::basic_nbuf<char> *monitor;
-public:
- test_run_parts():
- TestFixture()
- {}
-
- void setUp()
- {
- this->monitor = new sbuild::basic_nbuf<char>();
- this->saved = std::cerr.std::ios::rdbuf(this->monitor);
- }
-
- void tearDown()
- {
- std::cerr.std::ios::rdbuf(this->saved);
- delete this->monitor;
- }
-
-
- virtual ~test_run_parts()
- {}
-
- void
- test_construction()
+ void SetUp()
{
- sbuild::run_parts rp(TESTDATADIR "/run-parts.ex1");
+ monitor = new sbuild::basic_nbuf<char>();
+ saved = std::cerr.std::ios::rdbuf(monitor);
}
- void
- test_construction_fail()
+ void TearDown()
{
- sbuild::run_parts rp(TESTDATADIR "/invalid_dir");
+ std::cerr.std::ios::rdbuf(saved);
+ delete monitor;
}
+};
- void test_run()
- {
- sbuild::run_parts rp(TESTDATADIR "/run-parts.ex1");
+TEST_F(RunParts, Construct)
+{
+ ASSERT_NO_THROW(sbuild::run_parts rp(TESTDATADIR "/run-parts.ex1"));
+}
- int status;
+TEST_F(RunParts, ConstructFail)
+{
+ ASSERT_THROW(sbuild::run_parts rp(TESTDATADIR "/invalid_dir"),
+ boost::filesystem::filesystem_error);
+}
- sbuild::string_list command;
- sbuild::environment env(environ);
+TEST_F(RunParts, Run1)
+{
+ sbuild::run_parts rp(TESTDATADIR "/run-parts.ex1");
- command.push_back("ok");
- status = rp.run(command, env);
- CPPUNIT_ASSERT(status == EXIT_SUCCESS);
+ int status;
- command.clear();
- command.push_back("fail");
- status = rp.run(command, env);
- CPPUNIT_ASSERT(status == EXIT_FAILURE);
+ sbuild::string_list command;
+ sbuild::environment env(environ);
- command.clear();
- command.push_back("fail2");
- status = rp.run(command, env);
- CPPUNIT_ASSERT(status == EXIT_FAILURE);
- }
+ command.push_back("ok");
+ status = rp.run(command, env);
+ ASSERT_EQ(status, EXIT_SUCCESS);
- void test_run2()
- {
- sbuild::run_parts rp(TESTDATADIR "/run-parts.ex2");
+ command.clear();
+ command.push_back("fail");
+ status = rp.run(command, env);
+ ASSERT_EQ(status, EXIT_FAILURE);
- int status;
+ command.clear();
+ command.push_back("fail2");
+ status = rp.run(command, env);
+ ASSERT_EQ(status, EXIT_FAILURE);
+}
- sbuild::string_list command;
- sbuild::environment env(environ);
+TEST_F(RunParts, Run2)
+{
+ sbuild::run_parts rp(TESTDATADIR "/run-parts.ex2");
- command.push_back("ok");
- status = rp.run(command, env);
- CPPUNIT_ASSERT(status == EXIT_SUCCESS);
- }
+ int status;
- void test_run3()
- {
- sbuild::run_parts rp(TESTDATADIR "/run-parts.ex3");
+ sbuild::string_list command;
+ sbuild::environment env(environ);
- int status;
+ command.push_back("ok");
+ status = rp.run(command, env);
+ ASSERT_EQ(status, EXIT_SUCCESS);
+}
- sbuild::string_list command;
- sbuild::environment env(environ);
+TEST_F(RunParts, Run3)
+{
+ sbuild::run_parts rp(TESTDATADIR "/run-parts.ex3");
- command.push_back("ok");
- status = rp.run(command, env);
- CPPUNIT_ASSERT(status == EXIT_FAILURE);
- }
+ int status;
-};
+ sbuild::string_list command;
+ sbuild::environment env(environ);
-CPPUNIT_TEST_SUITE_REGISTRATION(test_run_parts);
+ command.push_back("ok");
+ status = rp.run(command, env);
+ ASSERT_EQ(status, EXIT_FAILURE);
+}
diff --git a/test/sbuild/util.cc b/test/sbuild/util.cc
index 6a6fa661..46856d10 100644
--- a/test/sbuild/util.cc
+++ b/test/sbuild/util.cc
@@ -16,79 +16,58 @@
*
*********************************************************************/
+#include <gtest/gtest.h>
+
#include <sbuild/util.h>
#include <cstdlib>
-#include <cppunit/extensions/HelperMacros.h>
-
-using namespace CppUnit;
-
-class test_util : public TestCase
+TEST(Util, Basename)
{
- CPPUNIT_TEST_SUITE(test_util);
- CPPUNIT_TEST(test_basename);
- CPPUNIT_TEST(test_dirname);
- CPPUNIT_TEST(test_string_list_to_string);
- CPPUNIT_TEST(test_split_string);
- CPPUNIT_TEST(test_find_program_in_path);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- test_util()
- {}
-
- void test_basename()
- {
- CPPUNIT_ASSERT(sbuild::basename("/usr/bin/perl") == "perl");
- CPPUNIT_ASSERT(sbuild::basename("/usr/lib") == "lib");
- CPPUNIT_ASSERT(sbuild::basename("/usr/") == "usr");
- CPPUNIT_ASSERT(sbuild::basename("usr") == "usr");
- CPPUNIT_ASSERT(sbuild::basename("/") == "/");
- CPPUNIT_ASSERT(sbuild::basename(".") == ".");
- CPPUNIT_ASSERT(sbuild::basename("..") == "..");
- }
-
- void test_dirname()
- {
- CPPUNIT_ASSERT(sbuild::dirname("/usr/bin/perl") == "/usr/bin");
- CPPUNIT_ASSERT(sbuild::dirname("/usr/lib") == "/usr");
- CPPUNIT_ASSERT(sbuild::dirname("/usr/") == "/");
- CPPUNIT_ASSERT(sbuild::dirname("usr") == ".");
- CPPUNIT_ASSERT(sbuild::dirname("/") == "/");
- CPPUNIT_ASSERT(sbuild::dirname(".") == ".");
- CPPUNIT_ASSERT(sbuild::dirname("..") == ".");
- }
+ ASSERT_EQ(sbuild::basename("/usr/bin/perl"), "perl");
+ ASSERT_EQ(sbuild::basename("/usr/lib"), "lib");
+ ASSERT_EQ(sbuild::basename("/usr/"), "usr");
+ ASSERT_EQ(sbuild::basename("usr"), "usr");
+ ASSERT_EQ(sbuild::basename("/"), "/");
+ ASSERT_EQ(sbuild::basename("."), ".");
+ ASSERT_EQ(sbuild::basename(".."), "..");
+}
- void test_string_list_to_string()
- {
- sbuild::string_list items;
- items.push_back("foo");
- items.push_back("bar");
- items.push_back("baz");
-
- CPPUNIT_ASSERT(sbuild::string_list_to_string(items, "--") ==
- "foo--bar--baz");
- }
+TEST(Util, Dirname)
+{
+ ASSERT_EQ(sbuild::dirname("/usr/bin/perl"), "/usr/bin");
+ ASSERT_EQ(sbuild::dirname("/usr/lib"), "/usr");
+ ASSERT_EQ(sbuild::dirname("/usr/"), "/");
+ ASSERT_EQ(sbuild::dirname("usr"), ".");
+ ASSERT_EQ(sbuild::dirname("/"), "/");
+ ASSERT_EQ(sbuild::dirname("."), ".");
+ ASSERT_EQ(sbuild::dirname(".."), ".");
+}
- void test_split_string()
- {
- sbuild::string_list items =
- sbuild::split_string("/usr/share/info", "/");
+TEST(Util, StringListToString)
+{
+ sbuild::string_list items;
+ items.push_back("foo");
+ items.push_back("bar");
+ items.push_back("baz");
- CPPUNIT_ASSERT(items.size() == 3 &&
- items[0] == "usr" &&
- items[1] == "share" &&
- items[2] == "info");
- }
+ ASSERT_EQ(sbuild::string_list_to_string(items, "--"), "foo--bar--baz");
+}
- void test_find_program_in_path()
- {
- std::string path("/usr/local/bin:/usr/bin:/bin");
- CPPUNIT_ASSERT(sbuild::find_program_in_path("sh", path, "") == "/bin/sh");
- CPPUNIT_ASSERT(sbuild::find_program_in_path("sed", path, "") == "/bin/sed");
- }
+TEST(Util, SplitString)
+{
+ sbuild::string_list items =
+ sbuild::split_string("/usr/share/info", "/");
-};
+ ASSERT_EQ(items.size(), 3);
+ ASSERT_EQ(items[0], "usr");
+ ASSERT_EQ(items[1], "share");
+ ASSERT_EQ(items[2], "info");
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_util);
+TEST(Util, FindProgramInPath)
+{
+ std::string path("/usr/local/bin:/usr/bin:/bin");
+ ASSERT_EQ(sbuild::find_program_in_path("sh", path, ""), "/bin/sh");
+ ASSERT_EQ(sbuild::find_program_in_path("sed", path, ""), "/bin/sed");
+}