@@ -1,419 +1,428 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
26 | |||
27 | class tst_QBarSeries : public QObject |
|
27 | class tst_QBarSeries : public QObject | |
28 | { |
|
28 | { | |
29 | Q_OBJECT |
|
29 | Q_OBJECT | |
30 |
|
30 | |||
31 | public slots: |
|
31 | public slots: | |
32 | void initTestCase(); |
|
32 | void initTestCase(); | |
33 | void cleanupTestCase(); |
|
33 | void cleanupTestCase(); | |
34 | void init(); |
|
34 | void init(); | |
35 | void cleanup(); |
|
35 | void cleanup(); | |
36 |
|
36 | |||
37 | private slots: |
|
37 | private slots: | |
38 | void qbarseries_data(); |
|
38 | void qbarseries_data(); | |
39 | void qbarseries(); |
|
39 | void qbarseries(); | |
40 | void type_data(); |
|
40 | void type_data(); | |
41 | void type(); |
|
41 | void type(); | |
42 | void setCategories_data(); |
|
42 | void setCategories_data(); | |
43 | void setCategories(); |
|
43 | void setCategories(); | |
44 | void appendBarSet_data(); |
|
44 | void appendBarSet_data(); | |
45 | void appendBarSet(); |
|
45 | void appendBarSet(); | |
46 | void removeBarSet_data(); |
|
46 | void removeBarSet_data(); | |
47 | void removeBarSet(); |
|
47 | void removeBarSet(); | |
48 | void appendBarSets_data(); |
|
48 | void appendBarSets_data(); | |
49 | void appendBarSets(); |
|
49 | void appendBarSets(); | |
50 | void removeBarSets_data(); |
|
50 | void removeBarSets_data(); | |
51 | void removeBarSets(); |
|
51 | void removeBarSets(); | |
52 | void barsetCount_data(); |
|
52 | void barsetCount_data(); | |
53 | void barsetCount(); |
|
53 | void barsetCount(); | |
54 | void categoryCount_data(); |
|
54 | void categoryCount_data(); | |
55 | void categoryCount(); |
|
55 | void categoryCount(); | |
56 | void barSets_data(); |
|
56 | void barSets_data(); | |
57 | void barSets(); |
|
57 | void barSets(); | |
58 | void categories_data(); |
|
58 | void categories_data(); | |
59 | void categories(); |
|
59 | void categories(); | |
60 | void setLabelsVisible_data(); |
|
60 | void setLabelsVisible_data(); | |
61 | void setLabelsVisible(); |
|
61 | void setLabelsVisible(); | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | QBarSeries* m_barseries; |
|
64 | QBarSeries* m_barseries; | |
65 | QBarSeries* m_barseries_with_sets; |
|
65 | QBarSeries* m_barseries_with_sets; | |
66 |
|
66 | |||
67 | QList<QBarSet*> m_testSets; |
|
67 | QList<QBarSet*> m_testSets; | |
68 |
|
68 | |||
69 | QBarCategories m_categories; |
|
69 | QBarCategories m_categories; | |
70 | }; |
|
70 | }; | |
71 |
|
71 | |||
72 | void tst_QBarSeries::initTestCase() |
|
72 | void tst_QBarSeries::initTestCase() | |
73 | { |
|
73 | { | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void tst_QBarSeries::cleanupTestCase() |
|
76 | void tst_QBarSeries::cleanupTestCase() | |
77 | { |
|
77 | { | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_QBarSeries::init() |
|
80 | void tst_QBarSeries::init() | |
81 | { |
|
81 | { | |
82 | m_categories << "category0" << "category1" << "category2"; |
|
82 | m_categories << "category0" << "category1" << "category2"; | |
83 | m_barseries = new QBarSeries(); |
|
83 | m_barseries = new QBarSeries(); | |
84 | m_barseries->setCategories(m_categories); |
|
84 | m_barseries->setCategories(m_categories); | |
85 | m_barseries_with_sets = new QBarSeries(); |
|
85 | m_barseries_with_sets = new QBarSeries(); | |
86 | m_barseries_with_sets->setCategories(m_categories); |
|
86 | m_barseries_with_sets->setCategories(m_categories); | |
87 |
|
87 | |||
88 | for (int i=0; i<5; i++) { |
|
88 | for (int i=0; i<5; i++) { | |
89 | m_testSets.append(new QBarSet("testset")); |
|
89 | m_testSets.append(new QBarSet("testset")); | |
90 | m_barseries_with_sets->appendBarSet(m_testSets.at(i)); |
|
90 | m_barseries_with_sets->appendBarSet(m_testSets.at(i)); | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void tst_QBarSeries::cleanup() |
|
94 | void tst_QBarSeries::cleanup() | |
95 | { |
|
95 | { | |
96 | foreach(QBarSet* s, m_testSets) { |
|
96 | foreach(QBarSet* s, m_testSets) { | |
97 | m_barseries_with_sets->removeBarSet(s); |
|
97 | m_barseries_with_sets->removeBarSet(s); | |
98 | delete s; |
|
98 | delete s; | |
99 | } |
|
99 | } | |
100 | m_testSets.clear(); |
|
100 | m_testSets.clear(); | |
101 |
|
101 | |||
102 | delete m_barseries; |
|
102 | delete m_barseries; | |
103 | m_barseries = 0; |
|
103 | m_barseries = 0; | |
104 | delete m_barseries_with_sets; |
|
104 | delete m_barseries_with_sets; | |
105 | m_barseries_with_sets = 0; |
|
105 | m_barseries_with_sets = 0; | |
106 | m_categories.clear(); |
|
106 | m_categories.clear(); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void tst_QBarSeries::qbarseries_data() |
|
109 | void tst_QBarSeries::qbarseries_data() | |
110 | { |
|
110 | { | |
111 | QTest::addColumn<QBarCategories> ("categories"); |
|
111 | QTest::addColumn<QBarCategories> ("categories"); | |
112 | QBarCategories c; |
|
112 | QBarCategories c; | |
113 | c << "category0" << "category1" << "category2"; |
|
113 | c << "category0" << "category1" << "category2"; | |
114 | QTest::newRow("categories") << c; |
|
114 | QTest::newRow("categories") << c; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_QBarSeries::qbarseries() |
|
117 | void tst_QBarSeries::qbarseries() | |
118 | { |
|
118 | { | |
119 | QFETCH(QBarCategories, categories); |
|
119 | QFETCH(QBarCategories, categories); | |
120 | QBarSeries *barseries = new QBarSeries(); |
|
120 | QBarSeries *barseries = new QBarSeries(); | |
121 | QVERIFY(barseries != 0); |
|
121 | QVERIFY(barseries != 0); | |
122 | barseries->setCategories(categories); |
|
122 | barseries->setCategories(categories); | |
123 | QBarCategories verifyCategories = barseries->categories(); |
|
123 | QBarCategories verifyCategories = barseries->categories(); | |
124 |
|
124 | |||
125 | QVERIFY(verifyCategories.count() == categories.count()); |
|
125 | QVERIFY(verifyCategories.count() == categories.count()); | |
126 | for (int i=0; i<categories.count(); i++) { |
|
126 | for (int i=0; i<categories.count(); i++) { | |
127 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); |
|
127 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); | |
128 | } |
|
128 | } | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void tst_QBarSeries::type_data() |
|
131 | void tst_QBarSeries::type_data() | |
132 | { |
|
132 | { | |
133 |
|
133 | |||
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void tst_QBarSeries::type() |
|
136 | void tst_QBarSeries::type() | |
137 | { |
|
137 | { | |
138 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
138 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void tst_QBarSeries::setCategories_data() |
|
141 | void tst_QBarSeries::setCategories_data() | |
142 | { |
|
142 | { | |
143 | QTest::addColumn<QBarCategories> ("categories"); |
|
143 | QTest::addColumn<QBarCategories> ("categories"); | |
144 | QBarCategories categories; |
|
144 | QBarCategories categories; | |
145 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; |
|
145 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; | |
146 | QTest::newRow("cat") << categories; |
|
146 | QTest::newRow("cat") << categories; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void tst_QBarSeries::setCategories() |
|
149 | void tst_QBarSeries::setCategories() | |
150 | { |
|
150 | { | |
151 | QVERIFY(m_barseries->categories().count() == m_categories.count()); |
|
151 | QVERIFY(m_barseries->categories().count() == m_categories.count()); | |
152 |
|
152 | |||
153 | QFETCH(QBarCategories, categories); |
|
153 | QFETCH(QBarCategories, categories); | |
154 | m_barseries->setCategories(categories); |
|
154 | m_barseries->setCategories(categories); | |
155 |
|
155 | |||
156 | QVERIFY(m_barseries->categories().count() == categories.count()); |
|
156 | QVERIFY(m_barseries->categories().count() == categories.count()); | |
157 | for (int i=0; i<categories.count(); i++) { |
|
157 | for (int i=0; i<categories.count(); i++) { | |
158 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); |
|
158 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void tst_QBarSeries::appendBarSet_data() |
|
162 | void tst_QBarSeries::appendBarSet_data() | |
163 | { |
|
163 | { | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void tst_QBarSeries::appendBarSet() |
|
166 | void tst_QBarSeries::appendBarSet() | |
167 | { |
|
167 | { | |
168 | QVERIFY(m_barseries->barsetCount() == 0); |
|
168 | QVERIFY(m_barseries->barsetCount() == 0); | |
169 |
|
169 | |||
170 | bool ret = false; |
|
170 | bool ret = false; | |
171 |
|
171 | |||
172 | // Try adding barset |
|
172 | // Try adding barset | |
173 | QBarSet *barset = new QBarSet("testset"); |
|
173 | QBarSet *barset = new QBarSet("testset"); | |
174 | ret = m_barseries->appendBarSet(barset); |
|
174 | ret = m_barseries->appendBarSet(barset); | |
175 |
|
175 | |||
176 | QVERIFY(ret == true); |
|
176 | QVERIFY(ret == true); | |
177 | QVERIFY(m_barseries->barsetCount() == 1); |
|
177 | QVERIFY(m_barseries->barsetCount() == 1); | |
178 |
|
178 | |||
179 | // Try adding another set |
|
179 | // Try adding another set | |
180 | QBarSet *barset2 = new QBarSet("testset2"); |
|
180 | QBarSet *barset2 = new QBarSet("testset2"); | |
181 | ret = m_barseries->appendBarSet(barset2); |
|
181 | ret = m_barseries->appendBarSet(barset2); | |
182 |
|
182 | |||
183 | QVERIFY(ret == true); |
|
183 | QVERIFY(ret == true); | |
184 | QVERIFY(m_barseries->barsetCount() == 2); |
|
184 | QVERIFY(m_barseries->barsetCount() == 2); | |
185 |
|
185 | |||
186 | // Try adding same set again |
|
186 | // Try adding same set again | |
187 | ret = m_barseries->appendBarSet(barset2); |
|
187 | ret = m_barseries->appendBarSet(barset2); | |
188 | QVERIFY(ret == false); |
|
188 | QVERIFY(ret == false); | |
189 | QVERIFY(m_barseries->barsetCount() == 2); |
|
189 | QVERIFY(m_barseries->barsetCount() == 2); | |
190 |
|
190 | |||
191 | // Try adding null set |
|
191 | // Try adding null set | |
192 | ret = m_barseries->appendBarSet(0); |
|
192 | ret = m_barseries->appendBarSet(0); | |
193 | QVERIFY(ret == false); |
|
193 | QVERIFY(ret == false); | |
194 | QVERIFY(m_barseries->barsetCount() == 2); |
|
194 | QVERIFY(m_barseries->barsetCount() == 2); | |
195 |
|
195 | |||
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | void tst_QBarSeries::removeBarSet_data() |
|
198 | void tst_QBarSeries::removeBarSet_data() | |
199 | { |
|
199 | { | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | void tst_QBarSeries::removeBarSet() |
|
202 | void tst_QBarSeries::removeBarSet() | |
203 | { |
|
203 | { | |
204 | int count = m_testSets.count(); |
|
204 | int count = m_testSets.count(); | |
205 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
205 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
206 |
|
206 | |||
207 | // Try to remove null pointer (should not remove, should not crash) |
|
207 | // Try to remove null pointer (should not remove, should not crash) | |
208 | bool ret = false; |
|
208 | bool ret = false; | |
209 | ret = m_barseries_with_sets->removeBarSet(0); |
|
209 | ret = m_barseries_with_sets->removeBarSet(0); | |
210 | QVERIFY(ret == false); |
|
210 | QVERIFY(ret == false); | |
211 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
211 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
212 |
|
212 | |||
213 | // Try to remove invalid pointer (should not remove, should not crash) |
|
213 | // Try to remove invalid pointer (should not remove, should not crash) | |
214 | ret = m_barseries_with_sets->removeBarSet((QBarSet*) (m_testSets.at(0) + 1) ); |
|
214 | ret = m_barseries_with_sets->removeBarSet((QBarSet*) (m_testSets.at(0) + 1) ); | |
215 | QVERIFY(ret == false); |
|
215 | QVERIFY(ret == false); | |
216 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
216 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
217 |
|
217 | |||
218 | // remove some sets |
|
218 | // remove some sets | |
219 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(2)); |
|
219 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(2)); | |
220 | QVERIFY(ret == true); |
|
220 | QVERIFY(ret == true); | |
221 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(3)); |
|
221 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(3)); | |
222 | QVERIFY(ret == true); |
|
222 | QVERIFY(ret == true); | |
223 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(4)); |
|
223 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(4)); | |
224 | QVERIFY(ret == true); |
|
224 | QVERIFY(ret == true); | |
225 |
|
225 | |||
226 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); |
|
226 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); | |
227 |
|
227 | |||
228 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
228 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
229 |
|
229 | |||
230 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
230 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
231 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
231 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
232 |
|
232 | |||
233 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
233 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
234 | ret = false; |
|
234 | ret = false; | |
235 | for (int i=0; i<count; i++) { |
|
235 | for (int i=0; i<count; i++) { | |
236 | ret |= m_barseries_with_sets->removeBarSet(m_testSets.at(i)); |
|
236 | ret |= m_barseries_with_sets->removeBarSet(m_testSets.at(i)); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | QVERIFY(ret == true); |
|
239 | QVERIFY(ret == true); | |
240 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
240 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | void tst_QBarSeries::appendBarSets_data() |
|
243 | void tst_QBarSeries::appendBarSets_data() | |
244 | { |
|
244 | { | |
245 |
|
245 | |||
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | void tst_QBarSeries::appendBarSets() |
|
248 | void tst_QBarSeries::appendBarSets() | |
249 | { |
|
249 | { | |
250 | int count = 5; |
|
250 | int count = 5; | |
251 | QVERIFY(m_barseries->barsetCount() == 0); |
|
251 | QVERIFY(m_barseries->barsetCount() == 0); | |
252 |
|
252 | |||
253 | QList<QBarSet*> sets; |
|
253 | QList<QBarSet*> sets; | |
254 | for (int i=0; i<count; i++) { |
|
254 | for (int i=0; i<count; i++) { | |
255 | sets.append(new QBarSet("testset")); |
|
255 | sets.append(new QBarSet("testset")); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | // Append new sets (should succeed, count should match the count of sets) |
|
258 | // Append new sets (should succeed, count should match the count of sets) | |
259 | bool ret = false; |
|
259 | bool ret = false; | |
260 | ret = m_barseries->appendBarSets(sets); |
|
260 | ret = m_barseries->appendBarSets(sets); | |
261 | QVERIFY(ret == true); |
|
261 | QVERIFY(ret == true); | |
262 | QVERIFY(m_barseries->barsetCount() == count); |
|
262 | QVERIFY(m_barseries->barsetCount() == count); | |
263 |
|
263 | |||
264 | // Append same sets again (should fail, count should remain same) |
|
264 | // Append same sets again (should fail, count should remain same) | |
265 | ret = m_barseries->appendBarSets(sets); |
|
265 | ret = m_barseries->appendBarSets(sets); | |
266 | QVERIFY(ret == false); |
|
266 | QVERIFY(ret == false); | |
267 | QVERIFY(m_barseries->barsetCount() == count); |
|
267 | QVERIFY(m_barseries->barsetCount() == count); | |
268 |
|
268 | |||
269 | // Try append empty list (should succeed, but count should remain same) |
|
269 | // Try append empty list (should succeed, but count should remain same) | |
270 | QList<QBarSet*> invalidList; |
|
270 | QList<QBarSet*> invalidList; | |
271 | ret = m_barseries->appendBarSets(invalidList); |
|
271 | ret = m_barseries->appendBarSets(invalidList); | |
272 | QVERIFY(ret == true); |
|
272 | QVERIFY(ret == true); | |
273 | QVERIFY(m_barseries->barsetCount() == count); |
|
273 | QVERIFY(m_barseries->barsetCount() == count); | |
274 |
|
274 | |||
275 | // Try append list with one new and one existing set (should fail, count remains same) |
|
275 | // Try append list with one new and one existing set (should fail, count remains same) | |
276 | invalidList.append(new QBarSet("ok set")); |
|
276 | invalidList.append(new QBarSet("ok set")); | |
277 | invalidList.append(sets.at(0)); |
|
277 | invalidList.append(sets.at(0)); | |
278 | ret = m_barseries->appendBarSets(invalidList); |
|
278 | ret = m_barseries->appendBarSets(invalidList); | |
279 | QVERIFY(ret == false); |
|
279 | QVERIFY(ret == false); | |
280 | QVERIFY(m_barseries->barsetCount() == count); |
|
280 | QVERIFY(m_barseries->barsetCount() == count); | |
281 |
|
281 | |||
282 | // Try append list with null pointers (should fail, count remains same) |
|
282 | // Try append list with null pointers (should fail, count remains same) | |
283 | QList<QBarSet*> invalidList2; |
|
283 | QList<QBarSet*> invalidList2; | |
284 | invalidList2.append(0); |
|
284 | invalidList2.append(0); | |
285 | invalidList2.append(0); |
|
285 | invalidList2.append(0); | |
286 | invalidList2.append(0); |
|
286 | invalidList2.append(0); | |
287 | ret = m_barseries->appendBarSets(invalidList2); |
|
287 | ret = m_barseries->appendBarSets(invalidList2); | |
288 | QVERIFY(ret == false); |
|
288 | QVERIFY(ret == false); | |
289 | QVERIFY(m_barseries->barsetCount() == count); |
|
289 | QVERIFY(m_barseries->barsetCount() == count); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void tst_QBarSeries::removeBarSets_data() |
|
292 | void tst_QBarSeries::removeBarSets_data() | |
293 | { |
|
293 | { | |
294 |
|
294 | |||
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void tst_QBarSeries::removeBarSets() |
|
297 | void tst_QBarSeries::removeBarSets() | |
298 | { |
|
298 | { | |
299 | int count = m_testSets.count(); |
|
299 | int count = m_testSets.count(); | |
300 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
300 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
301 |
|
301 | |||
302 | // Try removing empty list of sets (should return false, since no barsets were removed) |
|
302 | // Try removing empty list of sets (should return false, since no barsets were removed) | |
303 | bool ret = false; |
|
303 | bool ret = false; | |
304 | QList<QBarSet*> invalidList; |
|
304 | QList<QBarSet*> invalidList; | |
305 | ret = m_barseries_with_sets->removeBarSets(invalidList); |
|
305 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
306 | QVERIFY(ret == false); |
|
306 | QVERIFY(ret == false); | |
307 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
307 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
308 |
|
308 | |||
309 | // Add some null pointers to list |
|
309 | // Add some null pointers to list | |
310 | invalidList.append(0); |
|
310 | invalidList.append(0); | |
311 | invalidList.append(0); |
|
311 | invalidList.append(0); | |
312 | invalidList.append(0); |
|
312 | invalidList.append(0); | |
313 |
|
313 | |||
314 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) |
|
314 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) | |
315 | ret = m_barseries_with_sets->removeBarSets(invalidList); |
|
315 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
316 | QVERIFY(ret == false); |
|
316 | QVERIFY(ret == false); | |
317 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
317 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
318 |
|
318 | |||
319 | // remove all sets (should return true, since sets were removed) |
|
319 | // remove all sets (should return true, since sets were removed) | |
320 | ret = m_barseries_with_sets->removeBarSets(m_testSets); |
|
320 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |
321 | QVERIFY(ret == true); |
|
321 | QVERIFY(ret == true); | |
322 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
322 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
323 |
|
323 | |||
324 | // Try removing invalid list again (should return false, since no barsets were removed) |
|
324 | // Try removing invalid list again (should return false, since no barsets were removed) | |
325 | ret = m_barseries_with_sets->removeBarSets(invalidList); |
|
325 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
326 | QVERIFY(ret == false); |
|
326 | QVERIFY(ret == false); | |
327 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
327 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
328 |
|
328 | |||
329 | // remove all sets again (should return false, since barsets were already removed) |
|
329 | // remove all sets again (should return false, since barsets were already removed) | |
330 | ret = m_barseries_with_sets->removeBarSets(m_testSets); |
|
330 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |
331 | QVERIFY(ret == false); |
|
331 | QVERIFY(ret == false); | |
332 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
332 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void tst_QBarSeries::barsetCount_data() |
|
335 | void tst_QBarSeries::barsetCount_data() | |
336 | { |
|
336 | { | |
337 |
|
337 | |||
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | void tst_QBarSeries::barsetCount() |
|
340 | void tst_QBarSeries::barsetCount() | |
341 | { |
|
341 | { | |
342 | QVERIFY(m_barseries->barsetCount() == 0); |
|
342 | QVERIFY(m_barseries->barsetCount() == 0); | |
343 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); |
|
343 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | void tst_QBarSeries::categoryCount_data() |
|
346 | void tst_QBarSeries::categoryCount_data() | |
347 | { |
|
347 | { | |
348 |
|
348 | |||
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | void tst_QBarSeries::categoryCount() |
|
351 | void tst_QBarSeries::categoryCount() | |
352 | { |
|
352 | { | |
353 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); |
|
353 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); | |
354 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); |
|
354 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | void tst_QBarSeries::barSets_data() |
|
357 | void tst_QBarSeries::barSets_data() | |
358 | { |
|
358 | { | |
359 |
|
359 | |||
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void tst_QBarSeries::barSets() |
|
362 | void tst_QBarSeries::barSets() | |
363 | { |
|
363 | { | |
364 | QVERIFY(m_barseries->barSets().count() == 0); |
|
364 | QVERIFY(m_barseries->barSets().count() == 0); | |
365 |
|
365 | |||
366 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
366 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
367 | QVERIFY(sets.count() == m_testSets.count()); |
|
367 | QVERIFY(sets.count() == m_testSets.count()); | |
368 |
|
368 | |||
369 | for (int i=0; i<m_testSets.count(); i++) { |
|
369 | for (int i=0; i<m_testSets.count(); i++) { | |
370 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
370 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
371 | } |
|
371 | } | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | void tst_QBarSeries::categories_data() |
|
374 | void tst_QBarSeries::categories_data() | |
375 | { |
|
375 | { | |
376 |
|
376 | |||
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | void tst_QBarSeries::categories() |
|
379 | void tst_QBarSeries::categories() | |
380 | { |
|
380 | { | |
381 | QBarCategories categories = m_barseries->categories(); |
|
381 | QBarCategories categories = m_barseries->categories(); | |
382 |
|
382 | |||
383 | QVERIFY(categories.count() == m_categories.count()); |
|
383 | QVERIFY(categories.count() == m_categories.count()); | |
384 | for (int i=0; i<m_categories.count(); i++) { |
|
384 | for (int i=0; i<m_categories.count(); i++) { | |
385 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); |
|
385 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); | |
386 | } |
|
386 | } | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | void tst_QBarSeries::setLabelsVisible_data() |
|
389 | void tst_QBarSeries::setLabelsVisible_data() | |
390 | { |
|
390 | { | |
391 |
|
391 | |||
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | void tst_QBarSeries::setLabelsVisible() |
|
394 | void tst_QBarSeries::setLabelsVisible() | |
395 | { |
|
395 | { | |
|
396 | // labels should be invisible by default | |||
396 | foreach (QBarSet* s, m_testSets) { |
|
397 | foreach (QBarSet* s, m_testSets) { | |
397 | QVERIFY(s->labelsVisible() == false); |
|
398 | QVERIFY(s->labelsVisible() == false); | |
398 | } |
|
399 | } | |
399 |
|
400 | |||
|
401 | // turn labels to visible | |||
400 | m_barseries_with_sets->setLabelsVisible(true); |
|
402 | m_barseries_with_sets->setLabelsVisible(true); | |
401 | foreach (QBarSet* s, m_testSets) { |
|
403 | foreach (QBarSet* s, m_testSets) { | |
402 | QVERIFY(s->labelsVisible() == true); |
|
404 | QVERIFY(s->labelsVisible() == true); | |
403 | } |
|
405 | } | |
404 |
|
406 | |||
|
407 | // turn labels to invisible | |||
405 | m_barseries_with_sets->setLabelsVisible(false); |
|
408 | m_barseries_with_sets->setLabelsVisible(false); | |
406 | foreach (QBarSet* s, m_testSets) { |
|
409 | foreach (QBarSet* s, m_testSets) { | |
407 | QVERIFY(s->labelsVisible() == false); |
|
410 | QVERIFY(s->labelsVisible() == false); | |
408 | } |
|
411 | } | |
|
412 | ||||
|
413 | // without parameter, should turn labels to visible | |||
|
414 | m_barseries_with_sets->setLabelsVisible(); | |||
|
415 | foreach (QBarSet* s, m_testSets) { | |||
|
416 | QVERIFY(s->labelsVisible() == true); | |||
|
417 | } | |||
409 | } |
|
418 | } | |
410 |
|
419 | |||
411 | /* |
|
420 | /* | |
412 | bool setModel(QAbstractItemModel *model); |
|
421 | bool setModel(QAbstractItemModel *model); | |
413 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
422 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
414 | void setModelMappingRange(int first, int count = -1); |
|
423 | void setModelMappingRange(int first, int count = -1); | |
415 | */ |
|
424 | */ | |
416 | QTEST_MAIN(tst_QBarSeries) |
|
425 | QTEST_MAIN(tst_QBarSeries) | |
417 |
|
426 | |||
418 | #include "tst_qbarseries.moc" |
|
427 | #include "tst_qbarseries.moc" | |
419 |
|
428 |
General Comments 0
You need to be logged in to leave comments.
Login now