add log database loading tests
This commit is contained in:
parent
4eddeb7d52
commit
e5756587a3
@ -424,7 +424,7 @@ void GuhCore::init() {
|
|||||||
m_timeManager = new TimeManager(QTimeZone::systemTimeZoneId(), this);
|
m_timeManager = new TimeManager(QTimeZone::systemTimeZoneId(), this);
|
||||||
|
|
||||||
qCDebug(dcApplication) << "Creating Log Engine";
|
qCDebug(dcApplication) << "Creating Log Engine";
|
||||||
m_logger = new LogEngine(this);
|
m_logger = new LogEngine(GuhSettings::logPath(), this);
|
||||||
|
|
||||||
qCDebug(dcApplication) << "Creating Device Manager (locale:" << m_configuration->locale() << ")";
|
qCDebug(dcApplication) << "Creating Device Manager (locale:" << m_configuration->locale() << ")";
|
||||||
m_deviceManager = new DeviceManager(m_configuration->locale(), this);
|
m_deviceManager = new DeviceManager(m_configuration->locale(), this);
|
||||||
|
|||||||
@ -132,11 +132,11 @@
|
|||||||
namespace guhserver {
|
namespace guhserver {
|
||||||
|
|
||||||
/*! Constructs the log engine with the given \a parent. */
|
/*! Constructs the log engine with the given \a parent. */
|
||||||
LogEngine::LogEngine(QObject *parent):
|
LogEngine::LogEngine(const QString &logPath, QObject *parent):
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
m_db = QSqlDatabase::addDatabase("QSQLITE", "logs");
|
m_db = QSqlDatabase::addDatabase("QSQLITE", "logs");
|
||||||
m_db.setDatabaseName(GuhSettings::logPath());
|
m_db.setDatabaseName(logPath);
|
||||||
m_dbMaxSize = 50000;
|
m_dbMaxSize = 50000;
|
||||||
m_overflow = 100;
|
m_overflow = 100;
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class LogEngine: public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LogEngine(QObject *parent = 0);
|
LogEngine(const QString &logPath = GuhSettings::logPath(), QObject *parent = 0);
|
||||||
~LogEngine();
|
~LogEngine();
|
||||||
|
|
||||||
QList<LogEntry> logEntries(const LogFilter &filter = LogFilter()) const;
|
QList<LogEntry> logEntries(const LogFilter &filter = LogFilter()) const;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ SUBDIRS = versioning \
|
|||||||
websocketserver \
|
websocketserver \
|
||||||
logging \
|
logging \
|
||||||
loggingdirect \
|
loggingdirect \
|
||||||
|
loggingloading \
|
||||||
restlogging \
|
restlogging \
|
||||||
#coap \ # temporary removed until fixed
|
#coap \ # temporary removed until fixed
|
||||||
configurations \
|
configurations \
|
||||||
|
|||||||
@ -64,6 +64,7 @@ private slots:
|
|||||||
|
|
||||||
void testHouseKeeping();
|
void testHouseKeeping();
|
||||||
|
|
||||||
|
|
||||||
// this has to be the last test
|
// this has to be the last test
|
||||||
void removeDevice();
|
void removeDevice();
|
||||||
};
|
};
|
||||||
@ -326,8 +327,8 @@ void TestLogging::actionLog()
|
|||||||
|
|
||||||
clientSpy.wait(200);
|
clientSpy.wait(200);
|
||||||
|
|
||||||
QVariant notification = checkNotification(clientSpy, "Logging.LogEntryAdded");
|
loggEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded");
|
||||||
QVERIFY(!notification.isNull());
|
QVERIFY(!loggEntryAddedVariants.isEmpty());
|
||||||
|
|
||||||
// get this logentry with filter
|
// get this logentry with filter
|
||||||
params.clear();
|
params.clear();
|
||||||
|
|||||||
BIN
tests/auto/loggingloading/guhd-broken.sqlite
Executable file
BIN
tests/auto/loggingloading/guhd-broken.sqlite
Executable file
Binary file not shown.
BIN
tests/auto/loggingloading/guhd-v2.sqlite
Executable file
BIN
tests/auto/loggingloading/guhd-v2.sqlite
Executable file
Binary file not shown.
6
tests/auto/loggingloading/loggingloading.pro
Normal file
6
tests/auto/loggingloading/loggingloading.pro
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include(../../../guh.pri)
|
||||||
|
include(../autotests.pri)
|
||||||
|
|
||||||
|
RESOURCES += loggingloading.qrc
|
||||||
|
TARGET = loggingloading
|
||||||
|
SOURCES += testloggingloading.cpp
|
||||||
6
tests/auto/loggingloading/loggingloading.qrc
Normal file
6
tests/auto/loggingloading/loggingloading.qrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<!DOCTYPE RCC><RCC version="1.0">
|
||||||
|
<qresource>
|
||||||
|
<file>guhd-v2.sqlite</file>
|
||||||
|
<file>guhd-broken.sqlite</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
139
tests/auto/loggingloading/testloggingloading.cpp
Normal file
139
tests/auto/loggingloading/testloggingloading.cpp
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* *
|
||||||
|
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
|
||||||
|
* *
|
||||||
|
* This file is part of guh. *
|
||||||
|
* *
|
||||||
|
* Guh is free software: you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation, version 2 of the License. *
|
||||||
|
* *
|
||||||
|
* Guh is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include "logging/logengine.h"
|
||||||
|
#include "logging/logvaluetool.h"
|
||||||
|
|
||||||
|
using namespace guhserver;
|
||||||
|
|
||||||
|
class TestLoggingLoading: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TestLoggingLoading(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void testLogMigration();
|
||||||
|
void testLogfileRotation();
|
||||||
|
|
||||||
|
void databaseSerializationTest_data();
|
||||||
|
void databaseSerializationTest();
|
||||||
|
};
|
||||||
|
|
||||||
|
TestLoggingLoading::TestLoggingLoading(QObject *parent): QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestLoggingLoading::testLogMigration()
|
||||||
|
{
|
||||||
|
Q_INIT_RESOURCE(loggingloading);
|
||||||
|
|
||||||
|
// Create LogEngine with log db from resource file
|
||||||
|
QString temporaryDbName = GuhSettings::settingsPath() + "/guhd-v2.sqlite";
|
||||||
|
|
||||||
|
if (QFile::exists(temporaryDbName))
|
||||||
|
QVERIFY(QFile(temporaryDbName).remove());
|
||||||
|
|
||||||
|
QVERIFY(QFile::copy(":/guhd-v2.sqlite", temporaryDbName));
|
||||||
|
QVERIFY(QFile::setPermissions(temporaryDbName, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther));
|
||||||
|
|
||||||
|
LogEngine *logEngine = new LogEngine(temporaryDbName, this);
|
||||||
|
// Check there is no rotated logfile
|
||||||
|
QVERIFY(!QFile::exists(temporaryDbName + ".1"));
|
||||||
|
|
||||||
|
delete logEngine;
|
||||||
|
|
||||||
|
QVERIFY(QFile(temporaryDbName).remove());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestLoggingLoading::testLogfileRotation()
|
||||||
|
{
|
||||||
|
Q_INIT_RESOURCE(loggingloading);
|
||||||
|
|
||||||
|
// Create LogEngine with log db from resource file
|
||||||
|
QString temporaryDbName = GuhSettings::settingsPath() + "/guhd-broken.sqlite";
|
||||||
|
QString rotatedDbName = GuhSettings::settingsPath() + "/guhd-broken.sqlite.1";
|
||||||
|
|
||||||
|
// Remove the files if there are some left
|
||||||
|
if (QFile::exists(temporaryDbName))
|
||||||
|
QVERIFY(QFile(temporaryDbName).remove());
|
||||||
|
|
||||||
|
if (QFile::exists(rotatedDbName))
|
||||||
|
QVERIFY(QFile(rotatedDbName).remove());
|
||||||
|
|
||||||
|
QVERIFY(QFile::copy(":/guhd-broken.sqlite", temporaryDbName));
|
||||||
|
QVERIFY(QFile::setPermissions(temporaryDbName, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther));
|
||||||
|
|
||||||
|
QVERIFY(!QFile::exists(rotatedDbName));
|
||||||
|
LogEngine *logEngine = new LogEngine(temporaryDbName, this);
|
||||||
|
QVERIFY(QFile::exists(rotatedDbName));
|
||||||
|
|
||||||
|
delete logEngine;
|
||||||
|
|
||||||
|
QVERIFY(QFile(temporaryDbName).remove());
|
||||||
|
QVERIFY(QFile(rotatedDbName).remove());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestLoggingLoading::databaseSerializationTest_data()
|
||||||
|
{
|
||||||
|
QUuid uuid = QUuid("3782732b-61b4-48e8-8d6d-b5205159d7cd");
|
||||||
|
|
||||||
|
QVariantMap variantMap;
|
||||||
|
variantMap.insert("string", "value");
|
||||||
|
variantMap.insert("int", 5);
|
||||||
|
variantMap.insert("double", 3.14);
|
||||||
|
variantMap.insert("uuid", uuid);
|
||||||
|
|
||||||
|
QVariantList variantList;
|
||||||
|
variantList.append(variantMap);
|
||||||
|
variantList.append("String");
|
||||||
|
variantList.append(3.14);
|
||||||
|
variantList.append(uuid);
|
||||||
|
|
||||||
|
QTest::addColumn<QVariant>("value");
|
||||||
|
|
||||||
|
QTest::newRow("QString") << QVariant(QString("Hello"));
|
||||||
|
QTest::newRow("Integer") << QVariant((int)2);
|
||||||
|
QTest::newRow("Double") << QVariant((double)2.34);
|
||||||
|
QTest::newRow("Float") << QVariant((float)2.34);
|
||||||
|
QTest::newRow("QColor") << QVariant(QColor(0,255,128));
|
||||||
|
QTest::newRow("QByteArray") << QVariant(QByteArray("\nthisisatestarray\n"));
|
||||||
|
QTest::newRow("QUuid") << QVariant(uuid);
|
||||||
|
QTest::newRow("QVariantMap") << QVariant(variantMap);
|
||||||
|
QTest::newRow("QVariantList") << QVariant(variantList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestLoggingLoading::databaseSerializationTest()
|
||||||
|
{
|
||||||
|
QFETCH(QVariant, value);
|
||||||
|
|
||||||
|
QString serializedValue = LogValueTool::serializeValue(value);
|
||||||
|
QVariant deserializedValue = LogValueTool::deserializeValue(serializedValue);
|
||||||
|
|
||||||
|
qDebug() << "Stored:" << value;
|
||||||
|
qDebug() << "Loaded:" << deserializedValue;
|
||||||
|
QCOMPARE(deserializedValue, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "testloggingloading.moc"
|
||||||
|
QTEST_MAIN(TestLoggingLoading)
|
||||||
Reference in New Issue
Block a user