diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-10-14 16:44:46 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-02 03:52:25 +0100 |
commit | 1c394490f4efe6055426257a8dfcec4cdf3e12af (patch) | |
tree | 029ccee9a19bf225dd148b347d52472f3c2f9ba8 /tests/auto/declarative/qdeclarativelistcompositor | |
parent | c177691118e4e2bace9b5c1f4f57343190e6ad64 (diff) |
Fix incorrect cache indexes when consecutive list items are removed.
When cached model items are removed listItemsRemoved will try and append
a new cache only range onto a preceding one where possible. Previously
it would then re-run that range so the current indexes in the list were
incremented before moving onto the next range, which meant that the
current indexes were incremented by size of the previous range twice.
Instead of processing the range a second time increment the cache
indexes directly when inserting a cache only range and move directly
onto the next range in the list.
Change-Id: I63418c4397f911cefb521c5a5b0dd25faf66e08b
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativelistcompositor')
-rw-r--r-- | tests/auto/declarative/qdeclarativelistcompositor/tst_qdeclarativelistcompositor.cpp | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativelistcompositor/tst_qdeclarativelistcompositor.cpp b/tests/auto/declarative/qdeclarativelistcompositor/tst_qdeclarativelistcompositor.cpp index 67bced6da8..94bb40ef3b 100644 --- a/tests/auto/declarative/qdeclarativelistcompositor/tst_qdeclarativelistcompositor.cpp +++ b/tests/auto/declarative/qdeclarativelistcompositor/tst_qdeclarativelistcompositor.cpp @@ -146,6 +146,10 @@ class tst_qdeclarativelistcompositor : public QObject } private slots: + void find_data(); + void find(); + void findInsertPosition_data(); + void findInsertPosition(); void insert(); void clearFlags_data(); void clearFlags(); @@ -164,6 +168,131 @@ private slots: void listItemsChanged(); }; +void tst_qdeclarativelistcompositor::find_data() +{ + QTest::addColumn<RangeList>("ranges"); + QTest::addColumn<C::Group>("startGroup"); + QTest::addColumn<int>("startIndex"); + QTest::addColumn<C::Group>("group"); + QTest::addColumn<int>("index"); + QTest::addColumn<int>("selectionIndex"); + QTest::addColumn<int>("visibleIndex"); + QTest::addColumn<int>("defaultIndex"); + QTest::addColumn<int>("cacheIndex"); + QTest::addColumn<int>("rangeFlags"); + QTest::addColumn<int>("rangeIndex"); + + int listA; void *a = &listA; + + QTest::newRow("Start") + << (RangeList() + << Range(a, 0, 1, int(C::PrependFlag | SelectionFlag | C::DefaultFlag | C::CacheFlag)) + << Range(a, 1, 1, int(C::AppendFlag | C::PrependFlag | C::CacheFlag)) + << Range(0, 0, 1, int(VisibleFlag| C::CacheFlag))) + << C::Cache << 2 + << Selection << 0 + << 0 << 0 << 0 << 0 + << int(C::PrependFlag | SelectionFlag | C::DefaultFlag | C::CacheFlag) << 0; +} + +void tst_qdeclarativelistcompositor::find() +{ + QFETCH(RangeList, ranges); + QFETCH(C::Group, startGroup); + QFETCH(int, startIndex); + QFETCH(C::Group, group); + QFETCH(int, index); + QFETCH(int, cacheIndex); + QFETCH(int, defaultIndex); + QFETCH(int, visibleIndex); + QFETCH(int, selectionIndex); + QFETCH(int, rangeFlags); + QFETCH(int, rangeIndex); + + QDeclarativeListCompositor compositor; + compositor.setGroupCount(4); + compositor.setDefaultGroups(VisibleFlag | C::DefaultFlag); + + foreach (const Range &range, ranges) + compositor.append(range.list, range.index, range.count, range.flags); + + compositor.find(startGroup, startIndex); + + QDeclarativeListCompositor::iterator it = compositor.find(group, index); + QCOMPARE(it.index[C::Cache], cacheIndex); + QCOMPARE(it.index[C::Default], defaultIndex); + QCOMPARE(it.index[Visible], visibleIndex); + QCOMPARE(it.index[Selection], selectionIndex); + QCOMPARE(it->flags, rangeFlags); + QCOMPARE(it->index, rangeIndex); +} + +void tst_qdeclarativelistcompositor::findInsertPosition_data() +{ + QTest::addColumn<RangeList>("ranges"); + QTest::addColumn<C::Group>("startGroup"); + QTest::addColumn<int>("startIndex"); + QTest::addColumn<C::Group>("group"); + QTest::addColumn<int>("index"); + QTest::addColumn<int>("selectionIndex"); + QTest::addColumn<int>("visibleIndex"); + QTest::addColumn<int>("defaultIndex"); + QTest::addColumn<int>("cacheIndex"); + QTest::addColumn<int>("rangeFlags"); + QTest::addColumn<int>("rangeIndex"); + + int listA; void *a = &listA; + + QTest::newRow("Start") + << (RangeList() + << Range(a, 0, 1, int(C::PrependFlag | SelectionFlag | C::DefaultFlag | C::CacheFlag)) + << Range(a, 1, 1, int(C::AppendFlag | C::PrependFlag | C::CacheFlag)) + << Range(0, 0, 1, int(VisibleFlag| C::CacheFlag))) + << C::Cache << 2 + << Selection << 0 + << 0 << 0 << 0 << 0 + << int(C::PrependFlag | SelectionFlag | C::DefaultFlag | C::CacheFlag) << 0; + QTest::newRow("1") + << (RangeList() + << Range(a, 0, 1, int(C::PrependFlag | SelectionFlag | C::DefaultFlag | C::CacheFlag)) + << Range(a, 1, 1, int(C::AppendFlag | C::PrependFlag | C::CacheFlag)) + << Range(0, 0, 1, int(VisibleFlag| C::CacheFlag))) + << C::Cache << 2 + << Selection << 1 + << 1 << 0 << 1 << 1 + << int(C::AppendFlag | C::PrependFlag | C::CacheFlag) << 1; +} + +void tst_qdeclarativelistcompositor::findInsertPosition() +{ + QFETCH(RangeList, ranges); + QFETCH(C::Group, startGroup); + QFETCH(int, startIndex); + QFETCH(C::Group, group); + QFETCH(int, index); + QFETCH(int, cacheIndex); + QFETCH(int, defaultIndex); + QFETCH(int, visibleIndex); + QFETCH(int, selectionIndex); + QFETCH(int, rangeFlags); + QFETCH(int, rangeIndex); + + QDeclarativeListCompositor compositor; + compositor.setGroupCount(4); + compositor.setDefaultGroups(VisibleFlag | C::DefaultFlag); + + foreach (const Range &range, ranges) + compositor.append(range.list, range.index, range.count, range.flags); + + QDeclarativeListCompositor::insert_iterator it = compositor.findInsertPosition(group, index); + QCOMPARE(it.index[C::Cache], cacheIndex); + QCOMPARE(it.index[C::Default], defaultIndex); + QCOMPARE(it.index[Visible], visibleIndex); + QCOMPARE(it.index[Selection], selectionIndex); + QCOMPARE(it->flags, rangeFlags); + QCOMPARE(it->index, rangeIndex); +} + void tst_qdeclarativelistcompositor::insert() { QDeclarativeListCompositor compositor; @@ -1067,6 +1196,30 @@ void tst_qdeclarativelistcompositor::listItemsRemoved_data() << IndexArray(defaultIndexes) << IndexArray() << IndexArray(); + } { static const int cacheIndexes[] = {/*A*/-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1}; + static const int defaultIndexes[] = {/*A*/0,1,2,3,4,5,6}; + QTest::newRow("Sparse remove") + << (RangeList() + << Range(a, 0, 2, C::CacheFlag) + << Range(a, 0, 1, C::DefaultFlag | C::CacheFlag) + << Range(a, 0, 1, C::CacheFlag) + << Range(a, 1, 5, C::DefaultFlag | C::CacheFlag) + << Range(a, 0, 1, C::CacheFlag) + << Range(a, 6, 2, C::DefaultFlag | C::CacheFlag) + << Range(a, 0, 1, C::CacheFlag) + << Range(a, 8, 3, C::DefaultFlag | C::CacheFlag) + << Range(a, 0, 1, C::CacheFlag) + << Range(a, 11, 1, C::DefaultFlag | C::CacheFlag) + << Range(a, 12, 5, C::DefaultFlag)) + << a << 1 << 10 + << (RemoveList() + << Remove(0, 0, 1, 4, 5, C::DefaultFlag | C::CacheFlag) + << Remove(0, 0, 1,10, 2, C::DefaultFlag | C::CacheFlag) + << Remove(0, 0, 1,13, 3, C::DefaultFlag | C::CacheFlag)) + << IndexArray(cacheIndexes) + << IndexArray(defaultIndexes) + << IndexArray() + << IndexArray(); } } |