1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <iostream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <gtest/gtest.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <log/logger.h>
#include <log/logger_manager.h>
#include <log/log_messages.h>
#include <log/logger_support.h>

using namespace isc;
using namespace isc::log;
using namespace std;

class LoggerLevelTest : public ::testing::Test {
protected:
    LoggerLevelTest() {
        // Logger initialization is done in main().  As logging tests may
        // alter the default logging output, it is reset here.
        setDefaultLoggingOutput();
    }
    ~LoggerLevelTest() {
        LoggerManager::reset();
    }
};


// Checks that the logger is named correctly.

TEST_F(LoggerLevelTest, Creation) {

    // Default
    isc::log::Level level1;
    EXPECT_EQ(isc::log::DEFAULT, level1.severity);
    EXPECT_EQ(isc::log::MIN_DEBUG_LEVEL, level1.dbglevel);

    // Single argument constructor.
    isc::log::Level level2(isc::log::FATAL);
    EXPECT_EQ(isc::log::FATAL, level2.severity);
    EXPECT_EQ(isc::log::MIN_DEBUG_LEVEL, level2.dbglevel);

    // Two-argument constructor
    isc::log::Level level3(isc::log::DEBUG, 42);
    EXPECT_EQ(isc::log::DEBUG, level3.severity);
    EXPECT_EQ(42, level3.dbglevel);
}

TEST_F(LoggerLevelTest, getSeverity) {
    EXPECT_EQ(DEBUG, getSeverity("DEBUG"));
    EXPECT_EQ(DEBUG, getSeverity("debug"));
    EXPECT_EQ(DEBUG, getSeverity("DeBuG"));
    EXPECT_EQ(INFO, getSeverity("INFO"));
    EXPECT_EQ(INFO, getSeverity("info"));
    EXPECT_EQ(INFO, getSeverity("iNfO"));
    EXPECT_EQ(WARN, getSeverity("WARN"));
    EXPECT_EQ(WARN, getSeverity("warn"));
    EXPECT_EQ(WARN, getSeverity("wARn"));
    EXPECT_EQ(ERROR, getSeverity("ERROR"));
    EXPECT_EQ(ERROR, getSeverity("error"));
    EXPECT_EQ(ERROR, getSeverity("ERRoR"));
    EXPECT_EQ(FATAL, getSeverity("FATAL"));
    EXPECT_EQ(FATAL, getSeverity("fatal"));
    EXPECT_EQ(FATAL, getSeverity("FAtaL"));

    // bad values should default to stdout
    EXPECT_EQ(INFO, getSeverity("some bad value"));
    EXPECT_EQ(INFO, getSeverity(""));

    LoggerManager::reset();
}