@@ -0,0 +1,6 | |||
|
1 | !include( ../auto.pri ) { | |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
|
3 | } | |
|
4 | SOURCES += tst_qpieseries.cpp | |
|
5 | ||
|
6 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,220 | |||
|
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 | #include <QtTest/QtTest> | |
|
22 | #include <qpieseries.h> | |
|
23 | #include <qpieslice.h> | |
|
24 | ||
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
26 | ||
|
27 | class tst_qpieseries : public QObject | |
|
28 | { | |
|
29 | Q_OBJECT | |
|
30 | ||
|
31 | public slots: | |
|
32 | void initTestCase(); | |
|
33 | void cleanupTestCase(); | |
|
34 | void init(); | |
|
35 | void cleanup(); | |
|
36 | ||
|
37 | private slots: | |
|
38 | void construction(); | |
|
39 | void append(); | |
|
40 | void insert(); | |
|
41 | void remove(); | |
|
42 | //void calculatedValues(); | |
|
43 | //void themes(); | |
|
44 | //void clickedSignal(); | |
|
45 | //void hoverSignal(); | |
|
46 | ||
|
47 | private: | |
|
48 | ||
|
49 | ||
|
50 | private: | |
|
51 | ||
|
52 | }; | |
|
53 | ||
|
54 | void tst_qpieseries::initTestCase() | |
|
55 | { | |
|
56 | } | |
|
57 | ||
|
58 | void tst_qpieseries::cleanupTestCase() | |
|
59 | { | |
|
60 | } | |
|
61 | ||
|
62 | void tst_qpieseries::init() | |
|
63 | { | |
|
64 | ||
|
65 | } | |
|
66 | ||
|
67 | void tst_qpieseries::cleanup() | |
|
68 | { | |
|
69 | ||
|
70 | } | |
|
71 | ||
|
72 | void tst_qpieseries::construction() | |
|
73 | { | |
|
74 | // verify default values | |
|
75 | QPieSeries s; | |
|
76 | QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); | |
|
77 | QVERIFY(s.count() == 0); | |
|
78 | QVERIFY(s.isEmpty()); | |
|
79 | QVERIFY(qFuzzyIsNull(s.sum())); | |
|
80 | QVERIFY(qFuzzyCompare(s.horizontalPosition(), 0.5)); | |
|
81 | QVERIFY(qFuzzyCompare(s.verticalPosition(), 0.5)); | |
|
82 | QVERIFY(qFuzzyCompare(s.pieSize(), 0.7)); | |
|
83 | QVERIFY(qFuzzyIsNull(s.pieStartAngle())); | |
|
84 | QVERIFY(qFuzzyCompare(s.pieEndAngle(), 360)); | |
|
85 | } | |
|
86 | ||
|
87 | void tst_qpieseries::append() | |
|
88 | { | |
|
89 | QPieSeries s; | |
|
90 | ||
|
91 | // append pointer | |
|
92 | QPieSlice *slice1 = 0; | |
|
93 | QVERIFY(!s.append(slice1)); | |
|
94 | slice1 = new QPieSlice(1, "slice 1"); | |
|
95 | QVERIFY(s.append(slice1)); | |
|
96 | QVERIFY(!s.append(slice1)); | |
|
97 | QCOMPARE(s.count(), 1); | |
|
98 | ||
|
99 | // append pointer list | |
|
100 | QList<QPieSlice *> list; | |
|
101 | QVERIFY(!s.append(list)); | |
|
102 | list << (QPieSlice *) 0; | |
|
103 | QVERIFY(!s.append(list)); | |
|
104 | list.clear(); | |
|
105 | list << new QPieSlice(2, "slice 2"); | |
|
106 | list << new QPieSlice(3, "slice 3"); | |
|
107 | QVERIFY(s.append(list)); | |
|
108 | QVERIFY(!s.append(list)); | |
|
109 | QCOMPARE(s.count(), 3); | |
|
110 | ||
|
111 | // append operator | |
|
112 | s << new QPieSlice(4, "slice 4"); | |
|
113 | s << slice1; // fails because already added | |
|
114 | QCOMPARE(s.count(), 4); | |
|
115 | ||
|
116 | // append with params | |
|
117 | QPieSlice *slice5 = s.append(5, "slice 5"); | |
|
118 | QVERIFY(slice5 != 0); | |
|
119 | QVERIFY(qFuzzyCompare(slice5->value(), 5.0)); | |
|
120 | QCOMPARE(slice5->label(), QString("slice 5")); | |
|
121 | QCOMPARE(s.count(), 5); | |
|
122 | ||
|
123 | // check slices | |
|
124 | QVERIFY(!s.isEmpty()); | |
|
125 | for (int i=0; i<s.count(); i++) { | |
|
126 | QVERIFY(qFuzzyCompare(s.slices().at(i)->value(), (qreal) i+1)); | |
|
127 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
|
128 | } | |
|
129 | } | |
|
130 | ||
|
131 | void tst_qpieseries::insert() | |
|
132 | { | |
|
133 | QPieSeries s; | |
|
134 | ||
|
135 | // insert one slice | |
|
136 | QPieSlice *slice1 = 0; | |
|
137 | QVERIFY(!s.insert(0, slice1)); | |
|
138 | slice1 = new QPieSlice(1, "slice 1"); | |
|
139 | QVERIFY(!s.insert(-1, slice1)); | |
|
140 | QVERIFY(!s.insert(5, slice1)); | |
|
141 | QVERIFY(s.insert(0, slice1)); | |
|
142 | QVERIFY(!s.insert(0, slice1)); | |
|
143 | QCOMPARE(s.count(), 1); | |
|
144 | ||
|
145 | // add some more slices | |
|
146 | s.append(2, "slice 2"); | |
|
147 | s.append(4, "slice 4"); | |
|
148 | QCOMPARE(s.count(), 3); | |
|
149 | ||
|
150 | // insert between slices | |
|
151 | s.insert(2, new QPieSlice(3, "slice 3")); | |
|
152 | QCOMPARE(s.count(), 4); | |
|
153 | ||
|
154 | // check slices | |
|
155 | for (int i=0; i<s.count(); i++) { | |
|
156 | QVERIFY(qFuzzyCompare(s.slices().at(i)->value(), (qreal) i+1)); | |
|
157 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
|
158 | } | |
|
159 | } | |
|
160 | ||
|
161 | void tst_qpieseries::remove() | |
|
162 | { | |
|
163 | QPieSeries s; | |
|
164 | ||
|
165 | // add some slices | |
|
166 | QPieSlice *slice1 = s.append(1, "slice 1"); | |
|
167 | QPieSlice *slice2 = s.append(2, "slice 2"); | |
|
168 | QPieSlice *slice3 = s.append(3, "slice 3"); | |
|
169 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
|
170 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
|
171 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
|
172 | QCOMPARE(s.count(), 3); | |
|
173 | ||
|
174 | // null pointer remove | |
|
175 | QVERIFY(!s.remove(0)); | |
|
176 | ||
|
177 | // remove first | |
|
178 | QVERIFY(s.remove(slice1)); | |
|
179 | QVERIFY(!s.remove(slice1)); | |
|
180 | QCOMPARE(s.count(), 2); | |
|
181 | QCOMPARE(s.slices().at(0)->label(), slice2->label()); | |
|
182 | ||
|
183 | // remove all | |
|
184 | s.clear(); | |
|
185 | QVERIFY(s.isEmpty()); | |
|
186 | QVERIFY(s.slices().isEmpty()); | |
|
187 | QCOMPARE(s.count(), 0); | |
|
188 | ||
|
189 | // check that slices were actually destroyed | |
|
190 | QCOMPARE(spy1.count(), 1); | |
|
191 | QCOMPARE(spy2.count(), 1); | |
|
192 | QCOMPARE(spy3.count(), 1); | |
|
193 | } | |
|
194 | ||
|
195 | /* | |
|
196 | void tst_qpieseries::calculatedValues() | |
|
197 | { | |
|
198 | ||
|
199 | } | |
|
200 | ||
|
201 | void tst_qpieseries::themes() | |
|
202 | { | |
|
203 | ||
|
204 | } | |
|
205 | ||
|
206 | void tst_qpieseries::clickedSignal() | |
|
207 | { | |
|
208 | ||
|
209 | } | |
|
210 | ||
|
211 | void tst_qpieseries::hoverSignal() | |
|
212 | { | |
|
213 | ||
|
214 | } | |
|
215 | */ | |
|
216 | ||
|
217 | QTEST_MAIN(tst_qpieseries) | |
|
218 | ||
|
219 | #include "tst_qpieseries.moc" | |
|
220 |
@@ -0,0 +1,6 | |||
|
1 | !include( ../auto.pri ) { | |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
|
3 | } | |
|
4 | SOURCES += tst_qpieslice.cpp | |
|
5 | ||
|
6 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -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 | #include <QtTest/QtTest> | |
|
22 | #include <qpieslice.h> | |
|
23 | ||
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
25 | ||
|
26 | class tst_qpieslice : public QObject | |
|
27 | { | |
|
28 | Q_OBJECT | |
|
29 | ||
|
30 | public slots: | |
|
31 | void initTestCase(); | |
|
32 | void cleanupTestCase(); | |
|
33 | void init(); | |
|
34 | void cleanup(); | |
|
35 | ||
|
36 | private slots: | |
|
37 | void construction(); | |
|
38 | void changedSignals(); | |
|
39 | ||
|
40 | private: | |
|
41 | ||
|
42 | ||
|
43 | private: | |
|
44 | ||
|
45 | }; | |
|
46 | ||
|
47 | void tst_qpieslice::initTestCase() | |
|
48 | { | |
|
49 | } | |
|
50 | ||
|
51 | void tst_qpieslice::cleanupTestCase() | |
|
52 | { | |
|
53 | } | |
|
54 | ||
|
55 | void tst_qpieslice::init() | |
|
56 | { | |
|
57 | ||
|
58 | } | |
|
59 | ||
|
60 | void tst_qpieslice::cleanup() | |
|
61 | { | |
|
62 | ||
|
63 | } | |
|
64 | ||
|
65 | void tst_qpieslice::construction() | |
|
66 | { | |
|
67 | // no params | |
|
68 | QPieSlice slice1; | |
|
69 | QVERIFY(qFuzzyIsNull(slice1.value())); | |
|
70 | QVERIFY(slice1.label().isEmpty()); | |
|
71 | QVERIFY(!slice1.isLabelVisible()); | |
|
72 | QVERIFY(!slice1.isExploded()); | |
|
73 | QCOMPARE(slice1.pen(), QPen()); | |
|
74 | QCOMPARE(slice1.brush(), QBrush()); | |
|
75 | QCOMPARE(slice1.labelPen(), QPen()); | |
|
76 | QCOMPARE(slice1.labelFont(), QFont()); | |
|
77 | QVERIFY(qFuzzyCompare(slice1.labelArmLengthFactor(), 0.15)); // default value | |
|
78 | QVERIFY(qFuzzyCompare(slice1.explodeDistanceFactor(), 0.15)); // default value | |
|
79 | QVERIFY(qFuzzyIsNull(slice1.percentage())); | |
|
80 | QVERIFY(qFuzzyIsNull(slice1.startAngle())); | |
|
81 | QVERIFY(qFuzzyIsNull(slice1.endAngle())); | |
|
82 | ||
|
83 | // value and label params | |
|
84 | QPieSlice slice2(1.0, "foobar"); | |
|
85 | QVERIFY(qFuzzyCompare(slice2.value(), 1.0)); | |
|
86 | QCOMPARE(slice2.label(), QString("foobar")); | |
|
87 | QVERIFY(!slice2.isLabelVisible()); | |
|
88 | QVERIFY(!slice2.isExploded()); | |
|
89 | QCOMPARE(slice2.pen(), QPen()); | |
|
90 | QCOMPARE(slice2.brush(), QBrush()); | |
|
91 | QCOMPARE(slice2.labelPen(), QPen()); | |
|
92 | QCOMPARE(slice2.labelFont(), QFont()); | |
|
93 | QVERIFY(qFuzzyCompare(slice2.labelArmLengthFactor(), 0.15)); // default value | |
|
94 | QVERIFY(qFuzzyCompare(slice2.explodeDistanceFactor(), 0.15)); // default value | |
|
95 | QVERIFY(qFuzzyIsNull(slice2.percentage())); | |
|
96 | QVERIFY(qFuzzyIsNull(slice2.startAngle())); | |
|
97 | QVERIFY(qFuzzyIsNull(slice2.endAngle())); | |
|
98 | } | |
|
99 | ||
|
100 | void tst_qpieslice::changedSignals() | |
|
101 | { | |
|
102 | // set everything twice to see we do not get unnecessary signals | |
|
103 | QPieSlice slice; | |
|
104 | QSignalSpy spy(&slice, SIGNAL(changed())); // TODO: this will be changed to something more refined | |
|
105 | slice.setValue(1); | |
|
106 | slice.setValue(1); | |
|
107 | slice.setLabel("foobar"); | |
|
108 | slice.setLabel("foobar"); | |
|
109 | slice.setLabelVisible(); | |
|
110 | slice.setLabelVisible(); | |
|
111 | slice.setExploded(); | |
|
112 | slice.setExploded(); | |
|
113 | slice.setPen(QPen(Qt::red)); | |
|
114 | slice.setPen(QPen(Qt::red)); | |
|
115 | slice.setBrush(QBrush(Qt::red)); | |
|
116 | slice.setBrush(QBrush(Qt::red)); | |
|
117 | slice.setLabelPen(QPen(Qt::green)); | |
|
118 | slice.setLabelPen(QPen(Qt::green)); | |
|
119 | slice.setLabelFont(QFont("Tahoma")); | |
|
120 | slice.setLabelFont(QFont("Tahoma")); | |
|
121 | slice.setLabelArmLengthFactor(0.1); | |
|
122 | slice.setLabelArmLengthFactor(0.1); | |
|
123 | slice.setExplodeDistanceFactor(0.1); | |
|
124 | slice.setExplodeDistanceFactor(0.1); | |
|
125 | QCOMPARE(spy.count(), 10); | |
|
126 | } | |
|
127 | ||
|
128 | QTEST_MAIN(tst_qpieslice) | |
|
129 | ||
|
130 | #include "tst_qpieslice.moc" | |
|
131 |
@@ -1,10 +1,10 | |||
|
1 | 1 | !include( ../test.pri ) { |
|
2 | 2 | error( "Couldn't find the test.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TEMPLATE = subdirs |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries | |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qpieslice qpieseries | |
|
7 | 7 | |
|
8 | 8 | test_private:{ |
|
9 | 9 | SUBDIRS += chartdataset domain |
|
10 | 10 | } |
General Comments 0
You need to be logged in to leave comments.
Login now