test: Add a test case for sorting on a model with no initial roles

This cause a crash when adding 2 rows to an empty ListModel
This commit is contained in:
Grecko 2018-03-22 19:16:00 +01:00
parent 6211989a48
commit 6ff055d47d
1 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,10 @@ Item {
ListElement { test: "fourth"; test2: "b" }
}
ListModel {
id: noRolesFirstListModel
}
property list<QtObject> sorters: [
QtObject {
property string tag: "no sorter"
@ -75,6 +79,12 @@ Item {
sourceModel: listModel
}
SortFilterProxyModel {
id: noRolesFirstProxyModel
sourceModel: noRolesFirstListModel
sorters: RoleSorter { roleName: "test" }
}
TestCase {
name: "SortersTests"
@ -113,6 +123,12 @@ Item {
verifyModelValues(testModel, expectedValues);
}
function test_noRolesFirstModel() {
noRolesFirstListModel.append([{test: "b"}, {test: "a"}]);
var expectedValues = ["a", "b"];
verifyModelValues(noRolesFirstProxyModel, expectedValues);
}
function verifyModelValues(model, expectedValues) {
verify(model.count === expectedValues.length,
"Expected count " + expectedValues.length + ", actual count: " + model.count);