From c59c9f417318119a8f39b6a2ed37c728981a3eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 9 Dec 2015 11:38:32 +0100 Subject: [PATCH] add invalid filter tests --- server/logging/logging.h | 3 ++ tests/auto/guhtestbase.h | 1 + tests/auto/logging/testlogging.cpp | 71 +++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/server/logging/logging.h b/server/logging/logging.h index f7bdb79b..20ddb3de 100644 --- a/server/logging/logging.h +++ b/server/logging/logging.h @@ -61,6 +61,9 @@ public: LoggingEventTypeActionsExecuted, LoggingEventTypeExitActionsExecuted }; + + Logging(QObject *parent = 0); + }; } diff --git a/tests/auto/guhtestbase.h b/tests/auto/guhtestbase.h index 997cbb2d..84181a58 100644 --- a/tests/auto/guhtestbase.h +++ b/tests/auto/guhtestbase.h @@ -23,6 +23,7 @@ #define GUHTESTBASE_H #include "typeutils.h" +#include "logging/logging.h" #include "mocktcpserver.h" #include "devicemanager.h" #include "ruleengine.h" diff --git a/tests/auto/logging/testlogging.cpp b/tests/auto/logging/testlogging.cpp index 26f0671e..d2ac8979 100644 --- a/tests/auto/logging/testlogging.cpp +++ b/tests/auto/logging/testlogging.cpp @@ -41,6 +41,10 @@ private: private slots: void initLogs(); + void systemLogs(); + + void invalidFilter_data(); + void invalidFilter(); void eventLogs(); void actionLog(); @@ -62,11 +66,76 @@ void TestLogging::initLogs() response = injectAndWait("Logging.GetLogEntries"); verifyLoggingError(response); - logEntries = response.toMap().value("params").toMap().value("logEntries").toList(); QVERIFY(logEntries.count() == 0); + + restartServer(); } +void TestLogging::systemLogs() +{ + // check the active system log at boot + QVariantMap params; + params.insert("loggingSources", QVariantList() << JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem)); + params.insert("eventTypes", QVariantList() << JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange)); + + // there should be 2 logs, one for shutdown, one for startup (from server restart) + QVariant response = injectAndWait("Logging.GetLogEntries", params); + verifyLoggingError(response); + QVariantList logEntries = response.toMap().value("params").toMap().value("logEntries").toList(); + QVERIFY(logEntries.count() == 2); + + QVariantMap logEntryShutdown = logEntries.first().toMap(); + + QCOMPARE(logEntryShutdown.value("active").toBool(), false); + QCOMPARE(logEntryShutdown.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange)); + QCOMPARE(logEntryShutdown.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem)); + QCOMPARE(logEntryShutdown.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); + + QVariantMap logEntryStartup = logEntries.last().toMap(); + + QCOMPARE(logEntryStartup.value("active").toBool(), true); + QCOMPARE(logEntryStartup.value("eventType").toString(), JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeActiveChange)); + QCOMPARE(logEntryStartup.value("source").toString(), JsonTypes::loggingSourceToString(Logging::LoggingSourceSystem)); + QCOMPARE(logEntryStartup.value("loggingLevel").toString(), JsonTypes::loggingLevelToString(Logging::LoggingLevelInfo)); +} + +void TestLogging::invalidFilter_data() +{ + QVariantMap invalidSourcesFilter; + invalidSourcesFilter.insert("loggingSources", QVariantList() << "bla"); + + QVariantMap invalidFilterValue; + invalidFilterValue.insert("loggingSource", QVariantList() << "bla"); + + QVariantMap invalidTypeIds; + invalidTypeIds.insert("typeId", QVariantList() << "bla" << "blub"); + + QVariantMap invalidEventTypes; + invalidEventTypes.insert("eventTypes", QVariantList() << JsonTypes::loggingEventTypeToString(Logging::LoggingEventTypeTrigger) << "blub"); + + QTest::addColumn("filter"); + + QTest::newRow("Invalid source") << invalidSourcesFilter; + QTest::newRow("Invalid filter value") << invalidFilterValue; + QTest::newRow("Invalid typeIds") << invalidTypeIds; + QTest::newRow("Invalid eventTypes") << invalidEventTypes; +} + +void TestLogging::invalidFilter() +{ + QFETCH(QVariantMap, filter); + QVariant response = injectAndWait("Logging.GetLogEntries", filter); + QVERIFY(!response.isNull()); + //qDebug() << QJsonDocument::fromVariant(response).toJson(); + + // verify json error + QVERIFY(response.toMap().value("status").toString() == "error"); + qDebug() << response.toMap().value("error").toString(); + +} + + void TestLogging::eventLogs() { QList devices = GuhCore::instance()->findConfiguredDevices(mockDeviceClassId);