]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3533] Reset logging when unit tests exit
authorStephen Morris <stephen@isc.org>
Fri, 5 Sep 2014 16:10:03 +0000 (17:10 +0100)
committerStephen Morris <stephen@isc.org>
Fri, 5 Sep 2014 16:10:03 +0000 (17:10 +0100)
Some unit tests in dhcpsrv altered the logging configuration but
never reset it. That configuration was then used for subsequent
tests and made them overly verbose.

src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc
src/lib/dhcpsrv/tests/logging_unittest.cc

index a354c0ffd724f2cc3c29c9d29ed59c543b781565..758f50b18fb92b1a6d0552f71c1a91ba4ad523a8 100644 (file)
@@ -19,6 +19,7 @@
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <config/ccsession.h>
 #include <gtest/gtest.h>
+#include <log/logger_unittest_support.h>
 
 #include <map>
 #include <string>
@@ -47,6 +48,7 @@ public:
     /// (the last in particular).
     ~DbAccessParserTest() {
         LeaseMgrFactory::destroy();
+        isc::log::resetUnitTestRootLogger();
     }
 
     /// @brief Build JSON String
index 41fc8603ba68b9e73cf817c8f24dfde50cd47887..2ae38d6b2fd7f9932258865766ffaaae2cefa3fb 100644 (file)
@@ -17,6 +17,7 @@
 #include <cc/data.h>
 #include <dhcpsrv/logging.h>
 #include <gtest/gtest.h>
+#include <log/logger_support.h>
 
 using namespace isc;
 using namespace isc::dhcp;
@@ -24,8 +25,29 @@ using namespace isc::data;
 
 namespace {
 
+/// @brief Logging Test Fixture Class
+///
+/// Trivial class that ensures that the logging is reset to its defaults after
+/// each test.  Strictly speaking this only resets the testing root logger (which
+/// has the name "kea") but as the only other logger mentioned here ("wombat")
+/// is not used elsewhere, that is sufficient.
+
+class LoggingTest : public ::testing::Test {
+    public:
+        /// @brief Constructor
+        LoggingTest() {}
+
+        /// @brief Destructor
+        ///
+        /// Reset root logger back to defaults.
+        ~LoggingTest() {
+            isc::log::resetUnitTestRootLogger();
+        }
+};
+
+
 // Checks that contructor is able to process specified storage properly
-TEST(LoggingTest, constructor) {
+TEST_F(LoggingTest, constructor) {
 
     ConfigurationPtr null_ptr;
     EXPECT_THROW(LogConfigParser parser(null_ptr), BadValue);
@@ -38,7 +60,7 @@ TEST(LoggingTest, constructor) {
 // Checks if the LogConfigParser class is able to transform JSON structures
 // into Configuration usable by log4cplus. This test checks for output
 // configured to stdout on debug level.
-TEST(LoggingTest, parsingConsoleOutput) {
+TEST_F(LoggingTest, parsingConsoleOutput) {
 
     const char* config_txt =
     "{ \"loggers\": ["
@@ -79,7 +101,7 @@ TEST(LoggingTest, parsingConsoleOutput) {
 // Checks if the LogConfigParser class is able to transform JSON structures
 // into Configuration usable by log4cplus. This test checks for output
 // configured to a file on INFO level.
-TEST(LoggingTest, parsingFile) {
+TEST_F(LoggingTest, parsingFile) {
 
     const char* config_txt =
     "{ \"loggers\": ["
@@ -119,7 +141,7 @@ TEST(LoggingTest, parsingFile) {
 // Checks if the LogConfigParser class is able to transform data structures
 // into Configuration usable by log4cplus. This test checks that more than
 // one logger can be configured.
-TEST(LoggingTest, multipleLoggers) {
+TEST_F(LoggingTest, multipleLoggers) {
 
     const char* config_txt =
     "{ \"loggers\": ["
@@ -174,7 +196,7 @@ TEST(LoggingTest, multipleLoggers) {
 // Checks if the LogConfigParser class is able to transform data structures
 // into Configuration usable by log4cplus. This test checks that more than
 // one logging destination can be configured.
-TEST(LoggingTest, multipleLoggingDestinations) {
+TEST_F(LoggingTest, multipleLoggingDestinations) {
 
     const char* config_txt =
     "{ \"loggers\": ["