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