summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2013-09-08 13:35:57 +0100
committerRoger Leigh <rleigh@debian.org>2013-09-08 20:08:11 +0100
commitfa71279d582dd7083a4ad9a211dbbbfb32a2536a (patch)
tree7a6a4c63ee484a2bdaa780ed9ebe9f7acb530d0a
parent2a7730be0ee929ca117b8e016d35724f3aa67478 (diff)
downloadschroot-fa71279d582dd7083a4ad9a211dbbbfb32a2536a.tar.gz
test: Convert test/sbuild/chroot to use gtest
-rw-r--r--test/Makefile.am24
-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
13 files changed, 1949 insertions, 2248 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index f829c531..9aef2c3a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -94,58 +94,58 @@ test_sbuild_chroot_btrfssnap_sources = \
test/sbuild/chroot/btrfs-snapshot.cc
endif
-test_sbuild_chroot_chroot_SOURCES = \
+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_chroot_LDADD = lib/test/libtest2.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_plain_LDADD = lib/test/libtest2.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_custom_LDADD = lib/test/libtest2.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_file_LDADD = lib/test/libtest2.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_directory_LDADD = lib/test/libtest2.la
test_sbuild_chroot_block_device_SOURCES = \
$(test_sbuild_chroot_blockdev_sources) \
test/sbuild/chroot/chroot.h
-test_sbuild_chroot_block_device_LDADD = lib/test/libtest.la
+test_sbuild_chroot_block_device_LDADD = lib/test/libtest2.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_lvm_snapshot_LDADD = lib/test/libtest2.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_btrfs_snapshot_LDADD = lib/test/libtest2.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_loopback_LDADD = lib/test/libtest2.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_LDADD = lib/test/libtest2.la
test_sbuild_chroot_config_SOURCES = test/sbuild/chroot/config.cc
-test_sbuild_chroot_config_LDADD = lib/test/libtest.la
+test_sbuild_chroot_config_LDADD = lib/test/libtest2.la
test_sbuild_environment_SOURCES = test/sbuild/environment.cc
test_sbuild_environment_LDADD = lib/test/libtest2.la
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());
+}