@@ -1,103 +1,102 | |||
|
1 | 1 | ##################### LIB ################################################# |
|
2 | 2 | |
|
3 | 3 | LIBRARY_NAME = QtCommercialChart |
|
4 | 4 | CONFIG(debug, debug|release) { |
|
5 | 5 | mac: LIBRARY_NAME = $$join(LIBRARY_NAME,,,_debug) |
|
6 | 6 | win32: LIBRARY_NAME = $$join(LIBRARY_NAME,,,d) |
|
7 | 7 | } |
|
8 | 8 | |
|
9 | 9 | LIBS += -l$$LIBRARY_NAME |
|
10 | 10 | |
|
11 | 11 | # This will undefine Q_DECL_EXPORT/Q_DECL_IMPORT at qchartglobal.h |
|
12 | 12 | # They should not be used for staticlib builds. |
|
13 | 13 | staticlib:DEFINES+=QTCOMMERCIALCHART_STATICLIB |
|
14 | 14 | |
|
15 | 15 | ##################### SHADOW CONFIG ################################################# |
|
16 | 16 | |
|
17 | 17 | !contains($${PWD}, $${OUT_PWD}){ |
|
18 | 18 | search = "$$PWD:::" |
|
19 | 19 | temp = $$split(search,"/") |
|
20 | 20 | temp = $$last(temp) |
|
21 | 21 | path = $$replace(search,$$temp,'') |
|
22 | 22 | temp = $$split(OUT_PWD,$$path) |
|
23 | 23 | temp = $$split(temp,'/') |
|
24 | 24 | temp = $$first(temp) |
|
25 | 25 | path = "$${path}$${temp}" |
|
26 | 26 | SHADOW=$$path |
|
27 | 27 | }else{ |
|
28 | 28 | SHADOW=$$PWD |
|
29 | 29 | CONFIG-=development_build |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | ##################### BUILD PATHS ################################################## |
|
33 | 33 | |
|
34 | 34 | CHART_BUILD_PUBLIC_HEADER_DIR = $$SHADOW/include |
|
35 | 35 | CHART_BUILD_PRIVATE_HEADER_DIR = $$CHART_BUILD_PUBLIC_HEADER_DIR/private |
|
36 | 36 | CHART_BUILD_LIB_DIR = $$SHADOW/lib |
|
37 | 37 | CHART_BUILD_DIR = $$SHADOW/build |
|
38 | 38 | CHART_BUILD_BIN_DIR = $$SHADOW/bin |
|
39 | 39 | CHART_BUILD_PLUGIN_DIR = $$CHART_BUILD_BIN_DIR/QtCommercial/Chart |
|
40 | 40 | CHART_BUILD_DOC_DIR = $$SHADOW/doc |
|
41 | 41 | |
|
42 | 42 | # Use own folders for debug and release builds |
|
43 | 43 | |
|
44 | 44 | CONFIG(debug, debug|release):CHART_BUILD_DIR = $$join(CHART_BUILD_DIR,,,/debug) |
|
45 | 45 | CONFIG(release, debug|release): CHART_BUILD_DIR = $$join(CHART_BUILD_DIR,,,/release) |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | win32:{ |
|
49 | 49 | CHART_BUILD_PUBLIC_HEADER_DIR = $$replace(CHART_BUILD_PUBLIC_HEADER_DIR, "/","\\") |
|
50 | 50 | CHART_BUILD_PRIVATE_HEADER_DIR = $$replace(CHART_BUILD_PRIVATE_HEADER_DIR, "/","\\") |
|
51 | 51 | CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\") |
|
52 | 52 | CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\") |
|
53 | 53 | CHART_BUILD_PLUGIN_DIR = $$replace(CHART_BUILD_PLUGIN_DIR, "/","\\") |
|
54 | 54 | CHART_BUILD_DOC_DIR = $$replace(CHART_BUILD_DOC_DIR, "/","\\") |
|
55 | 55 | CHART_BUILD_LIB_DIR = $$replace(CHART_BUILD_LIB_DIR, "/","\\") |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | mac: { |
|
59 | 59 | # Some Qt versions use an incompatible configuration on OSX which makes the build fail. |
|
60 | 60 | # As a work-around, set the minimum OSX version to 10.5. |
|
61 | 61 | QMAKE_CXXFLAGS *= -mmacosx-version-min=10.5 |
|
62 | 62 | QMAKE_LFLAGS *= -mmacosx-version-min=10.5 |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | linux-arm*: { |
|
66 | 66 | DEFINES+=QT_ON_ARM |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | ##################### INCLUDES ############################################################ |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | INCLUDEPATH += $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
73 | 73 | |
|
74 | 74 | !win32: { |
|
75 | 75 | LIBS += -L$$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR |
|
76 | 76 | } else { |
|
77 | 77 | win32-msvc*: { |
|
78 | 78 | # hack fix for error: |
|
79 | 79 | # "LINK : fatal error LNK1146: no argument specified with option '/LIBPATH:'" |
|
80 | 80 | QMAKE_LIBDIR += $$CHART_BUILD_LIB_DIR |
|
81 | 81 | } else { |
|
82 | 82 | LIBS += -L$$CHART_BUILD_LIB_DIR |
|
83 | 83 | } |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | ##################### DEVELOPMENT BUILD ################################################### |
|
87 | 87 | |
|
88 | 88 | development_build: { |
|
89 | 89 | DEFINES+=DEVELOPMENT_BUILD |
|
90 | 90 | CONFIG+=debug_and_release |
|
91 | 91 | CONFIG+=build_all |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | #################### COVERAGE ################################################################# |
|
95 | 95 | coverage: CONFIG += debug |
|
96 | 96 | |
|
97 | 97 | ##################### UNIT TESTS ############################################################## |
|
98 | 98 | |
|
99 | 99 | CONFIG(debug, debug|release) { |
|
100 | CONFIG+=test_private | |
|
101 | 100 | DEFINES+=BUILD_PRIVATE_UNIT_TESTS |
|
102 | 101 | } |
|
103 | 102 |
@@ -1,34 +1,35 | |||
|
1 | 1 | !include( ../tests.pri ) { |
|
2 | 2 | error( "Couldn't find the tests.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TEMPLATE = subdirs |
|
6 | 6 | SUBDIRS += \ |
|
7 | 7 | qchartview \ |
|
8 | 8 | qchart \ |
|
9 | 9 | qlineseries \ |
|
10 | 10 | qbarset \ |
|
11 | 11 | qbarseries \ |
|
12 | 12 | qstackedbarseries \ |
|
13 | 13 | qpercentbarseries \ |
|
14 | 14 | qpieslice qpieseries \ |
|
15 | 15 | qpiemodelmapper \ |
|
16 | 16 | qsplineseries \ |
|
17 | 17 | qscatterseries \ |
|
18 | 18 | qxymodelmapper \ |
|
19 | 19 | qbarmodelmapper \ |
|
20 | 20 | qhorizontalbarseries \ |
|
21 | 21 | qhorizontalstackedbarseries \ |
|
22 | 22 | qhorizontalpercentbarseries \ |
|
23 | 23 | qvalueaxis \ |
|
24 | 24 | qcategoryaxis \ |
|
25 | qbarcategoryaxis | |
|
25 | qbarcategoryaxis \ | |
|
26 | domain \ | |
|
27 | chartdataset | |
|
26 | 28 | |
|
27 | 29 | !linux-arm*: { |
|
28 | 30 | SUBDIRS += \ |
|
29 | 31 | qdatetimeaxis |
|
30 | 32 | } |
|
31 | 33 | |
|
32 | test_private:{ | |
|
33 | SUBDIRS += domain chartdataset | |
|
34 | } | |
|
34 | ||
|
35 |
@@ -1,623 +1,644 | |||
|
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 | #ifndef BUILD_PRIVATE_UNIT_TESTS | |
|
21 | #include <QtTest/QtTest> | |
|
22 | ||
|
23 | class tst_ChartDataSet: public QObject { | |
|
24 | ||
|
25 | Q_OBJECT | |
|
26 | ||
|
27 | private Q_SLOTS: | |
|
28 | void skip(); | |
|
29 | ||
|
30 | }; | |
|
31 | ||
|
32 | void tst_ChartDataSet::skip() | |
|
33 | { | |
|
34 | QSKIP("This test requires the debug version of library", SkipAll); | |
|
35 | } | |
|
36 | ||
|
37 | QTEST_MAIN(tst_ChartDataSet) | |
|
38 | #include "tst_chartdataset.moc" | |
|
39 | ||
|
40 | #else | |
|
20 | 41 | |
|
21 | 42 | #include <QtTest/QtTest> |
|
22 | 43 | #include <qabstractaxis.h> |
|
23 | 44 | #include <qvalueaxis.h> |
|
24 | 45 | #include <qbarcategoryaxis.h> |
|
25 | 46 | #include <qlineseries.h> |
|
26 | 47 | #include <qareaseries.h> |
|
27 | 48 | #include <qscatterseries.h> |
|
28 | 49 | #include <qsplineseries.h> |
|
29 | 50 | #include <qpieseries.h> |
|
30 | 51 | #include <qbarseries.h> |
|
31 | 52 | #include <qpercentbarseries.h> |
|
32 | 53 | #include <qstackedbarseries.h> |
|
33 | 54 | #include <private/chartdataset_p.h> |
|
34 | 55 | #include <private/domain_p.h> |
|
35 | 56 | #include <tst_definitions.h> |
|
36 | 57 | |
|
37 | 58 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
38 | 59 | |
|
39 | 60 | Q_DECLARE_METATYPE(Domain *) |
|
40 | 61 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
41 | 62 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
42 | 63 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
43 | 64 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
44 | 65 | Q_DECLARE_METATYPE(QLineSeries *) |
|
45 | 66 | |
|
46 | 67 | class tst_ChartDataSet: public QObject { |
|
47 | 68 | |
|
48 | 69 | Q_OBJECT |
|
49 | 70 | |
|
50 | 71 | public Q_SLOTS: |
|
51 | 72 | void initTestCase(); |
|
52 | 73 | void cleanupTestCase(); |
|
53 | 74 | void init(); |
|
54 | 75 | void cleanup(); |
|
55 | 76 | |
|
56 | 77 | private Q_SLOTS: |
|
57 | 78 | void chartdataset_data(); |
|
58 | 79 | void chartdataset(); |
|
59 | 80 | void addSeries_data(); |
|
60 | 81 | void addSeries(); |
|
61 | 82 | void setAxisX_data(); |
|
62 | 83 | void setAxisX(); |
|
63 | 84 | void setAxisY_data(); |
|
64 | 85 | void setAxisY(); |
|
65 | 86 | void removeSeries_data(); |
|
66 | 87 | void removeSeries(); |
|
67 | 88 | void removeAllSeries_data(); |
|
68 | 89 | void removeAllSeries(); |
|
69 | 90 | void seriesCount_data(); |
|
70 | 91 | void seriesCount(); |
|
71 | 92 | void seriesIndex_data(); |
|
72 | 93 | void seriesIndex(); |
|
73 | 94 | void domain_data(); |
|
74 | 95 | void domain(); |
|
75 | 96 | void zoomInDomain_data(); |
|
76 | 97 | void zoomInDomain(); |
|
77 | 98 | void zoomOutDomain_data(); |
|
78 | 99 | void zoomOutDomain(); |
|
79 | 100 | void scrollDomain_data(); |
|
80 | 101 | void scrollDomain(); |
|
81 | 102 | |
|
82 | 103 | private: |
|
83 | 104 | ChartDataSet* m_dataset; |
|
84 | 105 | }; |
|
85 | 106 | |
|
86 | 107 | void tst_ChartDataSet::initTestCase() |
|
87 | 108 | { |
|
88 | 109 | qRegisterMetaType<Domain*>(); |
|
89 | 110 | qRegisterMetaType<QAbstractAxis*>(); |
|
90 | 111 | qRegisterMetaType<QAbstractSeries*>(); |
|
91 | 112 | } |
|
92 | 113 | |
|
93 | 114 | void tst_ChartDataSet::cleanupTestCase() |
|
94 | 115 | { |
|
95 | 116 | } |
|
96 | 117 | |
|
97 | 118 | void tst_ChartDataSet::init() |
|
98 | 119 | { |
|
99 | 120 | m_dataset = new ChartDataSet(); |
|
100 | 121 | } |
|
101 | 122 | |
|
102 | 123 | |
|
103 | 124 | void tst_ChartDataSet::cleanup() |
|
104 | 125 | { |
|
105 | 126 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
106 | 127 | foreach(QAbstractSeries* serie, series) |
|
107 | 128 | { |
|
108 | 129 | m_dataset->removeSeries(serie); |
|
109 | 130 | } |
|
110 | 131 | } |
|
111 | 132 | |
|
112 | 133 | void tst_ChartDataSet::chartdataset_data() |
|
113 | 134 | { |
|
114 | 135 | } |
|
115 | 136 | |
|
116 | 137 | void tst_ChartDataSet::chartdataset() |
|
117 | 138 | { |
|
118 | 139 | QVERIFY(m_dataset->axisX(0) == 0); |
|
119 | 140 | QVERIFY(m_dataset->axisY(0) == 0); |
|
120 | 141 | QLineSeries* series = new QLineSeries(this); |
|
121 | 142 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
122 | 143 | QVERIFY(m_dataset->domain(series) == 0); |
|
123 | 144 | QVERIFY(m_dataset->axisX(series) == 0); |
|
124 | 145 | QVERIFY(m_dataset->axisY(series) == 0); |
|
125 | 146 | m_dataset->createDefaultAxes(); |
|
126 | 147 | } |
|
127 | 148 | |
|
128 | 149 | |
|
129 | 150 | void tst_ChartDataSet::addSeries_data() |
|
130 | 151 | { |
|
131 | 152 | QTest::addColumn<QAbstractSeries*>("series"); |
|
132 | 153 | |
|
133 | 154 | QAbstractSeries* line = new QLineSeries(this); |
|
134 | 155 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
135 | 156 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
136 | 157 | QAbstractSeries* spline = new QSplineSeries(this); |
|
137 | 158 | QAbstractSeries* pie = new QPieSeries(this); |
|
138 | 159 | QAbstractSeries* bar = new QBarSeries(this); |
|
139 | 160 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
140 | 161 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
141 | 162 | |
|
142 | 163 | QTest::newRow("line") << line; |
|
143 | 164 | QTest::newRow("area") << area; |
|
144 | 165 | QTest::newRow("scatter") << scatter; |
|
145 | 166 | QTest::newRow("spline") << spline; |
|
146 | 167 | QTest::newRow("pie") << pie; |
|
147 | 168 | QTest::newRow("bar") << bar; |
|
148 | 169 | QTest::newRow("percent") << percent; |
|
149 | 170 | QTest::newRow("stacked") << stacked; |
|
150 | 171 | } |
|
151 | 172 | |
|
152 | 173 | void tst_ChartDataSet::addSeries() |
|
153 | 174 | { |
|
154 | 175 | |
|
155 | 176 | QFETCH(QAbstractSeries*, series); |
|
156 | 177 | |
|
157 | 178 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
158 | 179 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
159 | 180 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
160 | 181 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
161 | 182 | |
|
162 | 183 | m_dataset->addSeries(series); |
|
163 | 184 | m_dataset->createDefaultAxes(); |
|
164 | 185 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
165 | 186 | TRY_COMPARE(spy0.count(), 0); |
|
166 | 187 | }else{ |
|
167 | 188 | TRY_COMPARE(spy0.count(), 2); |
|
168 | 189 | } |
|
169 | 190 | TRY_COMPARE(spy1.count(), 0); |
|
170 | 191 | TRY_COMPARE(spy2.count(), 1); |
|
171 | 192 | TRY_COMPARE(spy3.count(), 0); |
|
172 | 193 | } |
|
173 | 194 | |
|
174 | 195 | |
|
175 | 196 | void tst_ChartDataSet::setAxisX_data() |
|
176 | 197 | { |
|
177 | 198 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
178 | 199 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
179 | 200 | QTest::addColumn<int>("axisCount"); |
|
180 | 201 | |
|
181 | 202 | QAbstractSeries* line = new QLineSeries(this); |
|
182 | 203 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
183 | 204 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
184 | 205 | QAbstractSeries* spline = new QSplineSeries(this); |
|
185 | 206 | /*QAbstractSeries* pie = */new QPieSeries(this); |
|
186 | 207 | /*QAbstractSeries* bar = */new QBarSeries(this); |
|
187 | 208 | /*QAbstractSeries* percent = */new QPercentBarSeries(this); |
|
188 | 209 | /*QAbstractSeries* stacked = */new QStackedBarSeries(this); |
|
189 | 210 | |
|
190 | 211 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
191 | 212 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
192 | 213 | << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3; |
|
193 | 214 | |
|
194 | 215 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
195 | 216 | << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1; |
|
196 | 217 | |
|
197 | 218 | QList<QAbstractAxis*> axes0; |
|
198 | 219 | axes0 << new QValueAxis(this) << new QValueAxis(this); |
|
199 | 220 | axes0 << axes0.last(); |
|
200 | 221 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
201 | 222 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
202 | 223 | << axes0 << 2; |
|
203 | 224 | //TODO: add more test cases |
|
204 | 225 | } |
|
205 | 226 | |
|
206 | 227 | void tst_ChartDataSet::setAxisX() |
|
207 | 228 | { |
|
208 | 229 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
209 | 230 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
210 | 231 | QFETCH(int, axisCount); |
|
211 | 232 | |
|
212 | 233 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
213 | 234 | |
|
214 | 235 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
215 | 236 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
216 | 237 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
217 | 238 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
218 | 239 | |
|
219 | 240 | foreach(QAbstractSeries* series, seriesList){ |
|
220 | 241 | m_dataset->addSeries(series); |
|
221 | 242 | } |
|
222 | 243 | |
|
223 | 244 | TRY_COMPARE(spy0.count(), 0); |
|
224 | 245 | TRY_COMPARE(spy1.count(), 0); |
|
225 | 246 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
226 | 247 | TRY_COMPARE(spy3.count(), 0); |
|
227 | 248 | |
|
228 | 249 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
229 | 250 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
230 | 251 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
231 | 252 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
232 | 253 | |
|
233 | 254 | for(int i=0 ; i < seriesList.count(); i++){ |
|
234 | 255 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal); |
|
235 | 256 | } |
|
236 | 257 | |
|
237 | 258 | TRY_COMPARE(spy4.count(), axisCount); |
|
238 | 259 | TRY_COMPARE(spy5.count(), 0); |
|
239 | 260 | TRY_COMPARE(spy6.count(), 0); |
|
240 | 261 | TRY_COMPARE(spy7.count(), 0); |
|
241 | 262 | |
|
242 | 263 | for(int i=0 ; i < seriesList.count(); i++){ |
|
243 | 264 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
244 | 265 | } |
|
245 | 266 | } |
|
246 | 267 | |
|
247 | 268 | void tst_ChartDataSet::setAxisY_data() |
|
248 | 269 | { |
|
249 | 270 | setAxisX_data(); |
|
250 | 271 | } |
|
251 | 272 | |
|
252 | 273 | void tst_ChartDataSet::setAxisY() |
|
253 | 274 | { |
|
254 | 275 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
255 | 276 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
256 | 277 | QFETCH(int, axisCount); |
|
257 | 278 | |
|
258 | 279 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
259 | 280 | |
|
260 | 281 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
261 | 282 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
262 | 283 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
263 | 284 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
264 | 285 | |
|
265 | 286 | foreach(QAbstractSeries* series, seriesList){ |
|
266 | 287 | m_dataset->addSeries(series); |
|
267 | 288 | } |
|
268 | 289 | |
|
269 | 290 | TRY_COMPARE(spy0.count(), 0); |
|
270 | 291 | TRY_COMPARE(spy1.count(), 0); |
|
271 | 292 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
272 | 293 | TRY_COMPARE(spy3.count(), 0); |
|
273 | 294 | |
|
274 | 295 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
275 | 296 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
276 | 297 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
277 | 298 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
278 | 299 | |
|
279 | 300 | for(int i=0 ; i < seriesList.count(); i++){ |
|
280 | 301 | m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical); |
|
281 | 302 | } |
|
282 | 303 | |
|
283 | 304 | TRY_COMPARE(spy4.count(), axisCount); |
|
284 | 305 | TRY_COMPARE(spy5.count(), 0); |
|
285 | 306 | TRY_COMPARE(spy6.count(), 0); |
|
286 | 307 | TRY_COMPARE(spy7.count(), 0); |
|
287 | 308 | |
|
288 | 309 | for(int i=0 ; i < seriesList.count(); i++){ |
|
289 | 310 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
290 | 311 | } |
|
291 | 312 | } |
|
292 | 313 | |
|
293 | 314 | void tst_ChartDataSet::removeSeries_data() |
|
294 | 315 | { |
|
295 | 316 | addSeries_data(); |
|
296 | 317 | } |
|
297 | 318 | |
|
298 | 319 | void tst_ChartDataSet::removeSeries() |
|
299 | 320 | { |
|
300 | 321 | QFETCH(QAbstractSeries*, series); |
|
301 | 322 | |
|
302 | 323 | m_dataset->addSeries(series); |
|
303 | 324 | m_dataset->createDefaultAxes(); |
|
304 | 325 | |
|
305 | 326 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
306 | 327 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
307 | 328 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
308 | 329 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
309 | 330 | |
|
310 | 331 | m_dataset->removeSeries(series); |
|
311 | 332 | |
|
312 | 333 | TRY_COMPARE(spy0.count(), 0); |
|
313 | 334 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
314 | 335 | TRY_COMPARE(spy1.count(), 0); |
|
315 | 336 | } |
|
316 | 337 | else { |
|
317 | 338 | TRY_COMPARE(spy1.count(), 2); |
|
318 | 339 | } |
|
319 | 340 | TRY_COMPARE(spy2.count(), 0); |
|
320 | 341 | TRY_COMPARE(spy3.count(), 1); |
|
321 | 342 | } |
|
322 | 343 | |
|
323 | 344 | void tst_ChartDataSet::removeAllSeries_data() |
|
324 | 345 | { |
|
325 | 346 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
326 | 347 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
327 | 348 | QTest::addColumn<int>("axisCount"); |
|
328 | 349 | |
|
329 | 350 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
330 | 351 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
331 | 352 | << new QScatterSeries(this)) |
|
332 | 353 | << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) |
|
333 | 354 | << new QValueAxis(this)) << 3; |
|
334 | 355 | //TODO: |
|
335 | 356 | } |
|
336 | 357 | |
|
337 | 358 | void tst_ChartDataSet::removeAllSeries() |
|
338 | 359 | { |
|
339 | 360 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
340 | 361 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
341 | 362 | QFETCH(int, axisCount); |
|
342 | 363 | |
|
343 | 364 | foreach(QAbstractSeries* series, seriesList) { |
|
344 | 365 | m_dataset->addSeries(series); |
|
345 | 366 | } |
|
346 | 367 | |
|
347 | 368 | for (int i = 0; i < seriesList.count(); i++) { |
|
348 | 369 | m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal); |
|
349 | 370 | } |
|
350 | 371 | |
|
351 | 372 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
352 | 373 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
353 | 374 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
354 | 375 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
355 | 376 | |
|
356 | 377 | m_dataset->removeAllSeries(); |
|
357 | 378 | |
|
358 | 379 | TRY_COMPARE(spy0.count(), 0); |
|
359 | 380 | TRY_COMPARE(spy1.count(), axisCount); |
|
360 | 381 | TRY_COMPARE(spy2.count(), 0); |
|
361 | 382 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
362 | 383 | } |
|
363 | 384 | |
|
364 | 385 | |
|
365 | 386 | void tst_ChartDataSet::seriesCount_data() |
|
366 | 387 | { |
|
367 | 388 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
368 | 389 | QTest::addColumn<int>("seriesCount"); |
|
369 | 390 | |
|
370 | 391 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
371 | 392 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
372 | 393 | } |
|
373 | 394 | |
|
374 | 395 | void tst_ChartDataSet::seriesCount() |
|
375 | 396 | { |
|
376 | 397 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
377 | 398 | QFETCH(int, seriesCount); |
|
378 | 399 | |
|
379 | 400 | foreach(QAbstractSeries* series, seriesList){ |
|
380 | 401 | m_dataset->addSeries(series); |
|
381 | 402 | } |
|
382 | 403 | |
|
383 | 404 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
384 | 405 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
385 | 406 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
386 | 407 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
387 | 408 | |
|
388 | 409 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
389 | 410 | TRY_COMPARE(spy0.count(), 0); |
|
390 | 411 | TRY_COMPARE(spy1.count(), 0); |
|
391 | 412 | TRY_COMPARE(spy2.count(), 0); |
|
392 | 413 | TRY_COMPARE(spy3.count(), 0); |
|
393 | 414 | } |
|
394 | 415 | |
|
395 | 416 | void tst_ChartDataSet::seriesIndex_data() |
|
396 | 417 | { |
|
397 | 418 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
398 | 419 | |
|
399 | 420 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
400 | 421 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
401 | 422 | } |
|
402 | 423 | |
|
403 | 424 | void tst_ChartDataSet::seriesIndex() |
|
404 | 425 | { |
|
405 | 426 | |
|
406 | 427 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
407 | 428 | |
|
408 | 429 | foreach(QAbstractSeries* series, seriesList) { |
|
409 | 430 | m_dataset->addSeries(series); |
|
410 | 431 | } |
|
411 | 432 | |
|
412 | 433 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
413 | 434 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
414 | 435 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
415 | 436 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
416 | 437 | |
|
417 | 438 | for (int i = 0; i < seriesList.count(); i++) { |
|
418 | 439 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
419 | 440 | } |
|
420 | 441 | |
|
421 | 442 | TRY_COMPARE(spy0.count(), 0); |
|
422 | 443 | TRY_COMPARE(spy1.count(), 0); |
|
423 | 444 | TRY_COMPARE(spy2.count(), 0); |
|
424 | 445 | TRY_COMPARE(spy3.count(), 0); |
|
425 | 446 | |
|
426 | 447 | foreach(QAbstractSeries* series, seriesList) { |
|
427 | 448 | m_dataset->removeSeries(series); |
|
428 | 449 | } |
|
429 | 450 | |
|
430 | 451 | for (int i = 0; i < seriesList.count(); i++) { |
|
431 | 452 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
432 | 453 | } |
|
433 | 454 | |
|
434 | 455 | foreach(QAbstractSeries* series, seriesList) { |
|
435 | 456 | m_dataset->addSeries(series); |
|
436 | 457 | } |
|
437 | 458 | |
|
438 | 459 | for (int i = 0; i < seriesList.count(); i++) { |
|
439 | 460 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
440 | 461 | } |
|
441 | 462 | |
|
442 | 463 | m_dataset->removeSeries(seriesList.at(1)); |
|
443 | 464 | |
|
444 | 465 | for (int i = 0; i < seriesList.count(); i++) { |
|
445 | 466 | if (i != 1) |
|
446 | 467 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
447 | 468 | else |
|
448 | 469 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
449 | 470 | } |
|
450 | 471 | |
|
451 | 472 | m_dataset->addSeries(seriesList.at(1)); |
|
452 | 473 | |
|
453 | 474 | for (int i = 0; i < seriesList.count(); i++) { |
|
454 | 475 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
455 | 476 | } |
|
456 | 477 | |
|
457 | 478 | m_dataset->removeSeries(seriesList.at(2)); |
|
458 | 479 | |
|
459 | 480 | for (int i = 0; i < seriesList.count(); i++) { |
|
460 | 481 | if (i != 2) |
|
461 | 482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
462 | 483 | else |
|
463 | 484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
464 | 485 | } |
|
465 | 486 | |
|
466 | 487 | m_dataset->removeSeries(seriesList.at(0)); |
|
467 | 488 | |
|
468 | 489 | for (int i = 0; i < seriesList.count(); i++) { |
|
469 | 490 | if (i != 2 && i != 0) |
|
470 | 491 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
471 | 492 | else |
|
472 | 493 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
473 | 494 | } |
|
474 | 495 | |
|
475 | 496 | m_dataset->addSeries(seriesList.at(2)); |
|
476 | 497 | m_dataset->addSeries(seriesList.at(0)); |
|
477 | 498 | |
|
478 | 499 | for (int i = 0; i < seriesList.count(); i++) { |
|
479 | 500 | if (i == 2) |
|
480 | 501 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
481 | 502 | else if (i == 0) |
|
482 | 503 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
483 | 504 | else |
|
484 | 505 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
485 | 506 | } |
|
486 | 507 | |
|
487 | 508 | } |
|
488 | 509 | |
|
489 | 510 | void tst_ChartDataSet::domain_data() |
|
490 | 511 | { |
|
491 | 512 | addSeries_data(); |
|
492 | 513 | } |
|
493 | 514 | |
|
494 | 515 | void tst_ChartDataSet::domain() |
|
495 | 516 | { |
|
496 | 517 | QFETCH(QAbstractSeries*, series); |
|
497 | 518 | |
|
498 | 519 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
499 | 520 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
500 | 521 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
501 | 522 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
502 | 523 | |
|
503 | 524 | m_dataset->addSeries(series); |
|
504 | 525 | QVERIFY(m_dataset->domain(series)); |
|
505 | 526 | |
|
506 | 527 | |
|
507 | 528 | TRY_COMPARE(spy0.count(), 0); |
|
508 | 529 | TRY_COMPARE(spy1.count(), 0); |
|
509 | 530 | TRY_COMPARE(spy2.count(), 1); |
|
510 | 531 | |
|
511 | 532 | QList<QVariant> arguments = spy2.takeFirst(); |
|
512 | 533 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
513 | 534 | QVERIFY(m_dataset->domain(series) == domain); |
|
514 | 535 | |
|
515 | 536 | TRY_COMPARE(spy3.count(), 0); |
|
516 | 537 | |
|
517 | 538 | } |
|
518 | 539 | |
|
519 | 540 | void tst_ChartDataSet::zoomInDomain_data() |
|
520 | 541 | { |
|
521 | 542 | QTest::addColumn<bool >("sameAxis"); |
|
522 | 543 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
523 | 544 | QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
524 | 545 | QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
525 | 546 | } |
|
526 | 547 | |
|
527 | 548 | void tst_ChartDataSet::zoomInDomain() |
|
528 | 549 | { |
|
529 | 550 | QFETCH(bool, sameAxis); |
|
530 | 551 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
531 | 552 | |
|
532 | 553 | foreach(QAbstractSeries* series, seriesList) { |
|
533 | 554 | m_dataset->addSeries(series); |
|
534 | 555 | } |
|
535 | 556 | |
|
536 | 557 | if(sameAxis) m_dataset->createDefaultAxes(); |
|
537 | 558 | |
|
538 | 559 | QList<QSignalSpy*> spyList; |
|
539 | 560 | |
|
540 | 561 | foreach(QAbstractSeries* series, seriesList) { |
|
541 | 562 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated())); |
|
542 | 563 | } |
|
543 | 564 | |
|
544 | 565 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
545 | 566 | |
|
546 | 567 | foreach(QSignalSpy* spy, spyList) { |
|
547 | 568 | TRY_COMPARE(spy->count(), 1); |
|
548 | 569 | } |
|
549 | 570 | |
|
550 | 571 | qDeleteAll(spyList); |
|
551 | 572 | } |
|
552 | 573 | |
|
553 | 574 | |
|
554 | 575 | |
|
555 | 576 | void tst_ChartDataSet::zoomOutDomain_data() |
|
556 | 577 | { |
|
557 | 578 | zoomInDomain_data(); |
|
558 | 579 | } |
|
559 | 580 | |
|
560 | 581 | void tst_ChartDataSet::zoomOutDomain() |
|
561 | 582 | { |
|
562 | 583 | QFETCH(bool, sameAxis); |
|
563 | 584 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
564 | 585 | |
|
565 | 586 | foreach(QAbstractSeries* series, seriesList) { |
|
566 | 587 | m_dataset->addSeries(series); |
|
567 | 588 | } |
|
568 | 589 | |
|
569 | 590 | if (sameAxis) |
|
570 | 591 | m_dataset->createDefaultAxes(); |
|
571 | 592 | |
|
572 | 593 | QList<QSignalSpy*> spyList; |
|
573 | 594 | |
|
574 | 595 | foreach(QAbstractSeries* series, seriesList) { |
|
575 | 596 | spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated())); |
|
576 | 597 | } |
|
577 | 598 | |
|
578 | 599 | m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
579 | 600 | |
|
580 | 601 | foreach(QSignalSpy* spy, spyList) { |
|
581 | 602 | TRY_COMPARE(spy->count(), 1); |
|
582 | 603 | } |
|
583 | 604 | |
|
584 | 605 | qDeleteAll (spyList); |
|
585 | 606 | } |
|
586 | 607 | |
|
587 | 608 | void tst_ChartDataSet::scrollDomain_data() |
|
588 | 609 | { |
|
589 | 610 | zoomInDomain_data(); |
|
590 | 611 | } |
|
591 | 612 | |
|
592 | 613 | void tst_ChartDataSet::scrollDomain() |
|
593 | 614 | { |
|
594 | 615 | QFETCH(bool, sameAxis); |
|
595 | 616 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
596 | 617 | |
|
597 | 618 | foreach(QAbstractSeries* series, seriesList) { |
|
598 | 619 | m_dataset->addSeries(series); |
|
599 | 620 | } |
|
600 | 621 | |
|
601 | 622 | if (sameAxis) |
|
602 | 623 | m_dataset->createDefaultAxes(); |
|
603 | 624 | |
|
604 | 625 | QList<QSignalSpy*> spyList; |
|
605 | 626 | |
|
606 | 627 | foreach(QAbstractSeries* series, seriesList) { |
|
607 | 628 | spyList |
|
608 | 629 | << new QSignalSpy(m_dataset->domain(series), |
|
609 | 630 | SIGNAL(updated())); |
|
610 | 631 | } |
|
611 | 632 | |
|
612 | 633 | m_dataset->scrollDomain(10, 10, QSize(1000, 1000)); |
|
613 | 634 | |
|
614 | 635 | foreach(QSignalSpy* spy, spyList) { |
|
615 | 636 | TRY_COMPARE(spy->count(), 1); |
|
616 | 637 | } |
|
617 | 638 | |
|
618 | 639 | qDeleteAll(spyList); |
|
619 | 640 | } |
|
620 | 641 | |
|
621 | 642 | QTEST_MAIN(tst_ChartDataSet) |
|
622 | 643 | #include "tst_chartdataset.moc" |
|
623 | ||
|
644 | #endif |
@@ -1,4 +1,5 | |||
|
1 | 1 | !include( ../auto.pri ) { |
|
2 | 2 | error( "Couldn't find the auto.pri file!" ) |
|
3 | 3 | } |
|
4 | ||
|
4 | 5 | SOURCES += tst_domain.cpp |
@@ -1,681 +1,703 | |||
|
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 | #ifndef BUILD_PRIVATE_UNIT_TESTS | |
|
21 | ||
|
22 | #include <QtTest/QtTest> | |
|
23 | ||
|
24 | class tst_Domain: public QObject { | |
|
25 | ||
|
26 | Q_OBJECT | |
|
27 | ||
|
28 | private Q_SLOTS: | |
|
29 | void skip(); | |
|
30 | ||
|
31 | }; | |
|
32 | ||
|
33 | void tst_Domain::skip() | |
|
34 | { | |
|
35 | QSKIP("This test requires the debug version of library", SkipAll); | |
|
36 | } | |
|
37 | ||
|
38 | QTEST_MAIN(tst_Domain) | |
|
39 | #include "tst_domain.moc" | |
|
40 | ||
|
41 | #else | |
|
20 | 42 | |
|
21 | 43 | #include <QtTest/QtTest> |
|
22 | 44 | #include <private/domain_p.h> |
|
23 | 45 | #include <private/qabstractaxis_p.h> |
|
24 | 46 | #include <tst_definitions.h> |
|
25 | 47 | |
|
26 | 48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 49 | |
|
28 | 50 | Q_DECLARE_METATYPE(Domain*) |
|
29 | 51 | Q_DECLARE_METATYPE(QSizeF) |
|
30 | 52 | |
|
31 | 53 | |
|
32 | 54 | class AxisMock: public QAbstractAxisPrivate |
|
33 | 55 | { |
|
34 | 56 | Q_OBJECT |
|
35 | 57 | public: |
|
36 | 58 | AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);}; |
|
37 | 59 | ChartAxis* createGraphics(ChartPresenter* presenter) |
|
38 | 60 | { |
|
39 | 61 | Q_UNUSED(presenter); |
|
40 | 62 | return 0; |
|
41 | 63 | }; |
|
42 | 64 | void intializeDomain(Domain* domain) |
|
43 | 65 | { |
|
44 | 66 | Q_UNUSED(domain); |
|
45 | 67 | }; |
|
46 | 68 | void setMin(const QVariant &min) |
|
47 | 69 | { |
|
48 | 70 | Q_UNUSED(min); |
|
49 | 71 | } |
|
50 | 72 | qreal min() { return m_min;} |
|
51 | 73 | void setMax(const QVariant &max) |
|
52 | 74 | { |
|
53 | 75 | Q_UNUSED(max); |
|
54 | 76 | } |
|
55 | 77 | qreal max() { return m_max; } |
|
56 | 78 | void setRange(const QVariant &min, const QVariant &max) |
|
57 | 79 | { |
|
58 | 80 | Q_UNUSED(min); |
|
59 | 81 | Q_UNUSED(max); |
|
60 | 82 | }; |
|
61 | 83 | |
|
62 | 84 | int count () const { return m_count; } |
|
63 | 85 | |
|
64 | 86 | void handleDomainUpdated(){}; |
|
65 | 87 | public: |
|
66 | 88 | int m_count; |
|
67 | 89 | qreal m_min; |
|
68 | 90 | qreal m_max; |
|
69 | 91 | }; |
|
70 | 92 | |
|
71 | 93 | class tst_Domain: public QObject |
|
72 | 94 | { |
|
73 | 95 | Q_OBJECT |
|
74 | 96 | |
|
75 | 97 | public Q_SLOTS: |
|
76 | 98 | void initTestCase(); |
|
77 | 99 | void cleanupTestCase(); |
|
78 | 100 | void init(); |
|
79 | 101 | void cleanup(); |
|
80 | 102 | |
|
81 | 103 | private Q_SLOTS: |
|
82 | 104 | void domain(); |
|
83 | 105 | void handleAxisUpdatedX_data(); |
|
84 | 106 | void handleAxisUpdatedX(); |
|
85 | 107 | void handleAxisUpdatedY_data(); |
|
86 | 108 | void handleAxisUpdatedY(); |
|
87 | 109 | void isEmpty_data(); |
|
88 | 110 | void isEmpty(); |
|
89 | 111 | void maxX_data(); |
|
90 | 112 | void maxX(); |
|
91 | 113 | void maxY_data(); |
|
92 | 114 | void maxY(); |
|
93 | 115 | void minX_data(); |
|
94 | 116 | void minX(); |
|
95 | 117 | void minY_data(); |
|
96 | 118 | void minY(); |
|
97 | 119 | void operatorEquals_data(); |
|
98 | 120 | void operatorEquals(); |
|
99 | 121 | void setRange_data(); |
|
100 | 122 | void setRange(); |
|
101 | 123 | void setRangeX_data(); |
|
102 | 124 | void setRangeX(); |
|
103 | 125 | void setRangeY_data(); |
|
104 | 126 | void setRangeY(); |
|
105 | 127 | void spanX_data(); |
|
106 | 128 | void spanX(); |
|
107 | 129 | void spanY_data(); |
|
108 | 130 | void spanY(); |
|
109 | 131 | void zoom_data(); |
|
110 | 132 | void zoom(); |
|
111 | 133 | void move_data(); |
|
112 | 134 | void move(); |
|
113 | 135 | }; |
|
114 | 136 | |
|
115 | 137 | void tst_Domain::initTestCase() |
|
116 | 138 | { |
|
117 | 139 | } |
|
118 | 140 | |
|
119 | 141 | void tst_Domain::cleanupTestCase() |
|
120 | 142 | { |
|
121 | 143 | } |
|
122 | 144 | |
|
123 | 145 | void tst_Domain::init() |
|
124 | 146 | { |
|
125 | 147 | } |
|
126 | 148 | |
|
127 | 149 | void tst_Domain::cleanup() |
|
128 | 150 | { |
|
129 | 151 | } |
|
130 | 152 | |
|
131 | 153 | void tst_Domain::domain() |
|
132 | 154 | { |
|
133 | 155 | Domain domain; |
|
134 | 156 | |
|
135 | 157 | QCOMPARE(domain.isEmpty(), true); |
|
136 | 158 | QCOMPARE(domain.maxX(), 0.0); |
|
137 | 159 | QCOMPARE(domain.maxY(), 0.0); |
|
138 | 160 | QCOMPARE(domain.minX(), 0.0); |
|
139 | 161 | QCOMPARE(domain.minY(), 0.0); |
|
140 | 162 | } |
|
141 | 163 | |
|
142 | 164 | void tst_Domain::handleAxisUpdatedX_data() |
|
143 | 165 | { |
|
144 | 166 | QTest::addColumn<qreal>("min"); |
|
145 | 167 | QTest::addColumn<qreal>("max"); |
|
146 | 168 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
147 | 169 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
148 | 170 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
149 | 171 | } |
|
150 | 172 | |
|
151 | 173 | void tst_Domain::handleAxisUpdatedX() |
|
152 | 174 | { |
|
153 | 175 | QFETCH(qreal, min); |
|
154 | 176 | QFETCH(qreal, max); |
|
155 | 177 | |
|
156 | 178 | Domain domain; |
|
157 | 179 | |
|
158 | 180 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
159 | 181 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
160 | 182 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
161 | 183 | |
|
162 | 184 | AxisMock axis(Qt::Horizontal); |
|
163 | 185 | QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated())); |
|
164 | 186 | axis.m_min=min; |
|
165 | 187 | axis.m_max=max; |
|
166 | 188 | axis.emitUpdated(); |
|
167 | 189 | |
|
168 | 190 | QVERIFY(qFuzzyIsNull(domain.minX() - min)); |
|
169 | 191 | QVERIFY(qFuzzyIsNull(domain.maxX() - max)); |
|
170 | 192 | |
|
171 | 193 | QList<QVariant> arg1 = spy1.first(); |
|
172 | 194 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
173 | 195 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
174 | 196 | |
|
175 | 197 | TRY_COMPARE(spy0.count(), 1); |
|
176 | 198 | TRY_COMPARE(spy1.count(), 1); |
|
177 | 199 | TRY_COMPARE(spy2.count(), 0); |
|
178 | 200 | |
|
179 | 201 | } |
|
180 | 202 | |
|
181 | 203 | void tst_Domain::handleAxisUpdatedY_data() |
|
182 | 204 | { |
|
183 | 205 | QTest::addColumn<qreal>("min"); |
|
184 | 206 | QTest::addColumn<qreal>("max"); |
|
185 | 207 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
186 | 208 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
187 | 209 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
188 | 210 | } |
|
189 | 211 | |
|
190 | 212 | void tst_Domain::handleAxisUpdatedY() |
|
191 | 213 | { |
|
192 | 214 | QFETCH(qreal, min); |
|
193 | 215 | QFETCH(qreal, max); |
|
194 | 216 | |
|
195 | 217 | Domain domain; |
|
196 | 218 | |
|
197 | 219 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
198 | 220 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
199 | 221 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
200 | 222 | |
|
201 | 223 | AxisMock axis(Qt::Vertical); |
|
202 | 224 | QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated())); |
|
203 | 225 | axis.m_min = min; |
|
204 | 226 | axis.m_max = max; |
|
205 | 227 | axis.emitUpdated(); |
|
206 | 228 | |
|
207 | 229 | QVERIFY(qFuzzyIsNull(domain.minY() - min)); |
|
208 | 230 | QVERIFY(qFuzzyIsNull(domain.maxY() - max)); |
|
209 | 231 | |
|
210 | 232 | QList<QVariant> arg1 = spy2.first(); |
|
211 | 233 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
212 | 234 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
213 | 235 | |
|
214 | 236 | TRY_COMPARE(spy0.count(), 1); |
|
215 | 237 | TRY_COMPARE(spy1.count(), 0); |
|
216 | 238 | TRY_COMPARE(spy2.count(), 1); |
|
217 | 239 | } |
|
218 | 240 | |
|
219 | 241 | void tst_Domain::isEmpty_data() |
|
220 | 242 | { |
|
221 | 243 | QTest::addColumn<qreal>("minX"); |
|
222 | 244 | QTest::addColumn<qreal>("maxX"); |
|
223 | 245 | QTest::addColumn<qreal>("minY"); |
|
224 | 246 | QTest::addColumn<qreal>("maxY"); |
|
225 | 247 | QTest::addColumn<bool>("isEmpty"); |
|
226 | 248 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; |
|
227 | 249 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
228 | 250 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
229 | 251 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; |
|
230 | 252 | } |
|
231 | 253 | |
|
232 | 254 | void tst_Domain::isEmpty() |
|
233 | 255 | { |
|
234 | 256 | QFETCH(qreal, minX); |
|
235 | 257 | QFETCH(qreal, maxX); |
|
236 | 258 | QFETCH(qreal, minY); |
|
237 | 259 | QFETCH(qreal, maxY); |
|
238 | 260 | QFETCH(bool, isEmpty); |
|
239 | 261 | |
|
240 | 262 | Domain domain; |
|
241 | 263 | domain.setRange(minX, maxX, minY, maxY); |
|
242 | 264 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
243 | 265 | } |
|
244 | 266 | |
|
245 | 267 | void tst_Domain::maxX_data() |
|
246 | 268 | { |
|
247 | 269 | QTest::addColumn<qreal>("maxX1"); |
|
248 | 270 | QTest::addColumn<qreal>("maxX2"); |
|
249 | 271 | QTest::addColumn<int>("count"); |
|
250 | 272 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
251 | 273 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
252 | 274 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
253 | 275 | } |
|
254 | 276 | |
|
255 | 277 | void tst_Domain::maxX() |
|
256 | 278 | { |
|
257 | 279 | QFETCH(qreal, maxX1); |
|
258 | 280 | QFETCH(qreal, maxX2); |
|
259 | 281 | QFETCH(int, count); |
|
260 | 282 | |
|
261 | 283 | Domain domain; |
|
262 | 284 | |
|
263 | 285 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
264 | 286 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
265 | 287 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
266 | 288 | |
|
267 | 289 | domain.setMaxX(maxX1); |
|
268 | 290 | QCOMPARE(domain.maxX(), maxX1); |
|
269 | 291 | domain.setMaxX(maxX2); |
|
270 | 292 | QCOMPARE(domain.maxX(), maxX2); |
|
271 | 293 | |
|
272 | 294 | TRY_COMPARE(spy0.count(), count); |
|
273 | 295 | TRY_COMPARE(spy1.count(), count); |
|
274 | 296 | TRY_COMPARE(spy2.count(), 0); |
|
275 | 297 | |
|
276 | 298 | } |
|
277 | 299 | |
|
278 | 300 | void tst_Domain::maxY_data() |
|
279 | 301 | { |
|
280 | 302 | QTest::addColumn<qreal>("maxY1"); |
|
281 | 303 | QTest::addColumn<qreal>("maxY2"); |
|
282 | 304 | QTest::addColumn<int>("count"); |
|
283 | 305 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
284 | 306 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
285 | 307 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
286 | 308 | } |
|
287 | 309 | |
|
288 | 310 | void tst_Domain::maxY() |
|
289 | 311 | { |
|
290 | 312 | QFETCH(qreal, maxY1); |
|
291 | 313 | QFETCH(qreal, maxY2); |
|
292 | 314 | QFETCH(int, count); |
|
293 | 315 | |
|
294 | 316 | Domain domain; |
|
295 | 317 | |
|
296 | 318 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
297 | 319 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
298 | 320 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
299 | 321 | |
|
300 | 322 | domain.setMaxY(maxY1); |
|
301 | 323 | QCOMPARE(domain.maxY(), maxY1); |
|
302 | 324 | domain.setMaxY(maxY2); |
|
303 | 325 | QCOMPARE(domain.maxY(), maxY2); |
|
304 | 326 | |
|
305 | 327 | TRY_COMPARE(spy0.count(), count); |
|
306 | 328 | TRY_COMPARE(spy1.count(), 0); |
|
307 | 329 | TRY_COMPARE(spy2.count(), count); |
|
308 | 330 | } |
|
309 | 331 | |
|
310 | 332 | void tst_Domain::minX_data() |
|
311 | 333 | { |
|
312 | 334 | QTest::addColumn<qreal>("minX1"); |
|
313 | 335 | QTest::addColumn<qreal>("minX2"); |
|
314 | 336 | QTest::addColumn<int>("count"); |
|
315 | 337 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
316 | 338 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
317 | 339 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
318 | 340 | } |
|
319 | 341 | |
|
320 | 342 | void tst_Domain::minX() |
|
321 | 343 | { |
|
322 | 344 | QFETCH(qreal, minX1); |
|
323 | 345 | QFETCH(qreal, minX2); |
|
324 | 346 | QFETCH(int, count); |
|
325 | 347 | |
|
326 | 348 | Domain domain; |
|
327 | 349 | |
|
328 | 350 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
329 | 351 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
330 | 352 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
331 | 353 | |
|
332 | 354 | domain.setMinX(minX1); |
|
333 | 355 | QCOMPARE(domain.minX(), minX1); |
|
334 | 356 | domain.setMinX(minX2); |
|
335 | 357 | QCOMPARE(domain.minX(), minX2); |
|
336 | 358 | |
|
337 | 359 | TRY_COMPARE(spy0.count(), count); |
|
338 | 360 | TRY_COMPARE(spy1.count(), count); |
|
339 | 361 | TRY_COMPARE(spy2.count(), 0); |
|
340 | 362 | } |
|
341 | 363 | |
|
342 | 364 | void tst_Domain::minY_data() |
|
343 | 365 | { |
|
344 | 366 | QTest::addColumn<qreal>("minY1"); |
|
345 | 367 | QTest::addColumn<qreal>("minY2"); |
|
346 | 368 | QTest::addColumn<int>("count"); |
|
347 | 369 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
348 | 370 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
349 | 371 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
350 | 372 | } |
|
351 | 373 | |
|
352 | 374 | void tst_Domain::minY() |
|
353 | 375 | { |
|
354 | 376 | QFETCH(qreal, minY1); |
|
355 | 377 | QFETCH(qreal, minY2); |
|
356 | 378 | QFETCH(int, count); |
|
357 | 379 | |
|
358 | 380 | Domain domain; |
|
359 | 381 | |
|
360 | 382 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
361 | 383 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
362 | 384 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
363 | 385 | |
|
364 | 386 | domain.setMinY(minY1); |
|
365 | 387 | QCOMPARE(domain.minY(), minY1); |
|
366 | 388 | domain.setMinY(minY2); |
|
367 | 389 | QCOMPARE(domain.minY(), minY2); |
|
368 | 390 | |
|
369 | 391 | TRY_COMPARE(spy0.count(), count); |
|
370 | 392 | TRY_COMPARE(spy1.count(), 0); |
|
371 | 393 | TRY_COMPARE(spy2.count(), count); |
|
372 | 394 | } |
|
373 | 395 | |
|
374 | 396 | void tst_Domain::operatorEquals_data() |
|
375 | 397 | { |
|
376 | 398 | |
|
377 | 399 | QTest::addColumn<Domain*>("domain1"); |
|
378 | 400 | QTest::addColumn<Domain*>("domain2"); |
|
379 | 401 | QTest::addColumn<bool>("equals"); |
|
380 | 402 | QTest::addColumn<bool>("notEquals"); |
|
381 | 403 | Domain* a; |
|
382 | 404 | Domain* b; |
|
383 | 405 | a = new Domain(); |
|
384 | 406 | a->setRange(0, 100, 0, 100); |
|
385 | 407 | b = new Domain(); |
|
386 | 408 | b->setRange(0, 100, 0, 100); |
|
387 | 409 | QTest::newRow("equals") << a << b << true << false; |
|
388 | 410 | a = new Domain(); |
|
389 | 411 | a->setRange(0, 100, 0, 100); |
|
390 | 412 | b = new Domain(); |
|
391 | 413 | b->setRange(0, 100, 0, 1); |
|
392 | 414 | QTest::newRow("equals") << a << b << false << true; |
|
393 | 415 | a = new Domain(); |
|
394 | 416 | a->setRange(0, 100, 0, 100); |
|
395 | 417 | b = new Domain(); |
|
396 | 418 | b->setRange(0, 1, 0, 100); |
|
397 | 419 | QTest::newRow("equals") << a << b << false << true; |
|
398 | 420 | |
|
399 | 421 | } |
|
400 | 422 | |
|
401 | 423 | void tst_Domain::operatorEquals() |
|
402 | 424 | { |
|
403 | 425 | QFETCH(Domain*, domain1); |
|
404 | 426 | QFETCH(Domain*, domain2); |
|
405 | 427 | QFETCH(bool, equals); |
|
406 | 428 | QFETCH(bool, notEquals); |
|
407 | 429 | |
|
408 | 430 | Domain domain; |
|
409 | 431 | |
|
410 | 432 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
411 | 433 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
412 | 434 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
413 | 435 | |
|
414 | 436 | QCOMPARE(*domain1==*domain2, equals); |
|
415 | 437 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
416 | 438 | |
|
417 | 439 | TRY_COMPARE(spy0.count(), 0); |
|
418 | 440 | TRY_COMPARE(spy1.count(), 0); |
|
419 | 441 | TRY_COMPARE(spy2.count(), 0); |
|
420 | 442 | } |
|
421 | 443 | |
|
422 | 444 | void tst_Domain::setRange_data() |
|
423 | 445 | { |
|
424 | 446 | QTest::addColumn<qreal>("minX"); |
|
425 | 447 | QTest::addColumn<qreal>("maxX"); |
|
426 | 448 | QTest::addColumn<qreal>("minY"); |
|
427 | 449 | QTest::addColumn<qreal>("maxY"); |
|
428 | 450 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
429 | 451 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
430 | 452 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
431 | 453 | } |
|
432 | 454 | |
|
433 | 455 | void tst_Domain::setRange() |
|
434 | 456 | { |
|
435 | 457 | QFETCH(qreal, minX); |
|
436 | 458 | QFETCH(qreal, maxX); |
|
437 | 459 | QFETCH(qreal, minY); |
|
438 | 460 | QFETCH(qreal, maxY); |
|
439 | 461 | |
|
440 | 462 | Domain domain; |
|
441 | 463 | |
|
442 | 464 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
443 | 465 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
444 | 466 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
445 | 467 | |
|
446 | 468 | domain.setRange(minX, maxX, minY, maxY); |
|
447 | 469 | |
|
448 | 470 | QCOMPARE(domain.minX(), minX); |
|
449 | 471 | QCOMPARE(domain.maxX(), maxX); |
|
450 | 472 | QCOMPARE(domain.minY(), minY); |
|
451 | 473 | QCOMPARE(domain.maxY(), maxY); |
|
452 | 474 | |
|
453 | 475 | TRY_COMPARE(spy0.count(), 1); |
|
454 | 476 | TRY_COMPARE(spy1.count(), 1); |
|
455 | 477 | TRY_COMPARE(spy2.count(), 1); |
|
456 | 478 | |
|
457 | 479 | } |
|
458 | 480 | |
|
459 | 481 | void tst_Domain::setRangeX_data() |
|
460 | 482 | { |
|
461 | 483 | QTest::addColumn<qreal>("min"); |
|
462 | 484 | QTest::addColumn<qreal>("max"); |
|
463 | 485 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
464 | 486 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
465 | 487 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
466 | 488 | } |
|
467 | 489 | |
|
468 | 490 | void tst_Domain::setRangeX() |
|
469 | 491 | { |
|
470 | 492 | QFETCH(qreal, min); |
|
471 | 493 | QFETCH(qreal, max); |
|
472 | 494 | |
|
473 | 495 | Domain domain; |
|
474 | 496 | |
|
475 | 497 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
476 | 498 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
477 | 499 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
478 | 500 | |
|
479 | 501 | domain.setRangeX(min, max); |
|
480 | 502 | |
|
481 | 503 | QVERIFY(qFuzzyIsNull(domain.minX() - min)); |
|
482 | 504 | QVERIFY(qFuzzyIsNull(domain.maxX() - max)); |
|
483 | 505 | |
|
484 | 506 | QList<QVariant> arg1 = spy1.first(); |
|
485 | 507 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
486 | 508 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
487 | 509 | |
|
488 | 510 | TRY_COMPARE(spy0.count(), 1); |
|
489 | 511 | TRY_COMPARE(spy1.count(), 1); |
|
490 | 512 | TRY_COMPARE(spy2.count(), 0); |
|
491 | 513 | } |
|
492 | 514 | |
|
493 | 515 | void tst_Domain::setRangeY_data() |
|
494 | 516 | { |
|
495 | 517 | QTest::addColumn<qreal>("min"); |
|
496 | 518 | QTest::addColumn<qreal>("max"); |
|
497 | 519 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
498 | 520 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
499 | 521 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
500 | 522 | } |
|
501 | 523 | |
|
502 | 524 | void tst_Domain::setRangeY() |
|
503 | 525 | { |
|
504 | 526 | QFETCH(qreal, min); |
|
505 | 527 | QFETCH(qreal, max); |
|
506 | 528 | |
|
507 | 529 | Domain domain; |
|
508 | 530 | |
|
509 | 531 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
510 | 532 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
511 | 533 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
512 | 534 | |
|
513 | 535 | domain.setRangeY(min, max); |
|
514 | 536 | |
|
515 | 537 | QVERIFY(qFuzzyIsNull(domain.minY() - min)); |
|
516 | 538 | QVERIFY(qFuzzyIsNull(domain.maxY() - max)); |
|
517 | 539 | |
|
518 | 540 | QList<QVariant> arg1 = spy2.first(); |
|
519 | 541 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
520 | 542 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
521 | 543 | |
|
522 | 544 | TRY_COMPARE(spy0.count(), 1); |
|
523 | 545 | TRY_COMPARE(spy1.count(), 0); |
|
524 | 546 | TRY_COMPARE(spy2.count(), 1); |
|
525 | 547 | } |
|
526 | 548 | |
|
527 | 549 | void tst_Domain::spanX_data() |
|
528 | 550 | { |
|
529 | 551 | QTest::addColumn<qreal>("minX"); |
|
530 | 552 | QTest::addColumn<qreal>("maxX"); |
|
531 | 553 | QTest::addColumn<qreal>("spanX"); |
|
532 | 554 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
533 | 555 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
534 | 556 | } |
|
535 | 557 | |
|
536 | 558 | void tst_Domain::spanX() |
|
537 | 559 | { |
|
538 | 560 | QFETCH(qreal, minX); |
|
539 | 561 | QFETCH(qreal, maxX); |
|
540 | 562 | QFETCH(qreal, spanX); |
|
541 | 563 | |
|
542 | 564 | Domain domain; |
|
543 | 565 | |
|
544 | 566 | domain.setRangeX(minX, maxX); |
|
545 | 567 | |
|
546 | 568 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
547 | 569 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
548 | 570 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
549 | 571 | |
|
550 | 572 | QCOMPARE(domain.spanX(), spanX); |
|
551 | 573 | |
|
552 | 574 | TRY_COMPARE(spy0.count(), 0); |
|
553 | 575 | TRY_COMPARE(spy1.count(), 0); |
|
554 | 576 | TRY_COMPARE(spy2.count(), 0); |
|
555 | 577 | } |
|
556 | 578 | |
|
557 | 579 | void tst_Domain::spanY_data() |
|
558 | 580 | { |
|
559 | 581 | QTest::addColumn<qreal>("minY"); |
|
560 | 582 | QTest::addColumn<qreal>("maxY"); |
|
561 | 583 | QTest::addColumn<qreal>("spanY"); |
|
562 | 584 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
563 | 585 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
564 | 586 | } |
|
565 | 587 | |
|
566 | 588 | void tst_Domain::spanY() |
|
567 | 589 | { |
|
568 | 590 | QFETCH(qreal, minY); |
|
569 | 591 | QFETCH(qreal, maxY); |
|
570 | 592 | QFETCH(qreal, spanY); |
|
571 | 593 | |
|
572 | 594 | Domain domain; |
|
573 | 595 | |
|
574 | 596 | domain.setRangeY(minY, maxY); |
|
575 | 597 | |
|
576 | 598 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
577 | 599 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
578 | 600 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
579 | 601 | |
|
580 | 602 | QCOMPARE(domain.spanY(), spanY); |
|
581 | 603 | |
|
582 | 604 | TRY_COMPARE(spy0.count(), 0); |
|
583 | 605 | TRY_COMPARE(spy1.count(), 0); |
|
584 | 606 | TRY_COMPARE(spy2.count(), 0); |
|
585 | 607 | } |
|
586 | 608 | |
|
587 | 609 | void tst_Domain::zoom_data() |
|
588 | 610 | { |
|
589 | 611 | QTest::addColumn<QRectF>("rect0"); |
|
590 | 612 | QTest::addColumn<QSizeF>("size0"); |
|
591 | 613 | QTest::addColumn<QRectF>("rect1"); |
|
592 | 614 | QTest::addColumn<QSizeF>("size1"); |
|
593 | 615 | QTest::addColumn<QRectF>("rect2"); |
|
594 | 616 | QTest::addColumn<QSizeF>("size2"); |
|
595 | 617 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) |
|
596 | 618 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
597 | 619 | << QSizeF(1000, 1000); |
|
598 | 620 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) |
|
599 | 621 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
600 | 622 | << QSizeF(1000, 1000); |
|
601 | 623 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) |
|
602 | 624 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); |
|
603 | 625 | } |
|
604 | 626 | |
|
605 | 627 | void tst_Domain::zoom() |
|
606 | 628 | { |
|
607 | 629 | QFETCH(QRectF, rect0); |
|
608 | 630 | QFETCH(QSizeF, size0); |
|
609 | 631 | QFETCH(QRectF, rect1); |
|
610 | 632 | QFETCH(QSizeF, size1); |
|
611 | 633 | QFETCH(QRectF, rect2); |
|
612 | 634 | QFETCH(QSizeF, size2); |
|
613 | 635 | |
|
614 | 636 | Domain domain; |
|
615 | 637 | |
|
616 | 638 | domain.setRange(0, 1000, 0, 1000); |
|
617 | 639 | |
|
618 | 640 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
619 | 641 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
620 | 642 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
621 | 643 | |
|
622 | 644 | Domain domain0; |
|
623 | 645 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
624 | 646 | domain.zoomIn(rect0, size0); |
|
625 | 647 | Domain domain1; |
|
626 | 648 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
627 | 649 | domain.zoomIn(rect1, size1); |
|
628 | 650 | Domain domain2; |
|
629 | 651 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
630 | 652 | domain.zoomIn(rect2, size2); |
|
631 | 653 | domain.zoomOut(rect2, size2); |
|
632 | 654 | QCOMPARE(domain == domain2, true); |
|
633 | 655 | domain.zoomOut(rect1, size1); |
|
634 | 656 | QCOMPARE(domain == domain1, true); |
|
635 | 657 | domain.zoomOut(rect0, size0); |
|
636 | 658 | QCOMPARE(domain == domain0, true); |
|
637 | 659 | TRY_COMPARE(spy0.count(), 6); |
|
638 | 660 | TRY_COMPARE(spy1.count(), 6); |
|
639 | 661 | TRY_COMPARE(spy2.count(), 6); |
|
640 | 662 | } |
|
641 | 663 | |
|
642 | 664 | void tst_Domain::move_data() |
|
643 | 665 | { |
|
644 | 666 | QTest::addColumn<int>("dx"); |
|
645 | 667 | QTest::addColumn<int>("dy"); |
|
646 | 668 | QTest::addColumn<QSizeF>("size"); |
|
647 | 669 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); |
|
648 | 670 | QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); |
|
649 | 671 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); |
|
650 | 672 | QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); |
|
651 | 673 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); |
|
652 | 674 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); |
|
653 | 675 | } |
|
654 | 676 | |
|
655 | 677 | void tst_Domain::move() |
|
656 | 678 | { |
|
657 | 679 | QFETCH(int, dx); |
|
658 | 680 | QFETCH(int, dy); |
|
659 | 681 | QFETCH(QSizeF, size); |
|
660 | 682 | Domain domain; |
|
661 | 683 | |
|
662 | 684 | domain.setRange(0, size.width(), 0, size.height()); |
|
663 | 685 | |
|
664 | 686 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
665 | 687 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal))); |
|
666 | 688 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal))); |
|
667 | 689 | |
|
668 | 690 | domain.move(dx, dy, size); |
|
669 | 691 | |
|
670 | 692 | Domain result; |
|
671 | 693 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); |
|
672 | 694 | |
|
673 | 695 | QCOMPARE(domain == result, true); |
|
674 | 696 | TRY_COMPARE(spy0.count(), 1); |
|
675 | 697 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); |
|
676 | 698 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); |
|
677 | 699 | } |
|
678 | 700 | |
|
679 | 701 | QTEST_MAIN(tst_Domain) |
|
680 | 702 | #include "tst_domain.moc" |
|
681 | ||
|
703 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now