Test suite for settings system

Proof of concept still. Adds a test-specific function in Setting::Manager.
This commit is contained in:
Dale Glass 2022-10-22 20:18:51 +02:00
parent 13cf109d40
commit 334317b175
4 changed files with 98 additions and 0 deletions

View file

@ -120,6 +120,17 @@ namespace Setting {
}
}
/**
* @brief Forces saving the current configuration
*
* @warning This function is for testing only, should only be called from the test suite.
*/
void Manager::forceSave() {
withWriteLock([&] {
_qSettings.sync();
});
}
QString Manager::fileName() const {
return resultWithReadLock<QString>([&] {
return _qSettings.fileName();

View file

@ -44,6 +44,7 @@ namespace Setting {
void setArrayIndex(int i);
void setValue(const QString &key, const QVariant &value);
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
void forceSave();
protected:
~Manager();

View file

@ -0,0 +1,61 @@
//
// Created by Bradley Austin Davis on 2017/11/08
// Copyright 2013-2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "SettingsTests.h"
#include <QtTest/QtTest>
#include <SettingHandle.h>
#include <SettingManager.h>
#include <DependencyManager.h>
#include <QDebug>
#include <QCoreApplication>
#include "SettingInterface.h"
QTEST_MAIN(SettingsTests)
void SettingsTests::initTestCase() {
QCoreApplication::setOrganizationName("OverteTest");
DependencyManager::set<Setting::Manager>();
Setting::init();
}
void SettingsTests::cleanupTestCase() {
// Setting::cleanupSettingsSaveThread();
}
void SettingsTests::loadSettings() {
Settings s;
qDebug() << "Loaded" << s.fileName();
}
void SettingsTests::saveSettings() {
Settings s;
s.setValue("TestValue", "Hello");
auto sm = DependencyManager::get<Setting::Manager>();
sm->setValue("TestValueSM", "Hello");
// There seems to be a bug here, data gets lost without this call here.
sm->forceSave();
qDebug() << "Wrote" << s.fileName();
}
void SettingsTests::benchmarkSaveSettings() {
auto sm = DependencyManager::get<Setting::Manager>();
int i = 0;
QBENCHMARK {
sm->setValue("Benchmark", ++i);
sm->forceSave();
}
}

View file

@ -0,0 +1,25 @@
//
// Created by Dale Glass 2022/10/22
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef overte_SettingsTests_h
#define overte_SettingsTests_h
#include <QtCore/QObject>
class SettingsTests : public QObject {
Q_OBJECT
private slots:
void initTestCase();
void loadSettings();
void saveSettings();
void benchmarkSaveSettings();
void cleanupTestCase();
};
#endif // overte_SettingsTests_h