mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Slight cleanup of tests, use friend class to avoid exposing test functions
This commit is contained in:
parent
d9468f33aa
commit
0896807ca5
4 changed files with 17 additions and 14 deletions
|
@ -127,7 +127,7 @@ namespace Setting {
|
|||
*/
|
||||
void Manager::forceSave() {
|
||||
withWriteLock([&] {
|
||||
_qSettings.sync();
|
||||
_qSettings->sync();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
// This is for the testing system.
|
||||
class SettingsTests;
|
||||
class SettingsTestsWorker;
|
||||
|
||||
|
||||
|
||||
|
@ -50,7 +51,6 @@ 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();
|
||||
|
@ -59,6 +59,7 @@ namespace Setting {
|
|||
|
||||
void loadSetting(Interface* handle);
|
||||
void saveSetting(Interface* handle);
|
||||
void forceSave();
|
||||
|
||||
private slots:
|
||||
void startTimer();
|
||||
|
@ -73,7 +74,8 @@ namespace Setting {
|
|||
QHash<QString, QVariant> _pendingChanges;
|
||||
|
||||
friend class Interface;
|
||||
friend class SettingsTests;
|
||||
friend class ::SettingsTests;
|
||||
friend class ::SettingsTestsWorker;
|
||||
|
||||
friend void cleanupSettingsSaveThread();
|
||||
friend void setupSettingsSaveThread();
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
QTEST_MAIN(SettingsTests)
|
||||
|
||||
void SettingsTestThread::saveSettings() {
|
||||
void SettingsTestsWorker::saveSettings() {
|
||||
auto sm = DependencyManager::get<Setting::Manager>();
|
||||
QThread *thread = QThread::currentThread();
|
||||
|
||||
|
@ -75,7 +75,6 @@ void SettingsTests::benchmarkSetValue() {
|
|||
sm->setValue("BenchmarkSetValue", ++i);
|
||||
}
|
||||
|
||||
sm->forceSave();
|
||||
}
|
||||
|
||||
|
||||
|
@ -84,7 +83,7 @@ void SettingsTests::benchmarkSaveSettings() {
|
|||
int i = 0;
|
||||
|
||||
QBENCHMARK {
|
||||
sm->setValue("Benchmark", ++i);
|
||||
sm->setValue("BenchmarkSave", ++i);
|
||||
sm->forceSave();
|
||||
}
|
||||
|
||||
|
@ -96,22 +95,22 @@ void SettingsTests::benchmarkSetValueConcurrent() {
|
|||
int i = 0;
|
||||
|
||||
_settingsThread = new QThread(qApp);
|
||||
_settingsThreadObj = new SettingsTestThread;
|
||||
_testWorker = new SettingsTestsWorker();
|
||||
|
||||
_settingsThread->setObjectName("Save thread");
|
||||
_settingsThreadObj->moveToThread(_settingsThread);
|
||||
_testWorker->moveToThread(_settingsThread);
|
||||
|
||||
QObject::connect(_settingsThread, &QThread::started, _settingsThreadObj, &SettingsTestThread::saveSettings, Qt::QueuedConnection );
|
||||
QObject::connect(_settingsThread, &QThread::started, _testWorker, &SettingsTestsWorker::saveSettings, Qt::QueuedConnection );
|
||||
|
||||
_settingsThread->start();
|
||||
QBENCHMARK {
|
||||
sm->setValue("BenchmarkSetValue", ++i);
|
||||
sm->setValue("BenchmarkSetValueConcurrent", ++i);
|
||||
}
|
||||
|
||||
_settingsThread->requestInterruption();
|
||||
_settingsThread->wait();
|
||||
|
||||
delete _settingsThreadObj;
|
||||
delete _testWorker;
|
||||
delete _settingsThread;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,16 +12,18 @@
|
|||
#include <QtCore/QObject>
|
||||
|
||||
|
||||
class SettingsTestThread : public QObject {
|
||||
|
||||
|
||||
class SettingsTestsWorker : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void saveSettings();
|
||||
};
|
||||
|
||||
|
||||
class SettingsTests : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void loadSettings();
|
||||
|
@ -35,7 +37,7 @@ private slots:
|
|||
|
||||
private:
|
||||
QThread *_settingsThread = nullptr;
|
||||
SettingsTestThread *_settingsThreadObj = nullptr;
|
||||
SettingsTestsWorker *_testWorker = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue