##// END OF EJS Templates
Improved QML API test coverage
Tero Ahola -
r2243:9cb45eae013f
parent child
Show More
@@ -0,0 +1,125
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.2
24
25 Rectangle {
26 width: 400
27 height: 300
28
29 TestCase {
30 id: tc1
31 name: "tst_qml-qtquicktest BarSeries"
32 when: windowShown
33
34 function test_properties() {
35 compare(barSeries.barWidth, 0.5);
36 compare(barSeries.labelsVisible, false);
37 }
38
39 function test_append() {
40 var setCount = 5;
41 var valueCount = 50;
42 addedSpy.clear();
43 append(setCount, valueCount);
44
45 compare(barSeries.count, setCount);
46 for (var k = 0; k < setCount; k++) {
47 compare(barSeries.at(k).count, valueCount);
48 compare(barSeries.at(k).label, "barset" + k);
49 }
50 compare(addedSpy.count, setCount);
51
52 barSeries.clear();
53 compare(barSeries.count, 0);
54 }
55
56 function test_insert() {
57 var setCount = 5;
58 var valueCount = 50;
59 addedSpy.clear();
60 append(setCount, valueCount);
61
62 for (var i = 0; i < setCount; i++) {
63 var values = [];
64 for (var j = 0; j < valueCount; j++)
65 values[j] = Math.random() * 10;
66 var set = barSeries.insert(i, "barset" + i, values);
67 compare(set.label, "barset" + i);
68 }
69
70 compare(barSeries.count, setCount * 2);
71 for (var k = 0; k < setCount * 2; k++)
72 compare(barSeries.at(k).count, valueCount);
73 compare(addedSpy.count, 2 * setCount);
74
75 barSeries.clear();
76 compare(barSeries.count, 0);
77 }
78
79 function test_remove() {
80 var setCount = 5;
81 var valueCount = 50;
82 removedSpy.clear();
83 append(setCount, valueCount);
84
85 for (var k = 0; k < setCount; k++)
86 barSeries.remove(barSeries.at(0));
87
88 compare(barSeries.count, 0);
89 compare(removedSpy.count, setCount);
90 }
91
92 // Not a test function, used by one or more test functions
93 function append(setCount, valueCount) {
94 for (var i = 0; i < setCount; i++) {
95 var values = [];
96 for (var j = 0; j < valueCount; j++)
97 values[j] = Math.random() * 10;
98 barSeries.append("barset" + i, values);
99 }
100 }
101 }
102
103 ChartView {
104 id: chartView
105 anchors.fill: parent
106
107 BarSeries {
108 axisX: BarCategoriesAxis {}
109 axisY: ValuesAxis { min: 0; max: 10 }
110 id: barSeries
111 name: "bar"
112
113 SignalSpy {
114 id: addedSpy
115 target: barSeries
116 signalName: "barsetsAdded"
117 }
118 SignalSpy {
119 id: removedSpy
120 target: barSeries
121 signalName: "barsetsRemoved"
122 }
123 }
124 }
125 }
@@ -0,0 +1,125
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
24
25 Rectangle {
26 width: 400
27 height: 300
28
29 TestCase {
30 id: tc1
31 name: "tst_qml-qtquicktest BarSeries 1.1"
32 when: windowShown
33
34 function test_properties() {
35 compare(barSeries.barWidth, 0.5);
36 compare(barSeries.labelsVisible, false);
37 }
38
39 function test_append() {
40 var setCount = 5;
41 var valueCount = 50;
42 addedSpy.clear();
43 append(setCount, valueCount);
44
45 compare(barSeries.count, setCount);
46 for (var k = 0; k < setCount; k++) {
47 compare(barSeries.at(k).count, valueCount);
48 compare(barSeries.at(k).label, "barset" + k);
49 }
50 compare(addedSpy.count, setCount);
51
52 barSeries.clear();
53 compare(barSeries.count, 0);
54 }
55
56 function test_insert() {
57 var setCount = 5;
58 var valueCount = 50;
59 addedSpy.clear();
60 append(setCount, valueCount);
61
62 for (var i = 0; i < setCount; i++) {
63 var values = [];
64 for (var j = 0; j < valueCount; j++)
65 values[j] = Math.random() * 10;
66 var set = barSeries.insert(i, "barset" + i, values);
67 compare(set.label, "barset" + i);
68 }
69
70 compare(barSeries.count, setCount * 2);
71 for (var k = 0; k < setCount * 2; k++)
72 compare(barSeries.at(k).count, valueCount);
73 compare(addedSpy.count, 2 * setCount);
74
75 barSeries.clear();
76 compare(barSeries.count, 0);
77 }
78
79 function test_remove() {
80 var setCount = 5;
81 var valueCount = 50;
82 removedSpy.clear();
83 append(setCount, valueCount);
84
85 for (var k = 0; k < setCount; k++)
86 barSeries.remove(barSeries.at(0));
87
88 compare(barSeries.count, 0);
89 compare(removedSpy.count, setCount);
90 }
91
92 // Not a test function, used by one or more test functions
93 function append(setCount, valueCount) {
94 for (var i = 0; i < setCount; i++) {
95 var values = [];
96 for (var j = 0; j < valueCount; j++)
97 values[j] = Math.random() * 10;
98 barSeries.append("barset" + i, values);
99 }
100 }
101 }
102
103 ChartView {
104 id: chartView
105 anchors.fill: parent
106
107 BarSeries {
108 axisX: BarCategoriesAxis {}
109 axisY: ValuesAxis { min: 0; max: 10 }
110 id: barSeries
111 name: "bar"
112
113 SignalSpy {
114 id: addedSpy
115 target: barSeries
116 signalName: "barsetsAdded"
117 }
118 SignalSpy {
119 id: removedSpy
120 target: barSeries
121 signalName: "barsetsRemoved"
122 }
123 }
124 }
125 }
@@ -0,0 +1,79
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
24
25 Rectangle {
26 width: 400
27 height: 300
28
29 TestCase {
30 id: tc1
31 name: "tst_qml-qtquicktest ChartView Properties 1.1"
32 when: windowShown
33
34 function test_chartViewProperties() {
35 compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions");
36 verify(chartView.backgroundColor != undefined);
37 verify(chartView.bottomMargin > 0, "ChartView.bottomMargin");
38 verify(chartView.topMargin > 0, "ChartView.topMargin");
39 verify(chartView.leftMargin > 0, "ChartView.leftMargin");
40 verify(chartView.rightMargin > 0, "ChartView.rightMargin");
41 compare(chartView.count, 0, "ChartView.count");
42 compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled");
43 verify(chartView.plotArea.height > 0, "ChartView.plotArea.height");
44 verify(chartView.plotArea.width > 0, "ChartView.plotArea.width");
45 verify(chartView.plotArea.x > 0, "ChartView.plotArea.x");
46 verify(chartView.plotArea.y > 0, "ChartView.plotArea.y");
47 compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme");
48 compare(chartView.title, "", "ChartView.title");
49 compare(chartView.title, "", "ChartView.title");
50 verify(chartView.titleColor != undefined, "ChartView.titleColor");
51 compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold");
52 // Legend
53 compare(chartView.legend.visible, true, "ChartView.legend.visible");
54 compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment");
55 compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible");
56 verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor");
57 verify(chartView.legend.color != undefined, "ChartView.legend.color");
58 // Legend font
59 compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold");
60 compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization");
61 compare(chartView.legend.font.family, "arial", "ChartView.legend.font.family");
62 compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic");
63 compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing");
64 verify(chartView.legend.font.pixelSize > 0
65 && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize");
66 verify(chartView.legend.font.pointSize > 0
67 && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize");
68 compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout");
69 compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline");
70 compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight");
71 compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing");
72 }
73 }
74
75 ChartView {
76 id: chartView
77 anchors.fill: parent
78 }
79 }
@@ -0,0 +1,158
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
24
25 Rectangle {
26 width: 400
27 height: 300
28
29 TestCase {
30 id: tc1
31 name: "tst_qml-qtquicktest ChartView Functions 1.1"
32 when: windowShown
33
34 function test_chartViewSeriesAndAxes() {
35 // Create XY series
36 var line = chartView.createSeries(ChartView.SeriesTypeLine, "line");
37 verify(line != null && line != undefined);
38 var spline = chartView.createSeries(ChartView.SeriesTypeSpline, "spline");
39 verify(spline != null && spline != undefined);
40 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter");
41 verify(scatter != null && scatter != undefined);
42
43 // Create a series with specific axes
44 var line2 = chartView.createSeries(ChartView.SeriesTypeLine, "line2", chartView.axisX(line), chartView.axisY(line));
45
46 // Check that all the XY series use the same axes
47 verify(chartView.axisX(line) != null);
48 verify(chartView.axisY(line) != null);
49 compare(chartView.axisX(line), chartView.axisX(line2));
50 compare(chartView.axisY(line), chartView.axisY(line2));
51 compare(chartView.axisX(line), chartView.axisX(spline));
52 compare(chartView.axisY(line), chartView.axisY(spline));
53 compare(chartView.axisX(line), chartView.axisX(scatter));
54 compare(chartView.axisY(line), chartView.axisY(scatter));
55
56 var bar = chartView.createSeries(ChartView.SeriesTypeBar, "bar");
57 verify(bar != null && bar != undefined);
58 var stackedbar = chartView.createSeries(ChartView.SeriesTypeStackedBar, "stackedbar");
59 verify(stackedbar != null && stackedbar != undefined);
60 var percentbar = chartView.createSeries(ChartView.SeriesTypePercentBar, "percentbar");
61 verify(percentbar != null && percentbar != undefined);
62 var horizontalbar = chartView.createSeries(ChartView.SeriesTypeHorizontalBar, "horizontalbar");
63 verify(horizontalbar != null && horizontalbar != undefined);
64 var horizontalstackedbar = chartView.createSeries(ChartView.SeriesTypeHorizontalStackedBar, "horizontalstackedbar");
65 verify(horizontalstackedbar != null && horizontalstackedbar != undefined);
66 var horizontalpercentbar = chartView.createSeries(ChartView.SeriesTypeHorizontalPercentBar, "horizontalpercentbar");
67 verify(horizontalpercentbar != null && horizontalpercentbar != undefined);
68 var area = chartView.createSeries(ChartView.SeriesTypeArea, "area");
69 verify(area != null && area != undefined);
70
71 // Remove all series
72 chartView.removeAllSeries();
73 compare(chartView.count, 0);
74 }
75
76 function test_chartViewRange() {
77 // Set initial values
78 chartView.createSeries(ChartView.SeriesTypeLine, "line");
79 verify(chartView.axisX() != null);
80 verify(chartView.axisY() != null);
81 chartView.axisX().min = 1.0;
82 chartView.axisX().max = 2.0;
83 chartView.axisY().min = 1.0;
84 chartView.axisY().max = 2.0;
85
86 var xMax = chartView.axisX().max;
87 var xMin = chartView.axisX().min;
88 var yMax = chartView.axisY().max;
89 var yMin = chartView.axisY().min;
90
91 // zoom x 2.5
92 chartView.zoom(1.5);
93 verify(chartView.axisX().max < xMax);
94 verify(chartView.axisX().min > xMin);
95 verify(chartView.axisY().max < yMax);
96 verify(chartView.axisY().min > yMin);
97 xMax = chartView.axisX().max;
98 xMin = chartView.axisX().min;
99 yMax = chartView.axisY().max;
100 yMin = chartView.axisY().min;
101
102 // zoom x 0.5
103 chartView.zoom(0.5);
104 verify(chartView.axisX().max > xMax);
105 verify(chartView.axisX().min < xMin);
106 verify(chartView.axisY().max > yMax);
107 verify(chartView.axisY().min < yMin);
108 xMax = chartView.axisX().max;
109 xMin = chartView.axisX().min;
110 yMax = chartView.axisY().max;
111 yMin = chartView.axisY().min;
112
113 // Scroll up
114 chartView.scrollUp(10);
115 compare(chartView.axisX().max, xMax);
116 compare(chartView.axisX().min, xMin);
117 verify(chartView.axisY().max > yMax);
118 verify(chartView.axisY().min > yMin);
119 xMax = chartView.axisX().max;
120 xMin = chartView.axisX().min;
121 yMax = chartView.axisY().max;
122 yMin = chartView.axisY().min;
123
124 // Scroll down
125 chartView.scrollDown(10);
126 compare(chartView.axisX().max, xMax);
127 compare(chartView.axisX().min, xMin);
128 verify(chartView.axisY().max < yMax);
129 verify(chartView.axisY().min < yMin);
130 xMax = chartView.axisX().max;
131 xMin = chartView.axisX().min;
132 yMax = chartView.axisY().max;
133 yMin = chartView.axisY().min;
134
135 chartView.scrollLeft(10);
136 verify(chartView.axisX().max < xMax);
137 verify(chartView.axisX().min < xMin);
138 compare(chartView.axisY().max, yMax);
139 compare(chartView.axisY().min, yMin);
140 xMax = chartView.axisX().max;
141 xMin = chartView.axisX().min;
142 yMax = chartView.axisY().max;
143 yMin = chartView.axisY().min;
144
145 chartView.scrollRight(10);
146 verify(chartView.axisX().max > xMax);
147 verify(chartView.axisX().min > xMin);
148 compare(chartView.axisY().max, yMax);
149 compare(chartView.axisY().min, yMin);
150 }
151 }
152
153 ChartView {
154 id: chartView
155 anchors.fill: parent
156 title: "Chart"
157 }
158 }
@@ -0,0 +1,73
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
24
25 Rectangle {
26 width: 400
27 height: 300
28
29 TestCase {
30 id: tc1
31 name: "tst_qml-qtquicktest ChartView Signals 1.1"
32 when: windowShown
33
34 // Verify onSeriesAdded and onSeriesRemoved signals
35 function test_chartView() {
36 var series = chartView.createSeries(ChartView.SeriesTypeLine, "line");
37 seriesAddedSpy.wait();
38 compare(seriesAddedSpy.count, 1, "ChartView.onSeriesAdded");
39
40 // Modifying layout triggers more than one plotAreaChanged signal
41 chartView.titleFont.pixelSize = 50;
42 verify(plotAreaChangedSpy.count > 0, "ChartView.onPlotAreaChanged");
43
44 chartView.removeSeries(series);
45 seriesRemovedSpy.wait();
46 compare(seriesRemovedSpy.count, 1, "ChartView.onSeriesAdded");
47 }
48 }
49
50 ChartView {
51 id: chartView
52 anchors.fill: parent
53 title: "Chart"
54
55 SignalSpy {
56 id: plotAreaChangedSpy
57 target: chartView
58 signalName: "plotAreaChanged"
59 }
60
61 SignalSpy {
62 id: seriesAddedSpy
63 target: chartView
64 signalName: "seriesAdded"
65 }
66
67 SignalSpy {
68 id: seriesRemovedSpy
69 target: chartView
70 signalName: "seriesRemoved"
71 }
72 }
73 }
@@ -0,0 +1,131
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
24
25 Rectangle {
26 width: 400
27 height: 300
28
29 TestCase {
30 id: tc1
31 name: "tst_qml-qtquicktest PieSeries 1.1"
32 when: windowShown
33
34 function test_properties() {
35 compare(pieSeries.endAngle, 360);
36 compare(pieSeries.holeSize, 0);
37 compare(pieSeries.horizontalPosition, 0.5);
38 compare(pieSeries.size, 0.7);
39 compare(pieSeries.startAngle, 0);
40 compare(pieSeries.sum, 0);
41 compare(pieSeries.verticalPosition, 0.5);
42 }
43
44 function test_sliceproperties() {
45 var slice = pieSeries.append("slice", 10);
46 compare(slice.angleSpan, 360.0);
47 verify(slice.borderColor != undefined);
48 compare(slice.borderWidth, 0);
49 verify(slice.color != undefined);
50 compare(slice.explodeDistanceFactor, 0.15);
51 compare(slice.exploded, false);
52 compare(slice.label, "slice");
53 compare(slice.labelArmLengthFactor, 0.15);
54 verify(slice.labelColor != undefined);
55 compare(slice.labelFont.bold, false);
56 compare(slice.labelPosition, PieSlice.LabelOutside);
57 compare(slice.labelVisible, false);
58 compare(slice.percentage, 1.0);
59 compare(slice.startAngle, 0.0);
60 compare(slice.value, 10.0);
61 }
62
63 function test_append() {
64 addedSpy.clear();
65 countChangedSpy.clear();
66 sumChangedSpy.clear();
67 var count = 50;
68 for (var i = 0; i < count; i++)
69 pieSeries.append("slice" + i, Math.random());
70 compare(addedSpy.count, count);
71 compare(countChangedSpy.count, count);
72 compare(sumChangedSpy.count, count);
73 pieSeries.clear();
74 }
75
76 function test_remove() {
77 removedSpy.clear();
78 countChangedSpy.clear();
79 sumChangedSpy.clear();
80 var count = 50;
81 for (var i = 0; i < count; i++)
82 pieSeries.append("slice" + i, Math.random());
83 for (var j = 0; j < count; j++)
84 pieSeries.remove(pieSeries.at(0));
85 compare(removedSpy.count, count);
86 compare(countChangedSpy.count, 2 * count);
87 compare(sumChangedSpy.count, 2 * count);
88 compare(pieSeries.count, 0);
89 }
90
91 function test_find() {
92 var count = 50;
93 for (var i = 0; i < count; i++)
94 pieSeries.append("slice" + i, Math.random());
95 for (var j = 0; j < count; j++)
96 compare(pieSeries.find("slice" + j).label, "slice" + j);
97 pieSeries.clear();
98 }
99 }
100
101 ChartView {
102 id: chartView
103 anchors.fill: parent
104
105 PieSeries {
106 id: pieSeries
107 name: "pie"
108
109 SignalSpy {
110 id: addedSpy
111 target: pieSeries
112 signalName: "added"
113 }
114 SignalSpy {
115 id: removedSpy
116 target: pieSeries
117 signalName: "removed"
118 }
119 SignalSpy {
120 id: sumChangedSpy
121 target: pieSeries
122 signalName: "sumChanged"
123 }
124 SignalSpy {
125 id: countChangedSpy
126 target: pieSeries
127 signalName: "countChanged"
128 }
129 }
130 }
131 }
@@ -0,0 +1,250
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
24
25 Rectangle {
26 width: 400
27 height: 300
28
29 TestCase {
30 id: tc1
31 name: "tst_qml-qtquicktest XY Series 1.1"
32 when: windowShown
33
34 function test_properties() {
35 verify(lineSeries.color != undefined);
36 compare(lineSeries.pointsVisible, false);
37 compare(lineSeries.capStyle, Qt.SquareCap);
38 compare(lineSeries.style, Qt.SolidLine);
39 compare(lineSeries.width, 2.0);
40
41 verify(splineSeries.color != undefined);
42 compare(splineSeries.pointsVisible, false);
43 compare(splineSeries.capStyle, Qt.SquareCap);
44 compare(splineSeries.style, Qt.SolidLine);
45 compare(splineSeries.width, 2.0);
46
47 verify(scatterSeries.color != undefined);
48 verify(scatterSeries.borderColor != undefined);
49 compare(scatterSeries.borderWidth, 2.0);
50 compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle);
51 compare(scatterSeries.markerSize, 15.0);
52
53 verify(areaSeries.color != undefined);
54 verify(areaSeries.borderColor != undefined);
55 compare(areaSeries.borderWidth, 2.0);
56 }
57
58 function test_append() {
59 lineSeriesPointAddedSpy.clear();
60 splineSeriesPointAddedSpy.clear();
61 scatterSeriesPointAddedSpy.clear();
62 var count = append();
63 compare(lineSeries.count, count);
64 compare(splineSeries.count, count);
65 compare(scatterSeries.count, count);
66 tryCompare(lineSeriesPointAddedSpy.count, count);
67 tryCompare(splineSeriesPointAddedSpy.count, count);
68 tryCompare(scatterSeriesPointAddedSpy.count, count);
69 clear();
70 compare(lineSeries.count, 0);
71 compare(splineSeries.count, 0);
72 compare(scatterSeries.count, 0);
73 }
74
75 function test_replace() {
76 var count = append();
77 for (var i = 0; i < count; i++) {
78 lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random());
79 splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random());
80 scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random());
81 }
82 compare(lineSeries.count, count);
83 compare(splineSeries.count, count);
84 compare(scatterSeries.count, count);
85 tryCompare(lineSeriesPointReplacedSpy.count, count);
86 tryCompare(splineSeriesPointReplacedSpy.count, count);
87 tryCompare(scatterSeriesPointReplacedSpy.count, count);
88 clear();
89 }
90
91 function test_insert() {
92 var count = append();
93 lineSeriesPointAddedSpy.clear();
94 splineSeriesPointAddedSpy.clear();
95 scatterSeriesPointAddedSpy.clear();
96 for (var i = 0; i < count; i++) {
97 lineSeries.insert(i * 2, i, Math.random());
98 splineSeries.insert(i * 2, i, Math.random());
99 scatterSeries.insert(i * 2, i, Math.random());
100 }
101 compare(lineSeries.count, count * 2);
102 compare(splineSeries.count, count * 2);
103 compare(scatterSeries.count, count * 2);
104 tryCompare(lineSeriesPointAddedSpy.count, count);
105 tryCompare(splineSeriesPointAddedSpy.count, count);
106 tryCompare(scatterSeriesPointAddedSpy.count, count);
107 clear();
108 }
109
110 function test_remove() {
111 lineSeriesPointRemovedSpy.clear();
112 splineSeriesPointRemovedSpy.clear();
113 scatterSeriesPointRemovedSpy.clear();
114 var count = append();
115 for (var i = 0; i < count; i++) {
116 lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y);
117 splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y);
118 scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y);
119 }
120 compare(lineSeries.count, 0);
121 compare(splineSeries.count, 0);
122 compare(scatterSeries.count, 0);
123 tryCompare(lineSeriesPointRemovedSpy.count, count);
124 tryCompare(splineSeriesPointRemovedSpy.count, count);
125 tryCompare(scatterSeriesPointRemovedSpy.count, count);
126 }
127
128 // Not a test function, called from test functions
129 function append() {
130 var count = 100;
131 chartView.axisX().min = 0;
132 chartView.axisX().max = 100;
133 chartView.axisY().min = 0;
134 chartView.axisY().max = 1;
135
136 for (var i = 0; i < count; i++) {
137 lineSeries.append(i, Math.random());
138 splineSeries.append(i, Math.random());
139 scatterSeries.append(i, Math.random());
140 }
141
142 return count;
143 }
144
145 // Not a test function, called from test functions
146 function clear() {
147 lineSeries.clear();
148 splineSeries.clear();
149 scatterSeries.clear();
150 }
151 }
152
153 ChartView {
154 id: chartView
155 anchors.fill: parent
156
157 LineSeries {
158 id: lineSeries
159 name: "line"
160
161 SignalSpy {
162 id: lineSeriesPointAddedSpy
163 target: lineSeries
164 signalName: "pointAdded"
165 }
166
167 SignalSpy {
168 id: lineSeriesPointReplacedSpy
169 target: lineSeries
170 signalName: "pointReplaced"
171 }
172
173 SignalSpy {
174 id: lineSeriesPointsReplacedSpy
175 target: lineSeries
176 signalName: "pointsReplaced"
177 }
178
179 SignalSpy {
180 id: lineSeriesPointRemovedSpy
181 target: lineSeries
182 signalName: "pointRemoved"
183 }
184 }
185
186 AreaSeries {
187 id: areaSeries
188 name: "area"
189 upperSeries: lineSeries
190 }
191
192 SplineSeries {
193 id: splineSeries
194 name: "spline"
195
196 SignalSpy {
197 id: splineSeriesPointAddedSpy
198 target: splineSeries
199 signalName: "pointAdded"
200 }
201
202 SignalSpy {
203 id: splineSeriesPointReplacedSpy
204 target: splineSeries
205 signalName: "pointReplaced"
206 }
207
208 SignalSpy {
209 id: splineSeriesPointsReplacedSpy
210 target: splineSeries
211 signalName: "pointsReplaced"
212 }
213
214 SignalSpy {
215 id: splineSeriesPointRemovedSpy
216 target: splineSeries
217 signalName: "pointRemoved"
218 }
219 }
220
221 ScatterSeries {
222 id: scatterSeries
223 name: "scatter"
224
225 SignalSpy {
226 id: scatterSeriesPointAddedSpy
227 target: scatterSeries
228 signalName: "pointAdded"
229 }
230
231 SignalSpy {
232 id: scatterSeriesPointReplacedSpy
233 target: scatterSeries
234 signalName: "pointReplaced"
235 }
236
237 SignalSpy {
238 id: scatterSeriesPointsReplacedSpy
239 target: scatterSeries
240 signalName: "pointsReplaced"
241 }
242
243 SignalSpy {
244 id: scatterSeriesPointRemovedSpy
245 target: scatterSeries
246 signalName: "pointRemoved"
247 }
248 }
249 }
250 }
@@ -20,7 +20,7
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
@@ -38,6 +38,10 Rectangle {
38 verify(chartView.topMargin > 0, "ChartView.topMargin");
38 verify(chartView.topMargin > 0, "ChartView.topMargin");
39 verify(chartView.leftMargin > 0, "ChartView.leftMargin");
39 verify(chartView.leftMargin > 0, "ChartView.leftMargin");
40 verify(chartView.rightMargin > 0, "ChartView.rightMargin");
40 verify(chartView.rightMargin > 0, "ChartView.rightMargin");
41 verify(chartView.margins.bottom > 0, "ChartView.margins.bottom");
42 verify(chartView.margins.top > 0, "ChartView.margins.top");
43 verify(chartView.margins.left > 0, "ChartView.margins.left");
44 verify(chartView.margins.right > 0, "ChartView.margins.right");
41 compare(chartView.count, 0, "ChartView.count");
45 compare(chartView.count, 0, "ChartView.count");
42 compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled");
46 compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled");
43 verify(chartView.plotArea.height > 0, "ChartView.plotArea.height");
47 verify(chartView.plotArea.height > 0, "ChartView.plotArea.height");
@@ -20,7 +20,7
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
@@ -20,7 +20,7
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
@@ -20,7 +20,7
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
@@ -20,7 +20,7
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
General Comments 0
You need to be logged in to leave comments. Login now