From e8927d8a16a211c9994653bbb9ebbfd451e61c2b Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Tue, 4 Dec 2012 09:11:18 +0100 Subject: Add a test to verify that the cache is correctly updated after multiple insertions and removals. --- tests/client/cachetest.cpp | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'tests') 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() == data2.value()); } - // 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() << 3); + menu.insertItem(0, 4, "newMenu"); + QCOMPARE(menu.cacheIndexes(), QList() << 3); + menu.insertItem(0, 1, "newMenu"); QCOMPARE(menu.cacheIndexes(), QList() << 4); @@ -124,8 +127,8 @@ private Q_SLOTS: QVERIFY(data.value() == data2.value()); } - // 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() == data2.value()); } - // 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() << 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() << 6); + + menu.removeItem(0, 4); + menu.removeItem(0, 6); + menu.removeItem(0, 2); + QCOMPARE(menu.cacheIndexes(), QList() << 4); + + menu.removeItem(0, 4); + QVERIFY(menu.cacheIndexes().isEmpty()); + } }; QTEST_MAIN(CacheTest) -- cgit v1.2.3