|
@ -10,7 +10,8 @@ class ISettingsAccessorTest : public QObject |
|
|
Q_OBJECT |
|
|
Q_OBJECT |
|
|
|
|
|
|
|
|
protected: |
|
|
protected: |
|
|
QtMvvm::ISettingsAccessor *accessor = nullptr; |
|
|
QtMvvm::ISettingsAccessor *first = nullptr; |
|
|
|
|
|
QtMvvm::ISettingsAccessor *second = nullptr; |
|
|
|
|
|
|
|
|
virtual QtMvvm::ISettingsAccessor *createFirst() = 0; |
|
|
virtual QtMvvm::ISettingsAccessor *createFirst() = 0; |
|
|
virtual QtMvvm::ISettingsAccessor *createSecond() = 0; |
|
|
virtual QtMvvm::ISettingsAccessor *createSecond() = 0; |
|
@ -18,23 +19,23 @@ protected: |
|
|
|
|
|
|
|
|
private Q_SLOTS: |
|
|
private Q_SLOTS: |
|
|
void testAccessorValid() { |
|
|
void testAccessorValid() { |
|
|
accessor = createFirst(); |
|
|
first = createFirst(); |
|
|
QVERIFY(accessor); |
|
|
QVERIFY(first); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void testSimpleOperations() { |
|
|
void testSimpleOperations() { |
|
|
QSignalSpy changedSpy{accessor, &QtMvvm::ISettingsAccessor::entryChanged}; |
|
|
QSignalSpy changedSpy{first, &QtMvvm::ISettingsAccessor::entryChanged}; |
|
|
QSignalSpy removedSpy{accessor, &QtMvvm::ISettingsAccessor::entryRemoved}; |
|
|
QSignalSpy removedSpy{first, &QtMvvm::ISettingsAccessor::entryRemoved}; |
|
|
|
|
|
|
|
|
auto key = QStringLiteral("test/key"); |
|
|
auto key = QStringLiteral("test/key"); |
|
|
QVERIFY(!accessor->contains(key)); |
|
|
QVERIFY(!first->contains(key)); |
|
|
QCOMPARE(accessor->load(key, 24).toInt(), 24); |
|
|
QCOMPARE(first->load(key, 24).toInt(), 24); |
|
|
QVERIFY(changedSpy.isEmpty()); |
|
|
QVERIFY(changedSpy.isEmpty()); |
|
|
QVERIFY(removedSpy.isEmpty()); |
|
|
QVERIFY(removedSpy.isEmpty()); |
|
|
|
|
|
|
|
|
accessor->save(key, 42); |
|
|
first->save(key, 42); |
|
|
QVERIFY(accessor->contains(key)); |
|
|
QVERIFY(first->contains(key)); |
|
|
QCOMPARE(accessor->load(key, 24).toInt(), 42); |
|
|
QCOMPARE(first->load(key, 24).toInt(), 42); |
|
|
if(changedSpy.isEmpty()) |
|
|
if(changedSpy.isEmpty()) |
|
|
QVERIFY(changedSpy.wait()); |
|
|
QVERIFY(changedSpy.wait()); |
|
|
QCOMPARE(changedSpy.size(), 1); |
|
|
QCOMPARE(changedSpy.size(), 1); |
|
@ -43,9 +44,9 @@ private Q_SLOTS: |
|
|
QCOMPARE(changeEvent[1].toInt(), 42); |
|
|
QCOMPARE(changeEvent[1].toInt(), 42); |
|
|
QVERIFY(removedSpy.isEmpty()); |
|
|
QVERIFY(removedSpy.isEmpty()); |
|
|
|
|
|
|
|
|
accessor->remove(key); |
|
|
first->remove(key); |
|
|
QVERIFY(!accessor->contains(key)); |
|
|
QVERIFY(!first->contains(key)); |
|
|
QCOMPARE(accessor->load(key, 24).toInt(), 24); |
|
|
QCOMPARE(first->load(key, 24).toInt(), 24); |
|
|
if(removedSpy.isEmpty()) |
|
|
if(removedSpy.isEmpty()) |
|
|
QVERIFY(removedSpy.wait()); |
|
|
QVERIFY(removedSpy.wait()); |
|
|
QCOMPARE(removedSpy.size(), 1); |
|
|
QCOMPARE(removedSpy.size(), 1); |
|
@ -59,13 +60,13 @@ private Q_SLOTS: |
|
|
auto key2 = QStringLiteral("group/key/subkey"); |
|
|
auto key2 = QStringLiteral("group/key/subkey"); |
|
|
auto key3 = QStringLiteral("group/key/subgroup/subkey"); |
|
|
auto key3 = QStringLiteral("group/key/subgroup/subkey"); |
|
|
|
|
|
|
|
|
accessor->save(key0, true); |
|
|
first->save(key0, true); |
|
|
accessor->save(key1, true); |
|
|
first->save(key1, true); |
|
|
accessor->save(key2, true); |
|
|
first->save(key2, true); |
|
|
accessor->save(key3, true); |
|
|
first->save(key3, true); |
|
|
|
|
|
|
|
|
QSignalSpy removedSpy{accessor, &QtMvvm::ISettingsAccessor::entryRemoved}; |
|
|
QSignalSpy removedSpy{first, &QtMvvm::ISettingsAccessor::entryRemoved}; |
|
|
accessor->remove(key1); |
|
|
first->remove(key1); |
|
|
while(removedSpy.size() < 3) |
|
|
while(removedSpy.size() < 3) |
|
|
QVERIFY(removedSpy.wait()); |
|
|
QVERIFY(removedSpy.wait()); |
|
|
|
|
|
|
|
@ -83,14 +84,14 @@ private Q_SLOTS: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void testSync() { |
|
|
void testSync() { |
|
|
auto second = createSecond(); |
|
|
second = createSecond(); |
|
|
QVERIFY(second); |
|
|
QVERIFY(second); |
|
|
QSignalSpy changedSpy{second, &QtMvvm::ISettingsAccessor::entryChanged}; |
|
|
QSignalSpy changedSpy{second, &QtMvvm::ISettingsAccessor::entryChanged}; |
|
|
QSignalSpy removedSpy{accessor, &QtMvvm::ISettingsAccessor::entryRemoved}; |
|
|
QSignalSpy removedSpy{first, &QtMvvm::ISettingsAccessor::entryRemoved}; |
|
|
|
|
|
|
|
|
auto key = QStringLiteral("sync/key"); |
|
|
auto key = QStringLiteral("sync/key"); |
|
|
accessor->save(key, 13); |
|
|
first->save(key, 13); |
|
|
accessor->sync(); |
|
|
first->sync(); |
|
|
second->sync(); |
|
|
second->sync(); |
|
|
if(!testSyncChangeSignals()) |
|
|
if(!testSyncChangeSignals()) |
|
|
QEXPECT_FAIL("", "The testes accessor does not support notifying changes over multiple instances", Continue); |
|
|
QEXPECT_FAIL("", "The testes accessor does not support notifying changes over multiple instances", Continue); |
|
@ -100,13 +101,13 @@ private Q_SLOTS: |
|
|
QCOMPARE(changedSpy.size(), 1); |
|
|
QCOMPARE(changedSpy.size(), 1); |
|
|
auto changeEvent = changedSpy.takeFirst(); |
|
|
auto changeEvent = changedSpy.takeFirst(); |
|
|
QCOMPARE(changeEvent[0].toString(), key); |
|
|
QCOMPARE(changeEvent[0].toString(), key); |
|
|
QCOMPARE(changeEvent[1].toInt(), 42); |
|
|
QCOMPARE(changeEvent[1].toInt(), 13); |
|
|
} |
|
|
} |
|
|
QCOMPARE(second->load(key, 24).toInt(), 13); |
|
|
QCOMPARE(second->load(key, 24).toInt(), 13); |
|
|
|
|
|
|
|
|
second->remove(key); |
|
|
second->remove(key); |
|
|
second->sync(); |
|
|
second->sync(); |
|
|
accessor->sync(); |
|
|
first->sync(); |
|
|
if(!testSyncChangeSignals()) |
|
|
if(!testSyncChangeSignals()) |
|
|
QEXPECT_FAIL("", "The testes accessor does not support notifying changes over multiple instances", Continue); |
|
|
QEXPECT_FAIL("", "The testes accessor does not support notifying changes over multiple instances", Continue); |
|
|
if(removedSpy.isEmpty()) |
|
|
if(removedSpy.isEmpty()) |
|
@ -115,7 +116,7 @@ private Q_SLOTS: |
|
|
QCOMPARE(removedSpy.size(), 1); |
|
|
QCOMPARE(removedSpy.size(), 1); |
|
|
QCOMPARE(removedSpy.takeFirst()[0].toString(), key); |
|
|
QCOMPARE(removedSpy.takeFirst()[0].toString(), key); |
|
|
} |
|
|
} |
|
|
QCOMPARE(accessor->load(key, 24).toInt(), 24); |
|
|
QCOMPARE(first->load(key, 24).toInt(), 24); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|