tst_qvaluesaxis.cpp
351 lines
| 8.9 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" | ||||
#include "qvaluesaxis.h" | ||||
#include <qlineseries.h> | ||||
|
r1700 | class tst_QValuesAxis: public tst_QAbstractAxis | ||
|
r1699 | { | ||
|
r1700 | Q_OBJECT | ||
|
r1699 | |||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
void qvaluesaxis_data(); | ||||
void qvaluesaxis(); | ||||
|
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(); | ||||
private: | ||||
QValuesAxis* m_valuesaxis; | ||||
QLineSeries* m_series; | ||||
}; | ||||
void tst_QValuesAxis::initTestCase() | ||||
{ | ||||
} | ||||
void tst_QValuesAxis::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_QValuesAxis::init() | ||||
{ | ||||
m_valuesaxis = new QValuesAxis(); | ||||
tst_QAbstractAxis::init(m_valuesaxis); | ||||
m_series = new QLineSeries(); | ||||
|
r1700 | *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); | ||
|
r1699 | m_chart->addSeries(m_series); | ||
m_chart->createDefaultAxes(); | ||||
} | ||||
void tst_QValuesAxis::cleanup() | ||||
{ | ||||
delete m_series; | ||||
delete m_valuesaxis; | ||||
m_series = 0; | ||||
|
r1700 | m_valuesaxis = 0; | ||
|
r1699 | tst_QAbstractAxis::cleanup(); | ||
} | ||||
void tst_QValuesAxis::qvaluesaxis_data() | ||||
{ | ||||
} | ||||
void tst_QValuesAxis::qvaluesaxis() | ||||
{ | ||||
qabstractaxis(); | ||||
QVERIFY(qFuzzyIsNull(m_valuesaxis->max())); | ||||
QVERIFY(qFuzzyIsNull(m_valuesaxis->min())); | ||||
QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false); | ||||
QCOMPARE(m_valuesaxis->ticksCount(), 5); | ||||
QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues); | ||||
|
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); | ||||
QCOMPARE(m_valuesaxis->ticksCount(), 5); | ||||
} | ||||
|
r1700 | void tst_QValuesAxis::max_raw_data() | ||
|
r1699 | { | ||
QTest::addColumn<qreal>("max"); | ||||
|
r1700 | QTest::newRow("1.0") << 1.0; | ||
QTest::newRow("50.0") << 50.0; | ||||
QTest::newRow("101.0") << 101.0; | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::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 | |||
} | ||||
|
r1700 | void tst_QValuesAxis::max_data() | ||
|
r1699 | { | ||
|
r1700 | max_raw_data(); | ||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::max() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAxisX(m_valuesaxis, m_series); | ||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
max_raw(); | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::max_animation_data() | ||
|
r1699 | { | ||
|
r1700 | max_data(); | ||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::max_animation() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||
max(); | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::min_raw_data() | ||
|
r1699 | { | ||
QTest::addColumn<qreal>("min"); | ||||
|
r1700 | QTest::newRow("-1.0") << -1.0; | ||
QTest::newRow("-50.0") << -50.0; | ||||
QTest::newRow("-101.0") << -101.0; | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::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 | } | ||
|
r1700 | void tst_QValuesAxis::min_data() | ||
|
r1699 | { | ||
|
r1700 | min_raw_data(); | ||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::min() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAxisX(m_valuesaxis, m_series); | ||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
min_raw(); | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::min_animation_data() | ||
|
r1699 | { | ||
|
r1700 | min_data(); | ||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::min_animation() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||
min(); | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::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"); | ||||
QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6; | ||||
QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6; | ||||
QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5; | ||||
QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5; | ||||
QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6; | ||||
QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6; | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::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 | |||
|
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 | |||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 0); | ||||
|
r1700 | |||
m_valuesaxis->setTicksCount(ticks); | ||||
m_valuesaxis->setRange(min, max); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal"); | ||||
QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal"); | ||||
QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks); | ||||
QCOMPARE(spy0.count(), 1); | ||||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::range_raw_data() | ||
|
r1699 | { | ||
|
r1700 | QTest::addColumn<qreal>("min"); | ||
|
r1699 | QTest::addColumn<qreal>("max"); | ||
|
r1700 | QTest::newRow("1.0 - 101.0") << -1.0 << 101.0; | ||
QTest::newRow("25.0 - 75.0") << 25.0 << 75.0; | ||||
QTest::newRow("101.0") << 40.0 << 60.0; | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::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 | } | ||
|
r1700 | void tst_QValuesAxis::range_data() | ||
|
r1699 | { | ||
|
r1700 | range_raw_data(); | ||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::range() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAxisX(m_valuesaxis, m_series); | ||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
range_raw(); | ||||
} | ||||
|
r1699 | |||
|
r1700 | void tst_QValuesAxis::range_animation_data() | ||
{ | ||||
range_data(); | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::range_animation() | ||
|
r1699 | { | ||
|
r1700 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||
range(); | ||||
|
r1699 | } | ||
|
r1700 | void tst_QValuesAxis::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 | |||
|
r1700 | void tst_QValuesAxis::ticksCount() | ||
{ | ||||
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 | |||
|
r1700 | m_valuesaxis->setTicksCount(ticksCount); | ||
QCOMPARE(m_valuesaxis->ticksCount(), 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); | ||||
QCOMPARE(m_valuesaxis->ticksCount(), ticksCount); | ||||
|
r1699 | } | ||
QTEST_MAIN(tst_QValuesAxis) | ||||
#include "tst_qvaluesaxis.moc" | ||||