aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-04 14:58:58 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-04 14:58:58 +0000
commit141fbcee98400d120a19a9e31748ceb7fa4bf2cf (patch)
tree3cc41df436c929b6da2cfc243a05f515b7f27b81
parentb2964518999110ad1c1ba0b383d67f5edf5b09cf (diff)
downloadpaludis-141fbcee98400d120a19a9e31748ceb7fa4bf2cf.tar.gz
paludis-141fbcee98400d120a19a9e31748ceb7fa4bf2cf.tar.xz
Add Log level ll_qa. Add Log tests.
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/log.cc4
-rw-r--r--paludis/log.hh5
-rw-r--r--paludis/log_TEST.cc68
4 files changed, 78 insertions, 1 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 718b3a3..8aa7cf9 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -51,7 +51,7 @@ add(`join', `hh', `cc', `test')
add(`key_value_config_file', `hh', `cc', `test')
add(`keyword_name', `hh', `cc')
add(`line_config_file', `hh', `cc', `test')
-add(`log', `hh', `cc')
+add(`log', `hh', `cc', `test')
add(`mask_reasons', `hh', `cc')
add(`match_package', `hh', `cc')
add(`package_database', `hh', `cc', `test')
diff --git a/paludis/log.cc b/paludis/log.cc
index 09167e8..b48d8b5 100644
--- a/paludis/log.cc
+++ b/paludis/log.cc
@@ -63,6 +63,10 @@ Log::message(const LogLevel l, const std::string & s)
*_implementation->stream << "[DEBUG] ";
continue;
+ case ll_qa:
+ *_implementation->stream << "[QA] ";
+ continue;
+
case ll_warning:
*_implementation->stream << "[WARNING] ";
continue;
diff --git a/paludis/log.hh b/paludis/log.hh
index 91ff3c3..30a9dd4 100644
--- a/paludis/log.hh
+++ b/paludis/log.hh
@@ -28,10 +28,15 @@ namespace paludis
{
/**
* Specifies the level of a log message.
+ *
+ * Keep this in order. When deciding whether to display a message, Log
+ * uses message log level >= current log level, so it's important that
+ * least critical levels have lower numeric values.
*/
enum LogLevel
{
ll_debug, ///< Debug message
+ ll_qa, ///< QA messages
ll_warning, ///< Warning message
last_ll, ///< Number of items
initial_ll = ll_debug ///< Initial value
diff --git a/paludis/log_TEST.cc b/paludis/log_TEST.cc
new file mode 100644
index 0000000..31e51f7
--- /dev/null
+++ b/paludis/log_TEST.cc
@@ -0,0 +1,68 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "log.hh"
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+#include <sstream>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ /**
+ * \test Test Log.
+ *
+ * \ingroup Test
+ */
+ struct LogTest : TestCase
+ {
+ LogTest() : TestCase("log") { }
+
+ void run()
+ {
+ TEST_CHECK(Log::get_instance());
+ TEST_CHECK_EQUAL(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(ll_debug, "one");
+ 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(ll_debug, "two");
+ TEST_CHECK(t.str().empty());
+ Log::get_instance()->message(ll_warning, "three");
+ 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"));
+ }
+ } test_log;
+}
+