aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 14:58:50 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-27 14:58:50 +0100
commit05f626829d870d4aeb6f2197518eddb760acddb6 (patch)
tree5813cac9ba996a8c1c2298e6820f4a193e2cda82
parent2d485c86590f0ef51b70916717b6fdbd11b9b5d2 (diff)
downloadpaludis-05f626829d870d4aeb6f2197518eddb760acddb6.tar.gz
paludis-05f626829d870d4aeb6f2197518eddb760acddb6.tar.xz
gtest more
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/fuzzy_finder_TEST.cc178
2 files changed, 86 insertions, 94 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 42f5101..626ded5 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -51,7 +51,7 @@ add(`format_messages_output_manager', `hh', `fwd', `cc')
add(`formatted_pretty_printer', `hh', `fwd', `cc')
add(`forward_at_finish_output_manager', `hh', `fwd', `cc')
add(`fs_merger', `hh', `cc', `fwd', `se', `test', `testscript')
-add(`fuzzy_finder', `hh', `cc', `test')
+add(`fuzzy_finder', `hh', `cc', `gtest')
add(`generator', `hh', `cc', `fwd', `test')
add(`generator_handler', `hh', `cc', `fwd')
add(`hook', `hh', `cc', `fwd', `se')
diff --git a/paludis/fuzzy_finder_TEST.cc b/paludis/fuzzy_finder_TEST.cc
index eff7bf0..775454e 100644
--- a/paludis/fuzzy_finder_TEST.cc
+++ b/paludis/fuzzy_finder_TEST.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2007 Fernando J. Pereda
+ * Copyright (c) 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
@@ -19,107 +20,98 @@
#include <paludis/fuzzy_finder.hh>
#include <paludis/filter.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
+
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/make_named_values.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+#include <paludis/util/stringify.hh>
+
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
-namespace test_cases
+TEST(FuzzyCandidatesFinder, Works)
{
- struct FuzzyCandidatesFinderTest : TestCase
- {
- FuzzyCandidatesFinderTest() : TestCase("fuzzy candidates finder") { }
-
- void run()
- {
- TestEnvironment e;
-
- const std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("r1")
- )));
- r1->add_version("some-cat", "foo", "1");
- r1->add_version("other-cat", "foo", "1");
- r1->add_version("some-cat", "bar", "1");
- r1->add_version("some-cat", "one-two-three", "1");
- e.add_repository(1, r1);
-
- const std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("r2")
- )));
- e.add_repository(2, r2);
-
- FuzzyCandidatesFinder f1(e, std::string("some-cat/one-two-thee"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f1.begin(), f1.end()), 1);
-
- FuzzyCandidatesFinder f2(e, std::string("fio"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f2.begin(), f2.end()), 2);
-
- FuzzyCandidatesFinder f3(e, std::string("bra"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f3.begin(), f3.end()), 1);
-
- FuzzyCandidatesFinder f4(e, std::string("foobarandfriends"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f4.begin(), f4.end()), 0);
-
- FuzzyCandidatesFinder f5(e, std::string("some-cat/foo::r2"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f5.begin(), f5.end()), 0);
-
- FuzzyCandidatesFinder f6(e, std::string("some-cat/OnE-tWo-THEE"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f6.begin(), f6.end()), 1);
-
- }
- } fuzzy_candidates_finder_test;
-
- struct FuzzyRepositoriesFinderTest : TestCase
- {
- FuzzyRepositoriesFinderTest() : TestCase("fuzzy repositories finder") { }
-
- void run()
- {
- TestEnvironment e;
-
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("my-main-repository")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("x-new-repository")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("bar-overlay")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("baz-overlay")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("sunrise")))));
-
- FuzzyRepositoriesFinder f1(e, "my-main-respository");
- TEST_CHECK_EQUAL(std::distance(f1.begin(), f1.end()), 1);
-
- FuzzyRepositoriesFinder f2(e, "new-repository");
- TEST_CHECK_EQUAL(std::distance(f2.begin(), f2.end()), 1);
- TEST_CHECK_EQUAL(stringify(*f2.begin()), "x-new-repository");
-
- FuzzyRepositoriesFinder f3(e, "sunric3");
- TEST_CHECK_EQUAL(std::distance(f3.begin(), f3.end()), 1);
-
- FuzzyRepositoriesFinder f4(e, "bar-overlay");
- TEST_CHECK_EQUAL(std::distance(f4.begin(), f4.end()), 2);
-
- FuzzyRepositoriesFinder f5(e, "foo");
- TEST_CHECK_EQUAL(std::distance(f5.begin(), f5.end()), 0);
-
- FuzzyRepositoriesFinder f6(e, "new-repositori");
- TEST_CHECK_EQUAL(std::distance(f6.begin(), f6.end()), 1);
- }
- } fuzzy_repositories_finder_test;
+ TestEnvironment e;
+
+ const std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("r1")
+ )));
+ r1->add_version("some-cat", "foo", "1");
+ r1->add_version("other-cat", "foo", "1");
+ r1->add_version("some-cat", "bar", "1");
+ r1->add_version("some-cat", "one-two-three", "1");
+ e.add_repository(1, r1);
+
+ const std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("r2")
+ )));
+ e.add_repository(2, r2);
+
+ FuzzyCandidatesFinder f1(e, std::string("some-cat/one-two-thee"), filter::All());
+ EXPECT_EQ(1, std::distance(f1.begin(), f1.end()));
+
+ FuzzyCandidatesFinder f2(e, std::string("fio"), filter::All());
+ EXPECT_EQ(2, std::distance(f2.begin(), f2.end()));
+
+ FuzzyCandidatesFinder f3(e, std::string("bra"), filter::All());
+ EXPECT_EQ(1, std::distance(f3.begin(), f3.end()));
+
+ FuzzyCandidatesFinder f4(e, std::string("foobarandfriends"), filter::All());
+ EXPECT_EQ(0, std::distance(f4.begin(), f4.end()));
+
+ FuzzyCandidatesFinder f5(e, std::string("some-cat/foo::r2"), filter::All());
+ EXPECT_EQ(0, std::distance(f5.begin(), f5.end()));
+
+ FuzzyCandidatesFinder f6(e, std::string("some-cat/OnE-tWo-THEE"), filter::All());
+ EXPECT_EQ(1, std::distance(f6.begin(), f6.end()));
+
}
+
+TEST(FuzzyRepositoriesFinder, Works)
+{
+ TestEnvironment e;
+
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("my-main-repository")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("x-new-repository")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("bar-overlay")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("baz-overlay")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("sunrise")))));
+
+ FuzzyRepositoriesFinder f1(e, "my-main-respository");
+ EXPECT_EQ(1, std::distance(f1.begin(), f1.end()));
+
+ FuzzyRepositoriesFinder f2(e, "new-repository");
+ EXPECT_EQ(1, std::distance(f2.begin(), f2.end()));
+ EXPECT_EQ("x-new-repository", stringify(*f2.begin()));
+
+ FuzzyRepositoriesFinder f3(e, "sunric3");
+ EXPECT_EQ(1, std::distance(f3.begin(), f3.end()));
+
+ FuzzyRepositoriesFinder f4(e, "bar-overlay");
+ EXPECT_EQ(2, std::distance(f4.begin(), f4.end()));
+
+ FuzzyRepositoriesFinder f5(e, "foo");
+ EXPECT_EQ(0, std::distance(f5.begin(), f5.end()));
+
+ FuzzyRepositoriesFinder f6(e, "new-repositori");
+ EXPECT_EQ(1, std::distance(f6.begin(), f6.end()));
+}
+