aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-30 22:20:54 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-07-30 22:20:54 +0000
commite77c92b13aeb4f362aaf999fa65ee2c2bd431181 (patch)
tree173963a9916c417f37872ee634cbbceee41931c7
parentda9a5e3d71bd24ac2ec1a8b9c7d0424c2fe84031 (diff)
downloadpaludis-e77c92b13aeb4f362aaf999fa65ee2c2bd431181.tar.gz
paludis-e77c92b13aeb4f362aaf999fa65ee2c2bd431181.tar.xz
Remove some STL includes from the test framework headers
-rw-r--r--test/test_framework.cc72
-rw-r--r--test/test_framework.hh33
2 files changed, 63 insertions, 42 deletions
diff --git a/test/test_framework.cc b/test/test_framework.cc
index 06d5733..af8b608 100644
--- a/test/test_framework.cc
+++ b/test/test_framework.cc
@@ -20,6 +20,7 @@
#include "test_framework.hh"
#include <algorithm>
#include <iostream>
+#include <list>
#include <paludis/util/attributes.hh>
#include <unistd.h>
@@ -74,14 +75,25 @@ test::set_exception_to_debug_string(std::string (*f) (const std::exception &))
DebugStringHolder::get_instance()->set(f);
}
-std::list<std::string>
-TestMessageSuffix::_suffixes;
+namespace paludis
+{
+ template<>
+ struct Implementation<TestMessageSuffix> :
+ InternalCounted<Implementation<TestMessageSuffix> >
+ {
+ static std::list<std::string> suffixes;
+ };
+
+ std::list<std::string> Implementation<TestMessageSuffix>::suffixes;
+}
std::string
TestMessageSuffix::suffixes()
{
std::string result;
- std::list<std::string>::const_iterator i(_suffixes.begin()), end(_suffixes.end());
+ std::list<std::string>::const_iterator i(paludis::Implementation<TestMessageSuffix>::suffixes.begin()),
+ end(paludis::Implementation<TestMessageSuffix>::suffixes.end());
+
while (i != end)
{
result += *i++;
@@ -91,25 +103,37 @@ TestMessageSuffix::suffixes()
return result;
}
-TestMessageSuffix::TestMessageSuffix(const std::string & s, bool write)
+TestMessageSuffix::TestMessageSuffix(const std::string & s, bool write) :
+ paludis::PrivateImplementationPattern<TestMessageSuffix>(
+ new paludis::Implementation<TestMessageSuffix>)
{
- _suffixes.push_back(s);
+ paludis::Implementation<TestMessageSuffix>::suffixes.push_back(s);
if (write)
std::cout << "[" << s << "]" << std::flush;
}
-struct TestCase::Impl
+TestMessageSuffix::~TestMessageSuffix()
{
- const std::string name;
+ paludis::Implementation<TestMessageSuffix>::suffixes.pop_back();
+}
- Impl(const std::string & the_name) :
- name(the_name)
+namespace paludis
+{
+ template<>
+ struct Implementation<TestCase> :
+ InternalCounted<Implementation<TestCase> >
{
- }
-};
+ const std::string name;
+
+ Implementation(const std::string & the_name) :
+ name(the_name)
+ {
+ }
+ };
+}
TestCase::TestCase(const std::string & name) :
- _impl(new Impl(name))
+ paludis::PrivateImplementationPattern<TestCase>(new paludis::Implementation<TestCase>(name))
{
TestCaseList::register_test_case(this);
}
@@ -153,7 +177,7 @@ TestCase::call_run()
std::string
TestCase::name() const
{
- return _impl->name;
+ return _imp->name;
}
TestFailedException::TestFailedException(const char * const function, const char * const file,
@@ -169,6 +193,16 @@ TestFailedException::~TestFailedException() throw ()
{
}
+namespace
+{
+ std::list<TestCase *> *
+ get_test_case_list()
+ {
+ static std::list<TestCase *> l;
+ return &l;
+ }
+}
+
TestCaseList::TestCaseList()
{
}
@@ -177,6 +211,12 @@ TestCaseList::~TestCaseList()
{
}
+void
+TestCaseList::register_test_case(TestCase * const t)
+{
+ get_test_case_list()->push_back(t);
+}
+
class RunTest
{
private:
@@ -246,11 +286,11 @@ RunTest::operator() (TestCase * test_case) const
bool
TestCaseList::run_tests()
{
- bool had_a_failure(_get_test_case_list().empty());
+ bool had_a_failure(get_test_case_list()->empty());
std::for_each(
- TestCaseList::_get_test_case_list().begin(),
- TestCaseList::_get_test_case_list().end(),
+ get_test_case_list()->begin(),
+ get_test_case_list()->end(),
RunTest(&had_a_failure));
return ! had_a_failure;
diff --git a/test/test_framework.hh b/test/test_framework.hh
index 8576fb4..3f459c1 100644
--- a/test/test_framework.hh
+++ b/test/test_framework.hh
@@ -20,10 +20,8 @@
#ifndef PALUDIS_GUARD_TEST_TEST_FRAMEWORK_HH
#define PALUDIS_GUARD_TEST_TEST_FRAMEWORK_HH 1
-#include <list>
-#include <memory>
#include <paludis/util/stringify.hh>
-#include <sstream>
+#include <paludis/util/private_implementation_pattern.hh>
#include <string>
/** \file
@@ -39,11 +37,9 @@ namespace test
*
* \ingroup Test
*/
- class TestMessageSuffix
+ class TestMessageSuffix :
+ paludis::PrivateImplementationPattern<TestMessageSuffix>
{
- private:
- static std::list<std::string> _suffixes;
-
public:
/**
* Constructor.
@@ -53,10 +49,7 @@ namespace test
/**
* Destructor.
*/
- ~TestMessageSuffix()
- {
- _suffixes.pop_back();
- }
+ ~TestMessageSuffix();
/**
* Our suffixes.
@@ -69,12 +62,9 @@ namespace test
*
* \ingroup Test
*/
- class TestCase
+ class TestCase :
+ private paludis::PrivateImplementationPattern<TestCase>
{
- private:
- struct Impl;
- std::auto_ptr<Impl> _impl;
-
protected:
/**
* Check that a given assertion is true.
@@ -176,20 +166,11 @@ namespace test
TestCaseList();
~TestCaseList();
- static std::list<TestCase *> & _get_test_case_list()
- {
- static std::list<TestCase *> l;
- return l;
- }
-
public:
/**
* Register a TestCase instance.
*/
- inline static void register_test_case(TestCase * const test_case)
- {
- _get_test_case_list().push_back(test_case);
- }
+ static void register_test_case(TestCase * const test_case);
/**
* Run all tests.