diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 2173328..9ab63a7 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -1,4 +1,4 @@ -add_executable(log-analyzer-cli main.cpp) +add_executable(log-analyzer-cli main.cpp reporter.cpp) target_link_libraries(log-analyzer-cli core_lib) set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY EP_PREFIX ${CMAKE_BINARY_DIR}) \ No newline at end of file diff --git a/cli/main.cpp b/cli/main.cpp index 20cf373..2f78db0 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -1,4 +1,5 @@ #include "../core/analyzer.h" +#include "reporter.h" #include int main() { @@ -7,7 +8,9 @@ int main() { std::getline(std::cin, path); Analyzer analysis; - std::string report = analysis.analyze(path); + AnalysisResult result = analysis.analyze(path); + Reporter reporter; + std::string report = reporter.GenerateTextReport(result); std::cout << report; diff --git a/core/reporter.cpp b/cli/reporter.cpp similarity index 100% rename from core/reporter.cpp rename to cli/reporter.cpp diff --git a/core/reporter.h b/cli/reporter.h similarity index 95% rename from core/reporter.h rename to cli/reporter.h index 256a6f1..09d88b2 100644 --- a/core/reporter.h +++ b/cli/reporter.h @@ -1,5 +1,6 @@ #pragma once -#include "common.h" + +#include "../core/common.h" #include diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index a72f231..ccdd931 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -2,6 +2,5 @@ add_library(core_lib reader.cpp parser.cpp statistics.cpp - reporter.cpp analyzer.cpp ) \ No newline at end of file diff --git a/core/analyzer.cpp b/core/analyzer.cpp index 3126709..6717964 100644 --- a/core/analyzer.cpp +++ b/core/analyzer.cpp @@ -1,6 +1,6 @@ #include "analyzer.h" -std::string Analyzer::analyze(std::string path) { +AnalysisResult Analyzer::analyze(std::string path) { reader_.OpenFile(path); AnalysisResult res; @@ -11,7 +11,6 @@ std::string Analyzer::analyze(std::string path) { } reader_.CloseFile(); - std::string report = reporter_.GenerateTextReport(res); - return report; + return res; } \ No newline at end of file diff --git a/core/analyzer.h b/core/analyzer.h index 470f924..b7a9486 100644 --- a/core/analyzer.h +++ b/core/analyzer.h @@ -3,17 +3,15 @@ #include "reader.h" #include "parser.h" #include "statistics.h" -#include "reporter.h" #include class Analyzer { private: Reader reader_; Parser parser_; - Reporter reporter_; Statistics statistics_; public: - std::string analyze(std::string path); + AnalysisResult analyze(std::string path); }; diff --git a/core/parser.cpp b/core/parser.cpp index 02d28f5..650ea40 100644 --- a/core/parser.cpp +++ b/core/parser.cpp @@ -1,5 +1,4 @@ #include "parser.h" -#include LogFormat Parser::DetectFormat(const std::string& line) { if (line.find("HTTP/1.0") != std::string::npos) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c046de1..99ef735 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,6 @@ add_executable(test-runner test_reader.cpp test_parser.cpp test_statistics.cpp - test_reporter.cpp test_analyzer.cpp ) diff --git a/tests/test_analyzer.cpp b/tests/test_analyzer.cpp index 528d7b0..9a35386 100644 --- a/tests/test_analyzer.cpp +++ b/tests/test_analyzer.cpp @@ -3,20 +3,20 @@ TEST(AnalyzerTest, StandardTest) { Analyzer analyzer; fs::path path = fs::path("test_data") / "normal_test.log"; - std::string report = analyzer.analyze(path.string()); + AnalysisResult res = analyzer.analyze(path.string()); - EXPECT_TRUE(report.find("Sucсessful - 5") != std::string::npos); - EXPECT_TRUE(report.find("Failed Parsing - 8") != std::string::npos); - EXPECT_TRUE(report.find("192.168.2.145 - 4") != std::string::npos); - EXPECT_TRUE(report.find("20:00 - 2") != std::string::npos); - EXPECT_TRUE(report.find("500 - 2") != std::string::npos); - EXPECT_FALSE(report.find("402 - 1") != std::string::npos); + EXPECT_TRUE(res.successful_requests == 5); + EXPECT_TRUE(res.failed_parses == 8); + EXPECT_TRUE(res.ip["192.168.2.145"] == 4); + EXPECT_TRUE(res.time_distribution["20:00"] == 2); + EXPECT_TRUE(res.error_counts["500"] == 2); + EXPECT_FALSE(res.error_counts["402"] == 2); } TEST(AnalyzerTest, EmptyTest) { Analyzer analyzer; fs::path path = fs::path("test_data") / "empty_test.log"; - std::string report = analyzer.analyze(path.string()); + AnalysisResult res = analyzer.analyze(path.string()); - EXPECT_TRUE(report == "invalid file format or file empty"); + EXPECT_TRUE(res.total_processed == 0); } \ No newline at end of file diff --git a/tests/test_reporter.cpp b/tests/test_reporter.cpp deleted file mode 100644 index c1efa2e..0000000 --- a/tests/test_reporter.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "tests.h" - -class ReporterTest : public ::testing::Test { -protected: - AnalysisResult createSampleData() { - AnalysisResult result; - - result.total_processed = 1000; - result.successful_requests = 850; - result.error_requests = 150; - result.failed_parses = 5; - - result.ip["192.168.1.100"] = 45; - result.ip["10.0.0.25"] = 33; - result.ip["203.0.113.45"] = 22; - - result.time_distribution["14:00"] = 15; - result.time_distribution["15:00"] = 8; - - result.error_counts["404"] = 60; - result.error_counts["500"] = 25; - result.error_counts["403"] = 15; - - return result; - } - - AnalysisResult createEmptyData() { - AnalysisResult result; - return result; - } -}; - -TEST_F(ReporterTest, NormalTest) { - AnalysisResult res = createSampleData(); - Reporter reporter; - std::string report = reporter.GenerateTextReport(res); - - EXPECT_TRUE(report.find("Sucсessful - 850") != std::string::npos); - EXPECT_TRUE(report.find("Failed Parsing - 5") != std::string::npos); - EXPECT_TRUE(report.find("10.0.0.25 - 33") != std::string::npos); - EXPECT_TRUE(report.find("14:00 - 15") != std::string::npos); - EXPECT_TRUE(report.find("404 - 60") != std::string::npos); - EXPECT_FALSE(report.find("303 - 3") != std::string::npos); - -} - -TEST_F(ReporterTest, EmptyTest) { - AnalysisResult res = createEmptyData(); - Reporter reporter; - std::string report = reporter.GenerateTextReport(res); - - EXPECT_TRUE(report == "invalid file format or file empty"); -} diff --git a/tests/tests.h b/tests/tests.h index a591ed3..dbf032d 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -3,7 +3,6 @@ #include "../core/reader.h" #include "../core/parser.h" #include "../core/statistics.h" -#include "../core/reporter.h" #include "../core/analyzer.h" #include