2
* Copyright 2012 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
import Ubuntu.Components 0.1
22
name: "ModelSectionCounterAPI"
24
function initTestCase() {
25
var component = Qt.createComponent(Qt.resolvedUrl("../../../modules/Ubuntu/Components/ModelSectionCounter.qml"));
26
counter = component.createObject(parent);
29
function test_0_defaults() {
30
compare(counter.view, null, "ModelSectionCounter does not have valid view set");
31
compare(counter.count, 0, "ModelSectionCounter default sectionCount is 0");
32
compare(counter.cacheSections, false, "ModelSectionCounter does not cache sections");
33
compare(counter.cache, [], "ModelSectionCounter has empty section cache list");
36
function test_1_count_data() {
38
{tag: "Empty model", model: emptyModel, sectionProperty: "label", expect: 0, expectFail: false},
39
{tag: "ListModel", model: objectModel, sectionProperty: "label", expect: 8, expectFail: false},
40
{tag: "StringList model", model: stringModel, sectionProperty: "modelData", expect: 8, expectFail: false},
41
{tag: "VariantList model", model: variantModel, sectionProperty: "label", expect: 8, expectFail: false},
45
function test_1_count(data) {
47
expectFail("", data.tag);
48
list.model = data.model;
49
list.section.property = data.sectionProperty;
50
list.section.criteria = ViewSection.FirstCharacter;
52
compare(counter.count, data.expect, "Section count is wrong");
55
function test_2_cache() {
56
list.model = objectModel;
57
list.section.property = "label";
58
list.section.criteria = ViewSection.FirstCharacter;
60
counter.cacheSections = true;
61
var cache = ["1", "2", "3", "4", "5", "6", "7", "8"];
62
compare(counter.cache, cache, "Section cache is wrong");
64
counter.cacheSections = false;
66
compare(counter.cache, cache, "Section cache is wrong");
73
delegate: Item{ height: 40 }
74
section.delegate: Item{ height: 10 }
80
property var emptyModel: ListModel {}
82
property var objectModel: ListModel {
83
ListElement {label: "1"}
84
ListElement {label: "10"}
85
ListElement {label: "100"}
86
ListElement {label: "2"}
87
ListElement {label: "3"}
88
ListElement {label: "4"}
89
ListElement {label: "5"}
90
ListElement {label: "6"}
91
ListElement {label: "7"}
92
ListElement {label: "8"}
95
property var variantModel: [
108
property var stringModel: ["1", "10", "100", "2", "3", "4", "5", "6", "7", "8"]