mirror of
https://github.com/status-im/SortFilterProxyModel.git
synced 2025-02-22 07:38:23 +00:00
Add tests infrastructure, starting with RangeFilter and IndexFilter
* Add infrastructure for testing SortFilterProxyModel * Add tests for RangeFilter. * Add tests for IndexFilter.
This commit is contained in:
parent
472b344ff6
commit
fea3718d99
12
tests/SortFilterProxyModel.pro
Normal file
12
tests/SortFilterProxyModel.pro
Normal file
@ -0,0 +1,12 @@
|
||||
TEMPLATE = app
|
||||
TARGET = tst_sortfilterproxymodel
|
||||
QT += qml quick
|
||||
CONFIG += c++11 warn_on qmltestcase qml_debug
|
||||
|
||||
include(../SortFilterProxyModel.pri)
|
||||
|
||||
SOURCES += tst_sortfilterproxymodel.cpp
|
||||
|
||||
OTHER_FILES += \
|
||||
tst_rangefilter.qml \
|
||||
tst_indexfilter.qml
|
74
tests/tst_indexfilter.qml
Normal file
74
tests/tst_indexfilter.qml
Normal file
@ -0,0 +1,74 @@
|
||||
import QtQuick 2.0
|
||||
import SortFilterProxyModel 0.2
|
||||
import QtQml.Models 2.2
|
||||
import QtTest 1.1
|
||||
|
||||
Item {
|
||||
property list<IndexFilter> filters: [
|
||||
IndexFilter {
|
||||
property string tag: "basicUsage"
|
||||
property int expectedModelCount: 3
|
||||
property var expectedValues: [3, 1, 2];
|
||||
minimumIndex: 1; maximumIndex: 3
|
||||
},
|
||||
IndexFilter {
|
||||
property string tag: "outOfBounds"
|
||||
property int expectedModelCount: 0
|
||||
minimumIndex: 3; maximumIndex: 1
|
||||
},
|
||||
IndexFilter {
|
||||
property string tag: "0to0Inverted"
|
||||
property int expectedModelCount: 4
|
||||
property var expectedValues: [3,1,2,4]
|
||||
minimumIndex: 0; maximumIndex: 0; inverted: true
|
||||
},
|
||||
IndexFilter {
|
||||
property string tag: "0to0" // bug / issue #15
|
||||
property int expectedModelCount: 1
|
||||
property var expectedValues: [5]
|
||||
minimumIndex: 0; maximumIndex: 0
|
||||
},
|
||||
IndexFilter {
|
||||
property string tag: "basicUsageInverted"
|
||||
property int expectedModelCount: 2
|
||||
property var expectedValues: [5,4]
|
||||
minimumIndex: 1; maximumIndex: 3; inverted: true
|
||||
}
|
||||
]
|
||||
|
||||
ListModel {
|
||||
id: dataModel
|
||||
ListElement { value: 5 }
|
||||
ListElement { value: 3 }
|
||||
ListElement { value: 1 }
|
||||
ListElement { value: 2 }
|
||||
ListElement { value: 4 }
|
||||
}
|
||||
|
||||
SortFilterProxyModel {
|
||||
id: testModel
|
||||
// FIXME: Crashes/fails with error if I define ListModel directly within sourceModel
|
||||
sourceModel: dataModel
|
||||
}
|
||||
|
||||
TestCase {
|
||||
name: "IndexFilterTests"
|
||||
|
||||
function test_minMax_data() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
function test_minMax(filter) {
|
||||
testModel.filters = filter;
|
||||
|
||||
verify(testModel.count === filter.expectedModelCount,
|
||||
"Expected count " + filter.expectedModelCount + ", actual count: " + testModel.count);
|
||||
for (var i = 0; i < testModel.count; i++)
|
||||
{
|
||||
var modelValue = testModel.data(testModel.index(i, 0));
|
||||
verify(modelValue === filter.expectedValues[i],
|
||||
"Expected testModel value " + modelValue + ", actual: " + filter.expectedValues[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
92
tests/tst_rangefilter.qml
Normal file
92
tests/tst_rangefilter.qml
Normal file
@ -0,0 +1,92 @@
|
||||
import QtQuick 2.0
|
||||
import SortFilterProxyModel 0.2
|
||||
import QtQml.Models 2.2
|
||||
import QtTest 1.1
|
||||
|
||||
Item {
|
||||
property list<RangeFilter> filters: [
|
||||
RangeFilter {
|
||||
property string tag: "inclusive"
|
||||
property int expectedModelCount: 3
|
||||
property var expectedValues: [3, 2, 4]
|
||||
property QtObject dataModel: dataModel0
|
||||
roleName: "value"; minimumValue: 2; maximumValue: 4
|
||||
},
|
||||
RangeFilter {
|
||||
property string tag: "explicitInclusive"
|
||||
property int expectedModelCount: 3
|
||||
property var expectedValues: [3, 2, 4]
|
||||
property QtObject dataModel: dataModel0
|
||||
roleName: "value"; minimumValue: 2; maximumValue: 4; minimumInclusive: true; maximumInclusive: true
|
||||
},
|
||||
RangeFilter {
|
||||
property string tag: "inclusiveMinExclusiveMax"
|
||||
property int expectedModelCount: 2
|
||||
property var expectedValues: [2, 3]
|
||||
property QtObject dataModel: dataModel1
|
||||
roleName: "value"; minimumValue: 2; maximumValue: 4; minimumInclusive: true; maximumInclusive: false
|
||||
},
|
||||
RangeFilter {
|
||||
property string tag: "exclusiveMinInclusiveMax"
|
||||
property int expectedModelCount: 2
|
||||
property var expectedValues: [3, 4]
|
||||
property QtObject dataModel: dataModel1
|
||||
roleName: "value"; minimumValue: 2; maximumValue: 4; minimumInclusive: false; maximumInclusive: true
|
||||
},
|
||||
RangeFilter {
|
||||
property string tag: "exclusive"
|
||||
property int expectedModelCount: 1
|
||||
property var expectedValues: [3]
|
||||
property QtObject dataModel: dataModel1
|
||||
roleName: "value"; minimumValue: 2; maximumValue: 4; minimumInclusive: false; maximumInclusive: false
|
||||
},
|
||||
RangeFilter {
|
||||
property string tag: "outOfBoundsRange"
|
||||
property int expectedModelCount: 0
|
||||
property QtObject dataModel: dataModel1
|
||||
roleName: "value"; minimumValue: 4; maximumValue: 2
|
||||
}
|
||||
]
|
||||
|
||||
ListModel {
|
||||
id: dataModel0
|
||||
ListElement { value: 5 }
|
||||
ListElement { value: 3 }
|
||||
ListElement { value: 1 }
|
||||
ListElement { value: 2 }
|
||||
ListElement { value: 4 }
|
||||
}
|
||||
|
||||
ListModel {
|
||||
id: dataModel1
|
||||
ListElement { value: 5 }
|
||||
ListElement { value: 2 }
|
||||
ListElement { value: 3 }
|
||||
ListElement { value: 1 }
|
||||
ListElement { value: 4 }
|
||||
}
|
||||
|
||||
SortFilterProxyModel { id: testModel }
|
||||
|
||||
TestCase {
|
||||
name:"RangeFilterTests"
|
||||
|
||||
function test_minMax_data() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
function test_minMax(filter) {
|
||||
testModel.sourceModel = filter.dataModel;
|
||||
testModel.filters = filter;
|
||||
|
||||
verify(testModel.count === filter.expectedModelCount,
|
||||
"Expected count " + filter.expectedModelCount + ", actual count: " + testModel.count);
|
||||
for (var i = 0; i < testModel.count; i++)
|
||||
{
|
||||
var modelValue = testModel.data(testModel.index(i, 0), "value");
|
||||
verify(modelValue === filter.expectedValues[i],
|
||||
"Expected testModel value " + modelValue + ", actual: " + filter.expectedValues[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
2
tests/tst_sortfilterproxymodel.cpp
Normal file
2
tests/tst_sortfilterproxymodel.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#include <QtQuickTest/quicktest.h>
|
||||
QUICK_TEST_MAIN(SortFilterProxyModel)
|
Loading…
x
Reference in New Issue
Block a user