tst_chartdataset.cpp
410 lines
| 11.8 KiB
| text/x-c
|
CppLexer
|
r771 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r1977 | #ifndef BUILD_PRIVATE_UNIT_TESTS | ||
#include <QtTest/QtTest> | ||||
class tst_ChartDataSet: public QObject { | ||||
Q_OBJECT | ||||
private Q_SLOTS: | ||||
void skip(); | ||||
}; | ||||
void tst_ChartDataSet::skip() | ||||
{ | ||||
|
r2367 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | ||
QSKIP("This test requires the debug version of library"); | ||||
#else | ||||
|
r1977 | QSKIP("This test requires the debug version of library", SkipAll); | ||
|
r2367 | #endif | ||
|
r1977 | } | ||
QTEST_MAIN(tst_ChartDataSet) | ||||
#include "tst_chartdataset.moc" | ||||
#else | ||||
|
r771 | |||
|
r224 | #include <QtTest/QtTest> | ||
|
r1541 | #include <qabstractaxis.h> | ||
|
r1805 | #include <qvalueaxis.h> | ||
|
r1810 | #include <qbarcategoryaxis.h> | ||
|
r2273 | #include <qcategoryaxis.h> | ||
|
r2391 | #ifndef QT_ON_ARM | ||
#include "qdatetimeaxis.h" | ||||
#endif | ||||
|
r349 | #include <qlineseries.h> | ||
|
r1564 | #include <qareaseries.h> | ||
#include <qscatterseries.h> | ||||
#include <qsplineseries.h> | ||||
#include <qpieseries.h> | ||||
|
r1594 | #include <qbarseries.h> | ||
|
r1564 | #include <qpercentbarseries.h> | ||
#include <qstackedbarseries.h> | ||||
|
r224 | #include <private/chartdataset_p.h> | ||
|
r2275 | #include <private/abstractdomain_p.h> | ||
|
r1109 | #include <tst_definitions.h> | ||
|
r224 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
|
r2275 | Q_DECLARE_METATYPE(AbstractDomain *) | ||
|
r1541 | Q_DECLARE_METATYPE(QAbstractAxis *) | ||
|
r988 | Q_DECLARE_METATYPE(QAbstractSeries *) | ||
|
r1564 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | ||
Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | ||||
|
r2273 | Q_DECLARE_METATYPE(Qt::Alignment) | ||
Q_DECLARE_METATYPE(QList<Qt::Alignment>) | ||||
|
r988 | Q_DECLARE_METATYPE(QLineSeries *) | ||
|
r224 | |||
class tst_ChartDataSet: public QObject { | ||||
|
r771 | Q_OBJECT | ||
|
r2284 | public: | ||
tst_ChartDataSet():m_dataset(0){}; | ||||
|
r771 | |||
public Q_SLOTS: | ||||
|
r2247 | void initTestCase(); | ||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
|
r224 | |||
|
r771 | private Q_SLOTS: | ||
|
r2247 | void chartdataset_data(); | ||
void chartdataset(); | ||||
void addSeries_data(); | ||||
void addSeries(); | ||||
void removeSeries_data(); | ||||
void removeSeries(); | ||||
|
r2273 | void addAxis_data(); | ||
void addAxis(); | ||||
void removeAxis_data(); | ||||
void removeAxis(); | ||||
void attachAxis_data(); | ||||
void attachAxis(); | ||||
void detachAxis_data(); | ||||
void detachAxis(); | ||||
|
r1593 | |||
|
r1078 | private: | ||
ChartDataSet* m_dataset; | ||||
|
r224 | }; | ||
void tst_ChartDataSet::initTestCase() | ||||
{ | ||||
|
r2275 | qRegisterMetaType<AbstractDomain*>(); | ||
|
r2247 | qRegisterMetaType<QAbstractAxis*>(); | ||
|
r989 | qRegisterMetaType<QAbstractSeries*>(); | ||
|
r224 | } | ||
void tst_ChartDataSet::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_ChartDataSet::init() | ||||
{ | ||||
|
r2284 | Q_ASSERT(!m_dataset); | ||
|
r2273 | m_dataset = new ChartDataSet(0); | ||
|
r224 | } | ||
|
r1078 | |||
|
r224 | void tst_ChartDataSet::cleanup() | ||
{ | ||||
|
r2284 | delete m_dataset; | ||
m_dataset=0; | ||||
|
r224 | } | ||
void tst_ChartDataSet::chartdataset_data() | ||||
{ | ||||
} | ||||
void tst_ChartDataSet::chartdataset() | ||||
{ | ||||
|
r2273 | QVERIFY(m_dataset->axes().isEmpty()); | ||
QVERIFY(m_dataset->series().isEmpty()); | ||||
m_dataset->createDefaultAxes(); | ||||
|
r224 | } | ||
|
r1564 | |||
|
r224 | void tst_ChartDataSet::addSeries_data() | ||
{ | ||||
|
r2247 | QTest::addColumn<QAbstractSeries*>("series"); | ||
|
r1564 | |||
QAbstractSeries* line = new QLineSeries(this); | ||||
|
r2247 | QTest::newRow("line") << line; | ||
|
r2284 | |||
QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); | ||||
|
r2247 | QTest::newRow("area") << area; | ||
|
r2284 | |||
QAbstractSeries* scatter = new QScatterSeries(this); | ||||
|
r2247 | QTest::newRow("scatter") << scatter; | ||
|
r2284 | |||
QAbstractSeries* spline = new QSplineSeries(this); | ||||
|
r2247 | QTest::newRow("spline") << spline; | ||
|
r2284 | |||
QAbstractSeries* pie = new QPieSeries(this); | ||||
|
r2247 | QTest::newRow("pie") << pie; | ||
|
r2284 | |||
QAbstractSeries* bar = new QBarSeries(this); | ||||
|
r1564 | QTest::newRow("bar") << bar; | ||
|
r2284 | |||
QAbstractSeries* percent = new QPercentBarSeries(this); | ||||
|
r2247 | QTest::newRow("percent") << percent; | ||
|
r2284 | |||
QAbstractSeries* stacked = new QStackedBarSeries(this); | ||||
|
r2247 | QTest::newRow("stacked") << stacked; | ||
|
r1564 | } | ||
void tst_ChartDataSet::addSeries() | ||||
{ | ||||
QFETCH(QAbstractSeries*, series); | ||||
|
r2273 | QVERIFY(m_dataset->series().isEmpty()); | ||
|
r439 | |||
|
r2273 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | ||
|
r1564 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | ||
|
r2273 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | ||
|
r2110 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | ||
|
r439 | |||
|
r1564 | m_dataset->addSeries(series); | ||
|
r411 | |||
|
r2273 | QCOMPARE(m_dataset->series().count(),1); | ||
|
r1577 | TRY_COMPARE(spy0.count(), 0); | ||
|
r1109 | TRY_COMPARE(spy1.count(), 0); | ||
|
r2273 | TRY_COMPARE(spy2.count(), 1); | ||
|
r1564 | TRY_COMPARE(spy3.count(), 0); | ||
|
r224 | } | ||
|
r1564 | void tst_ChartDataSet::removeSeries_data() | ||
|
r224 | { | ||
|
r1564 | addSeries_data(); | ||
} | ||||
|
r974 | |||
|
r1564 | void tst_ChartDataSet::removeSeries() | ||
{ | ||||
QFETCH(QAbstractSeries*, series); | ||||
|
r2273 | QVERIFY(m_dataset->series().isEmpty()); | ||
|
r1564 | m_dataset->addSeries(series); | ||
|
r974 | |||
|
r2273 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | ||
|
r1564 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | ||
|
r2273 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | ||
|
r2110 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | ||
|
r974 | |||
|
r1564 | m_dataset->removeSeries(series); | ||
|
r974 | |||
|
r2273 | QCOMPARE(m_dataset->series().count(),0); | ||
|
r1109 | TRY_COMPARE(spy0.count(), 0); | ||
|
r2273 | TRY_COMPARE(spy1.count(), 0); | ||
|
r1109 | TRY_COMPARE(spy2.count(), 0); | ||
|
r1564 | TRY_COMPARE(spy3.count(), 1); | ||
|
r224 | } | ||
|
r2273 | void tst_ChartDataSet::addAxis_data() | ||
|
r910 | { | ||
|
r2273 | QTest::addColumn<QAbstractAxis*>("axis"); | ||
QAbstractAxis* value = new QValueAxis(this); | ||||
QAbstractAxis* category = new QCategoryAxis(this); | ||||
QAbstractAxis* barcategory = new QBarCategoryAxis(this); | ||||
|
r2391 | #ifndef Q_WS_QWS | ||
|
r2273 | QAbstractAxis* datetime = new QDateTimeAxis(this); | ||
|
r2391 | #endif | ||
|
r2273 | |||
QTest::newRow("value") << value; | ||||
QTest::newRow("category") << category; | ||||
QTest::newRow("barcategory") << barcategory; | ||||
|
r2391 | #ifndef Q_WS_QWS | ||
|
r2273 | QTest::newRow("datetime") << datetime; | ||
|
r2391 | #endif | ||
|
r910 | } | ||
|
r2273 | void tst_ChartDataSet::addAxis() | ||
|
r910 | { | ||
|
r2273 | QFETCH(QAbstractAxis*, axis); | ||
QVERIFY(m_dataset->axes().isEmpty()); | ||||
|
r910 | |||
|
r2273 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | ||
|
r2110 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | ||
|
r2273 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | ||
|
r2110 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | ||
|
r910 | |||
|
r2273 | m_dataset->addAxis(axis,Qt::AlignBottom); | ||
QCOMPARE(m_dataset->axes().count(),1); | ||||
TRY_COMPARE(spy0.count(), 1); | ||||
|
r1109 | TRY_COMPARE(spy1.count(), 0); | ||
TRY_COMPARE(spy2.count(), 0); | ||||
TRY_COMPARE(spy3.count(), 0); | ||||
|
r910 | } | ||
|
r2273 | void tst_ChartDataSet::removeAxis_data() | ||
|
r771 | { | ||
|
r2273 | addAxis_data(); | ||
|
r771 | } | ||
|
r2273 | void tst_ChartDataSet::removeAxis() | ||
|
r771 | { | ||
|
r2273 | QFETCH(QAbstractAxis*, axis); | ||
QVERIFY(m_dataset->series().isEmpty()); | ||||
m_dataset->addAxis(axis,Qt::AlignBottom); | ||||
|
r910 | |||
|
r2273 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | ||
|
r2110 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | ||
|
r2273 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | ||
|
r1078 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | ||
|
r771 | |||
|
r2273 | m_dataset->removeAxis(axis); | ||
|
r771 | |||
|
r2384 | QCOMPARE(m_dataset->axes().count(),0); | ||
|
r2273 | QCOMPARE(m_dataset->series().count(),0); | ||
|
r1109 | TRY_COMPARE(spy0.count(), 0); | ||
|
r2273 | TRY_COMPARE(spy1.count(), 1); | ||
|
r1109 | TRY_COMPARE(spy2.count(), 0); | ||
TRY_COMPARE(spy3.count(), 0); | ||||
|
r2273 | } | ||
|
r910 | |||
|
r2273 | void tst_ChartDataSet::attachAxis_data() | ||
|
r771 | { | ||
|
r2284 | |||
|
r2273 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | ||
QTest::addColumn<QList<QAbstractAxis*> >("axis"); | ||||
QTest::addColumn<QList<Qt::Alignment> >("alignment"); | ||||
QTest::addColumn<QAbstractSeries*>("attachSeries"); | ||||
QTest::addColumn<QAbstractAxis*>("attachAxis"); | ||||
QTest::addColumn<bool>("success"); | ||||
|
r771 | |||
|
r2284 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | ||
|
r2273 | QAbstractSeries* scatter = new QScatterSeries(this); | ||
QAbstractSeries* spline = new QSplineSeries(this); | ||||
QAbstractSeries* pie = new QPieSeries(this); | ||||
QAbstractSeries* bar = new QBarSeries(this); | ||||
QAbstractSeries* percent = new QPercentBarSeries(this); | ||||
QAbstractSeries* stacked = new QStackedBarSeries(this); | ||||
|
r1568 | |||
|
r2273 | QAbstractAxis* category = new QCategoryAxis(this); | ||
QAbstractAxis* barcategory = new QBarCategoryAxis(this); | ||||
|
r2391 | #ifndef Q_WS_QWS | ||
|
r2273 | QAbstractAxis* datetime = new QDateTimeAxis(this); | ||
|
r2391 | #endif | ||
|
r2284 | { | ||
QList<QAbstractSeries*> series; | ||||
QList<QAbstractAxis*> axes; | ||||
QList<Qt::Alignment> alignment; | ||||
QAbstractSeries* line = new QLineSeries(this); | ||||
QAbstractAxis* value1 = new QValueAxis(this); | ||||
QAbstractAxis* value2 = new QValueAxis(this); | ||||
series << line << 0; | ||||
axes << value1 << value2; | ||||
alignment << Qt::AlignBottom << Qt::AlignLeft; | ||||
QTest::newRow("first") << series << axes << alignment << line << value2 << true ; | ||||
} | ||||
|
r1593 | |||
|
r2284 | { | ||
QList<QAbstractSeries*> series; | ||||
QList<QAbstractAxis*> axes; | ||||
QList<Qt::Alignment> alignment; | ||||
QAbstractSeries* line = new QLineSeries(this); | ||||
QAbstractAxis* value1 = new QValueAxis(this); | ||||
QAbstractAxis* value2 = new QValueAxis(this); | ||||
series << 0 << line; | ||||
axes << value1 << value2; | ||||
alignment << Qt::AlignBottom << Qt::AlignLeft; | ||||
QTest::newRow("second") << series << axes << alignment << line << value1 << true; | ||||
} | ||||
|
r1593 | |||
|
r771 | } | ||
|
r2273 | void tst_ChartDataSet::attachAxis() | ||
|
r771 | { | ||
|
r2273 | QFETCH(QList<QAbstractSeries*>, series); | ||
QFETCH(QList<QAbstractAxis*>, axis); | ||||
QFETCH(QList<Qt::Alignment>, alignment); | ||||
QFETCH(QAbstractSeries*, attachSeries); | ||||
QFETCH(QAbstractAxis*, attachAxis); | ||||
QFETCH(bool, success); | ||||
|
r771 | |||
|
r2273 | Q_ASSERT(series.count() == axis.count()); | ||
Q_ASSERT(series.count() == alignment.count()); | ||||
|
r771 | |||
|
r2273 | QVERIFY(m_dataset->series().isEmpty()); | ||
QVERIFY(m_dataset->axes().isEmpty()); | ||||
|
r771 | |||
|
r2273 | for(int i = 0 ; i < series.count() ; i++){ | ||
if(series[i]) m_dataset->addSeries(series[i]); | ||||
if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); | ||||
if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | ||||
|
r1593 | } | ||
|
r771 | |||
|
r2273 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | ||
QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | ||||
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | ||||
QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | ||||
|
r771 | |||
|
r2273 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); | ||
|
r1593 | |||
|
r771 | } | ||
|
r2273 | void tst_ChartDataSet::detachAxis_data() | ||
|
r771 | { | ||
|
r2273 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | ||
QTest::addColumn<QList<QAbstractAxis*> >("axis"); | ||||
QTest::addColumn<QAbstractSeries*>("detachSeries"); | ||||
QTest::addColumn<QAbstractAxis*>("detachAxis"); | ||||
QTest::addColumn<bool>("success"); | ||||
|
r771 | |||
|
r2284 | { | ||
|
r2273 | QList<QAbstractSeries*> series; | ||
QList<QAbstractAxis*> axes; | ||||
QAbstractSeries* line = new QLineSeries(this); | ||||
QAbstractAxis* value = new QValueAxis(this); | ||||
series << line; | ||||
axes << value; | ||||
|
r2284 | QTest::newRow("first") << series << axes << line << value << true; | ||
} | ||||
|
r2273 | } | ||
|
r771 | |||
|
r2273 | void tst_ChartDataSet::detachAxis() | ||
{ | ||||
QFETCH(QList<QAbstractSeries*>, series); | ||||
QFETCH(QList<QAbstractAxis*>, axis); | ||||
QFETCH(QAbstractSeries*, detachSeries); | ||||
QFETCH(QAbstractAxis*, detachAxis); | ||||
QFETCH(bool, success); | ||||
|
r771 | |||
|
r2273 | Q_ASSERT(series.count() == axis.count()); | ||
|
r771 | |||
|
r2273 | QVERIFY(m_dataset->series().isEmpty()); | ||
QVERIFY(m_dataset->axes().isEmpty()); | ||||
|
r771 | |||
|
r2273 | for(int i = 0; i < series.count(); i++) { | ||
if(series[i]) m_dataset->addSeries(series[i]); | ||||
if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); | ||||
if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | ||||
|
r1593 | } | ||
|
r771 | |||
|
r2273 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | ||
QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | ||||
QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | ||||
QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | ||||
QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); | ||||
|
r771 | } | ||
|
r1593 | |||
|
r224 | QTEST_MAIN(tst_ChartDataSet) | ||
#include "tst_chartdataset.moc" | ||||
|
r1977 | #endif | ||