aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 16:44:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 16:44:34 +0000
commit8af939d947bff1f900f8211b05bcf2eb459616de (patch)
treecca8a32905d6164b9d539851631b37dc894aba03
parentcc291a58865c3d7e6489e39e7ba559a93f5f5428 (diff)
downloadpaludis-8af939d947bff1f900f8211b05bcf2eb459616de.tar.gz
paludis-8af939d947bff1f900f8211b05bcf2eb459616de.tar.xz
gtest more
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/options_TEST.cc163
2 files changed, 71 insertions, 94 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index f14c61d..4924f17 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -57,7 +57,7 @@ add(`mutex', `hh', `cc', `fwd', `test')
add(`named_value', `hh', `cc', `fwd')
add(`no_type', `hh')
add(`operators', `hh')
-add(`options', `hh', `fwd', `cc', `test')
+add(`options', `hh', `fwd', `cc', `gtest')
add(`pimp', `hh', `impl')
add(`pipe', `hh', `cc')
add(`pool', `hh', `cc', `impl', `gtest')
diff --git a/paludis/util/options_TEST.cc b/paludis/util/options_TEST.cc
index 2130648..ddf0ee7 100644
--- a/paludis/util/options_TEST.cc
+++ b/paludis/util/options_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2009, 2010 Ciaran McCreesh
+ * Copyright (c) 2007, 2009, 2010, 2011 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -17,102 +17,79 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "options.hh"
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+#include <paludis/util/options.hh>
+
+#include <gtest/gtest.h>
-using namespace test;
using namespace paludis;
-enum MyOption { mo_one, mo_two, mo_three, mo_four, mo_five, mo_six, mo_seven, mo_eight, mo_nine, mo_ten, last_mo };
-typedef Options<MyOption> MyOptions;
+namespace
+{
+ enum MyOption { mo_one, mo_two, mo_three, mo_four, mo_five, mo_six, mo_seven, mo_eight, mo_nine, mo_ten, last_mo };
+ typedef Options<MyOption> MyOptions;
+}
+
+TEST(Options, Works)
+{
+ MyOptions options, second;
+
+ EXPECT_TRUE(! options.any());
+
+ for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 1))
+ EXPECT_TRUE(! options[o]);
+
+ for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
+ options = options + o;
+
+ EXPECT_TRUE(options.any());
+
+ for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
+ EXPECT_TRUE(options[o]);
+
+ for (MyOption o(static_cast<MyOption>(1)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
+ EXPECT_TRUE(! options[o]);
+
+ for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 1))
+ second += o;
+
+ options |= second;
+
+ for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 1))
+ EXPECT_TRUE(options[o]);
+
+ for (MyOption o(static_cast<MyOption>(1)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
+ options -= o;
+
+ EXPECT_TRUE(options.any());
+
+ for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
+ options = options - o;
+
+ EXPECT_TRUE(! options.any());
+
+ second = { mo_three, mo_eight };
+ options |= second;
+ options += mo_seven;
+ EXPECT_TRUE(options.any());
+ options.subtract(second);
+ EXPECT_TRUE(options.any());
+ options -= mo_seven;
+ EXPECT_TRUE(! options.any());
+ EXPECT_TRUE(options.highest_bit() >= static_cast<int>(last_mo));
+}
-namespace test_cases
+TEST(Options, Initialiser)
{
- struct OptionsTest : TestCase
- {
- OptionsTest() : TestCase("options") { }
-
- void run()
- {
- MyOptions options, second;
-
- TEST_CHECK(! options.any());
-
- for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 1))
- {
- TestMessageSuffix so("o:" + stringify(o));
- TEST_CHECK(! options[o]);
- }
-
- for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
- options = options + o;
-
- TEST_CHECK(options.any());
-
- for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
- {
- TestMessageSuffix so("o:" + stringify(o));
- TEST_CHECK(options[o]);
- }
-
- for (MyOption o(static_cast<MyOption>(1)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
- {
- TestMessageSuffix so("o:" + stringify(o));
- TEST_CHECK(! options[o]);
- }
-
- for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 1))
- second += o;
-
- options |= second;
-
- for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 1))
- {
- TestMessageSuffix so("o:" + stringify(o));
- TEST_CHECK(options[o]);
- }
-
- for (MyOption o(static_cast<MyOption>(1)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
- options -= o;
-
- TEST_CHECK(options.any());
-
- for (MyOption o(static_cast<MyOption>(0)) ; o < last_mo ; o = static_cast<MyOption>(static_cast<long>(o) + 2))
- options = options - o;
-
- TEST_CHECK(! options.any());
-
- second = { mo_three, mo_eight };
- options |= second;
- options += mo_seven;
- TEST_CHECK(options.any());
- options.subtract(second);
- TEST_CHECK(options.any());
- options -= mo_seven;
- TEST_CHECK(! options.any());
- TEST_CHECK(options.highest_bit() >= static_cast<int>(last_mo));
- }
- } test_options;
-
- struct OptionsInitialiserTest : TestCase
- {
- OptionsInitialiserTest() : TestCase("options initialiser") { }
-
- void run()
- {
- MyOptions a({});
- TEST_CHECK(! a.any());
-
- MyOptions b({ mo_two, mo_four, mo_six });
- TEST_CHECK(! b[mo_one]);
- TEST_CHECK(b[mo_two]);
- TEST_CHECK(! b[mo_three]);
- TEST_CHECK(b[mo_four]);
- TEST_CHECK(! b[mo_five]);
- TEST_CHECK(b[mo_six]);
- TEST_CHECK(! b[mo_seven]);
- }
- } test_options_initialiser;
+ MyOptions a({});
+ EXPECT_TRUE(! a.any());
+
+ MyOptions b({ mo_two, mo_four, mo_six });
+ EXPECT_TRUE(! b[mo_one]);
+ EXPECT_TRUE(b[mo_two]);
+ EXPECT_TRUE(! b[mo_three]);
+ EXPECT_TRUE(b[mo_four]);
+ EXPECT_TRUE(! b[mo_five]);
+ EXPECT_TRUE(b[mo_six]);
+ EXPECT_TRUE(! b[mo_seven]);
}