mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 18:33:01 +02:00
Test suite for settings system
Proof of concept still. Adds a test-specific function in Setting::Manager.
This commit is contained in:
parent
13cf109d40
commit
334317b175
4 changed files with 98 additions and 0 deletions
|
@ -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 {
|
QString Manager::fileName() const {
|
||||||
return resultWithReadLock<QString>([&] {
|
return resultWithReadLock<QString>([&] {
|
||||||
return _qSettings.fileName();
|
return _qSettings.fileName();
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace Setting {
|
||||||
void setArrayIndex(int i);
|
void setArrayIndex(int i);
|
||||||
void setValue(const QString &key, const QVariant &value);
|
void setValue(const QString &key, const QVariant &value);
|
||||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||||
|
void forceSave();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~Manager();
|
~Manager();
|
||||||
|
|
61
tests/shared/src/SettingsTests.cpp
Normal file
61
tests/shared/src/SettingsTests.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
tests/shared/src/SettingsTests.h
Normal file
25
tests/shared/src/SettingsTests.h
Normal 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
|
Loading…
Reference in a new issue