-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleLoggerTest.cpp
More file actions
142 lines (116 loc) · 4.02 KB
/
SimpleLoggerTest.cpp
File metadata and controls
142 lines (116 loc) · 4.02 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* @file SimpleLoggerTest.cpp
* @brief Simple unit tests for the Logger library
* @author Omer Bulut
*/
#include "Logger.hpp"
#include <gtest/gtest.h>
#include <iostream>
#include <filesystem> // Added for file removal in LoggingMethodsExist test
class SimpleLoggerTest : public ::testing::Test {
protected:
void SetUp() override {
// Test setup
}
void TearDown() override {
// Test cleanup
}
};
// Test 1: Basic logger creation
TEST_F(SimpleLoggerTest, BasicCreation) {
Logger logger;
EXPECT_TRUE(logger.getLogger() != nullptr);
}
// Test 2: Basic logging methods exist
TEST_F(SimpleLoggerTest, LoggingMethodsExist) {
// Disable console output during this test to avoid format confusion
Logger::Config config;
config.consoleOutput = false; // Disable console output for clean test
config.logFilePath = "test_logs/test_output.log"; // Use file instead
Logger logger(config);
// These should not crash
EXPECT_NO_THROW(logger.info("Test info"));
EXPECT_NO_THROW(logger.warning("Test warning"));
EXPECT_NO_THROW(logger.error("Test error"));
EXPECT_NO_THROW(logger.debug("Test debug"));
EXPECT_NO_THROW(logger.trace("Test trace"));
EXPECT_NO_THROW(logger.fatal("Test fatal"));
// Clean up test log file
std::filesystem::remove("test_logs/test_output.log");
}
// Test 3: Configuration structure
TEST_F(SimpleLoggerTest, ConfigStructure) {
Logger::Config config;
// Test default values
EXPECT_EQ(config.minLevel, Logger::LogLevel::INFO);
EXPECT_EQ(config.consoleOutput, true);
EXPECT_EQ(config.asyncLogging, false); // Changed default to false for better compatibility
EXPECT_EQ(config.maxFileSize, 10 * 1024 * 1024); // 10MB
EXPECT_EQ(config.maxFiles, 5);
EXPECT_EQ(config.queueSize, 8192);
EXPECT_EQ(config.flushInterval, 3);
}
// Test 4: Log level enum
TEST_F(SimpleLoggerTest, LogLevelEnum) {
// Test that all log levels are defined
EXPECT_EQ(static_cast<int>(Logger::LogLevel::TRACE), 0);
EXPECT_EQ(static_cast<int>(Logger::LogLevel::DEBUG), 1);
EXPECT_EQ(static_cast<int>(Logger::LogLevel::INFO), 2);
EXPECT_EQ(static_cast<int>(Logger::LogLevel::WARNING), 3);
EXPECT_EQ(static_cast<int>(Logger::LogLevel::ERROR), 4);
EXPECT_EQ(static_cast<int>(Logger::LogLevel::FATAL), 5);
}
// Test 5: Logger with custom config
TEST_F(SimpleLoggerTest, CustomConfig) {
Logger::Config config;
config.consoleOutput = true;
config.asyncLogging = false;
Logger logger(config);
EXPECT_TRUE(logger.getLogger() != nullptr);
// Should not crash
EXPECT_NO_THROW(logger.info("Test with custom config"));
}
// Test 6: Set log level
TEST_F(SimpleLoggerTest, SetLogLevel) {
Logger logger;
// Should not crash
EXPECT_NO_THROW(logger.setLogLevel(Logger::LogLevel::DEBUG));
EXPECT_NO_THROW(logger.setLogLevel(Logger::LogLevel::WARNING));
EXPECT_NO_THROW(logger.setLogLevel(Logger::LogLevel::ERROR));
}
// Test 7: Flush method
TEST_F(SimpleLoggerTest, FlushMethod) {
Logger logger;
// Should not crash
EXPECT_NO_THROW(logger.flush());
}
// Test 8: Get logger instance
TEST_F(SimpleLoggerTest, GetLoggerInstance) {
Logger logger;
auto spdlog_logger = logger.getLogger();
EXPECT_TRUE(spdlog_logger != nullptr);
}
// Test 9: Multiple logger instances
TEST_F(SimpleLoggerTest, MultipleInstances) {
Logger logger1;
Logger logger2;
EXPECT_TRUE(logger1.getLogger() != nullptr);
EXPECT_TRUE(logger2.getLogger() != nullptr);
// Should not crash
EXPECT_NO_THROW(logger1.info("From logger 1"));
EXPECT_NO_THROW(logger2.info("From logger 2"));
}
// Test 10: Logger destruction
TEST_F(SimpleLoggerTest, LoggerDestruction) {
{
Logger logger;
logger.info("Test message");
// Logger should be destroyed here without issues
}
// Should not crash
EXPECT_TRUE(true);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}