diff options
Diffstat (limited to 'paludis/util/deferred_construction_ptr_TEST.cc')
-rw-r--r-- | paludis/util/deferred_construction_ptr_TEST.cc | 122 |
1 files changed, 40 insertions, 82 deletions
diff --git a/paludis/util/deferred_construction_ptr_TEST.cc b/paludis/util/deferred_construction_ptr_TEST.cc index 06ae1a8e1..0deca72d8 100644 --- a/paludis/util/deferred_construction_ptr_TEST.cc +++ b/paludis/util/deferred_construction_ptr_TEST.cc @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2008, 2010 Ciaran McCreesh + * Copyright (c) 2008, 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 @@ -19,12 +19,10 @@ #include <paludis/util/deferred_construction_ptr.hh> #include <paludis/util/active_object_ptr.hh> -#include <test/test_runner.hh> -#include <test/test_framework.hh> -#include <test/test_concepts.hh> + +#include <gtest/gtest.h> using namespace paludis; -using namespace test; namespace { @@ -47,91 +45,51 @@ namespace { return std::make_shared<std::string>("chimp"); } -} -namespace test_cases -{ - typedef DeferredConstructionPtr<int *> DeferredIntPtr; - TESTCASE_SEMIREGULAR(DeferredIntPtr, DeferredIntPtr(make_ten)); - - typedef DeferredConstructionPtr<std::shared_ptr<int> > DeferredSharedIntPtr; - TESTCASE_SEMIREGULAR(DeferredSharedIntPtr, DeferredSharedIntPtr(make_ten_shared)); + struct Flag + { + bool value; + Flag() : value(false) { } + }; - struct TestDereference : TestCase + static std::shared_ptr<Flag> make_flag() { - TestDereference() : TestCase("dereference") { } + return std::make_shared<Flag>(); + } +} - void run() - { - DeferredConstructionPtr<std::string *> p(make_monkey); - TEST_CHECK_EQUAL(p->length(), 6u); +TEST(DeferredConstructionPtr, Dereference) +{ + DeferredConstructionPtr<std::string *> p(make_monkey); + EXPECT_EQ(6u, p->length()); - DeferredConstructionPtr<std::shared_ptr<std::string> > q(make_chimp_shared); - TEST_CHECK_EQUAL(q->length(), 5u); - } - } test_dereference; + DeferredConstructionPtr<std::shared_ptr<std::string> > q(make_chimp_shared); + EXPECT_EQ(5u, q->length()); +} - struct TestDeferredActive : TestCase - { - TestDeferredActive() : TestCase("dereferred active") { } +TEST(DeferredConstructionPtr, Active) +{ + ActiveObjectPtr<DeferredConstructionPtr<std::string *> > p(( + DeferredConstructionPtr<std::string *>(make_monkey))); + EXPECT_EQ(6u, p->length()); - void run() - { - ActiveObjectPtr<DeferredConstructionPtr<std::string *> > p(( - DeferredConstructionPtr<std::string *>(make_monkey))); - TEST_CHECK_EQUAL(p->length(), 6u); + ActiveObjectPtr<DeferredConstructionPtr<std::shared_ptr<std::string> > > q(( + DeferredConstructionPtr<std::shared_ptr<std::string> >(make_chimp_shared))); + EXPECT_EQ(5u, q->length()); +} - ActiveObjectPtr<DeferredConstructionPtr<std::shared_ptr<std::string> > > q(( - DeferredConstructionPtr<std::shared_ptr<std::string> >(make_chimp_shared))); - TEST_CHECK_EQUAL(q->length(), 5u); - } - } test_dereferred_active; +TEST(DeferredConstructionPtr, ConstructOnceOnly) +{ + DeferredConstructionPtr<std::shared_ptr<Flag> > f(make_flag); + f->value = true; + EXPECT_TRUE(f->value); +} - struct TestConstructOnlyOnce : TestCase - { - TestConstructOnlyOnce() : TestCase("construct only once") { } - - struct Flag - { - bool value; - Flag() : value(false) { } - }; - - static std::shared_ptr<Flag> make_flag() - { - return std::make_shared<Flag>(); - } - - void run() - { - DeferredConstructionPtr<std::shared_ptr<Flag> > f(make_flag); - f->value = true; - TEST_CHECK(f->value); - } - } test_construct_only_once; - - struct TestConstructOnlyOnceActive : TestCase - { - TestConstructOnlyOnceActive() : TestCase("construct only once active") { } - - struct Flag - { - bool value; - Flag() : value(false) { } - }; - - static std::shared_ptr<Flag> make_flag() - { - return std::make_shared<Flag>(); - } - - void run() - { - ActiveObjectPtr<DeferredConstructionPtr<std::shared_ptr<Flag> > > f(( - DeferredConstructionPtr<std::shared_ptr<Flag> >(make_flag))); - f->value = true; - TEST_CHECK(f->value); - } - } test_construct_only_once_active; +TEST(DeferredConstructionPtr, ConstructOnceOnlyActive) +{ + ActiveObjectPtr<DeferredConstructionPtr<std::shared_ptr<Flag> > > f(( + DeferredConstructionPtr<std::shared_ptr<Flag> >(make_flag))); + f->value = true; + EXPECT_TRUE(f->value); } |