@@ -1,661 +1,681 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <private/domain_p.h> |
|
23 | 23 | #include <private/qabstractaxis_p.h> |
|
24 | 24 | #include <tst_definitions.h> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | Q_DECLARE_METATYPE(Domain*) |
|
29 | 29 | Q_DECLARE_METATYPE(QSizeF) |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | class AxisMock: public QAbstractAxisPrivate |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | public: |
|
36 | 36 | AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);}; |
|
37 |
ChartAxis* createGraphics(ChartPresenter* presenter) |
|
|
38 | void intializeDomain(Domain* domain){}; | |
|
39 | void setMin(const QVariant &min){} | |
|
37 | ChartAxis* createGraphics(ChartPresenter* presenter) | |
|
38 | { | |
|
39 | Q_UNUSED(presenter); | |
|
40 | return 0; | |
|
41 | }; | |
|
42 | void intializeDomain(Domain* domain) | |
|
43 | { | |
|
44 | Q_UNUSED(domain); | |
|
45 | }; | |
|
46 | void setMin(const QVariant &min) | |
|
47 | { | |
|
48 | Q_UNUSED(min); | |
|
49 | } | |
|
40 | 50 | qreal min() { return m_min;} |
|
41 |
void setMax(const QVariant &max) |
|
|
51 | void setMax(const QVariant &max) | |
|
52 | { | |
|
53 | Q_UNUSED(max); | |
|
54 | } | |
|
42 | 55 | qreal max() { return m_max; } |
|
43 |
void setRange(const QVariant &min, const QVariant &max) |
|
|
56 | void setRange(const QVariant &min, const QVariant &max) | |
|
57 | { | |
|
58 | Q_UNUSED(min); | |
|
59 | Q_UNUSED(max); | |
|
60 | }; | |
|
61 | ||
|
62 | int count () const { return m_count; } | |
|
44 | 63 | |
|
45 | 64 | void handleDomainUpdated(){}; |
|
46 | 65 | public: |
|
66 | int m_count; | |
|
47 | 67 | qreal m_min; |
|
48 | 68 | qreal m_max; |
|
49 | 69 | }; |
|
50 | 70 | |
|
51 | 71 | class tst_Domain: public QObject |
|
52 | 72 | { |
|
53 | 73 | Q_OBJECT |
|
54 | 74 | |
|
55 | 75 | public Q_SLOTS: |
|
56 | 76 | void initTestCase(); |
|
57 | 77 | void cleanupTestCase(); |
|
58 | 78 | void init(); |
|
59 | 79 | void cleanup(); |
|
60 | 80 | |
|
61 | 81 | private Q_SLOTS: |
|
62 | 82 | void domain(); |
|
63 | 83 | void handleAxisUpdatedX_data(); |
|
64 | 84 | void handleAxisUpdatedX(); |
|
65 | 85 | void handleAxisUpdatedY_data(); |
|
66 | 86 | void handleAxisUpdatedY(); |
|
67 | 87 | void isEmpty_data(); |
|
68 | 88 | void isEmpty(); |
|
69 | 89 | void maxX_data(); |
|
70 | 90 | void maxX(); |
|
71 | 91 | void maxY_data(); |
|
72 | 92 | void maxY(); |
|
73 | 93 | void minX_data(); |
|
74 | 94 | void minX(); |
|
75 | 95 | void minY_data(); |
|
76 | 96 | void minY(); |
|
77 | 97 | void operatorEquals_data(); |
|
78 | 98 | void operatorEquals(); |
|
79 | 99 | void setRange_data(); |
|
80 | 100 | void setRange(); |
|
81 | 101 | void setRangeX_data(); |
|
82 | 102 | void setRangeX(); |
|
83 | 103 | void setRangeY_data(); |
|
84 | 104 | void setRangeY(); |
|
85 | 105 | void spanX_data(); |
|
86 | 106 | void spanX(); |
|
87 | 107 | void spanY_data(); |
|
88 | 108 | void spanY(); |
|
89 | 109 | void zoom_data(); |
|
90 | 110 | void zoom(); |
|
91 | 111 | void move_data(); |
|
92 | 112 | void move(); |
|
93 | 113 | }; |
|
94 | 114 | |
|
95 | 115 | void tst_Domain::initTestCase() |
|
96 | 116 | { |
|
97 | 117 | } |
|
98 | 118 | |
|
99 | 119 | void tst_Domain::cleanupTestCase() |
|
100 | 120 | { |
|
101 | 121 | } |
|
102 | 122 | |
|
103 | 123 | void tst_Domain::init() |
|
104 | 124 | { |
|
105 | 125 | } |
|
106 | 126 | |
|
107 | 127 | void tst_Domain::cleanup() |
|
108 | 128 | { |
|
109 | 129 | } |
|
110 | 130 | |
|
111 | 131 | void tst_Domain::domain() |
|
112 | 132 | { |
|
113 | 133 | Domain domain; |
|
114 | 134 | |
|
115 | 135 | QCOMPARE(domain.isEmpty(), true); |
|
116 | 136 | QCOMPARE(domain.maxX(), 0.0); |
|
117 | 137 | QCOMPARE(domain.maxY(), 0.0); |
|
118 | 138 | QCOMPARE(domain.minX(), 0.0); |
|
119 | 139 | QCOMPARE(domain.minY(), 0.0); |
|
120 | 140 | } |
|
121 | 141 | |
|
122 | 142 | void tst_Domain::handleAxisUpdatedX_data() |
|
123 | 143 | { |
|
124 | 144 | QTest::addColumn<qreal>("min"); |
|
125 | 145 | QTest::addColumn<qreal>("max"); |
|
126 | 146 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
127 | 147 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
128 | 148 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
129 | 149 | } |
|
130 | 150 | |
|
131 | 151 | void tst_Domain::handleAxisUpdatedX() |
|
132 | 152 | { |
|
133 | 153 | QFETCH(qreal, min); |
|
134 | 154 | QFETCH(qreal, max); |
|
135 | 155 | |
|
136 | 156 | Domain domain; |
|
137 | 157 | |
|
138 | 158 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
139 | 159 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
140 | 160 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
141 | 161 | |
|
142 | 162 | AxisMock axis(Qt::Horizontal); |
|
143 | 163 | QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated())); |
|
144 | 164 | axis.m_min=min; |
|
145 | 165 | axis.m_max=max; |
|
146 | 166 | axis.emitUpdated(); |
|
147 | 167 | |
|
148 | 168 | QVERIFY(qFuzzyIsNull(domain.minX() - min)); |
|
149 | 169 | QVERIFY(qFuzzyIsNull(domain.maxX() - max)); |
|
150 | 170 | |
|
151 | 171 | QList<QVariant> arg1 = spy1.first(); |
|
152 | 172 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
153 | 173 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
154 | 174 | |
|
155 | 175 | TRY_COMPARE(spy0.count(), 1); |
|
156 | 176 | TRY_COMPARE(spy1.count(), 1); |
|
157 | 177 | TRY_COMPARE(spy2.count(), 0); |
|
158 | 178 | |
|
159 | 179 | } |
|
160 | 180 | |
|
161 | 181 | void tst_Domain::handleAxisUpdatedY_data() |
|
162 | 182 | { |
|
163 | 183 | QTest::addColumn<qreal>("min"); |
|
164 | 184 | QTest::addColumn<qreal>("max"); |
|
165 | 185 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
166 | 186 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
167 | 187 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
168 | 188 | } |
|
169 | 189 | |
|
170 | 190 | void tst_Domain::handleAxisUpdatedY() |
|
171 | 191 | { |
|
172 | 192 | QFETCH(qreal, min); |
|
173 | 193 | QFETCH(qreal, max); |
|
174 | 194 | |
|
175 | 195 | Domain domain; |
|
176 | 196 | |
|
177 | 197 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
178 | 198 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
179 | 199 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
180 | 200 | |
|
181 | 201 | AxisMock axis(Qt::Vertical); |
|
182 | 202 | QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated())); |
|
183 | 203 | axis.m_min = min; |
|
184 | 204 | axis.m_max = max; |
|
185 | 205 | axis.emitUpdated(); |
|
186 | 206 | |
|
187 | 207 | QVERIFY(qFuzzyIsNull(domain.minY() - min)); |
|
188 | 208 | QVERIFY(qFuzzyIsNull(domain.maxY() - max)); |
|
189 | 209 | |
|
190 | 210 | QList<QVariant> arg1 = spy2.first(); |
|
191 | 211 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
192 | 212 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
193 | 213 | |
|
194 | 214 | TRY_COMPARE(spy0.count(), 1); |
|
195 | 215 | TRY_COMPARE(spy1.count(), 0); |
|
196 | 216 | TRY_COMPARE(spy2.count(), 1); |
|
197 | 217 | } |
|
198 | 218 | |
|
199 | 219 | void tst_Domain::isEmpty_data() |
|
200 | 220 | { |
|
201 | 221 | QTest::addColumn<qreal>("minX"); |
|
202 | 222 | QTest::addColumn<qreal>("maxX"); |
|
203 | 223 | QTest::addColumn<qreal>("minY"); |
|
204 | 224 | QTest::addColumn<qreal>("maxY"); |
|
205 | 225 | QTest::addColumn<bool>("isEmpty"); |
|
206 | 226 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; |
|
207 | 227 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
208 | 228 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
209 | 229 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; |
|
210 | 230 | } |
|
211 | 231 | |
|
212 | 232 | void tst_Domain::isEmpty() |
|
213 | 233 | { |
|
214 | 234 | QFETCH(qreal, minX); |
|
215 | 235 | QFETCH(qreal, maxX); |
|
216 | 236 | QFETCH(qreal, minY); |
|
217 | 237 | QFETCH(qreal, maxY); |
|
218 | 238 | QFETCH(bool, isEmpty); |
|
219 | 239 | |
|
220 | 240 | Domain domain; |
|
221 | 241 | domain.setRange(minX, maxX, minY, maxY); |
|
222 | 242 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
223 | 243 | } |
|
224 | 244 | |
|
225 | 245 | void tst_Domain::maxX_data() |
|
226 | 246 | { |
|
227 | 247 | QTest::addColumn<qreal>("maxX1"); |
|
228 | 248 | QTest::addColumn<qreal>("maxX2"); |
|
229 | 249 | QTest::addColumn<int>("count"); |
|
230 | 250 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
231 | 251 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
232 | 252 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
233 | 253 | } |
|
234 | 254 | |
|
235 | 255 | void tst_Domain::maxX() |
|
236 | 256 | { |
|
237 | 257 | QFETCH(qreal, maxX1); |
|
238 | 258 | QFETCH(qreal, maxX2); |
|
239 | 259 | QFETCH(int, count); |
|
240 | 260 | |
|
241 | 261 | Domain domain; |
|
242 | 262 | |
|
243 | 263 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
244 | 264 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
245 | 265 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
246 | 266 | |
|
247 | 267 | domain.setMaxX(maxX1); |
|
248 | 268 | QCOMPARE(domain.maxX(), maxX1); |
|
249 | 269 | domain.setMaxX(maxX2); |
|
250 | 270 | QCOMPARE(domain.maxX(), maxX2); |
|
251 | 271 | |
|
252 | 272 | TRY_COMPARE(spy0.count(), count); |
|
253 | 273 | TRY_COMPARE(spy1.count(), count); |
|
254 | 274 | TRY_COMPARE(spy2.count(), 0); |
|
255 | 275 | |
|
256 | 276 | } |
|
257 | 277 | |
|
258 | 278 | void tst_Domain::maxY_data() |
|
259 | 279 | { |
|
260 | 280 | QTest::addColumn<qreal>("maxY1"); |
|
261 | 281 | QTest::addColumn<qreal>("maxY2"); |
|
262 | 282 | QTest::addColumn<int>("count"); |
|
263 | 283 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
264 | 284 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
265 | 285 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
266 | 286 | } |
|
267 | 287 | |
|
268 | 288 | void tst_Domain::maxY() |
|
269 | 289 | { |
|
270 | 290 | QFETCH(qreal, maxY1); |
|
271 | 291 | QFETCH(qreal, maxY2); |
|
272 | 292 | QFETCH(int, count); |
|
273 | 293 | |
|
274 | 294 | Domain domain; |
|
275 | 295 | |
|
276 | 296 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
277 | 297 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
278 | 298 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
279 | 299 | |
|
280 | 300 | domain.setMaxY(maxY1); |
|
281 | 301 | QCOMPARE(domain.maxY(), maxY1); |
|
282 | 302 | domain.setMaxY(maxY2); |
|
283 | 303 | QCOMPARE(domain.maxY(), maxY2); |
|
284 | 304 | |
|
285 | 305 | TRY_COMPARE(spy0.count(), count); |
|
286 | 306 | TRY_COMPARE(spy1.count(), 0); |
|
287 | 307 | TRY_COMPARE(spy2.count(), count); |
|
288 | 308 | } |
|
289 | 309 | |
|
290 | 310 | void tst_Domain::minX_data() |
|
291 | 311 | { |
|
292 | 312 | QTest::addColumn<qreal>("minX1"); |
|
293 | 313 | QTest::addColumn<qreal>("minX2"); |
|
294 | 314 | QTest::addColumn<int>("count"); |
|
295 | 315 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
296 | 316 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
297 | 317 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
298 | 318 | } |
|
299 | 319 | |
|
300 | 320 | void tst_Domain::minX() |
|
301 | 321 | { |
|
302 | 322 | QFETCH(qreal, minX1); |
|
303 | 323 | QFETCH(qreal, minX2); |
|
304 | 324 | QFETCH(int, count); |
|
305 | 325 | |
|
306 | 326 | Domain domain; |
|
307 | 327 | |
|
308 | 328 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
309 | 329 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
310 | 330 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
311 | 331 | |
|
312 | 332 | domain.setMinX(minX1); |
|
313 | 333 | QCOMPARE(domain.minX(), minX1); |
|
314 | 334 | domain.setMinX(minX2); |
|
315 | 335 | QCOMPARE(domain.minX(), minX2); |
|
316 | 336 | |
|
317 | 337 | TRY_COMPARE(spy0.count(), count); |
|
318 | 338 | TRY_COMPARE(spy1.count(), count); |
|
319 | 339 | TRY_COMPARE(spy2.count(), 0); |
|
320 | 340 | } |
|
321 | 341 | |
|
322 | 342 | void tst_Domain::minY_data() |
|
323 | 343 | { |
|
324 | 344 | QTest::addColumn<qreal>("minY1"); |
|
325 | 345 | QTest::addColumn<qreal>("minY2"); |
|
326 | 346 | QTest::addColumn<int>("count"); |
|
327 | 347 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
328 | 348 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
329 | 349 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
330 | 350 | } |
|
331 | 351 | |
|
332 | 352 | void tst_Domain::minY() |
|
333 | 353 | { |
|
334 | 354 | QFETCH(qreal, minY1); |
|
335 | 355 | QFETCH(qreal, minY2); |
|
336 | 356 | QFETCH(int, count); |
|
337 | 357 | |
|
338 | 358 | Domain domain; |
|
339 | 359 | |
|
340 | 360 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
341 | 361 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
342 | 362 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
343 | 363 | |
|
344 | 364 | domain.setMinY(minY1); |
|
345 | 365 | QCOMPARE(domain.minY(), minY1); |
|
346 | 366 | domain.setMinY(minY2); |
|
347 | 367 | QCOMPARE(domain.minY(), minY2); |
|
348 | 368 | |
|
349 | 369 | TRY_COMPARE(spy0.count(), count); |
|
350 | 370 | TRY_COMPARE(spy1.count(), 0); |
|
351 | 371 | TRY_COMPARE(spy2.count(), count); |
|
352 | 372 | } |
|
353 | 373 | |
|
354 | 374 | void tst_Domain::operatorEquals_data() |
|
355 | 375 | { |
|
356 | 376 | |
|
357 | 377 | QTest::addColumn<Domain*>("domain1"); |
|
358 | 378 | QTest::addColumn<Domain*>("domain2"); |
|
359 | 379 | QTest::addColumn<bool>("equals"); |
|
360 | 380 | QTest::addColumn<bool>("notEquals"); |
|
361 | 381 | Domain* a; |
|
362 | 382 | Domain* b; |
|
363 | 383 | a = new Domain(); |
|
364 | 384 | a->setRange(0, 100, 0, 100); |
|
365 | 385 | b = new Domain(); |
|
366 | 386 | b->setRange(0, 100, 0, 100); |
|
367 | 387 | QTest::newRow("equals") << a << b << true << false; |
|
368 | 388 | a = new Domain(); |
|
369 | 389 | a->setRange(0, 100, 0, 100); |
|
370 | 390 | b = new Domain(); |
|
371 | 391 | b->setRange(0, 100, 0, 1); |
|
372 | 392 | QTest::newRow("equals") << a << b << false << true; |
|
373 | 393 | a = new Domain(); |
|
374 | 394 | a->setRange(0, 100, 0, 100); |
|
375 | 395 | b = new Domain(); |
|
376 | 396 | b->setRange(0, 1, 0, 100); |
|
377 | 397 | QTest::newRow("equals") << a << b << false << true; |
|
378 | 398 | |
|
379 | 399 | } |
|
380 | 400 | |
|
381 | 401 | void tst_Domain::operatorEquals() |
|
382 | 402 | { |
|
383 | 403 | QFETCH(Domain*, domain1); |
|
384 | 404 | QFETCH(Domain*, domain2); |
|
385 | 405 | QFETCH(bool, equals); |
|
386 | 406 | QFETCH(bool, notEquals); |
|
387 | 407 | |
|
388 | 408 | Domain domain; |
|
389 | 409 | |
|
390 | 410 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
391 | 411 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
392 | 412 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
393 | 413 | |
|
394 | 414 | QCOMPARE(*domain1==*domain2, equals); |
|
395 | 415 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
396 | 416 | |
|
397 | 417 | TRY_COMPARE(spy0.count(), 0); |
|
398 | 418 | TRY_COMPARE(spy1.count(), 0); |
|
399 | 419 | TRY_COMPARE(spy2.count(), 0); |
|
400 | 420 | } |
|
401 | 421 | |
|
402 | 422 | void tst_Domain::setRange_data() |
|
403 | 423 | { |
|
404 | 424 | QTest::addColumn<qreal>("minX"); |
|
405 | 425 | QTest::addColumn<qreal>("maxX"); |
|
406 | 426 | QTest::addColumn<qreal>("minY"); |
|
407 | 427 | QTest::addColumn<qreal>("maxY"); |
|
408 | 428 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
409 | 429 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
410 | 430 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
411 | 431 | } |
|
412 | 432 | |
|
413 | 433 | void tst_Domain::setRange() |
|
414 | 434 | { |
|
415 | 435 | QFETCH(qreal, minX); |
|
416 | 436 | QFETCH(qreal, maxX); |
|
417 | 437 | QFETCH(qreal, minY); |
|
418 | 438 | QFETCH(qreal, maxY); |
|
419 | 439 | |
|
420 | 440 | Domain domain; |
|
421 | 441 | |
|
422 | 442 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
423 | 443 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
424 | 444 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
425 | 445 | |
|
426 | 446 | domain.setRange(minX, maxX, minY, maxY); |
|
427 | 447 | |
|
428 | 448 | QCOMPARE(domain.minX(), minX); |
|
429 | 449 | QCOMPARE(domain.maxX(), maxX); |
|
430 | 450 | QCOMPARE(domain.minY(), minY); |
|
431 | 451 | QCOMPARE(domain.maxY(), maxY); |
|
432 | 452 | |
|
433 | 453 | TRY_COMPARE(spy0.count(), 1); |
|
434 | 454 | TRY_COMPARE(spy1.count(), 1); |
|
435 | 455 | TRY_COMPARE(spy2.count(), 1); |
|
436 | 456 | |
|
437 | 457 | } |
|
438 | 458 | |
|
439 | 459 | void tst_Domain::setRangeX_data() |
|
440 | 460 | { |
|
441 | 461 | QTest::addColumn<qreal>("min"); |
|
442 | 462 | QTest::addColumn<qreal>("max"); |
|
443 | 463 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
444 | 464 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
445 | 465 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
446 | 466 | } |
|
447 | 467 | |
|
448 | 468 | void tst_Domain::setRangeX() |
|
449 | 469 | { |
|
450 | 470 | QFETCH(qreal, min); |
|
451 | 471 | QFETCH(qreal, max); |
|
452 | 472 | |
|
453 | 473 | Domain domain; |
|
454 | 474 | |
|
455 | 475 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
456 | 476 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
457 | 477 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
458 | 478 | |
|
459 | 479 | domain.setRangeX(min, max); |
|
460 | 480 | |
|
461 | 481 | QVERIFY(qFuzzyIsNull(domain.minX() - min)); |
|
462 | 482 | QVERIFY(qFuzzyIsNull(domain.maxX() - max)); |
|
463 | 483 | |
|
464 | 484 | QList<QVariant> arg1 = spy1.first(); |
|
465 | 485 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
466 | 486 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
467 | 487 | |
|
468 | 488 | TRY_COMPARE(spy0.count(), 1); |
|
469 | 489 | TRY_COMPARE(spy1.count(), 1); |
|
470 | 490 | TRY_COMPARE(spy2.count(), 0); |
|
471 | 491 | } |
|
472 | 492 | |
|
473 | 493 | void tst_Domain::setRangeY_data() |
|
474 | 494 | { |
|
475 | 495 | QTest::addColumn<qreal>("min"); |
|
476 | 496 | QTest::addColumn<qreal>("max"); |
|
477 | 497 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
478 | 498 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
479 | 499 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
480 | 500 | } |
|
481 | 501 | |
|
482 | 502 | void tst_Domain::setRangeY() |
|
483 | 503 | { |
|
484 | 504 | QFETCH(qreal, min); |
|
485 | 505 | QFETCH(qreal, max); |
|
486 | 506 | |
|
487 | 507 | Domain domain; |
|
488 | 508 | |
|
489 | 509 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
490 | 510 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
491 | 511 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
492 | 512 | |
|
493 | 513 | domain.setRangeY(min, max); |
|
494 | 514 | |
|
495 | 515 | QVERIFY(qFuzzyIsNull(domain.minY() - min)); |
|
496 | 516 | QVERIFY(qFuzzyIsNull(domain.maxY() - max)); |
|
497 | 517 | |
|
498 | 518 | QList<QVariant> arg1 = spy2.first(); |
|
499 | 519 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
500 | 520 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
501 | 521 | |
|
502 | 522 | TRY_COMPARE(spy0.count(), 1); |
|
503 | 523 | TRY_COMPARE(spy1.count(), 0); |
|
504 | 524 | TRY_COMPARE(spy2.count(), 1); |
|
505 | 525 | } |
|
506 | 526 | |
|
507 | 527 | void tst_Domain::spanX_data() |
|
508 | 528 | { |
|
509 | 529 | QTest::addColumn<qreal>("minX"); |
|
510 | 530 | QTest::addColumn<qreal>("maxX"); |
|
511 | 531 | QTest::addColumn<qreal>("spanX"); |
|
512 | 532 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
513 | 533 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
514 | 534 | } |
|
515 | 535 | |
|
516 | 536 | void tst_Domain::spanX() |
|
517 | 537 | { |
|
518 | 538 | QFETCH(qreal, minX); |
|
519 | 539 | QFETCH(qreal, maxX); |
|
520 | 540 | QFETCH(qreal, spanX); |
|
521 | 541 | |
|
522 | 542 | Domain domain; |
|
523 | 543 | |
|
524 | 544 | domain.setRangeX(minX, maxX); |
|
525 | 545 | |
|
526 | 546 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
527 | 547 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
528 | 548 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
529 | 549 | |
|
530 | 550 | QCOMPARE(domain.spanX(), spanX); |
|
531 | 551 | |
|
532 | 552 | TRY_COMPARE(spy0.count(), 0); |
|
533 | 553 | TRY_COMPARE(spy1.count(), 0); |
|
534 | 554 | TRY_COMPARE(spy2.count(), 0); |
|
535 | 555 | } |
|
536 | 556 | |
|
537 | 557 | void tst_Domain::spanY_data() |
|
538 | 558 | { |
|
539 | 559 | QTest::addColumn<qreal>("minY"); |
|
540 | 560 | QTest::addColumn<qreal>("maxY"); |
|
541 | 561 | QTest::addColumn<qreal>("spanY"); |
|
542 | 562 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
543 | 563 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
544 | 564 | } |
|
545 | 565 | |
|
546 | 566 | void tst_Domain::spanY() |
|
547 | 567 | { |
|
548 | 568 | QFETCH(qreal, minY); |
|
549 | 569 | QFETCH(qreal, maxY); |
|
550 | 570 | QFETCH(qreal, spanY); |
|
551 | 571 | |
|
552 | 572 | Domain domain; |
|
553 | 573 | |
|
554 | 574 | domain.setRangeY(minY, maxY); |
|
555 | 575 | |
|
556 | 576 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
557 | 577 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
558 | 578 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
559 | 579 | |
|
560 | 580 | QCOMPARE(domain.spanY(), spanY); |
|
561 | 581 | |
|
562 | 582 | TRY_COMPARE(spy0.count(), 0); |
|
563 | 583 | TRY_COMPARE(spy1.count(), 0); |
|
564 | 584 | TRY_COMPARE(spy2.count(), 0); |
|
565 | 585 | } |
|
566 | 586 | |
|
567 | 587 | void tst_Domain::zoom_data() |
|
568 | 588 | { |
|
569 | 589 | QTest::addColumn<QRectF>("rect0"); |
|
570 | 590 | QTest::addColumn<QSizeF>("size0"); |
|
571 | 591 | QTest::addColumn<QRectF>("rect1"); |
|
572 | 592 | QTest::addColumn<QSizeF>("size1"); |
|
573 | 593 | QTest::addColumn<QRectF>("rect2"); |
|
574 | 594 | QTest::addColumn<QSizeF>("size2"); |
|
575 | 595 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) |
|
576 | 596 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
577 | 597 | << QSizeF(1000, 1000); |
|
578 | 598 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) |
|
579 | 599 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
580 | 600 | << QSizeF(1000, 1000); |
|
581 | 601 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) |
|
582 | 602 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); |
|
583 | 603 | } |
|
584 | 604 | |
|
585 | 605 | void tst_Domain::zoom() |
|
586 | 606 | { |
|
587 | 607 | QFETCH(QRectF, rect0); |
|
588 | 608 | QFETCH(QSizeF, size0); |
|
589 | 609 | QFETCH(QRectF, rect1); |
|
590 | 610 | QFETCH(QSizeF, size1); |
|
591 | 611 | QFETCH(QRectF, rect2); |
|
592 | 612 | QFETCH(QSizeF, size2); |
|
593 | 613 | |
|
594 | 614 | Domain domain; |
|
595 | 615 | |
|
596 | 616 | domain.setRange(0, 1000, 0, 1000); |
|
597 | 617 | |
|
598 | 618 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
599 | 619 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
600 | 620 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
601 | 621 | |
|
602 | 622 | Domain domain0; |
|
603 | 623 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
604 | 624 | domain.zoomIn(rect0, size0); |
|
605 | 625 | Domain domain1; |
|
606 | 626 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
607 | 627 | domain.zoomIn(rect1, size1); |
|
608 | 628 | Domain domain2; |
|
609 | 629 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
610 | 630 | domain.zoomIn(rect2, size2); |
|
611 | 631 | domain.zoomOut(rect2, size2); |
|
612 | 632 | QCOMPARE(domain == domain2, true); |
|
613 | 633 | domain.zoomOut(rect1, size1); |
|
614 | 634 | QCOMPARE(domain == domain1, true); |
|
615 | 635 | domain.zoomOut(rect0, size0); |
|
616 | 636 | QCOMPARE(domain == domain0, true); |
|
617 | 637 | TRY_COMPARE(spy0.count(), 6); |
|
618 | 638 | TRY_COMPARE(spy1.count(), 6); |
|
619 | 639 | TRY_COMPARE(spy2.count(), 6); |
|
620 | 640 | } |
|
621 | 641 | |
|
622 | 642 | void tst_Domain::move_data() |
|
623 | 643 | { |
|
624 | 644 | QTest::addColumn<int>("dx"); |
|
625 | 645 | QTest::addColumn<int>("dy"); |
|
626 | 646 | QTest::addColumn<QSizeF>("size"); |
|
627 | 647 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); |
|
628 | 648 | QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); |
|
629 | 649 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); |
|
630 | 650 | QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); |
|
631 | 651 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); |
|
632 | 652 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); |
|
633 | 653 | } |
|
634 | 654 | |
|
635 | 655 | void tst_Domain::move() |
|
636 | 656 | { |
|
637 | 657 | QFETCH(int, dx); |
|
638 | 658 | QFETCH(int, dy); |
|
639 | 659 | QFETCH(QSizeF, size); |
|
640 | 660 | Domain domain; |
|
641 | 661 | |
|
642 | 662 | domain.setRange(0, size.width(), 0, size.height()); |
|
643 | 663 | |
|
644 | 664 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
645 | 665 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
646 | 666 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
647 | 667 | |
|
648 | 668 | domain.move(dx, dy, size); |
|
649 | 669 | |
|
650 | 670 | Domain result; |
|
651 | 671 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); |
|
652 | 672 | |
|
653 | 673 | QCOMPARE(domain == result, true); |
|
654 | 674 | TRY_COMPARE(spy0.count(), 1); |
|
655 | 675 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); |
|
656 | 676 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); |
|
657 | 677 | } |
|
658 | 678 | |
|
659 | 679 | QTEST_MAIN(tst_Domain) |
|
660 | 680 | #include "tst_domain.moc" |
|
661 | 681 |
General Comments 0
You need to be logged in to leave comments.
Login now