@@ -1,403 +1,410 | |||||
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 | #ifndef BUILD_PRIVATE_UNIT_TESTS |
|
20 | #ifndef BUILD_PRIVATE_UNIT_TESTS | |
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 |
|
22 | |||
23 | class tst_ChartDataSet: public QObject { |
|
23 | class tst_ChartDataSet: public QObject { | |
24 |
|
24 | |||
25 | Q_OBJECT |
|
25 | Q_OBJECT | |
26 |
|
26 | |||
27 | private Q_SLOTS: |
|
27 | private Q_SLOTS: | |
28 | void skip(); |
|
28 | void skip(); | |
29 |
|
29 | |||
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | void tst_ChartDataSet::skip() |
|
32 | void tst_ChartDataSet::skip() | |
33 | { |
|
33 | { | |
34 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
34 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
35 | QSKIP("This test requires the debug version of library"); |
|
35 | QSKIP("This test requires the debug version of library"); | |
36 | #else |
|
36 | #else | |
37 | QSKIP("This test requires the debug version of library", SkipAll); |
|
37 | QSKIP("This test requires the debug version of library", SkipAll); | |
38 | #endif |
|
38 | #endif | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QTEST_MAIN(tst_ChartDataSet) |
|
41 | QTEST_MAIN(tst_ChartDataSet) | |
42 | #include "tst_chartdataset.moc" |
|
42 | #include "tst_chartdataset.moc" | |
43 |
|
43 | |||
44 | #else |
|
44 | #else | |
45 |
|
45 | |||
46 | #include <QtTest/QtTest> |
|
46 | #include <QtTest/QtTest> | |
47 | #include <qabstractaxis.h> |
|
47 | #include <qabstractaxis.h> | |
48 | #include <qvalueaxis.h> |
|
48 | #include <qvalueaxis.h> | |
49 | #include <qbarcategoryaxis.h> |
|
49 | #include <qbarcategoryaxis.h> | |
50 | #include <qcategoryaxis.h> |
|
50 | #include <qcategoryaxis.h> | |
51 | #include <qdatetimeaxis.h> |
|
51 | #ifndef QT_ON_ARM | |
|
52 | #include "qdatetimeaxis.h" | |||
|
53 | #endif | |||
52 | #include <qlineseries.h> |
|
54 | #include <qlineseries.h> | |
53 | #include <qareaseries.h> |
|
55 | #include <qareaseries.h> | |
54 | #include <qscatterseries.h> |
|
56 | #include <qscatterseries.h> | |
55 | #include <qsplineseries.h> |
|
57 | #include <qsplineseries.h> | |
56 | #include <qpieseries.h> |
|
58 | #include <qpieseries.h> | |
57 | #include <qbarseries.h> |
|
59 | #include <qbarseries.h> | |
58 | #include <qpercentbarseries.h> |
|
60 | #include <qpercentbarseries.h> | |
59 | #include <qstackedbarseries.h> |
|
61 | #include <qstackedbarseries.h> | |
60 | #include <private/chartdataset_p.h> |
|
62 | #include <private/chartdataset_p.h> | |
61 | #include <private/abstractdomain_p.h> |
|
63 | #include <private/abstractdomain_p.h> | |
62 | #include <tst_definitions.h> |
|
64 | #include <tst_definitions.h> | |
63 |
|
65 | |||
64 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
66 | QTCOMMERCIALCHART_USE_NAMESPACE | |
65 |
|
67 | |||
66 | Q_DECLARE_METATYPE(AbstractDomain *) |
|
68 | Q_DECLARE_METATYPE(AbstractDomain *) | |
67 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
69 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
68 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
70 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
69 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
71 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
70 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
72 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
71 | Q_DECLARE_METATYPE(Qt::Alignment) |
|
73 | Q_DECLARE_METATYPE(Qt::Alignment) | |
72 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) |
|
74 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) | |
73 | Q_DECLARE_METATYPE(QLineSeries *) |
|
75 | Q_DECLARE_METATYPE(QLineSeries *) | |
74 |
|
76 | |||
75 | class tst_ChartDataSet: public QObject { |
|
77 | class tst_ChartDataSet: public QObject { | |
76 |
|
78 | |||
77 | Q_OBJECT |
|
79 | Q_OBJECT | |
78 | public: |
|
80 | public: | |
79 | tst_ChartDataSet():m_dataset(0){}; |
|
81 | tst_ChartDataSet():m_dataset(0){}; | |
80 |
|
82 | |||
81 | public Q_SLOTS: |
|
83 | public Q_SLOTS: | |
82 | void initTestCase(); |
|
84 | void initTestCase(); | |
83 | void cleanupTestCase(); |
|
85 | void cleanupTestCase(); | |
84 | void init(); |
|
86 | void init(); | |
85 | void cleanup(); |
|
87 | void cleanup(); | |
86 |
|
88 | |||
87 | private Q_SLOTS: |
|
89 | private Q_SLOTS: | |
88 | void chartdataset_data(); |
|
90 | void chartdataset_data(); | |
89 | void chartdataset(); |
|
91 | void chartdataset(); | |
90 | void addSeries_data(); |
|
92 | void addSeries_data(); | |
91 | void addSeries(); |
|
93 | void addSeries(); | |
92 | void removeSeries_data(); |
|
94 | void removeSeries_data(); | |
93 | void removeSeries(); |
|
95 | void removeSeries(); | |
94 | void addAxis_data(); |
|
96 | void addAxis_data(); | |
95 | void addAxis(); |
|
97 | void addAxis(); | |
96 | void removeAxis_data(); |
|
98 | void removeAxis_data(); | |
97 | void removeAxis(); |
|
99 | void removeAxis(); | |
98 | void attachAxis_data(); |
|
100 | void attachAxis_data(); | |
99 | void attachAxis(); |
|
101 | void attachAxis(); | |
100 | void detachAxis_data(); |
|
102 | void detachAxis_data(); | |
101 | void detachAxis(); |
|
103 | void detachAxis(); | |
102 |
|
104 | |||
103 | private: |
|
105 | private: | |
104 | ChartDataSet* m_dataset; |
|
106 | ChartDataSet* m_dataset; | |
105 | }; |
|
107 | }; | |
106 |
|
108 | |||
107 | void tst_ChartDataSet::initTestCase() |
|
109 | void tst_ChartDataSet::initTestCase() | |
108 | { |
|
110 | { | |
109 | qRegisterMetaType<AbstractDomain*>(); |
|
111 | qRegisterMetaType<AbstractDomain*>(); | |
110 | qRegisterMetaType<QAbstractAxis*>(); |
|
112 | qRegisterMetaType<QAbstractAxis*>(); | |
111 | qRegisterMetaType<QAbstractSeries*>(); |
|
113 | qRegisterMetaType<QAbstractSeries*>(); | |
112 | } |
|
114 | } | |
113 |
|
115 | |||
114 | void tst_ChartDataSet::cleanupTestCase() |
|
116 | void tst_ChartDataSet::cleanupTestCase() | |
115 | { |
|
117 | { | |
116 | } |
|
118 | } | |
117 |
|
119 | |||
118 | void tst_ChartDataSet::init() |
|
120 | void tst_ChartDataSet::init() | |
119 | { |
|
121 | { | |
120 | Q_ASSERT(!m_dataset); |
|
122 | Q_ASSERT(!m_dataset); | |
121 | m_dataset = new ChartDataSet(0); |
|
123 | m_dataset = new ChartDataSet(0); | |
122 | } |
|
124 | } | |
123 |
|
125 | |||
124 |
|
126 | |||
125 | void tst_ChartDataSet::cleanup() |
|
127 | void tst_ChartDataSet::cleanup() | |
126 | { |
|
128 | { | |
127 | delete m_dataset; |
|
129 | delete m_dataset; | |
128 | m_dataset=0; |
|
130 | m_dataset=0; | |
129 | } |
|
131 | } | |
130 |
|
132 | |||
131 | void tst_ChartDataSet::chartdataset_data() |
|
133 | void tst_ChartDataSet::chartdataset_data() | |
132 | { |
|
134 | { | |
133 | } |
|
135 | } | |
134 |
|
136 | |||
135 | void tst_ChartDataSet::chartdataset() |
|
137 | void tst_ChartDataSet::chartdataset() | |
136 | { |
|
138 | { | |
137 | QVERIFY(m_dataset->axes().isEmpty()); |
|
139 | QVERIFY(m_dataset->axes().isEmpty()); | |
138 | QVERIFY(m_dataset->series().isEmpty()); |
|
140 | QVERIFY(m_dataset->series().isEmpty()); | |
139 | m_dataset->createDefaultAxes(); |
|
141 | m_dataset->createDefaultAxes(); | |
140 | } |
|
142 | } | |
141 |
|
143 | |||
142 |
|
144 | |||
143 | void tst_ChartDataSet::addSeries_data() |
|
145 | void tst_ChartDataSet::addSeries_data() | |
144 | { |
|
146 | { | |
145 | QTest::addColumn<QAbstractSeries*>("series"); |
|
147 | QTest::addColumn<QAbstractSeries*>("series"); | |
146 |
|
148 | |||
147 | QAbstractSeries* line = new QLineSeries(this); |
|
149 | QAbstractSeries* line = new QLineSeries(this); | |
148 | QTest::newRow("line") << line; |
|
150 | QTest::newRow("line") << line; | |
149 |
|
151 | |||
150 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); |
|
152 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); | |
151 | QTest::newRow("area") << area; |
|
153 | QTest::newRow("area") << area; | |
152 |
|
154 | |||
153 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
155 | QAbstractSeries* scatter = new QScatterSeries(this); | |
154 | QTest::newRow("scatter") << scatter; |
|
156 | QTest::newRow("scatter") << scatter; | |
155 |
|
157 | |||
156 | QAbstractSeries* spline = new QSplineSeries(this); |
|
158 | QAbstractSeries* spline = new QSplineSeries(this); | |
157 | QTest::newRow("spline") << spline; |
|
159 | QTest::newRow("spline") << spline; | |
158 |
|
160 | |||
159 | QAbstractSeries* pie = new QPieSeries(this); |
|
161 | QAbstractSeries* pie = new QPieSeries(this); | |
160 | QTest::newRow("pie") << pie; |
|
162 | QTest::newRow("pie") << pie; | |
161 |
|
163 | |||
162 | QAbstractSeries* bar = new QBarSeries(this); |
|
164 | QAbstractSeries* bar = new QBarSeries(this); | |
163 | QTest::newRow("bar") << bar; |
|
165 | QTest::newRow("bar") << bar; | |
164 |
|
166 | |||
165 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
167 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
166 | QTest::newRow("percent") << percent; |
|
168 | QTest::newRow("percent") << percent; | |
167 |
|
169 | |||
168 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
170 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
169 | QTest::newRow("stacked") << stacked; |
|
171 | QTest::newRow("stacked") << stacked; | |
170 | } |
|
172 | } | |
171 |
|
173 | |||
172 | void tst_ChartDataSet::addSeries() |
|
174 | void tst_ChartDataSet::addSeries() | |
173 | { |
|
175 | { | |
174 | QFETCH(QAbstractSeries*, series); |
|
176 | QFETCH(QAbstractSeries*, series); | |
175 | QVERIFY(m_dataset->series().isEmpty()); |
|
177 | QVERIFY(m_dataset->series().isEmpty()); | |
176 |
|
178 | |||
177 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
179 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
178 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
180 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
179 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
181 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
180 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
182 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
181 |
|
183 | |||
182 | m_dataset->addSeries(series); |
|
184 | m_dataset->addSeries(series); | |
183 |
|
185 | |||
184 | QCOMPARE(m_dataset->series().count(),1); |
|
186 | QCOMPARE(m_dataset->series().count(),1); | |
185 | TRY_COMPARE(spy0.count(), 0); |
|
187 | TRY_COMPARE(spy0.count(), 0); | |
186 | TRY_COMPARE(spy1.count(), 0); |
|
188 | TRY_COMPARE(spy1.count(), 0); | |
187 | TRY_COMPARE(spy2.count(), 1); |
|
189 | TRY_COMPARE(spy2.count(), 1); | |
188 | TRY_COMPARE(spy3.count(), 0); |
|
190 | TRY_COMPARE(spy3.count(), 0); | |
189 | } |
|
191 | } | |
190 |
|
192 | |||
191 | void tst_ChartDataSet::removeSeries_data() |
|
193 | void tst_ChartDataSet::removeSeries_data() | |
192 | { |
|
194 | { | |
193 | addSeries_data(); |
|
195 | addSeries_data(); | |
194 | } |
|
196 | } | |
195 |
|
197 | |||
196 | void tst_ChartDataSet::removeSeries() |
|
198 | void tst_ChartDataSet::removeSeries() | |
197 | { |
|
199 | { | |
198 | QFETCH(QAbstractSeries*, series); |
|
200 | QFETCH(QAbstractSeries*, series); | |
199 | QVERIFY(m_dataset->series().isEmpty()); |
|
201 | QVERIFY(m_dataset->series().isEmpty()); | |
200 | m_dataset->addSeries(series); |
|
202 | m_dataset->addSeries(series); | |
201 |
|
203 | |||
202 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
204 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
203 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
205 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
204 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
206 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
205 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
207 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
206 |
|
208 | |||
207 | m_dataset->removeSeries(series); |
|
209 | m_dataset->removeSeries(series); | |
208 |
|
210 | |||
209 | QCOMPARE(m_dataset->series().count(),0); |
|
211 | QCOMPARE(m_dataset->series().count(),0); | |
210 | TRY_COMPARE(spy0.count(), 0); |
|
212 | TRY_COMPARE(spy0.count(), 0); | |
211 | TRY_COMPARE(spy1.count(), 0); |
|
213 | TRY_COMPARE(spy1.count(), 0); | |
212 | TRY_COMPARE(spy2.count(), 0); |
|
214 | TRY_COMPARE(spy2.count(), 0); | |
213 | TRY_COMPARE(spy3.count(), 1); |
|
215 | TRY_COMPARE(spy3.count(), 1); | |
214 | } |
|
216 | } | |
215 |
|
217 | |||
216 | void tst_ChartDataSet::addAxis_data() |
|
218 | void tst_ChartDataSet::addAxis_data() | |
217 | { |
|
219 | { | |
218 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
220 | QTest::addColumn<QAbstractAxis*>("axis"); | |
219 | QAbstractAxis* value = new QValueAxis(this); |
|
221 | QAbstractAxis* value = new QValueAxis(this); | |
220 | QAbstractAxis* category = new QCategoryAxis(this); |
|
222 | QAbstractAxis* category = new QCategoryAxis(this); | |
221 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
223 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
|
224 | #ifndef Q_WS_QWS | |||
222 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
225 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
|
226 | #endif | |||
223 |
|
227 | |||
224 | QTest::newRow("value") << value; |
|
228 | QTest::newRow("value") << value; | |
225 | QTest::newRow("category") << category; |
|
229 | QTest::newRow("category") << category; | |
226 | QTest::newRow("barcategory") << barcategory; |
|
230 | QTest::newRow("barcategory") << barcategory; | |
|
231 | #ifndef Q_WS_QWS | |||
227 | QTest::newRow("datetime") << datetime; |
|
232 | QTest::newRow("datetime") << datetime; | |
|
233 | #endif | |||
228 | } |
|
234 | } | |
229 |
|
235 | |||
230 | void tst_ChartDataSet::addAxis() |
|
236 | void tst_ChartDataSet::addAxis() | |
231 | { |
|
237 | { | |
232 | QFETCH(QAbstractAxis*, axis); |
|
238 | QFETCH(QAbstractAxis*, axis); | |
233 | QVERIFY(m_dataset->axes().isEmpty()); |
|
239 | QVERIFY(m_dataset->axes().isEmpty()); | |
234 |
|
240 | |||
235 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
241 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
236 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
242 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
237 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
243 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
238 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
244 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
239 |
|
245 | |||
240 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
246 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
241 |
|
247 | |||
242 | QCOMPARE(m_dataset->axes().count(),1); |
|
248 | QCOMPARE(m_dataset->axes().count(),1); | |
243 | TRY_COMPARE(spy0.count(), 1); |
|
249 | TRY_COMPARE(spy0.count(), 1); | |
244 | TRY_COMPARE(spy1.count(), 0); |
|
250 | TRY_COMPARE(spy1.count(), 0); | |
245 | TRY_COMPARE(spy2.count(), 0); |
|
251 | TRY_COMPARE(spy2.count(), 0); | |
246 | TRY_COMPARE(spy3.count(), 0); |
|
252 | TRY_COMPARE(spy3.count(), 0); | |
247 | } |
|
253 | } | |
248 |
|
254 | |||
249 | void tst_ChartDataSet::removeAxis_data() |
|
255 | void tst_ChartDataSet::removeAxis_data() | |
250 | { |
|
256 | { | |
251 | addAxis_data(); |
|
257 | addAxis_data(); | |
252 | } |
|
258 | } | |
253 |
|
259 | |||
254 | void tst_ChartDataSet::removeAxis() |
|
260 | void tst_ChartDataSet::removeAxis() | |
255 | { |
|
261 | { | |
256 | QFETCH(QAbstractAxis*, axis); |
|
262 | QFETCH(QAbstractAxis*, axis); | |
257 | QVERIFY(m_dataset->series().isEmpty()); |
|
263 | QVERIFY(m_dataset->series().isEmpty()); | |
258 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
264 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
259 |
|
265 | |||
260 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
266 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
261 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
267 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
262 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
268 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
263 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
269 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
264 |
|
270 | |||
265 | m_dataset->removeAxis(axis); |
|
271 | m_dataset->removeAxis(axis); | |
266 |
|
272 | |||
267 | QCOMPARE(m_dataset->axes().count(),0); |
|
273 | QCOMPARE(m_dataset->axes().count(),0); | |
268 | QCOMPARE(m_dataset->series().count(),0); |
|
274 | QCOMPARE(m_dataset->series().count(),0); | |
269 | TRY_COMPARE(spy0.count(), 0); |
|
275 | TRY_COMPARE(spy0.count(), 0); | |
270 | TRY_COMPARE(spy1.count(), 1); |
|
276 | TRY_COMPARE(spy1.count(), 1); | |
271 | TRY_COMPARE(spy2.count(), 0); |
|
277 | TRY_COMPARE(spy2.count(), 0); | |
272 | TRY_COMPARE(spy3.count(), 0); |
|
278 | TRY_COMPARE(spy3.count(), 0); | |
273 | } |
|
279 | } | |
274 |
|
280 | |||
275 | void tst_ChartDataSet::attachAxis_data() |
|
281 | void tst_ChartDataSet::attachAxis_data() | |
276 | { |
|
282 | { | |
277 |
|
283 | |||
278 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
284 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
279 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
285 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
280 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
286 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); | |
281 | QTest::addColumn<QAbstractSeries*>("attachSeries"); |
|
287 | QTest::addColumn<QAbstractSeries*>("attachSeries"); | |
282 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
288 | QTest::addColumn<QAbstractAxis*>("attachAxis"); | |
283 | QTest::addColumn<bool>("success"); |
|
289 | QTest::addColumn<bool>("success"); | |
284 |
|
290 | |||
285 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
291 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
286 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
292 | QAbstractSeries* scatter = new QScatterSeries(this); | |
287 | QAbstractSeries* spline = new QSplineSeries(this); |
|
293 | QAbstractSeries* spline = new QSplineSeries(this); | |
288 | QAbstractSeries* pie = new QPieSeries(this); |
|
294 | QAbstractSeries* pie = new QPieSeries(this); | |
289 | QAbstractSeries* bar = new QBarSeries(this); |
|
295 | QAbstractSeries* bar = new QBarSeries(this); | |
290 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
296 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
291 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
297 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
292 |
|
298 | |||
293 | QAbstractAxis* category = new QCategoryAxis(this); |
|
299 | QAbstractAxis* category = new QCategoryAxis(this); | |
294 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
300 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
|
301 | #ifndef Q_WS_QWS | |||
295 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
302 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
296 |
|
303 | #endif | ||
297 | { |
|
304 | { | |
298 | QList<QAbstractSeries*> series; |
|
305 | QList<QAbstractSeries*> series; | |
299 | QList<QAbstractAxis*> axes; |
|
306 | QList<QAbstractAxis*> axes; | |
300 | QList<Qt::Alignment> alignment; |
|
307 | QList<Qt::Alignment> alignment; | |
301 | QAbstractSeries* line = new QLineSeries(this); |
|
308 | QAbstractSeries* line = new QLineSeries(this); | |
302 | QAbstractAxis* value1 = new QValueAxis(this); |
|
309 | QAbstractAxis* value1 = new QValueAxis(this); | |
303 | QAbstractAxis* value2 = new QValueAxis(this); |
|
310 | QAbstractAxis* value2 = new QValueAxis(this); | |
304 | series << line << 0; |
|
311 | series << line << 0; | |
305 | axes << value1 << value2; |
|
312 | axes << value1 << value2; | |
306 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
313 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
307 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; |
|
314 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; | |
308 | } |
|
315 | } | |
309 |
|
316 | |||
310 | { |
|
317 | { | |
311 | QList<QAbstractSeries*> series; |
|
318 | QList<QAbstractSeries*> series; | |
312 | QList<QAbstractAxis*> axes; |
|
319 | QList<QAbstractAxis*> axes; | |
313 | QList<Qt::Alignment> alignment; |
|
320 | QList<Qt::Alignment> alignment; | |
314 | QAbstractSeries* line = new QLineSeries(this); |
|
321 | QAbstractSeries* line = new QLineSeries(this); | |
315 | QAbstractAxis* value1 = new QValueAxis(this); |
|
322 | QAbstractAxis* value1 = new QValueAxis(this); | |
316 | QAbstractAxis* value2 = new QValueAxis(this); |
|
323 | QAbstractAxis* value2 = new QValueAxis(this); | |
317 | series << 0 << line; |
|
324 | series << 0 << line; | |
318 | axes << value1 << value2; |
|
325 | axes << value1 << value2; | |
319 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
326 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
320 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; |
|
327 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; | |
321 | } |
|
328 | } | |
322 |
|
329 | |||
323 | } |
|
330 | } | |
324 |
|
331 | |||
325 | void tst_ChartDataSet::attachAxis() |
|
332 | void tst_ChartDataSet::attachAxis() | |
326 | { |
|
333 | { | |
327 | QFETCH(QList<QAbstractSeries*>, series); |
|
334 | QFETCH(QList<QAbstractSeries*>, series); | |
328 | QFETCH(QList<QAbstractAxis*>, axis); |
|
335 | QFETCH(QList<QAbstractAxis*>, axis); | |
329 | QFETCH(QList<Qt::Alignment>, alignment); |
|
336 | QFETCH(QList<Qt::Alignment>, alignment); | |
330 | QFETCH(QAbstractSeries*, attachSeries); |
|
337 | QFETCH(QAbstractSeries*, attachSeries); | |
331 | QFETCH(QAbstractAxis*, attachAxis); |
|
338 | QFETCH(QAbstractAxis*, attachAxis); | |
332 | QFETCH(bool, success); |
|
339 | QFETCH(bool, success); | |
333 |
|
340 | |||
334 | Q_ASSERT(series.count() == axis.count()); |
|
341 | Q_ASSERT(series.count() == axis.count()); | |
335 | Q_ASSERT(series.count() == alignment.count()); |
|
342 | Q_ASSERT(series.count() == alignment.count()); | |
336 |
|
343 | |||
337 | QVERIFY(m_dataset->series().isEmpty()); |
|
344 | QVERIFY(m_dataset->series().isEmpty()); | |
338 | QVERIFY(m_dataset->axes().isEmpty()); |
|
345 | QVERIFY(m_dataset->axes().isEmpty()); | |
339 |
|
346 | |||
340 | for(int i = 0 ; i < series.count() ; i++){ |
|
347 | for(int i = 0 ; i < series.count() ; i++){ | |
341 | if(series[i]) m_dataset->addSeries(series[i]); |
|
348 | if(series[i]) m_dataset->addSeries(series[i]); | |
342 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); |
|
349 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); | |
343 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
350 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |
344 | } |
|
351 | } | |
345 |
|
352 | |||
346 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
353 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
347 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
354 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
348 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
355 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
349 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
356 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
350 |
|
357 | |||
351 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); |
|
358 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); | |
352 |
|
359 | |||
353 | } |
|
360 | } | |
354 |
|
361 | |||
355 | void tst_ChartDataSet::detachAxis_data() |
|
362 | void tst_ChartDataSet::detachAxis_data() | |
356 | { |
|
363 | { | |
357 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
364 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
358 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
365 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
359 | QTest::addColumn<QAbstractSeries*>("detachSeries"); |
|
366 | QTest::addColumn<QAbstractSeries*>("detachSeries"); | |
360 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
367 | QTest::addColumn<QAbstractAxis*>("detachAxis"); | |
361 | QTest::addColumn<bool>("success"); |
|
368 | QTest::addColumn<bool>("success"); | |
362 |
|
369 | |||
363 | { |
|
370 | { | |
364 | QList<QAbstractSeries*> series; |
|
371 | QList<QAbstractSeries*> series; | |
365 | QList<QAbstractAxis*> axes; |
|
372 | QList<QAbstractAxis*> axes; | |
366 | QAbstractSeries* line = new QLineSeries(this); |
|
373 | QAbstractSeries* line = new QLineSeries(this); | |
367 | QAbstractAxis* value = new QValueAxis(this); |
|
374 | QAbstractAxis* value = new QValueAxis(this); | |
368 | series << line; |
|
375 | series << line; | |
369 | axes << value; |
|
376 | axes << value; | |
370 | QTest::newRow("first") << series << axes << line << value << true; |
|
377 | QTest::newRow("first") << series << axes << line << value << true; | |
371 | } |
|
378 | } | |
372 | } |
|
379 | } | |
373 |
|
380 | |||
374 | void tst_ChartDataSet::detachAxis() |
|
381 | void tst_ChartDataSet::detachAxis() | |
375 | { |
|
382 | { | |
376 | QFETCH(QList<QAbstractSeries*>, series); |
|
383 | QFETCH(QList<QAbstractSeries*>, series); | |
377 | QFETCH(QList<QAbstractAxis*>, axis); |
|
384 | QFETCH(QList<QAbstractAxis*>, axis); | |
378 | QFETCH(QAbstractSeries*, detachSeries); |
|
385 | QFETCH(QAbstractSeries*, detachSeries); | |
379 | QFETCH(QAbstractAxis*, detachAxis); |
|
386 | QFETCH(QAbstractAxis*, detachAxis); | |
380 | QFETCH(bool, success); |
|
387 | QFETCH(bool, success); | |
381 |
|
388 | |||
382 | Q_ASSERT(series.count() == axis.count()); |
|
389 | Q_ASSERT(series.count() == axis.count()); | |
383 |
|
390 | |||
384 | QVERIFY(m_dataset->series().isEmpty()); |
|
391 | QVERIFY(m_dataset->series().isEmpty()); | |
385 | QVERIFY(m_dataset->axes().isEmpty()); |
|
392 | QVERIFY(m_dataset->axes().isEmpty()); | |
386 |
|
393 | |||
387 | for(int i = 0; i < series.count(); i++) { |
|
394 | for(int i = 0; i < series.count(); i++) { | |
388 | if(series[i]) m_dataset->addSeries(series[i]); |
|
395 | if(series[i]) m_dataset->addSeries(series[i]); | |
389 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); |
|
396 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); | |
390 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
397 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |
391 | } |
|
398 | } | |
392 |
|
399 | |||
393 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
400 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
394 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
401 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
395 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
402 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
396 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
403 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
397 |
|
404 | |||
398 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); |
|
405 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); | |
399 | } |
|
406 | } | |
400 |
|
407 | |||
401 | QTEST_MAIN(tst_ChartDataSet) |
|
408 | QTEST_MAIN(tst_ChartDataSet) | |
402 | #include "tst_chartdataset.moc" |
|
409 | #include "tst_chartdataset.moc" | |
403 | #endif |
|
410 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now