Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit d275e73

Browse files
committed
added iterator tests
1 parent 0d5f0ae commit d275e73

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

tests/auto/datasync/TestDataStore/tst_datastore.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private Q_SLOTS:
2020
void testAll();
2121
void testContains();
2222
void testFind();
23+
void testIterate();
2324
void testRemove_data();
2425
void testRemove();
2526
void testClear();
@@ -142,6 +143,53 @@ void TestDataStore::testFind()
142143
}
143144
}
144145

146+
void TestDataStore::testIterate()
147+
{
148+
try {
149+
//normal iterate
150+
{
151+
QList<TestData> objects = TestLib::generateData(429, 432);
152+
store->iterate<TestData>([&](const TestData &data){
153+
auto ok = false;
154+
[&](){
155+
QVERIFY(!objects.isEmpty());
156+
QCOMPARE(data, objects.takeFirst());
157+
ok = true;
158+
}();
159+
return ok;
160+
});
161+
QVERIFY(objects.isEmpty());
162+
}
163+
164+
//iterate with delete
165+
{
166+
QList<TestData> objects = TestLib::generateData(429, 432);
167+
objects.removeAt(2);
168+
bool first = true;
169+
store->iterate<TestData>([&](const TestData &data){
170+
auto ok = false;
171+
[&](){
172+
if(first) {
173+
QVERIFY(data.id != 431);
174+
first = false;
175+
store->remove<TestData>(431);
176+
}
177+
QVERIFY(!objects.isEmpty());
178+
QCOMPARE(data, objects.takeFirst());
179+
ok = true;
180+
}();
181+
return ok;
182+
});
183+
QVERIFY(objects.isEmpty());
184+
185+
//re-add for further tests
186+
store->save(TestLib::generateData(431));
187+
}
188+
} catch(QException &e) {
189+
QFAIL(e.what());
190+
}
191+
}
192+
145193
void TestDataStore::testRemove_data()
146194
{
147195
QTest::addColumn<int>("key");

tests/auto/datasync/TestDataTypeStore/tst_datatypestore.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ void TestDataTypeStore::testSimple()
7676
QList<int> k = {0, 1, 2, 3};
7777
QCOMPAREUNORDERED(store.keys(), k);
7878
QCOMPAREUNORDERED(store.loadAll(), TestLib::generateData(0, 3));
79+
auto iterCount = 0;
80+
store.iterate([&](const TestData &data){
81+
iterCount++;
82+
return true;
83+
});
84+
QCOMPARE(iterCount, 4);
7985

8086
QVERIFY(store.remove(1));
8187
QCOMPARE(store.count(), 3);
@@ -186,7 +192,7 @@ void TestDataTypeStore::testCaching(std::function<QList<T>(int,int)> generator,
186192
}
187193
}
188194

189-
static void dataTypeStoreCompiletest_DO_NOT_CALL()
195+
Q_DECL_UNUSED static void dataTypeStoreCompiletest_DO_NOT_CALL()
190196
{
191197
DataTypeStore<TestData, int> t1;
192198
t1.count();
@@ -196,7 +202,7 @@ static void dataTypeStoreCompiletest_DO_NOT_CALL()
196202
t1.save(TestData());
197203
t1.remove(5);
198204
t1.search(QStringLiteral("47"));
199-
t1.iterate([](TestData) {
205+
t1.iterate([](const TestData &) {
200206
return false;
201207
});
202208
t1.clear();

0 commit comments

Comments
 (0)