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