Debian Codegraph @

tests/auto/qml-qtquicktest/data/tst_barseries_1_2.qml

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.0
5 import QtTest 1.0
6 import QtCharts 1.2
7
8 Rectangle {
9 width: 400
10 height: 300
11
12 TestCase {
13 id: tc1
14 name: "tst_qml-qtquicktest BarSeries 1.2"
15 when: windowShown
16
17 function test_properties() {
18 compare(barSeries.barWidth, 0.5);
19 compare(barSeries.labelsVisible, false);
20 }
21
22 function test_axes() {
23 verify(chartView.axisX() == barSeries.axisX);
24 verify(chartView.axisY() == barSeries.axisY);
25
26 compare(barSeries.axisX, stackedBarSeries.axisX);
27 compare(barSeries.axisY, stackedBarSeries.axisY);
28
29 compare(barSeries.axisX, percentBarSeries.axisX);
30 compare(barSeries.axisY, percentBarSeries.axisY);
31 }
32
33 function test_append() {
34 var setCount = 5;
35 var valueCount = 50;
36 addedSpy.clear();
37 append(setCount, valueCount);
38
39 compare(barSeries.count, setCount);
40 for (var k = 0; k < setCount; k++) {
41 compare(barSeries.at(k).count, valueCount);
42 compare(barSeries.at(k).label, "barset" + k);
43 }
44 compare(addedSpy.count, setCount);
45
46 barSeries.clear();
47 compare(barSeries.count, 0);
48 }
49
50 function test_insert() {
51 var setCount = 5;
52 var valueCount = 50;
53 addedSpy.clear();
54 append(setCount, valueCount);
55
56 for (var i = 0; i < setCount; i++) {
57 var values = [];
58 for (var j = 0; j < valueCount; j++)
59 values[j] = Math.random() * 10;
60 var set = barSeries.insert(i, "barset" + i, values);
61 compare(set.label, "barset" + i);
62 }
63
64 compare(barSeries.count, setCount * 2);
65 for (var k = 0; k < setCount * 2; k++)
66 compare(barSeries.at(k).count, valueCount);
67 compare(addedSpy.count, 2 * setCount);
68
69 barSeries.clear();
70 compare(barSeries.count, 0);
71 }
72
73 function test_remove() {
74 var setCount = 5;
75 var valueCount = 50;
76 removedSpy.clear();
77 append(setCount, valueCount);
78
79 for (var k = 0; k < setCount; k++)
80 barSeries.remove(barSeries.at(0));
81
82 compare(barSeries.count, 0);
83 compare(removedSpy.count, setCount);
84 }
85
86 // Not a test function, used by one or more test functions
87 function append(setCount, valueCount) {
88 for (var i = 0; i < setCount; i++) {
89 var values = [];
90 for (var j = 0; j < valueCount; j++)
91 values[j] = Math.random() * 10;
92 barSeries.append("barset" + i, values);
93 }
94 }
95 }
96
97 ChartView {
98 id: chartView
99 anchors.fill: parent
100
101 BarSeries {
102 id: barSeries
103 name: "bar"
104 axisX: BarCategoryAxis {}
105 axisY: ValueAxis { min: 0; max: 10 }
106
107 SignalSpy {
108 id: addedSpy
109 target: barSeries
110 signalName: "barsetsAdded"
111 }
112 SignalSpy {
113 id: removedSpy
114 target: barSeries
115 signalName: "barsetsRemoved"
116 }
117 }
118
119 StackedBarSeries {
120 id: stackedBarSeries
121 name: "stackedBar"
122 }
123
124 PercentBarSeries {
125 id: percentBarSeries
126 name: "percentBar"
127 }
128 }
129 }