diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:51:45 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:51:45 +0300 |
| commit | d3261e64152397db2dca4d691a990c6bc2a6f4dd (patch) | |
| tree | fac2f7be638651181a72453d714f0f96675c2b8b /archived/projt-launcher/tests/LogEventParser_test.cpp | |
| parent | 31b9a8949ed0a288143e23bf739f2eb64fdc63be (diff) | |
| download | Project-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.tar.gz Project-Tick-d3261e64152397db2dca4d691a990c6bc2a6f4dd.zip | |
NOISSUE add archived projects
Signed-off-by: Mehmet Samet Duman <yongdohyun@projecttick.org>
Diffstat (limited to 'archived/projt-launcher/tests/LogEventParser_test.cpp')
| -rw-r--r-- | archived/projt-launcher/tests/LogEventParser_test.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/archived/projt-launcher/tests/LogEventParser_test.cpp b/archived/projt-launcher/tests/LogEventParser_test.cpp new file mode 100644 index 0000000000..66f622b96f --- /dev/null +++ b/archived/projt-launcher/tests/LogEventParser_test.cpp @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-3.0-only +// SPDX-FileCopyrightText: 2026 Project Tick +// SPDX-FileContributor: Project Tick Team + +#include <QTest> + +#include <logs/LogEventParser.hpp> + +using projt::logs::LogEventParser; + +class LogEventParserTest : public QObject +{ + Q_OBJECT + + private slots: + void parseLog4jComplete() + { + LogEventParser parser; + const QString xml = + "<log4j:Event logger=\"Test.Logger\" timestamp=\"1700000000\" level=\"WARN\" thread=\"Main\">" + "<log4j:Message>Hello World</log4j:Message>" + "</log4j:Event>"; + + parser.pushLine(xml); + auto item = parser.popNext(); + QVERIFY(item.has_value()); + QVERIFY(std::holds_alternative<LogEventParser::LogRecord>(item.value())); + + auto entry = std::get<LogEventParser::LogRecord>(item.value()); + QCOMPARE(entry.logger, QStringLiteral("Test.Logger")); + QCOMPARE(entry.levelText, QStringLiteral("WARN")); + QCOMPARE(entry.level, MessageLevel::Warning); + QCOMPARE(entry.thread, QStringLiteral("Main")); + QCOMPARE(entry.message, QStringLiteral("Hello World")); + QCOMPARE(entry.timestamp.toSecsSinceEpoch(), 1700000000LL); + } + + void parseLog4jMissingLogger() + { + LogEventParser parser; + const QString xml = "<log4j:Event timestamp=\"1700000000\" level=\"INFO\" thread=\"Main\">" + "<log4j:Message>Missing logger</log4j:Message>" + "</log4j:Event>"; + + parser.pushLine(xml); + auto item = parser.popNext(); + QVERIFY(!item.has_value()); + auto err = parser.lastError(); + QVERIFY(err.has_value()); + QVERIFY(err->message.contains(QStringLiteral("missing logger"), Qt::CaseInsensitive)); + } + + void parseLog4jPendingChunk() + { + LogEventParser parser; + const QString partial = + "<log4j:Event logger=\"Test.Logger\" timestamp=\"1700000000\" level=\"INFO\" thread=\"Main\">" + "<log4j:Message>Partial"; + const QString remainder = "</log4j:Message></log4j:Event>"; + + parser.pushLine(partial); + auto first = parser.popNext(); + QVERIFY(first.has_value()); + QVERIFY(std::holds_alternative<LogEventParser::PendingChunk>(first.value())); + + parser.pushLine(remainder); + auto second = parser.popNext(); + QVERIFY(second.has_value()); + QVERIFY(std::holds_alternative<LogEventParser::LogRecord>(second.value())); + auto entry = std::get<LogEventParser::LogRecord>(second.value()); + QCOMPARE(entry.message, QStringLiteral("Partial")); + } + + void parseLog4jLeadingWhitespace() + { + LogEventParser parser; + const QString xml = + " <log4j:Event logger=\"Test.Logger\" timestamp=\"1700000000\" level=\"INFO\" thread=\"Main\">" + "<log4j:Message>Whitespace</log4j:Message>" + "</log4j:Event>"; + + parser.pushLine(xml); + auto item = parser.popNext(); + QVERIFY(item.has_value()); + QVERIFY(std::holds_alternative<LogEventParser::LogRecord>(item.value())); + } + + void guessLevelFromLine_data() + { + QTest::addColumn<QString>("line"); + QTest::addColumn<int>("fallback"); + QTest::addColumn<int>("expected"); + + QTest::newRow("header-info") << "[12:34:56] [Server thread/INFO] Hello" + << static_cast<int>(MessageLevel::Unknown) << static_cast<int>(MessageLevel::Info); + + QTest::newRow("bracket-severe") << "[SEVERE] Something bad" << static_cast<int>(MessageLevel::Unknown) + << static_cast<int>(MessageLevel::Error); + + QTest::newRow("warning-tag") << "[WARNING] Potential issue" << static_cast<int>(MessageLevel::Unknown) + << static_cast<int>(MessageLevel::Warning); + + QTest::newRow("fatal-overwrite") << "overwriting existing" << static_cast<int>(MessageLevel::Unknown) + << static_cast<int>(MessageLevel::Fatal); + + QTest::newRow("fallback-preserved") + << "overwriting existing" << static_cast<int>(MessageLevel::Info) << static_cast<int>(MessageLevel::Info); + } + + void guessLevelFromLine() + { + QFETCH(QString, line); + QFETCH(int, fallback); + QFETCH(int, expected); + + auto result = LogEventParser::guessLevelFromLine(line, static_cast<MessageLevel::Enum>(fallback)); + QCOMPARE(static_cast<int>(result), expected); + } +}; + +QTEST_GUILESS_MAIN(LogEventParserTest) + +#include "LogEventParser_test.moc" |
