aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 19:08:35 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 19:08:35 +0000
commit06bd9765c5444f1a0eaf19f3fd5f19a5469c3277 (patch)
tree0535d705174e1c92f6963bc044cd5f2fec2236b7
parente8c5280f6f0de63a11fb964f4840c204268d5409 (diff)
downloadpaludis-06bd9765c5444f1a0eaf19f3fd5f19a5469c3277.tar.gz
paludis-06bd9765c5444f1a0eaf19f3fd5f19a5469c3277.tar.xz
gtest more
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/log_TEST.cc137
2 files changed, 60 insertions, 79 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 148c571..83a08cf 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -47,7 +47,7 @@ add(`iterator_funcs', `hh', `test')
add(`indirect_iterator', `hh', `fwd', `impl', `test')
add(`is_file_with_extension', `hh', `cc', `se', `test', `testscript')
add(`join', `hh', `test')
-add(`log', `hh', `cc', `se', `test')
+add(`log', `hh', `cc', `se', `gtest')
add(`make_named_values', `hh', `cc')
add(`make_null_shared_ptr', `hh')
add(`make_shared_copy', `hh', `fwd')
diff --git a/paludis/util/log_TEST.cc b/paludis/util/log_TEST.cc
index a461240..f609186 100644
--- a/paludis/util/log_TEST.cc
+++ b/paludis/util/log_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2008, 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
@@ -18,18 +18,12 @@
*/
#include <paludis/util/log.hh>
+
#include <sstream>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
-/** \file
- * Test cases for Log.
- *
- * \ingroup grptestcases
- */
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
namespace
{
@@ -58,75 +52,62 @@ namespace
}
}
-namespace test_cases
+TEST(Log, Messages)
{
- struct LogTest : TestCase
- {
- LogTest() : TestCase("log") { }
-
- void run()
- {
- Log::destroy_instance();
-
- TEST_CHECK(Log::get_instance());
- TEST_CHECK(Log::get_instance() == Log::get_instance());
-
- std::stringstream s;
- Log::get_instance()->set_log_stream(&s);
- Log::get_instance()->set_log_level(ll_debug);
-
- TEST_CHECK(s.str().empty());
- Log::get_instance()->message("test.log", ll_debug, lc_no_context) << "one";
- Log::get_instance()->complete_pending();
- TEST_CHECK(! s.str().empty());
- TEST_CHECK(std::string::npos != s.str().find("one"));
-
- std::stringstream t;
- Log::get_instance()->set_log_stream(&t);
- TEST_CHECK(t.str().empty());
-
- Log::get_instance()->set_log_level(ll_warning);
- Log::get_instance()->message("test.log", ll_debug, lc_no_context) << "two";
- Log::get_instance()->complete_pending();
- TEST_CHECK(t.str().empty());
- Log::get_instance()->message("test.log", ll_warning, lc_no_context) << "three" << "." << 14;
- Log::get_instance()->complete_pending();
- TEST_CHECK(! t.str().empty());
- TEST_CHECK(std::string::npos == t.str().find("one"));
- TEST_CHECK(std::string::npos == t.str().find("two"));
- TEST_CHECK(std::string::npos != t.str().find("three.14"));
- }
- } test_log;
-
- struct LogExceptionTest : TestCase
- {
- LogExceptionTest() : TestCase("log exception") { }
-
- void run()
- {
- Log::destroy_instance();
-
- std::stringstream s;
- Log::get_instance()->set_log_stream(&s);
- Log::get_instance()->set_log_level(ll_debug);
- TEST_CHECK(s.str().empty());
-
- TEST_CHECK_THROWS(Log::get_instance()->message("test.log", ll_debug, lc_no_context) << throws_a_monkey(), Monkey);
- Log::get_instance()->complete_pending();
- TEST_CHECK(s.str().empty());
- TEST_CHECK_THROWS(Log::get_instance()->message("test.log", ll_debug, lc_no_context)
- << "one" << throws_a_monkey() << "two", Monkey);
- Log::get_instance()->complete_pending();
- TEST_CHECK(s.str().empty());
-
- TEST_CHECK_THROWS(Log::get_instance()->message("test.log", ll_debug, lc_no_context) << throws_a_monkey_when_stringified(), Monkey);
- Log::get_instance()->complete_pending();
- TEST_CHECK(s.str().empty());
- TEST_CHECK_THROWS(Log::get_instance()->message("test.log", ll_debug, lc_no_context)
- << "one" << throws_a_monkey_when_stringified() << "two", Monkey);
- Log::get_instance()->complete_pending();
- TEST_CHECK(s.str().empty());
- }
- } test_log_exception;
+ Log::destroy_instance();
+
+ ASSERT_TRUE(Log::get_instance());
+ EXPECT_TRUE(Log::get_instance() == Log::get_instance());
+
+ std::stringstream s;
+ Log::get_instance()->set_log_stream(&s);
+ Log::get_instance()->set_log_level(ll_debug);
+
+ EXPECT_TRUE(s.str().empty());
+ Log::get_instance()->message("test.log", ll_debug, lc_no_context) << "one";
+ Log::get_instance()->complete_pending();
+ EXPECT_TRUE(! s.str().empty());
+ EXPECT_TRUE(std::string::npos != s.str().find("one"));
+
+ std::stringstream t;
+ Log::get_instance()->set_log_stream(&t);
+ EXPECT_TRUE(t.str().empty());
+
+ Log::get_instance()->set_log_level(ll_warning);
+ Log::get_instance()->message("test.log", ll_debug, lc_no_context) << "two";
+ Log::get_instance()->complete_pending();
+ EXPECT_TRUE(t.str().empty());
+ Log::get_instance()->message("test.log", ll_warning, lc_no_context) << "three" << "." << 14;
+ Log::get_instance()->complete_pending();
+ EXPECT_TRUE(! t.str().empty());
+ EXPECT_TRUE(std::string::npos == t.str().find("one"));
+ EXPECT_TRUE(std::string::npos == t.str().find("two"));
+ EXPECT_TRUE(std::string::npos != t.str().find("three.14"));
+}
+
+TEST(Log, Exceptions)
+{
+ Log::destroy_instance();
+
+ std::stringstream s;
+ Log::get_instance()->set_log_stream(&s);
+ Log::get_instance()->set_log_level(ll_debug);
+ EXPECT_TRUE(s.str().empty());
+
+ EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context) << throws_a_monkey(), Monkey);
+ Log::get_instance()->complete_pending();
+ EXPECT_TRUE(s.str().empty());
+ EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context)
+ << "one" << throws_a_monkey() << "two", Monkey);
+ Log::get_instance()->complete_pending();
+ EXPECT_TRUE(s.str().empty());
+
+ EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context) << throws_a_monkey_when_stringified(), Monkey);
+ Log::get_instance()->complete_pending();
+ EXPECT_TRUE(s.str().empty());
+ EXPECT_THROW(Log::get_instance()->message("test.log", ll_debug, lc_no_context)
+ << "one" << throws_a_monkey_when_stringified() << "two", Monkey);
+ Log::get_instance()->complete_pending();
+ EXPECT_TRUE(s.str().empty());
}