Add setting for Setting::Handle

This commit is contained in:
Dale Glass 2022-11-01 17:04:39 +01:00
parent 0e50b51a63
commit 72bcd6a008
2 changed files with 38 additions and 0 deletions

View file

@ -75,6 +75,10 @@ void SettingsTests::testSettings() {
s.setValue("settingsTest", 1);
QVERIFY(sm->value("settingsTest") == 1);
QVERIFY(!sm->contains("nonExistingKey"));
QVERIFY(sm->value("nonExistingKey") == QVariant());
}
void SettingsTests::testGroups() {
@ -142,6 +146,37 @@ void SettingsTests::testArrayInGroup() {
QVERIFY(sm->value("valueNotInArrayOrGroup") == 8);
}
void SettingsTests::testHandleUnused() {
{
Setting::Handle<int> testHandle("unused_handle", -1);
}
}
void SettingsTests::testHandle() {
auto sm = DependencyManager::get<Setting::Manager>();
Setting::Handle<int> testHandle("integer_value", -1);
QVERIFY(!testHandle.isSet());
QVERIFY(testHandle.get() == -1);
QVERIFY(testHandle.get(-5) == -5);
QVERIFY(testHandle.getDefault() == -1);
testHandle.set(42);
QVERIFY(testHandle.get() == 42);
QVERIFY(testHandle.isSet());
QVERIFY(sm->value("integer_value") == 42);
testHandle.reset();
QVERIFY(testHandle.get() == -1);
QVERIFY(testHandle.isSet());
QVERIFY(sm->value("integer_value") == -1);
testHandle.remove();
QVERIFY(!testHandle.isSet());
}
void SettingsTests::benchmarkSetValue() {
auto sm = DependencyManager::get<Setting::Manager>();
int i = 0;

View file

@ -34,6 +34,9 @@ private slots:
void testArray();
void testArrayInGroup();
void testHandleUnused();
void testHandle();
void benchmarkSetValue();
void benchmarkSaveSettings();