diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-03 09:43:33 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-11-03 09:43:33 +0000 |
commit | 93ac0acba1baa63a4709e623a7790349df41c299 (patch) | |
tree | b5918a077970e7337fc609fb6a8050273362bb75 /tests | |
parent | 567b5bc67e54f496027da2e6d99aa7b39d64a606 (diff) | |
parent | 85793744503112e13abe47b31d108f6b6ee998d9 (diff) |
Merge "Merge remote-tracking branch 'origin/5.9' into 5.10" into refs/staging/5.10v5.10.0-beta4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qchart/tst_qchart.cpp | 112 | ||||
-rw-r--r-- | tests/auto/qvalueaxis/tst_qvalueaxis.cpp | 1 | ||||
-rw-r--r-- | tests/manual/chartwidgettest/mainwidget.cpp | 3 |
3 files changed, 115 insertions, 1 deletions
diff --git a/tests/auto/qchart/tst_qchart.cpp b/tests/auto/qchart/tst_qchart.cpp index 3e835792..7347f16b 100644 --- a/tests/auto/qchart/tst_qchart.cpp +++ b/tests/auto/qchart/tst_qchart.cpp @@ -40,6 +40,7 @@ #include <QtCharts/QStackedBarSeries> #include <QtCharts/QValueAxis> #include <QtCharts/QBarCategoryAxis> +#include <QtCharts/QDateTimeAxis> #include "tst_definitions.h" QT_CHARTS_USE_NAMESPACE @@ -122,6 +123,8 @@ private slots: void createDefaultAxesForLineSeries(); void axisPolarOrientation(); void backgroundRoundness(); + void zoomInAndOut_data(); + void zoomInAndOut(); private: void createTestData(); @@ -1088,6 +1091,115 @@ void tst_QChart::backgroundRoundness() QVERIFY(m_chart->backgroundRoundness() == 100.0); } +void tst_QChart::zoomInAndOut_data() +{ + const qreal hourInMSecs = 60.0 * 60.0 * 1000.0; + + QTest::addColumn<QString>("axisXType"); + QTest::addColumn<QString>("axisYType"); + QTest::addColumn<qreal>("minX"); + QTest::addColumn<qreal>("maxX"); + QTest::addColumn<qreal>("minY"); + QTest::addColumn<qreal>("maxY"); + + QTest::newRow("value-value-normal") << "QValueAxis" << "QValueAxis" << 0.0 << 100.0 << 0.0 << 100.0; + QTest::newRow("value-value-small") << "QValueAxis" << "QValueAxis" << -1e-12 << 1e-13 << -1e-12 << 1e-13; + QTest::newRow("value-value-mixed") << "QValueAxis" << "QValueAxis" << 0.0 << 100.0 << -1e-12 << 1e-13; + + QTest::newRow("datetime-datetime-normal") << "QDateTimeAxis" << "QDateTimeAxis" + << 0.0 << hourInMSecs << 0.0 << hourInMSecs; + QTest::newRow("datetime-datetime-small") << "QDateTimeAxis" << "QDateTimeAxis" + << 0.0 << 60.0 << 0.0 << 60.0; + QTest::newRow("datetime-datetime-mixed") << "QDateTimeAxis" << "QDateTimeAxis" + << 0.0 << hourInMSecs << 0.0 << 60.0; +} + +#define CHECK_AXIS_RANGES_MATCH \ + if (valueAxisX) { \ + QVERIFY(valueAxisX->min() == minX); \ + QVERIFY(valueAxisX->max() == maxX); \ + } else if (dateTimeAxisX) { \ + QVERIFY(dateTimeAxisX->min().toMSecsSinceEpoch() == minX); \ + QVERIFY(dateTimeAxisX->max().toMSecsSinceEpoch() == maxX); \ + } \ + if (valueAxisY) { \ + QVERIFY(valueAxisY->min() == minY); \ + QVERIFY(valueAxisY->max() == maxY); \ + } else if (dateTimeAxisY) { \ + QVERIFY(dateTimeAxisY->min().toMSecsSinceEpoch() == minY); \ + QVERIFY(dateTimeAxisY->max().toMSecsSinceEpoch() == maxY); \ + } + +void tst_QChart::zoomInAndOut() +{ + QFETCH(QString, axisXType); + QFETCH(QString, axisYType); + QFETCH(qreal, minX); + QFETCH(qreal, maxX); + QFETCH(qreal, minY); + QFETCH(qreal, maxY); + + createTestData(); + QAbstractAxis *axisX = 0; + QAbstractAxis *axisY = 0; + QValueAxis *valueAxisX = 0; + QValueAxis *valueAxisY = 0; + QDateTimeAxis *dateTimeAxisX = 0; + QDateTimeAxis *dateTimeAxisY = 0; + + if (axisXType == "QValueAxis") { + axisX = valueAxisX = new QValueAxis(m_chart); + valueAxisX->setRange(minX, maxX); + } else if (axisXType == "QDateTimeAxis") { + axisX = dateTimeAxisX = new QDateTimeAxis(m_chart); + dateTimeAxisX->setRange(QDateTime::fromMSecsSinceEpoch(minX), QDateTime::fromMSecsSinceEpoch(maxX)); + } + if (axisXType == "QValueAxis") { + axisY = valueAxisY = new QValueAxis(m_chart); + valueAxisY->setRange(minY, maxY); + } else if (axisXType == "QDateTimeAxis") { + axisY = dateTimeAxisY = new QDateTimeAxis(m_chart); + dateTimeAxisY->setRange(QDateTime::fromMSecsSinceEpoch(minY), QDateTime::fromMSecsSinceEpoch(maxY)); + } + + m_chart->setAxisX(axisX, m_chart->series().first()); + m_chart->setAxisY(axisY, m_chart->series().first()); + CHECK_AXIS_RANGES_MATCH + + m_chart->zoomIn(); + if (valueAxisX) { + QVERIFY(valueAxisX->min() != minX); + QVERIFY(valueAxisX->max() != maxX); + } else if (dateTimeAxisX) { + QVERIFY(dateTimeAxisX->min().toMSecsSinceEpoch() != minX); + QVERIFY(dateTimeAxisX->max().toMSecsSinceEpoch() != maxX); + } + if (valueAxisY) { + QVERIFY(valueAxisY->min() != minY); + QVERIFY(valueAxisY->max() != maxY); + } else if (dateTimeAxisY) { + QVERIFY(dateTimeAxisY->min().toMSecsSinceEpoch() != minY); + QVERIFY(dateTimeAxisY->max().toMSecsSinceEpoch() != maxY); + } + + m_chart->zoomReset(); + CHECK_AXIS_RANGES_MATCH + + m_chart->zoomIn(); + m_chart->zoomIn(); + m_chart->zoomReset(); + CHECK_AXIS_RANGES_MATCH + + m_chart->zoomOut(); + m_chart->zoomReset(); + CHECK_AXIS_RANGES_MATCH + + m_chart->zoomOut(); + m_chart->zoomOut(); + m_chart->zoomReset(); + CHECK_AXIS_RANGES_MATCH +} + QTEST_MAIN(tst_QChart) #include "tst_qchart.moc" diff --git a/tests/auto/qvalueaxis/tst_qvalueaxis.cpp b/tests/auto/qvalueaxis/tst_qvalueaxis.cpp index d5d69a5b..4de89cb1 100644 --- a/tests/auto/qvalueaxis/tst_qvalueaxis.cpp +++ b/tests/auto/qvalueaxis/tst_qvalueaxis.cpp @@ -285,6 +285,7 @@ void tst_QValueAxis::range_raw_data() QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0; QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0; QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0; + QTest::newRow("smallNumbers") << (qreal)-1e-12 << (qreal)1e-13; } void tst_QValueAxis::range_raw() diff --git a/tests/manual/chartwidgettest/mainwidget.cpp b/tests/manual/chartwidgettest/mainwidget.cpp index 3ff15810..ebb00f22 100644 --- a/tests/manual/chartwidgettest/mainwidget.cpp +++ b/tests/manual/chartwidgettest/mainwidget.cpp @@ -48,13 +48,14 @@ #include <QtWidgets/QLabel> #include <QtWidgets/QSpacerItem> #include <QtWidgets/QMessageBox> -#include <qmath.h> #include <QtCore/QDebug> #include <QtCore/QRandomGenerator> #include <QtGui/QStandardItemModel> #include <QtCharts/QBarCategoryAxis> #include <QtWidgets/QOpenGLWidget> +#include <qmath.h> + QT_CHARTS_USE_NAMESPACE MainWidget::MainWidget(QWidget *parent) : |