-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.cpp
67 lines (65 loc) · 2.85 KB
/
logger_test.cpp
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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "logger.hpp"
#include <gtest/gtest.h>
#include <sstream>
#define DEFUN_TEST_FUNC(name, output1, output2, output3, output4, output5, func, ...) \
TEST(LoggerTest, name) \
{ \
{ \
std::ostringstream oss; \
Logger logger(oss, Logger::LEVEL_DEBUG); \
logger.func(__VA_ARGS__); \
EXPECT_EQ(std::string(output1), oss.str()); \
} \
{ \
std::ostringstream oss; \
Logger logger(oss, Logger::LEVEL_INFO); \
logger.func(__VA_ARGS__); \
EXPECT_EQ(std::string(output2), oss.str()); \
} \
{ \
std::ostringstream oss; \
Logger logger(oss, Logger::LEVEL_WARN); \
logger.func(__VA_ARGS__); \
EXPECT_EQ(std::string(output3), oss.str()); \
} \
{ \
std::ostringstream oss; \
Logger logger(oss, Logger::LEVEL_ERROR); \
logger.func(__VA_ARGS__); \
EXPECT_EQ(std::string(output4), oss.str()); \
} \
{ \
std::ostringstream oss; \
Logger logger(oss, Logger::LEVEL_FATAL); \
logger.func(__VA_ARGS__); \
EXPECT_EQ(std::string(output5), oss.str()); \
} \
}
DEFUN_TEST_FUNC(debug, "DEBUG: Hello.\n", "", "", "", "", debug, "Hello.");
DEFUN_TEST_FUNC(info, "INFO: Hello.\n", "INFO: Hello.\n", "", "", "", info, "Hello.");
DEFUN_TEST_FUNC(warn, "WARN: Hello.\n", "WARN: Hello.\n", "WARN: Hello.\n", "", "", warn, "Hello.");
DEFUN_TEST_FUNC(error, "ERROR: Hello.\n", "ERROR: Hello.\n", "ERROR: Hello.\n", "ERROR: Hello.\n", "", error, "Hello.");
DEFUN_TEST_FUNC(fatal, "FATAL: Hello.\n", "FATAL: Hello.\n", "FATAL: Hello.\n", "FATAL: Hello.\n", "FATAL: Hello.\n", fatal, "Hello.");
DEFUN_TEST_FUNC(log_debug, "DEBUG: Hello.\n", "", "", "", "", log, Logger::LEVEL_DEBUG, "Hello.");
DEFUN_TEST_FUNC(log_info, "INFO: Hello.\n", "INFO: Hello.\n", "", "", "", log, Logger::LEVEL_INFO, "Hello.");
DEFUN_TEST_FUNC(log_warn, "WARN: Hello.\n", "WARN: Hello.\n", "WARN: Hello.\n", "", "", log, Logger::LEVEL_WARN, "Hello.");
DEFUN_TEST_FUNC(log_error, "ERROR: Hello.\n", "ERROR: Hello.\n", "ERROR: Hello.\n", "ERROR: Hello.\n", "", log, Logger::LEVEL_ERROR, "Hello.");
DEFUN_TEST_FUNC(log_fatal, "FATAL: Hello.\n", "FATAL: Hello.\n", "FATAL: Hello.\n", "FATAL: Hello.\n", "FATAL: Hello.\n", log, Logger::LEVEL_FATAL, "Hello.");
TEST(LoggerTest, set_level)
{
std::stringstream oss;
Logger logger(oss, Logger::LEVEL_DEBUG);
logger.debug("Hello.");
EXPECT_EQ(std::string("DEBUG: Hello.\n"), oss.str());
oss.str("");
logger.set_level(Logger::LEVEL_INFO);
logger.debug("Hello.");
EXPECT_EQ(std::string(""), oss.str());
oss.str("");
logger.set_level(Logger::LEVEL_DEBUG);
logger.debug("Hello.");
EXPECT_EQ(std::string("DEBUG: Hello.\n"), oss.str());
}