initial commit
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#include "logger/logger.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
using namespace radiantwave::logger;
|
||||
|
||||
TEST(LoggerTest, InitializeAndWriteLog) {
|
||||
std::string temp_path = (std::filesystem::temp_directory_path() / "test_rw_logger1.txt").string();
|
||||
if (std::filesystem::exists(temp_path)) {
|
||||
std::filesystem::remove(temp_path);
|
||||
}
|
||||
|
||||
Logger logger;
|
||||
EXPECT_TRUE(logger.initialize(temp_path));
|
||||
|
||||
logger.info("System", "System starting up");
|
||||
logger.warning("WiFi", "Network connection lost (interface wlan0 carrier dropped)");
|
||||
logger.error("Database", "Database query failed (SQLITE_CORRUPT table proclamations)");
|
||||
|
||||
auto entries = logger.getEntries();
|
||||
ASSERT_EQ(entries.size(), 3u);
|
||||
|
||||
EXPECT_EQ(entries[0].component, "System");
|
||||
EXPECT_EQ(entries[0].level, LogLevel::Info);
|
||||
|
||||
EXPECT_EQ(entries[1].component, "WiFi");
|
||||
EXPECT_EQ(entries[1].level, LogLevel::Warning);
|
||||
|
||||
EXPECT_EQ(entries[2].component, "Database");
|
||||
EXPECT_EQ(entries[2].level, LogLevel::Error);
|
||||
|
||||
std::filesystem::remove(temp_path);
|
||||
}
|
||||
|
||||
TEST(LoggerTest, FilterLogs) {
|
||||
std::string temp_path = (std::filesystem::temp_directory_path() / "test_rw_logger2.txt").string();
|
||||
if (std::filesystem::exists(temp_path)) {
|
||||
std::filesystem::remove(temp_path);
|
||||
}
|
||||
|
||||
Logger logger;
|
||||
ASSERT_TRUE(logger.initialize(temp_path));
|
||||
|
||||
logger.debug("Core", "Debug tracing");
|
||||
logger.info("Core", "Info message");
|
||||
logger.warning("Core", "Warning message");
|
||||
logger.error("Core", "Error message");
|
||||
|
||||
auto min_warn = logger.getEntriesFiltered(LogLevel::Warning, false);
|
||||
ASSERT_EQ(min_warn.size(), 2u); // Warning and Error
|
||||
|
||||
auto exact_error = logger.getEntriesFiltered(LogLevel::Error, true);
|
||||
ASSERT_EQ(exact_error.size(), 1u);
|
||||
EXPECT_EQ(exact_error[0].message, "Error message");
|
||||
|
||||
std::filesystem::remove(temp_path);
|
||||
}
|
||||
Reference in New Issue
Block a user