1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include <QtCharts/QCandlestickSet>
31#include <QtCore/QDateTime>
32#include <QtTest/QtTest>
33
34QT_CHARTS_USE_NAMESPACE
35
36class tst_QCandlestickSet : public QObject
37{
38 Q_OBJECT
39
40public Q_SLOTS:
41 void initTestCase();
42 void cleanupTestCase();
43 void init();
44 void cleanup();
45
46private Q_SLOTS:
47 void qCandlestickSet_data();
48 void qCandlestickSet();
49 void timestamp_data();
50 void timestamp();
51 void open_data();
52 void open();
53 void high_data();
54 void high();
55 void low_data();
56 void low();
57 void close_data();
58 void close();
59 void brush();
60 void pen();
61
62private:
63 QCandlestickSet* m_candlestickSet;
64};
65
66void tst_QCandlestickSet::initTestCase()
67{
68}
69
70void tst_QCandlestickSet::cleanupTestCase()
71{
72 QTest::qWait(ms: 1); // Allow final deleteLaters to run
73}
74
75void tst_QCandlestickSet::init()
76{
77 m_candlestickSet = new QCandlestickSet(QDateTime::currentMSecsSinceEpoch());
78 m_candlestickSet->setOpen(2345.67);
79 m_candlestickSet->setHigh(4567.89);
80 m_candlestickSet->setLow(1234.56);
81 m_candlestickSet->setClose(3456.78);
82}
83
84void tst_QCandlestickSet::cleanup()
85{
86 delete m_candlestickSet;
87 m_candlestickSet = nullptr;
88}
89
90void tst_QCandlestickSet::qCandlestickSet_data()
91{
92 QTest::addColumn<qreal>(name: "timestamp");
93 QTest::addColumn<qreal>(name: "expectedTimestamp");
94
95 QTest::newRow(dataTag: "timestamp less than zero") << -1.0 << 0.0;
96 QTest::newRow(dataTag: "timestamp equals zero") << 0.0 << 0.0;
97 QTest::newRow(dataTag: "timestamp greater than zero") << 1.0 << 1.0;
98 QTest::newRow(dataTag: "timestamp rounded down") << 4.321 << 4.0;
99 QTest::newRow(dataTag: "timestamp rounded up") << 5.678 << 6.0;
100}
101
102void tst_QCandlestickSet::qCandlestickSet()
103{
104 QFETCH(qreal, timestamp);
105 QFETCH(qreal, expectedTimestamp);
106
107 QCandlestickSet candlestickSet(timestamp);
108 QCOMPARE(candlestickSet.timestamp(), expectedTimestamp);
109}
110
111void tst_QCandlestickSet::timestamp_data()
112{
113 QTest::addColumn<qreal>(name: "timestamp");
114 QTest::addColumn<qreal>(name: "expectedTimestamp");
115
116 QTest::newRow(dataTag: "timestamp less than zero") << -1.0 << 0.0;
117 QTest::newRow(dataTag: "timestamp equals zero") << 0.0 << 0.0;
118 QTest::newRow(dataTag: "timestamp greater than zero") << 1.0 << 1.0;
119 QTest::newRow(dataTag: "timestamp rounded down") << 4.321 << 4.0;
120 QTest::newRow(dataTag: "timestamp rounded up") << 5.678 << 6.0;
121}
122
123void tst_QCandlestickSet::timestamp()
124{
125 QFETCH(qreal, timestamp);
126 QFETCH(qreal, expectedTimestamp);
127
128 QSignalSpy spy(m_candlestickSet, SIGNAL(timestampChanged()));
129
130 m_candlestickSet->setTimestamp(timestamp);
131 QCOMPARE(m_candlestickSet->timestamp(), expectedTimestamp);
132 QCOMPARE(spy.count(), 1);
133
134 // Try set same timestamp value
135 m_candlestickSet->setTimestamp(expectedTimestamp);
136 QCOMPARE(m_candlestickSet->timestamp(), expectedTimestamp);
137 QCOMPARE(spy.count(), 1);
138}
139
140void tst_QCandlestickSet::open_data()
141{
142 QTest::addColumn<qreal>(name: "open");
143
144 QTest::newRow(dataTag: "open less than zero") << -1.234;
145 QTest::newRow(dataTag: "open equals zero") << 0.0;
146 QTest::newRow(dataTag: "open greater than zero") << 1.234;
147}
148
149void tst_QCandlestickSet::open()
150{
151 QFETCH(qreal, open);
152
153 QSignalSpy spy(m_candlestickSet, SIGNAL(openChanged()));
154
155 m_candlestickSet->setOpen(open);
156 QCOMPARE(m_candlestickSet->open(), open);
157 QCOMPARE(spy.count(), 1);
158
159 // Try set same open value
160 m_candlestickSet->setOpen(open);
161 QCOMPARE(m_candlestickSet->open(), open);
162 QCOMPARE(spy.count(), 1);
163}
164
165void tst_QCandlestickSet::high_data()
166{
167 QTest::addColumn<qreal>(name: "high");
168
169 QTest::newRow(dataTag: "high less than zero") << -1.234;
170 QTest::newRow(dataTag: "high equals zero") << 0.0;
171 QTest::newRow(dataTag: "high greater than zero") << 1.234;
172}
173
174void tst_QCandlestickSet::high()
175{
176 QFETCH(qreal, high);
177
178 QSignalSpy spy(m_candlestickSet, SIGNAL(highChanged()));
179
180 m_candlestickSet->setHigh(high);
181 QCOMPARE(m_candlestickSet->high(), high);
182 QCOMPARE(spy.count(), 1);
183
184 // Try set same high value
185 m_candlestickSet->setHigh(high);
186 QCOMPARE(m_candlestickSet->high(), high);
187 QCOMPARE(spy.count(), 1);
188}
189
190void tst_QCandlestickSet::low_data()
191{
192 QTest::addColumn<qreal>(name: "low");
193
194 QTest::newRow(dataTag: "low less than zero") << -1.234;
195 QTest::newRow(dataTag: "low equals zero") << 0.0;
196 QTest::newRow(dataTag: "low greater than zero") << 1.234;
197}
198
199void tst_QCandlestickSet::low()
200{
201 QFETCH(qreal, low);
202
203 QSignalSpy spy(m_candlestickSet, SIGNAL(lowChanged()));
204
205 m_candlestickSet->setLow(low);
206 QCOMPARE(m_candlestickSet->low(), low);
207 QCOMPARE(spy.count(), 1);
208
209 // Try set same low value
210 m_candlestickSet->setLow(low);
211 QCOMPARE(m_candlestickSet->low(), low);
212 QCOMPARE(spy.count(), 1);
213}
214
215void tst_QCandlestickSet::close_data()
216{
217 QTest::addColumn<qreal>(name: "close");
218
219 QTest::newRow(dataTag: "close less than zero") << -1.234;
220 QTest::newRow(dataTag: "close equals zero") << 0.0;
221 QTest::newRow(dataTag: "close greater than zero") << 1.234;
222}
223
224void tst_QCandlestickSet::close()
225{
226 QFETCH(qreal, close);
227
228 QSignalSpy spy(m_candlestickSet, SIGNAL(closeChanged()));
229
230 m_candlestickSet->setClose(close);
231 QCOMPARE(m_candlestickSet->close(), close);
232 QCOMPARE(spy.count(), 1);
233
234 // Try set same close value
235 m_candlestickSet->setClose(close);
236 QCOMPARE(m_candlestickSet->close(), close);
237 QCOMPARE(spy.count(), 1);
238}
239
240void tst_QCandlestickSet::brush()
241{
242 QSignalSpy spy(m_candlestickSet, SIGNAL(brushChanged()));
243
244 QCOMPARE(m_candlestickSet->brush(), QBrush(Qt::NoBrush));
245
246 m_candlestickSet->setBrush(QBrush(Qt::NoBrush));
247 QCOMPARE(m_candlestickSet->brush(), QBrush(Qt::NoBrush));
248 QCOMPARE(spy.count(), 0);
249
250 QBrush brush(QColor(128, 128, 128, 128));
251 m_candlestickSet->setBrush(brush);
252 QCOMPARE(m_candlestickSet->brush(), brush);
253 QCOMPARE(spy.count(), 1);
254
255 // Try set same brush
256 m_candlestickSet->setBrush(brush);
257 QCOMPARE(m_candlestickSet->brush(), brush);
258 QCOMPARE(spy.count(), 1);
259}
260
261void tst_QCandlestickSet::pen()
262{
263 QSignalSpy spy(m_candlestickSet, SIGNAL(penChanged()));
264
265 QCOMPARE(m_candlestickSet->pen(), QPen(Qt::NoPen));
266
267 m_candlestickSet->setPen(QPen(Qt::NoPen));
268 QCOMPARE(m_candlestickSet->pen(), QPen(Qt::NoPen));
269 QCOMPARE(spy.count(), 0);
270
271 QPen pen(QColor(128, 128, 128, 128));
272 m_candlestickSet->setPen(pen);
273 QCOMPARE(m_candlestickSet->pen(), pen);
274 QCOMPARE(spy.count(), 1);
275
276 // Try set same pen
277 m_candlestickSet->setPen(pen);
278 QCOMPARE(m_candlestickSet->pen(), pen);
279 QCOMPARE(spy.count(), 1);
280}
281
282QTEST_GUILESS_MAIN(tst_QCandlestickSet)
283
284#include "tst_qcandlestickset.moc"
285

source code of qtcharts/tests/auto/qcandlestickset/tst_qcandlestickset.cpp