tst_qdatetimeaxis.cpp
312 lines
| 8.2 KiB
| text/x-c
|
CppLexer
|
r1719 | /**************************************************************************** | ||
** | ||||
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
|
r1719 | ** All rights reserved. | ||
|
r2740 | ** For any questions to Digia, please use contact form at http://qt.io | ||
|
r1719 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r1719 | ** | ||
|
r2740 | ** Licensees holding valid commercial license for Qt may use this file in | ||
** accordance with the Qt License Agreement provided with the Software | ||||
** or, alternatively, in accordance with the terms contained in a written | ||||
** agreement between you and Digia. | ||||
|
r1719 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r1719 | ** | ||
****************************************************************************/ | ||||
#include "../qabstractaxis/tst_qabstractaxis.h" | ||||
|
r2714 | #include <QtCharts/QDateTimeAxis> | ||
#include <QtCharts/QLineSeries> | ||||
|
r1719 | |||
|
r1728 | class tst_QDateTimeAxis : public QObject//: public tst_QAbstractAxis | ||
|
r1719 | { | ||
|
r1728 | Q_OBJECT | ||
|
r1719 | |||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
|
r1728 | void qdatetimeaxis_data(); | ||
void qdatetimeaxis(); | ||||
void max_raw_data(); | ||||
void max_raw(); | ||||
void max_data(); | ||||
void max(); | ||||
|
r1737 | void max_animation_data(); | ||
void max_animation(); | ||||
|
r1728 | void min_raw_data(); | ||
void min_raw(); | ||||
void min_data(); | ||||
void min(); | ||||
|
r1737 | void min_animation_data(); | ||
void min_animation(); | ||||
|
r1733 | void range_raw_data(); | ||
void range_raw(); | ||||
void range_data(); | ||||
void range(); | ||||
|
r1737 | void range_animation_data(); | ||
void range_animation(); | ||||
|
r1719 | |||
private: | ||||
|
r1728 | QDateTimeAxis *m_dateTimeAxisX; | ||
QDateTimeAxis *m_dateTimeAxisY; | ||||
|
r1719 | QLineSeries* m_series; | ||
|
r1728 | QChartView* m_view; | ||
QChart* m_chart; | ||||
|
r1719 | }; | ||
void tst_QDateTimeAxis::initTestCase() | ||||
{ | ||||
} | ||||
void tst_QDateTimeAxis::cleanupTestCase() | ||||
{ | ||||
|
r2733 | QTest::qWait(1); // Allow final deleteLaters to run | ||
|
r1719 | } | ||
void tst_QDateTimeAxis::init() | ||||
{ | ||||
|
r1728 | m_dateTimeAxisX = new QDateTimeAxis(); | ||
m_dateTimeAxisY = new QDateTimeAxis(); | ||||
|
r1719 | m_series = new QLineSeries(); | ||
*m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); | ||||
|
r1733 | // tst_QAbstractAxis::init(m_datetimeaxis, m_series); | ||
|
r1728 | |||
|
r1829 | m_view = new QChartView; | ||
|
r1728 | m_chart = m_view->chart(); | ||
|
r1719 | m_chart->addSeries(m_series); | ||
|
r1728 | m_chart->setAxisY(m_dateTimeAxisY, m_series); | ||
m_chart->setAxisX(m_dateTimeAxisX, m_series); | ||||
|
r1719 | } | ||
void tst_QDateTimeAxis::cleanup() | ||||
{ | ||||
delete m_series; | ||||
|
r1728 | delete m_dateTimeAxisX; | ||
delete m_dateTimeAxisY; | ||||
|
r1719 | m_series = 0; | ||
|
r1728 | m_dateTimeAxisX = 0; | ||
m_dateTimeAxisY = 0; | ||||
delete m_view; | ||||
m_view = 0; | ||||
m_chart = 0; | ||||
|
r1733 | // tst_QAbstractAxis::cleanup(); | ||
|
r1719 | } | ||
|
r1728 | void tst_QDateTimeAxis::qdatetimeaxis_data() | ||
{ | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::qdatetimeaxis() | ||
{ | ||||
|
r1733 | // qabstractaxis(); | ||
|
r1728 | QCOMPARE(m_dateTimeAxisX->type(), QAbstractAxis::AxisTypeDateTime); | ||
|
r1719 | |||
|
r1728 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
|
r1719 | |||
|
r1728 | QVERIFY(m_dateTimeAxisX->max().toMSecsSinceEpoch() != 0); | ||
QVERIFY(m_dateTimeAxisX->min().toMSecsSinceEpoch() != 0); | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::max_raw_data() | ||
{ | ||||
QTest::addColumn<QDateTime>("max"); | ||||
QTest::addColumn<bool>("valid"); | ||||
QDateTime dateTime; | ||||
dateTime.setDate(QDate(2012, 7, 19)); | ||||
QTest::newRow("19.7.2012 - Valid") << dateTime << true; | ||||
dateTime.setDate(QDate(2012, 17, 32)); | ||||
QTest::newRow("32.17.2012 - Invalid") << dateTime << false; | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::max_raw() | ||
{ | ||||
QFETCH(QDateTime, max); | ||||
QFETCH(bool, valid); | ||||
QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); | ||||
QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); | ||||
|
r2110 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime,QDateTime))); | ||
|
r1728 | |||
m_dateTimeAxisX->setMax(max); | ||||
if (valid) { | ||||
QVERIFY2(m_dateTimeAxisX->max() == max, "Not equal"); | ||||
QCOMPARE(spy0.count(), 1); | ||||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 1); | ||||
} else { | ||||
|
r1733 | QVERIFY2(m_dateTimeAxisX->max() != max, "Date is invalid and should not be set"); | ||
|
r1728 | QCOMPARE(spy0.count(), 0); | ||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 0); | ||||
} | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::max_data() | ||
{ | ||||
max_raw_data(); | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::max() | ||
{ | ||||
|
r1829 | // m_chart->setAxisX(m_dateTimeAxisX, m_series); | ||
|
r1728 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
max_raw(); | ||||
} | ||||
|
r1719 | |||
|
r1737 | void tst_QDateTimeAxis::max_animation_data() | ||
{ | ||||
max_data(); | ||||
} | ||||
|
r1719 | |||
|
r1737 | void tst_QDateTimeAxis::max_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||||
max(); | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::min_raw_data() | ||
{ | ||||
QTest::addColumn<QDateTime>("min"); | ||||
QTest::addColumn<bool>("valid"); | ||||
QDateTime dateTime; | ||||
dateTime.setDate(QDate(1908, 1, 11)); | ||||
QTest::newRow("11.1.1908 - Valid") << dateTime << true; // negative MSecs from Epoch | ||||
dateTime.setDate(QDate(2012, 17, 32)); | ||||
QTest::newRow("32.17.2012 - Invalid") << dateTime << false; | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::min_raw() | ||
{ | ||||
QFETCH(QDateTime, min); | ||||
QFETCH(bool, valid); | ||||
QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); | ||||
QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); | ||||
|
r2110 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime,QDateTime))); | ||
|
r1728 | |||
m_dateTimeAxisX->setMin(min); | ||||
if (valid) { | ||||
QVERIFY2(m_dateTimeAxisX->min() == min, "Not equal"); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
} else { | ||||
|
r1733 | QVERIFY2(m_dateTimeAxisX->min() != min, "Date is invalid and should not be set"); | ||
|
r1728 | QCOMPARE(spy0.count(), 0); | ||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 0); | ||||
} | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::min_data() | ||
{ | ||||
min_raw_data(); | ||||
} | ||||
|
r1719 | |||
|
r1728 | void tst_QDateTimeAxis::min() | ||
{ | ||||
|
r1829 | // m_chart->setAxisX(m_dateTimeAxisX, m_series); | ||
|
r1728 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
min_raw(); | ||||
} | ||||
|
r1719 | |||
|
r1737 | void tst_QDateTimeAxis::min_animation_data() | ||
{ | ||||
min_data(); | ||||
} | ||||
|
r1719 | |||
|
r1737 | void tst_QDateTimeAxis::min_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||||
min(); | ||||
} | ||||
|
r1719 | |||
|
r1733 | void tst_QDateTimeAxis::range_raw_data() | ||
{ | ||||
QTest::addColumn<QDateTime>("min"); | ||||
QTest::addColumn<bool>("minValid"); | ||||
QTest::addColumn<QDateTime>("max"); | ||||
QTest::addColumn<bool>("maxValid"); | ||||
|
r1719 | |||
|
r1733 | QDateTime minDateTime; | ||
QDateTime maxDateTime; | ||||
minDateTime.setDate(QDate(1908, 1, 11)); | ||||
maxDateTime.setDate(QDate(1958, 11, 21)); | ||||
QTest::newRow("11.1.1908 - min valid, 21.12.1958 - max valid") << minDateTime << true << maxDateTime << true; // negative MSecs from Epoch, min < max | ||||
|
r1719 | |||
|
r1733 | minDateTime.setDate(QDate(2012, 17, 32)); | ||
QTest::newRow("32.17.2012 - min invalid, 21.12.1958 - max valid") << minDateTime << false << maxDateTime << true; | ||||
|
r1719 | |||
|
r1733 | maxDateTime.setDate(QDate(2017, 0, 1)); | ||
QTest::newRow("32.17.2012 - min invalid, 1.0.2017 - max invalid") << minDateTime << false << maxDateTime << false; | ||||
|
r1719 | |||
|
r1733 | minDateTime.setDate(QDate(2012, 1, 1)); | ||
QTest::newRow("1.1.2012 - min valid, 1.0.2017 - max invalid") << minDateTime << true << maxDateTime << false; | ||||
|
r1719 | |||
|
r1733 | maxDateTime.setDate(QDate(2005, 2, 5)); | ||
QTest::newRow("1.1.2012 - min valid, 5.2.2005 - max valid") << minDateTime << true << maxDateTime << true; // min > max | ||||
} | ||||
|
r1719 | |||
|
r1733 | void tst_QDateTimeAxis::range_raw() | ||
{ | ||||
QFETCH(QDateTime, min); | ||||
QFETCH(bool, minValid); | ||||
QFETCH(QDateTime, max); | ||||
QFETCH(bool, maxValid); | ||||
QSignalSpy spy0(m_dateTimeAxisX, SIGNAL(maxChanged(QDateTime))); | ||||
QSignalSpy spy1(m_dateTimeAxisX, SIGNAL(minChanged(QDateTime))); | ||||
|
r2110 | QSignalSpy spy2(m_dateTimeAxisX, SIGNAL(rangeChanged(QDateTime,QDateTime))); | ||
|
r1733 | |||
m_dateTimeAxisX->setRange(min, max); | ||||
if (minValid && maxValid && min < max) { | ||||
QCOMPARE(spy0.count(), 1); | ||||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
} else { | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 0); | ||||
} | ||||
} | ||||
void tst_QDateTimeAxis::range_data() | ||||
{ | ||||
range_raw_data(); | ||||
} | ||||
void tst_QDateTimeAxis::range() | ||||
{ | ||||
|
r1829 | // m_chart->setAxisX(m_dateTimeAxisX, m_series); | ||
|
r1733 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
range_raw(); | ||||
} | ||||
|
r1719 | |||
|
r1737 | void tst_QDateTimeAxis::range_animation_data() | ||
{ | ||||
range_data(); | ||||
} | ||||
|
r1719 | |||
|
r1737 | void tst_QDateTimeAxis::range_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||||
range(); | ||||
} | ||||
|
r1719 | |||
QTEST_MAIN(tst_QDateTimeAxis) | ||||
#include "tst_qdatetimeaxis.moc" | ||||