tst_qvalueaxis.cpp
415 lines
| 11.3 KiB
| text/x-c
|
CppLexer
|
r1699 | /**************************************************************************** | ||
|
r1700 | ** | ||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r1699 | |||
#include "../qabstractaxis/tst_qabstractaxis.h" | ||||
|
r1805 | #include "qvalueaxis.h" | ||
|
r1699 | #include <qlineseries.h> | ||
|
r1804 | class tst_QValueAxis: public tst_QAbstractAxis | ||
|
r1699 | { | ||
|
r1700 | Q_OBJECT | ||
|
r1699 | |||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
|
r1805 | void qvalueaxis_data(); | ||
void qvalueaxis(); | ||||
|
r1700 | void max_raw_data(); | ||
void max_raw(); | ||||
|
r1699 | void max_data(); | ||
void max(); | ||||
|
r1700 | void max_animation_data(); | ||
void max_animation(); | ||||
void min_raw_data(); | ||||
void min_raw(); | ||||
|
r1699 | void min_data(); | ||
void min(); | ||||
|
r1700 | void min_animation_data(); | ||
void min_animation(); | ||||
|
r1699 | void niceNumbersEnabled_data(); | ||
void niceNumbersEnabled(); | ||||
|
r1700 | void range_raw_data(); | ||
void range_raw(); | ||||
void range_data(); | ||||
void range(); | ||||
void range_animation_data(); | ||||
void range_animation(); | ||||
|
r1699 | void ticksCount_data(); | ||
void ticksCount(); | ||||
|
r1705 | void noautoscale_data(); | ||
void noautoscale(); | ||||
void autoscale_data(); | ||||
void autoscale(); | ||||
|
r1699 | |||
private: | ||||
|
r1804 | QValueAxis* m_valuesaxis; | ||
|
r1699 | QLineSeries* m_series; | ||
}; | ||||
|
r1804 | void tst_QValueAxis::initTestCase() | ||
|
r1699 | { | ||
} | ||||
|
r1804 | void tst_QValueAxis::cleanupTestCase() | ||
|
r1699 | { | ||
} | ||||
|
r1804 | void tst_QValueAxis::init() | ||
|
r1699 | { | ||
|
r1804 | m_valuesaxis = new QValueAxis(); | ||
|
r1699 | m_series = new QLineSeries(); | ||
|
r1700 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); | ||
|
r1704 | tst_QAbstractAxis::init(m_valuesaxis,m_series); | ||
|
r1699 | m_chart->addSeries(m_series); | ||
m_chart->createDefaultAxes(); | ||||
} | ||||
|
r1804 | void tst_QValueAxis::cleanup() | ||
|
r1699 | { | ||
delete m_series; | ||||
delete m_valuesaxis; | ||||
m_series = 0; | ||||
|
r1700 | m_valuesaxis = 0; | ||
|
r1699 | tst_QAbstractAxis::cleanup(); | ||
} | ||||
|
r1805 | void tst_QValueAxis::qvalueaxis_data() | ||
|
r1699 | { | ||
} | ||||
|
r1805 | void tst_QValueAxis::qvalueaxis() | ||
|
r1699 | { | ||
qabstractaxis(); | ||||
QVERIFY(qFuzzyIsNull(m_valuesaxis->max())); | ||||
QVERIFY(qFuzzyIsNull(m_valuesaxis->min())); | ||||
QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false); | ||||
|
r1807 | QCOMPARE(m_valuesaxis->tickCount(), 5); | ||
|
r1818 | QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValue); | ||
|
r1699 | |||
|
r1700 | m_chart->setAxisX(m_valuesaxis, m_series); | ||
|
r1699 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
QVERIFY(!qFuzzyIsNull(m_valuesaxis->max())); | ||||
QVERIFY(!qFuzzyIsNull(m_valuesaxis->min())); | ||||
QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false); | ||||
|
r1807 | QCOMPARE(m_valuesaxis->tickCount(), 5); | ||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::max_raw_data() | ||
|
r1699 | { | ||
QTest::addColumn<qreal>("max"); | ||||
|
r1822 | QTest::newRow("1.0") << (qreal)1.0; | ||
QTest::newRow("50.0") << (qreal)50.0; | ||||
QTest::newRow("101.0") << (qreal)101.0; | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::max_raw() | ||
|
r1699 | { | ||
QFETCH(qreal, max); | ||||
|
r1700 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | ||||
QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | ||||
|
r1699 | |||
|
r1700 | m_valuesaxis->setMax(max); | ||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal"); | ||||
|
r1699 | |||
|
r1700 | QCOMPARE(spy0.count(), 1); | ||
|
r1699 | QCOMPARE(spy1.count(), 0); | ||
|
r1700 | QCOMPARE(spy2.count(), 1); | ||
|
r1699 | |||
} | ||||
|
r1804 | void tst_QValueAxis::max_data() | ||
|
r1699 | { | ||
|
r1700 | max_raw_data(); | ||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::max() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAxisX(m_valuesaxis, m_series); | ||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
max_raw(); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::max_animation_data() | ||
|
r1699 | { | ||
|
r1700 | max_data(); | ||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::max_animation() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||
max(); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::min_raw_data() | ||
|
r1699 | { | ||
QTest::addColumn<qreal>("min"); | ||||
|
r1943 | QTest::newRow("-1.0") << (qreal)-1.0; | ||
QTest::newRow("-50.0") << (qreal)-50.0; | ||||
QTest::newRow("-101.0") << (qreal)-101.0; | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::min_raw() | ||
|
r1699 | { | ||
QFETCH(qreal, min); | ||||
|
r1700 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | ||||
QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | ||||
|
r1699 | |||
|
r1700 | m_valuesaxis->setMin(min); | ||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal"); | ||||
|
r1699 | |||
QCOMPARE(spy0.count(), 0); | ||||
|
r1700 | QCOMPARE(spy1.count(), 1); | ||
QCOMPARE(spy2.count(), 1); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::min_data() | ||
|
r1699 | { | ||
|
r1700 | min_raw_data(); | ||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::min() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAxisX(m_valuesaxis, m_series); | ||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
min_raw(); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::min_animation_data() | ||
|
r1699 | { | ||
|
r1700 | min_data(); | ||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::min_animation() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||
min(); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::niceNumbersEnabled_data() | ||
|
r1699 | { | ||
|
r1700 | QTest::addColumn<bool>("niceNumbersEnabled"); | ||
QTest::addColumn<qreal>("min"); | ||||
QTest::addColumn<qreal>("max"); | ||||
QTest::addColumn<int>("ticks"); | ||||
QTest::addColumn<qreal>("expectedMin"); | ||||
QTest::addColumn<qreal>("expectedMax"); | ||||
QTest::addColumn<int>("expectedTicks"); | ||||
|
r1943 | QTest::newRow("true 0.1 , 99.0 , 5") << true << (qreal)0.1 << (qreal)99.0 << 5 << (qreal)0.0 << (qreal)100.0 << 6; | ||
QTest::newRow("true 1 , 10.0 , 5") << true << (qreal)1.0 << (qreal)10.0 << 5 << (qreal)0.0 << (qreal)10.0 << 6; | ||||
QTest::newRow("true 0.1 , 6.6 , 5") << true << (qreal)0.1 << (qreal)6.6 << 5 << (qreal)0.0 << (qreal)8.0 << 5; | ||||
QTest::newRow("false 0.1 , 6.6 , 5") << false << (qreal)0.1 << (qreal)6.6 << 5 << (qreal)0.1 << (qreal)6.6 << 5; | ||||
QTest::newRow("true 0.1, 99, 5") << true << (qreal)0.1 << (qreal)99.0 << 5 << (qreal)0.0 << (qreal)100.0 << 6; | ||||
QTest::newRow("true 5, 93.5 , 5") << true << (qreal)5.0 << (qreal)93.5 << 5 << (qreal)0.0 << (qreal)100.0 << 6; | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::niceNumbersEnabled() | ||
|
r1699 | { | ||
|
r1700 | QFETCH(bool, niceNumbersEnabled); | ||
QFETCH(qreal, min); | ||||
QFETCH(qreal, max); | ||||
QFETCH(int, ticks); | ||||
QFETCH(qreal, expectedMin); | ||||
QFETCH(qreal, expectedMax); | ||||
QFETCH(int, expectedTicks); | ||||
|
r1699 | |||
|
r1738 | m_valuesaxis->setRange(min, max); | ||
|
r1807 | m_valuesaxis->setTickCount(ticks); | ||
|
r1738 | |||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | ||||
|
r1700 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | ||||
QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | ||||
|
r1699 | |||
|
r1700 | m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled); | ||
QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled); | ||||
|
r1699 | |||
|
r1738 | if(!qFuzzyIsNull(expectedMin - min)) | ||
QCOMPARE(spy1.count(), 1); | ||||
if(!qFuzzyIsNull(expectedMax - max)) | ||||
QCOMPARE(spy0.count(), 1); | ||||
if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max))) | ||||
QCOMPARE(spy2.count(), 1); | ||||
|
r1700 | |||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal"); | ||||
|
r1807 | QCOMPARE(m_valuesaxis->tickCount(), expectedTicks); | ||
|
r1700 | |||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::range_raw_data() | ||
|
r1699 | { | ||
|
r1700 | QTest::addColumn<qreal>("min"); | ||
|
r1699 | QTest::addColumn<qreal>("max"); | ||
|
r1943 | 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; | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::range_raw() | ||
|
r1699 | { | ||
|
r1700 | QFETCH(qreal, min); | ||
|
r1699 | QFETCH(qreal, max); | ||
|
r1700 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | ||||
QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | ||||
|
r1699 | |||
|
r1700 | m_valuesaxis->setRange(min, max); | ||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | ||||
|
r1699 | |||
|
r1700 | QCOMPARE(spy0.count(), 1); | ||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::range_data() | ||
|
r1699 | { | ||
|
r1700 | range_raw_data(); | ||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::range() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAxisX(m_valuesaxis, m_series); | ||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
range_raw(); | ||||
} | ||||
|
r1699 | |||
|
r1804 | void tst_QValueAxis::range_animation_data() | ||
|
r1700 | { | ||
range_data(); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::range_animation() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||
range(); | ||||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::ticksCount_data() | ||
|
r1699 | { | ||
|
r1700 | QTest::addColumn<int>("ticksCount"); | ||
QTest::addColumn<int>("expectedCount"); | ||||
QTest::newRow("0") << 2; | ||||
QTest::newRow("1") << 2; | ||||
QTest::newRow("2") << 2; | ||||
QTest::newRow("3") << 3; | ||||
QTest::newRow("-1") << 2; | ||||
} | ||||
|
r1699 | |||
|
r1804 | void tst_QValueAxis::ticksCount() | ||
|
r1700 | { | ||
QFETCH(int, ticksCount); | ||||
|
r1699 | |||
|
r1700 | QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | ||||
QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | ||||
|
r1699 | |||
|
r1807 | m_valuesaxis->setTickCount(ticksCount); | ||
QCOMPARE(m_valuesaxis->tickCount(), ticksCount); | ||||
|
r1699 | |||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 0); | ||||
|
r1700 | |||
m_chart->setAxisX(m_valuesaxis, m_series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
|
r1807 | QCOMPARE(m_valuesaxis->tickCount(), ticksCount); | ||
|
r1699 | } | ||
|
r1804 | void tst_QValueAxis::noautoscale_data() | ||
|
r1705 | { | ||
QTest::addColumn<qreal>("min"); | ||||
QTest::addColumn<qreal>("max"); | ||||
|
r1943 | 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; | ||||
|
r1705 | } | ||
|
r1804 | void tst_QValueAxis::noautoscale() | ||
|
r1705 | { | ||
QFETCH(qreal, min); | ||||
QFETCH(qreal, max); | ||||
QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | ||||
QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | ||||
QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | ||||
m_valuesaxis->setRange(min, max); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | ||||
QCOMPARE(spy0.count(), 1); | ||||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
m_chart->setAxisX(m_valuesaxis, m_series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal"); | ||||
} | ||||
|
r1804 | void tst_QValueAxis::autoscale_data() | ||
|
r1705 | { | ||
} | ||||
|
r1804 | void tst_QValueAxis::autoscale() | ||
|
r1705 | { | ||
QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal))); | ||||
QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal))); | ||||
QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal))); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal"); | ||||
m_chart->setAxisX(m_valuesaxis, m_series); | ||||
QCOMPARE(spy0.count(), 1); | ||||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal"); | ||||
} | ||||
|
r1804 | QTEST_MAIN(tst_QValueAxis) | ||
|
r1805 | #include "tst_qvalueaxis.moc" | ||
|
r1699 | |||