tst_qlineseries.cpp
470 lines
| 10.6 KiB
| text/x-c
|
CppLexer
|
r1064 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r1058 | #include <QtTest/QtTest> | ||
#include <qlineseries.h> | ||||
|
r1064 | #include <qchartview.h> | ||
|
r1071 | #include <QStandardItemModel> | ||
|
r1064 | |||
Q_DECLARE_METATYPE(QList<QPointF>) | ||||
|
r1058 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
class tst_QLineSeries : public QObject | ||||
{ | ||||
Q_OBJECT | ||||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
|
r1064 | void qlineseries_data(); | ||
void qlineseries(); | ||||
|
r1070 | void append_raw_data(); | ||
void append_raw(); | ||||
void append_chart_data(); | ||||
void append_chart(); | ||||
void append_chart_animation_data(); | ||||
void append_chart_animation(); | ||||
void chart_append_data(); | ||||
void chart_append(); | ||||
void count_raw_data(); | ||||
void count_raw(); | ||||
|
r1058 | void oper_data(); | ||
void oper(); | ||||
void pen_data(); | ||||
void pen(); | ||||
|
r1070 | void pointsVisible_raw_data(); | ||
void pointsVisible_raw(); | ||||
void remove_raw_data(); | ||||
void remove_raw(); | ||||
void remove_chart_data(); | ||||
void remove_chart(); | ||||
void remove_chart_animation_data(); | ||||
void remove_chart_animation(); | ||||
|
r1058 | void removeAll_data(); | ||
void removeAll(); | ||||
void replace_data(); | ||||
void replace(); | ||||
void setModel_data(); | ||||
void setModel(); | ||||
void setModelMapping_data(); | ||||
void setModelMapping(); | ||||
|
r1070 | private: | ||
void append_data(); | ||||
void count_data(); | ||||
void pointsVisible_data(); | ||||
|
r1058 | |||
|
r1064 | private: | ||
QChartView* m_view; | ||||
QChart* m_chart; | ||||
|
r1070 | QLineSeries* m_series; | ||
|
r1058 | }; | ||
void tst_QLineSeries::initTestCase() | ||||
{ | ||||
} | ||||
void tst_QLineSeries::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_QLineSeries::init() | ||||
{ | ||||
|
r1070 | m_view = new QChartView(new QChart()); | ||
m_chart = m_view->chart(); | ||||
m_series = new QLineSeries(); | ||||
|
r1058 | } | ||
void tst_QLineSeries::cleanup() | ||||
{ | ||||
|
r1070 | delete m_series; | ||
|
r1064 | delete m_view; | ||
m_view = 0; | ||||
m_chart = 0; | ||||
|
r1070 | m_series = 0; | ||
|
r1058 | } | ||
|
r1064 | void tst_QLineSeries::qlineseries_data() | ||
|
r1058 | { | ||
|
r1070 | |||
|
r1058 | } | ||
|
r1064 | void tst_QLineSeries::qlineseries() | ||
|
r1058 | { | ||
|
r1064 | QLineSeries series; | ||
QCOMPARE(series.count(),0); | ||||
QCOMPARE(series.brush(), QBrush()); | ||||
QCOMPARE(series.points(), QList<QPointF>()); | ||||
QCOMPARE(series.pen(), QPen()); | ||||
|
r1058 | QCOMPARE(series.pointsVisible(), false); | ||
|
r1064 | |||
series.append(QList<QPointF>()); | ||||
series.append(0.0,0.0); | ||||
series.append(QPointF()); | ||||
series.remove(0.0,0.0); | ||||
|
r1058 | series.remove(QPointF()); | ||
series.removeAll(); | ||||
|
r1064 | |||
series.replace(QPointF(),QPointF()); | ||||
series.replace(0,0,0,0); | ||||
|
r1058 | series.setBrush(QBrush()); | ||
|
r1064 | |||
|
r1058 | QCOMPARE(series.setModel((QAbstractItemModel*)0), false); | ||
|
r1064 | |||
series.setModelMapping(-1, -1, Qt::Orientation(0)); | ||||
|
r1058 | series.setPen(QPen()); | ||
series.setPointsVisible(false); | ||||
|
r1070 | |||
m_chart->addSeries(&series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
|
r1058 | } | ||
void tst_QLineSeries::append_data() | ||||
{ | ||||
|
r1070 | QTest::addColumn< QList<QPointF> >("points"); | ||
QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); | ||||
QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); | ||||
|
r1058 | } | ||
|
r1070 | void tst_QLineSeries::append_raw_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::append_raw() | ||
{ | ||||
QFETCH(QList<QPointF>, points); | ||||
QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||||
QTest::qWait(200); | ||||
m_series->append(points); | ||||
QTest::qWait(200); | ||||
|
r1058 | QCOMPARE(spy0.count(), 0); | ||
|
r1070 | QCOMPARE(m_series->points(), points); | ||
|
r1058 | } | ||
|
r1070 | void tst_QLineSeries::chart_append_data() | ||
|
r1058 | { | ||
|
r1070 | append_data(); | ||
|
r1058 | } | ||
|
r1070 | void tst_QLineSeries::chart_append() | ||
|
r1058 | { | ||
|
r1070 | append_raw(); | ||
m_chart->addSeries(m_series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::append_chart_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::append_chart() | ||
{ | ||||
m_view->show(); | ||||
m_chart->addSeries(m_series); | ||||
append_raw(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::append_chart_animation_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::append_chart_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::AllAnimations); | ||||
append_chart(); | ||||
|
r1058 | } | ||
void tst_QLineSeries::count_data() | ||||
{ | ||||
QTest::addColumn<int>("count"); | ||||
QTest::newRow("0") << 0; | ||||
|
r1070 | QTest::newRow("5") << 5; | ||
QTest::newRow("10") << 5; | ||||
|
r1058 | } | ||
|
r1070 | void tst_QLineSeries::count_raw_data() | ||
|
r1058 | { | ||
|
r1070 | count_data(); | ||
|
r1058 | } | ||
|
r1070 | void tst_QLineSeries::count_raw() | ||
|
r1058 | { | ||
|
r1070 | QFETCH(int, count); | ||
|
r1058 | |||
|
r1070 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||
|
r1058 | |||
|
r1070 | for(int i=0 ; i< count; ++i) | ||
m_series->append(i,i); | ||||
|
r1058 | |||
QCOMPARE(spy0.count(), 0); | ||||
|
r1070 | QCOMPARE(m_series->count(), count); | ||
|
r1058 | } | ||
void tst_QLineSeries::oper_data() | ||||
{ | ||||
|
r1070 | append_data(); | ||
|
r1058 | } | ||
void tst_QLineSeries::oper() | ||||
{ | ||||
QFETCH(QList<QPointF>, points); | ||||
|
r1070 | QLineSeries series; | ||
|
r1058 | |||
QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | ||||
|
r1070 | foreach(const QPointF& point,points) | ||
{ | ||||
series<<point; | ||||
} | ||||
|
r1058 | |||
|
r1070 | QCOMPARE(series.points(), points); | ||
|
r1058 | QCOMPARE(spy0.count(), 0); | ||
} | ||||
|
r1070 | |||
|
r1058 | void tst_QLineSeries::pen_data() | ||
{ | ||||
QTest::addColumn<QPen>("pen"); | ||||
QTest::newRow("null") << QPen(); | ||||
|
r1070 | QTest::newRow("blue") << QPen(Qt::blue); | ||
QTest::newRow("black") << QPen(Qt::black); | ||||
QTest::newRow("red") << QPen(Qt::red); | ||||
|
r1058 | } | ||
void tst_QLineSeries::pen() | ||||
{ | ||||
QFETCH(QPen, pen); | ||||
|
r1070 | QLineSeries series; | ||
|
r1058 | |||
QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | ||||
|
r1070 | series.setPen(pen); | ||
|
r1058 | |||
|
r1070 | QCOMPARE(spy0.count(), 0); | ||
|
r1058 | QCOMPARE(series.pen(), pen); | ||
|
r1070 | m_chart->addSeries(&series); | ||
if(pen!=QPen()) QCOMPARE(series.pen(), pen); | ||||
|
r1058 | } | ||
void tst_QLineSeries::pointsVisible_data() | ||||
{ | ||||
QTest::addColumn<bool>("pointsVisible"); | ||||
QTest::newRow("true") << true; | ||||
QTest::newRow("false") << false; | ||||
} | ||||
|
r1070 | void tst_QLineSeries::pointsVisible_raw_data() | ||
{ | ||||
pointsVisible_data(); | ||||
} | ||||
void tst_QLineSeries::pointsVisible_raw() | ||||
|
r1058 | { | ||
QFETCH(bool, pointsVisible); | ||||
|
r1070 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||
m_series->setPointsVisible(pointsVisible); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(m_series->pointsVisible(), pointsVisible); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::remove_raw_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::remove_raw() | ||
{ | ||||
QFETCH(QList<QPointF>, points); | ||||
QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||||
m_series->append(points); | ||||
QTest::qWait(200); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(m_series->points(), points); | ||||
|
r1058 | |||
|
r1070 | foreach(const QPointF& point,points) | ||
{ | ||||
m_series->remove(point); | ||||
QTest::qWait(200); | ||||
} | ||||
|
r1058 | |||
QCOMPARE(spy0.count(), 0); | ||||
|
r1070 | QCOMPARE(m_series->points().count(), 0); | ||
|
r1058 | } | ||
|
r1070 | void tst_QLineSeries::remove_chart_data() | ||
|
r1058 | { | ||
|
r1070 | append_data(); | ||
|
r1058 | } | ||
|
r1070 | void tst_QLineSeries::remove_chart() | ||
|
r1058 | { | ||
|
r1070 | m_view->show(); | ||
m_chart->addSeries(m_series); | ||||
remove_raw(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::remove_chart_animation_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
|
r1058 | |||
|
r1070 | void tst_QLineSeries::remove_chart_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::AllAnimations); | ||||
remove_chart(); | ||||
|
r1058 | } | ||
|
r1070 | |||
|
r1058 | void tst_QLineSeries::removeAll_data() | ||
{ | ||||
|
r1070 | append_data(); | ||
|
r1058 | } | ||
void tst_QLineSeries::removeAll() | ||||
{ | ||||
#if 0 | ||||
QFETCH(int, foo); | ||||
SubQXYSeries series; | ||||
QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | ||||
QSignalSpy spy1(&series, SIGNAL(selected())); | ||||
series.removeAll(); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
#endif | ||||
QSKIP("Test is not implemented.", SkipAll); | ||||
} | ||||
void tst_QLineSeries::replace_data() | ||||
{ | ||||
QTest::addColumn<QPointF>("point"); | ||||
QTest::newRow("null") << QPointF(); | ||||
} | ||||
void tst_QLineSeries::replace() | ||||
{ | ||||
#if 0 | ||||
QFETCH(QPointF, point); | ||||
SubQXYSeries series; | ||||
QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | ||||
QSignalSpy spy1(&series, SIGNAL(selected())); | ||||
series.replace(point); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
#endif | ||||
QSKIP("Test is not implemented.", SkipAll); | ||||
} | ||||
void tst_QLineSeries::setModel_data() | ||||
{ | ||||
QTest::addColumn<int>("modelCount"); | ||||
QTest::addColumn<bool>("setModel"); | ||||
QTest::newRow("null") << 0 << false; | ||||
} | ||||
void tst_QLineSeries::setModel() | ||||
{ | ||||
#if 0 | ||||
QFETCH(int, modelCount); | ||||
QFETCH(bool, setModel); | ||||
SubQXYSeries series; | ||||
QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | ||||
QSignalSpy spy1(&series, SIGNAL(selected())); | ||||
QCOMPARE(series.setModel(model), setModel); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
#endif | ||||
QSKIP("Test is not implemented.", SkipAll); | ||||
} | ||||
Q_DECLARE_METATYPE(Qt::Orientation) | ||||
void tst_QLineSeries::setModelMapping_data() | ||||
{ | ||||
QTest::addColumn<int>("modelX"); | ||||
QTest::addColumn<int>("modelY"); | ||||
QTest::addColumn<Qt::Orientation>("orientation"); | ||||
|
r1071 | QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical; | ||
QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical; | ||||
QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical; | ||||
QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal; | ||||
QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal; | ||||
QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal; | ||||
|
r1058 | } | ||
void tst_QLineSeries::setModelMapping() | ||||
{ | ||||
QFETCH(int, modelX); | ||||
QFETCH(int, modelY); | ||||
QFETCH(Qt::Orientation, orientation); | ||||
|
r1071 | QLineSeries series; | ||
|
r1058 | |||
|
r1071 | // model has not been set so setting mapping should do nothing | ||
|
r1058 | series.setModelMapping(modelX, modelY, orientation); | ||
|
r1071 | QCOMPARE(series.mapX(), -1); | ||
QCOMPARE(series.mapY(), -1); | ||||
QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | ||||
|
r1058 | |||
|
r1071 | // now let us set the model | ||
series.setModel(new QStandardItemModel()); | ||||
series.setModelMapping(modelX, modelY, orientation); | ||||
QCOMPARE(series.mapX(), modelX); | ||||
QCOMPARE(series.mapY(), modelY); | ||||
QVERIFY2(series.mapOrientation() == orientation, "not good"); | ||||
// now let us remove the model, the values should go back to default ones. | ||||
series.setModel(0); | ||||
QCOMPARE(series.mapX(), -1); | ||||
QCOMPARE(series.mapY(), -1); | ||||
QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | ||||
|
r1058 | } | ||
QTEST_MAIN(tst_QLineSeries) | ||||
#include "tst_qlineseries.moc" | ||||