tst_qcategoryaxis.cpp
318 lines
| 8.5 KiB
| text/x-c
|
CppLexer
|
r1708 | /**************************************************************************** | ||
** | ||||
|
r2776 | ** Copyright (C) 2015 The Qt Company Ltd | ||
|
r1708 | ** All rights reserved. | ||
|
r2776 | ** For any questions to The Qt Company, please use contact form at http://qt.io | ||
|
r1708 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r1708 | ** | ||
|
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 | ||||
|
r2776 | ** agreement between you and The Qt Company. | ||
|
r1708 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r1708 | ** | ||
****************************************************************************/ | ||||
#include "../qabstractaxis/tst_qabstractaxis.h" | ||||
|
r2714 | #include <QtCharts/QCategoryAxis> | ||
#include <QtCharts/QLineSeries> | ||||
|
r1708 | |||
|
r1816 | class tst_QCategoryAxis: public tst_QAbstractAxis | ||
|
r1708 | { | ||
Q_OBJECT | ||||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
|
r1817 | void qcategoryaxis_data(); | ||
void qcategoryaxis(); | ||||
|
r1708 | |||
void max_raw_data(); | ||||
void max_raw(); | ||||
void max_data(); | ||||
void max(); | ||||
void max_animation_data(); | ||||
void max_animation(); | ||||
void min_raw_data(); | ||||
void min_raw(); | ||||
void min_data(); | ||||
void min(); | ||||
void min_animation_data(); | ||||
void min_animation(); | ||||
void range_raw_data(); | ||||
void range_raw(); | ||||
void range_data(); | ||||
void range(); | ||||
void range_animation_data(); | ||||
void range_animation(); | ||||
|
r2780 | void labels_position(); | ||
|
r1708 | |||
void interval_data(); | ||||
void interval(); | ||||
private: | ||||
|
r1846 | QCategoryAxis* m_categoryaxis; | ||
|
r1708 | QLineSeries* m_series; | ||
}; | ||||
|
r1816 | void tst_QCategoryAxis::initTestCase() | ||
|
r1708 | { | ||
|
r2780 | qRegisterMetaType<QCategoryAxis::AxisLabelsPosition>("QCategoryAxis::AxisLabelsPosition"); | ||
|
r1708 | } | ||
|
r1816 | void tst_QCategoryAxis::cleanupTestCase() | ||
|
r1708 | { | ||
|
r2733 | QTest::qWait(1); // Allow final deleteLaters to run | ||
|
r1708 | } | ||
|
r1816 | void tst_QCategoryAxis::init() | ||
|
r1708 | { | ||
|
r1846 | m_categoryaxis = new QCategoryAxis(); | ||
|
r1708 | m_series = new QLineSeries(); | ||
*m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100); | ||||
|
r1846 | tst_QAbstractAxis::init(m_categoryaxis, m_series); | ||
|
r1708 | m_chart->addSeries(m_series); | ||
m_chart->createDefaultAxes(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::cleanup() | ||
|
r1708 | { | ||
delete m_series; | ||||
|
r1846 | delete m_categoryaxis; | ||
|
r1708 | m_series = 0; | ||
|
r1846 | m_categoryaxis = 0; | ||
|
r1708 | tst_QAbstractAxis::cleanup(); | ||
} | ||||
|
r1817 | void tst_QCategoryAxis::qcategoryaxis_data() | ||
|
r1708 | { | ||
} | ||||
|
r1817 | void tst_QCategoryAxis::qcategoryaxis() | ||
|
r1708 | { | ||
qabstractaxis(); | ||||
|
r2242 | QVERIFY(qFuzzyCompare(m_categoryaxis->max(), 0)); | ||
QVERIFY(qFuzzyCompare(m_categoryaxis->min(), 0)); | ||||
|
r1846 | QCOMPARE(m_categoryaxis->type(), QAbstractAxis::AxisTypeCategory); | ||
|
r2780 | QCOMPARE(m_categoryaxis->labelsPosition(), QCategoryAxis::AxisLabelsPositionCenter); | ||
|
r1708 | |||
|
r1846 | m_chart->setAxisX(m_categoryaxis, m_series); | ||
|
r1708 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
|
r2242 | QVERIFY(!qFuzzyCompare(m_categoryaxis->max(), 0)); | ||
QVERIFY(!qFuzzyCompare(m_categoryaxis->min(), 0)); | ||||
|
r1708 | } | ||
|
r1816 | void tst_QCategoryAxis::max_raw_data() | ||
|
r1708 | { | ||
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; | ||||
|
r1708 | } | ||
|
r1816 | void tst_QCategoryAxis::max_raw() | ||
|
r1708 | { | ||
QFETCH(qreal, max); | ||||
|
r1846 | QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal))); | ||||
|
r2110 | QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal))); | ||
|
r1708 | |||
|
r1846 | m_categoryaxis->setMax(max); | ||
|
r2242 | QVERIFY2(qFuzzyCompare(m_categoryaxis->max(), max), "Not equal"); | ||
|
r1708 | |||
QCOMPARE(spy0.count(), 1); | ||||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 1); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::max_data() | ||
|
r1708 | { | ||
max_raw_data(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::max() | ||
|
r1708 | { | ||
|
r1846 | m_chart->setAxisX(m_categoryaxis, m_series); | ||
|
r1708 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
max_raw(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::max_animation_data() | ||
|
r1708 | { | ||
max_data(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::max_animation() | ||
|
r1708 | { | ||
m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||||
max(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::min_raw_data() | ||
|
r1708 | { | ||
QTest::addColumn<qreal>("min"); | ||||
|
r1957 | QTest::newRow("-1.0") << (qreal)-1.0; | ||
QTest::newRow("-50.0") << (qreal)-50.0; | ||||
QTest::newRow("-101.0") << (qreal)-101.0; | ||||
|
r1708 | } | ||
|
r1816 | void tst_QCategoryAxis::min_raw() | ||
|
r1708 | { | ||
QFETCH(qreal, min); | ||||
|
r1846 | QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal))); | ||||
|
r2110 | QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal))); | ||
|
r1708 | |||
|
r1846 | m_categoryaxis->setMin(min); | ||
|
r2242 | QVERIFY2(qFuzzyCompare(m_categoryaxis->min(), min), "Not equal"); | ||
|
r1708 | |||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::min_data() | ||
|
r1708 | { | ||
min_raw_data(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::min() | ||
|
r1708 | { | ||
|
r1846 | m_chart->setAxisX(m_categoryaxis, m_series); | ||
|
r1708 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
min_raw(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::min_animation_data() | ||
|
r1708 | { | ||
min_data(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::min_animation() | ||
|
r1708 | { | ||
m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||||
min(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::range_raw_data() | ||
|
r1708 | { | ||
QTest::addColumn<qreal>("min"); | ||||
QTest::addColumn<qreal>("max"); | ||||
|
r1957 | 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("-35.0 - 0.0") << (qreal)-35.0 << (qreal)10.0; | ||||
QTest::newRow("-35.0 - 0.0") << (qreal)-35.0 << (qreal)-15.0; | ||||
QTest::newRow("0.0 - 0.0") << (qreal)-0.1 << (qreal)0.1; | ||||
|
r1708 | } | ||
|
r1816 | void tst_QCategoryAxis::range_raw() | ||
|
r1708 | { | ||
QFETCH(qreal, min); | ||||
QFETCH(qreal, max); | ||||
|
r1846 | QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal))); | ||
QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal))); | ||||
|
r2110 | QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal))); | ||
|
r1708 | |||
|
r1846 | m_categoryaxis->setRange(min, max); | ||
|
r2242 | QVERIFY2(qFuzzyCompare(m_categoryaxis->min(), min), "Min not equal"); | ||
QVERIFY2(qFuzzyCompare(m_categoryaxis->max(), max), "Max not equal"); | ||||
|
r1708 | |||
QCOMPARE(spy0.count(), 1); | ||||
QCOMPARE(spy1.count(), 1); | ||||
QCOMPARE(spy2.count(), 1); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::range_data() | ||
|
r1708 | { | ||
range_raw_data(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::range() | ||
|
r1708 | { | ||
|
r1846 | m_chart->setAxisX(m_categoryaxis, m_series); | ||
|
r1708 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
range_raw(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::range_animation_data() | ||
|
r1708 | { | ||
range_data(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::range_animation() | ||
|
r1708 | { | ||
m_chart->setAnimationOptions(QChart::GridAxisAnimations); | ||||
range(); | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::interval_data() | ||
|
r1708 | { | ||
// | ||||
} | ||||
|
r1816 | void tst_QCategoryAxis::interval() | ||
|
r1708 | { | ||
// append one correct interval | ||||
|
r1846 | m_categoryaxis->append("first", (qreal)45); | ||
|
r1847 | QCOMPARE(m_categoryaxis->startValue("first"), (qreal)0); | ||
QCOMPARE(m_categoryaxis->endValue("first"), (qreal)45); | ||||
|
r1708 | |||
// append one more correct interval | ||||
|
r1846 | m_categoryaxis->append("second", (qreal)75); | ||
|
r1847 | QCOMPARE(m_categoryaxis->startValue("second"), (qreal)45); | ||
QCOMPARE(m_categoryaxis->endValue("second"), (qreal)75); | ||||
|
r1708 | |||
// append one incorrect interval | ||||
|
r1846 | m_categoryaxis->append("third", (qreal)15); | ||
QCOMPARE(m_categoryaxis->count(), 2); | ||||
|
r1847 | QCOMPARE(m_categoryaxis->endValue(m_categoryaxis->categoriesLabels().last()), (qreal)75); | ||
|
r1708 | // QCOMPARE(intervalMax("first"), (qreal)75); | ||
// append one more correct interval | ||||
|
r1846 | m_categoryaxis->append("third", (qreal)100); | ||
QCOMPARE(m_categoryaxis->count(), 3); | ||||
|
r1847 | QCOMPARE(m_categoryaxis->startValue("third"), (qreal)75); | ||
QCOMPARE(m_categoryaxis->endValue("third"), (qreal)100); | ||||
|
r1708 | |||
// remove one interval | ||||
|
r1846 | m_categoryaxis->remove("first"); | ||
QCOMPARE(m_categoryaxis->count(), 2); | ||||
|
r1847 | QCOMPARE(m_categoryaxis->startValue("second"), (qreal)0); // second interval should extend to firstInterval minimum | ||
QCOMPARE(m_categoryaxis->endValue("second"), (qreal)75); | ||||
|
r1708 | |||
|
r1779 | // remove one interval | ||
|
r1846 | m_categoryaxis->replaceLabel("second", "replaced"); | ||
QCOMPARE(m_categoryaxis->count(), 2); | ||||
|
r1847 | QCOMPARE(m_categoryaxis->startValue("replaced"), (qreal)0); // second interval should extend to firstInterval minimum | ||
QCOMPARE(m_categoryaxis->endValue("replaced"), (qreal)75); | ||||
|
r1708 | } | ||
|
r2780 | void tst_QCategoryAxis::labels_position() | ||
{ | ||||
QSignalSpy spy(m_categoryaxis, | ||||
SIGNAL(labelsPositionChanged(QCategoryAxis::AxisLabelsPosition))); | ||||
m_categoryaxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue); | ||||
QCOMPARE(m_categoryaxis->labelsPosition(), QCategoryAxis::AxisLabelsPositionOnValue); | ||||
QCOMPARE(spy.count(), 1); | ||||
} | ||||
|
r1816 | QTEST_MAIN(tst_QCategoryAxis) | ||
|
r1817 | #include "tst_qcategoryaxis.moc" | ||
|
r1708 | |||