aboutsummaryrefslogtreecommitdiff
path: root/tests/client
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier.tilloy@canonical.com>2012-12-04 09:11:18 +0100
committerOlivier Tilloy <olivier.tilloy@canonical.com>2012-12-04 09:11:18 +0100
commite8927d8a16a211c9994653bbb9ebbfd451e61c2b (patch)
tree3ec3e39a7d1f5da3520d6702a437d74284b65479 /tests/client
parentbf8e579d5da42dc554a6889402a62c19ce02f2bc (diff)
downloadqmenumodel-e8927d8a16a211c9994653bbb9ebbfd451e61c2b.tar.gz
qmenumodel-e8927d8a16a211c9994653bbb9ebbfd451e61c2b.tar.bz2
qmenumodel-e8927d8a16a211c9994653bbb9ebbfd451e61c2b.zip
Add a test to verify that the cache is correctly updated after multiple insertions and removals.
Diffstat (limited to 'tests/client')
-rw-r--r--tests/client/cachetest.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/tests/client/cachetest.cpp b/tests/client/cachetest.cpp
index 9719023..abd3331 100644
--- a/tests/client/cachetest.cpp
+++ b/tests/client/cachetest.cpp
@@ -81,7 +81,7 @@ private Q_SLOTS:
g_type_init();
}
- // Test if the link attribute always returns the same cached menu
+ // Verify that the link attribute always returns the same cached menu
void testStaticMenuCache()
{
TestModel menu;
@@ -105,8 +105,8 @@ private Q_SLOTS:
QVERIFY(data.value<QObject*>() == data2.value<QObject*>());
}
- // Test if the cache is correctly updated after inserting a new item
- void testAddItem()
+ // Verify that the cache is correctly updated after inserting a new item
+ void testInsertItems()
{
TestModel menu;
@@ -114,6 +114,9 @@ private Q_SLOTS:
QVariant data = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList<int>() << 3);
+ menu.insertItem(0, 4, "newMenu");
+ QCOMPARE(menu.cacheIndexes(), QList<int>() << 3);
+
menu.insertItem(0, 1, "newMenu");
QCOMPARE(menu.cacheIndexes(), QList<int>() << 4);
@@ -124,8 +127,8 @@ private Q_SLOTS:
QVERIFY(data.value<QObject*>() == data2.value<QObject*>());
}
- // Test if the cache is correctly updated after removing an item that wasn’t cached
- void testRemoveItem()
+ // Verify that the cache is correctly updated after removing an item that wasn’t cached
+ void testRemoveNonCachedItem()
{
TestModel menu;
@@ -143,7 +146,7 @@ private Q_SLOTS:
QVERIFY(data.value<QObject*>() == data2.value<QObject*>());
}
- // Test if the cache is correctly updated after removing a cached item
+ // Verify that the cache is correctly updated after removing a cached item
void testRemoveCachedItem()
{
TestModel menu;
@@ -155,6 +158,31 @@ private Q_SLOTS:
menu.removeItem(0, 3);
QVERIFY(menu.cacheIndexes().isEmpty());
}
+
+ // Verify that the cache is correctly updated after multiple insertions and removals
+ void testMultiplesUpdates()
+ {
+ TestModel menu;
+ QVERIFY(menu.cacheIndexes().isEmpty());
+
+ menu.data(menu.index(3), QMenuModel::LinkSection);
+ QCOMPARE(menu.cacheIndexes(), QList<int>() << 3);
+
+ menu.insertItem(0, 1, "newMenu");
+ menu.insertItem(0, 2, "newMenu");
+ menu.insertItem(0, 6, "newMenu");
+ menu.insertItem(0, 3, "newMenu");
+ menu.insertItem(0, 7, "newMenu");
+ QCOMPARE(menu.cacheIndexes(), QList<int>() << 6);
+
+ menu.removeItem(0, 4);
+ menu.removeItem(0, 6);
+ menu.removeItem(0, 2);
+ QCOMPARE(menu.cacheIndexes(), QList<int>() << 4);
+
+ menu.removeItem(0, 4);
+ QVERIFY(menu.cacheIndexes().isEmpty());
+ }
};
QTEST_MAIN(CacheTest)