tst_qchart.cpp
794 lines
| 22.1 KiB
| text/x-c
|
CppLexer
Marek Rosa
|
r1365 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
Michal Klocek
|
r896 | #include <QtTest/QtTest> | ||
#include <qchartview.h> | ||||
#include <qlineseries.h> | ||||
#include <qareaseries.h> | ||||
#include <qscatterseries.h> | ||||
#include <qsplineseries.h> | ||||
#include <qpieseries.h> | ||||
sauimone
|
r1586 | #include <qabstractbarseries.h> | ||
sauimone
|
r1594 | #include <qbarseries.h> | ||
Michal Klocek
|
r896 | #include <qpercentbarseries.h> | ||
#include <qstackedbarseries.h> | ||||
Marek Rosa
|
r1805 | #include <qvalueaxis.h> | ||
Marek Rosa
|
r1810 | #include <qbarcategoryaxis.h> | ||
Michal Klocek
|
r896 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
Michal Klocek
|
r1541 | Q_DECLARE_METATYPE(QAbstractAxis *) | ||
Marek Rosa
|
r1804 | Q_DECLARE_METATYPE(QValueAxis *) | ||
Marek Rosa
|
r1808 | Q_DECLARE_METATYPE(QBarCategoryAxis *) | ||
Tero Ahola
|
r988 | Q_DECLARE_METATYPE(QAbstractSeries *) | ||
Michal Klocek
|
r914 | Q_DECLARE_METATYPE(QChart::AnimationOption) | ||
Michal Klocek
|
r929 | Q_DECLARE_METATYPE(QBrush) | ||
Q_DECLARE_METATYPE(QPen) | ||||
Q_DECLARE_METATYPE(QChart::ChartTheme) | ||||
Michal Klocek
|
r896 | |||
class tst_QChart : public QObject | ||||
{ | ||||
Q_OBJECT | ||||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
void qchart_data(); | ||||
void qchart(); | ||||
void addSeries_data(); | ||||
void addSeries(); | ||||
void animationOptions_data(); | ||||
void animationOptions(); | ||||
void axisX_data(); | ||||
void axisX(); | ||||
void axisY_data(); | ||||
void axisY(); | ||||
void backgroundBrush_data(); | ||||
void backgroundBrush(); | ||||
void backgroundPen_data(); | ||||
void backgroundPen(); | ||||
void isBackgroundVisible_data(); | ||||
void isBackgroundVisible(); | ||||
void legend_data(); | ||||
void legend(); | ||||
Michal Klocek
|
r1883 | void plotArea_data(); | ||
void plotArea(); | ||||
Michal Klocek
|
r896 | void removeAllSeries_data(); | ||
void removeAllSeries(); | ||||
void removeSeries_data(); | ||||
void removeSeries(); | ||||
Michal Klocek
|
r1660 | void scroll_right_data(); | ||
void scroll_right(); | ||||
void scroll_left_data(); | ||||
void scroll_left(); | ||||
void scroll_up_data(); | ||||
void scroll_up(); | ||||
void scroll_down_data(); | ||||
void scroll_down(); | ||||
Michal Klocek
|
r896 | void theme_data(); | ||
void theme(); | ||||
void title_data(); | ||||
void title(); | ||||
void titleBrush_data(); | ||||
void titleBrush(); | ||||
void titleFont_data(); | ||||
void titleFont(); | ||||
void zoomIn_data(); | ||||
void zoomIn(); | ||||
void zoomOut_data(); | ||||
void zoomOut(); | ||||
Michal Klocek
|
r914 | private: | ||
void createTestData(); | ||||
Michal Klocek
|
r896 | private: | ||
QChartView* m_view; | ||||
QChart* m_chart; | ||||
}; | ||||
void tst_QChart::initTestCase() | ||||
{ | ||||
} | ||||
void tst_QChart::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_QChart::init() | ||||
{ | ||||
m_view = new QChartView(new QChart()); | ||||
m_chart = m_view->chart(); | ||||
Michal Klocek
|
r914 | } | ||
Michal Klocek
|
r896 | |||
void tst_QChart::cleanup() | ||||
{ | ||||
delete m_view; | ||||
m_view = 0; | ||||
m_chart = 0; | ||||
} | ||||
Michal Klocek
|
r1660 | |||
void tst_QChart::createTestData() | ||||
{ | ||||
QLineSeries* series0 = new QLineSeries(this); | ||||
*series0 << QPointF(0, 0) << QPointF(100, 100); | ||||
m_chart->addSeries(series0); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
} | ||||
Michal Klocek
|
r896 | void tst_QChart::qchart_data() | ||
{ | ||||
} | ||||
void tst_QChart::qchart() | ||||
{ | ||||
QVERIFY(m_chart); | ||||
QVERIFY(m_chart->legend()); | ||||
Jani Honkonen
|
r1227 | QVERIFY(m_chart->legend()->isVisible()); | ||
Michal Klocek
|
r896 | |||
QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | ||||
Michal Klocek
|
r1660 | QVERIFY(!m_chart->axisX()); | ||
QVERIFY(!m_chart->axisY()); | ||||
Michal Klocek
|
r896 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | ||
QVERIFY(m_chart->backgroundPen()!=QPen()); | ||||
QCOMPARE(m_chart->isBackgroundVisible(), true); | ||||
Michal Klocek
|
r1883 | QVERIFY(m_chart->plotArea().top()==0); | ||
QVERIFY(m_chart->plotArea().left()==0); | ||||
QVERIFY(m_chart->plotArea().right()==0); | ||||
QVERIFY(m_chart->plotArea().bottom()==0); | ||||
Michal Klocek
|
r929 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | ||
QCOMPARE(m_chart->title(), QString()); | ||||
//QCOMPARE(m_chart->titleBrush(),QBrush()); | ||||
//QCOMPARE(m_chart->titleFont(),QFont()); | ||||
Michal Klocek
|
r896 | m_chart->removeAllSeries(); | ||
Michal Klocek
|
r1553 | m_chart->scroll(0,0); | ||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | m_chart->zoomIn(); | ||
m_chart->zoomIn(QRectF()); | ||||
m_chart->zoomOut(); | ||||
Michal Klocek
|
r1883 | |||
m_view->show(); | ||||
QVERIFY(m_chart->plotArea().top()>0); | ||||
QVERIFY(m_chart->plotArea().left()>0); | ||||
QVERIFY(m_chart->plotArea().right()>0); | ||||
QVERIFY(m_chart->plotArea().bottom()>0); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::addSeries_data() | ||||
{ | ||||
Tero Ahola
|
r988 | QTest::addColumn<QAbstractSeries *>("series"); | ||
Michal Klocek
|
r1660 | |||
QAbstractSeries* line = new QLineSeries(this); | ||||
QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | ||||
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); | ||||
QTest::newRow("lineSeries") << line; | ||||
QTest::newRow("areaSeries") << area; | ||||
QTest::newRow("scatterSeries") << scatter; | ||||
QTest::newRow("splineSeries") << spline; | ||||
QTest::newRow("pieSeries") << pie; | ||||
QTest::newRow("barSeries") << bar; | ||||
QTest::newRow("percentBarSeries") << percent; | ||||
QTest::newRow("stackedBarSeries") << stacked; | ||||
Michal Klocek
|
r896 | |||
} | ||||
void tst_QChart::addSeries() | ||||
{ | ||||
Tero Ahola
|
r988 | QFETCH(QAbstractSeries *, series); | ||
Michal Klocek
|
r914 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
Jani Honkonen
|
r1314 | QVERIFY(!series->chart()); | ||
Jani Honkonen
|
r1316 | QCOMPARE(m_chart->series().count(), 0); | ||
Michal Klocek
|
r1541 | m_chart->addSeries(series); | ||
Jani Honkonen
|
r1316 | QCOMPARE(m_chart->series().count(), 1); | ||
QCOMPARE(m_chart->series().first(), series); | ||||
Jani Honkonen
|
r1314 | QVERIFY(series->chart() == m_chart); | ||
Michal Klocek
|
r1660 | m_chart->createDefaultAxes(); | ||
if(series->type()!=QAbstractSeries::SeriesTypePie){ | ||||
QVERIFY(m_chart->axisY(series)); | ||||
QVERIFY(m_chart->axisX(series)); | ||||
}else{ | ||||
QVERIFY(!m_chart->axisY(series)); | ||||
QVERIFY(!m_chart->axisX(series)); | ||||
} | ||||
Michal Klocek
|
r974 | m_chart->removeSeries(series); | ||
Jani Honkonen
|
r1314 | QVERIFY(!series->chart()); | ||
Jani Honkonen
|
r1316 | QCOMPARE(m_chart->series().count(), 0); | ||
Michal Klocek
|
r896 | } | ||
void tst_QChart::animationOptions_data() | ||||
{ | ||||
Michal Klocek
|
r914 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | ||
QTest::newRow("AllAnimations") << QChart::AllAnimations; | ||||
QTest::newRow("NoAnimation") << QChart::NoAnimation; | ||||
QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | ||||
QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::animationOptions() | ||||
{ | ||||
Michal Klocek
|
r914 | createTestData(); | ||
QFETCH(QChart::AnimationOption, animationOptions); | ||||
m_chart->setAnimationOptions(animationOptions); | ||||
QCOMPARE(m_chart->animationOptions(), animationOptions); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::axisX_data() | ||||
{ | ||||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r1660 | QTest::addColumn<QAbstractAxis*>("axis"); | ||
QTest::addColumn<QAbstractSeries *>("series"); | ||||
Marek Rosa
|
r1808 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); | ||
QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | ||||
QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); | ||||
QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); | ||||
QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); | ||||
QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); | ||||
QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | ||||
QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | ||||
Michal Klocek
|
r1660 | |||
Marek Rosa
|
r1804 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); | ||
QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | ||||
QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); | ||||
QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); | ||||
QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); | ||||
QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); | ||||
QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | ||||
QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | ||||
Michal Klocek
|
r1660 | |||
Michal Klocek
|
r896 | } | ||
void tst_QChart::axisX() | ||||
{ | ||||
Michal Klocek
|
r1660 | QFETCH(QAbstractAxis*, axis); | ||
QFETCH(QAbstractSeries*, series); | ||||
QVERIFY(!m_chart->axisX()); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
m_chart->addSeries(series); | ||||
m_chart->setAxisX(axis,series); | ||||
QVERIFY(m_chart->axisX(series)==axis); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::axisY_data() | ||||
{ | ||||
Michal Klocek
|
r1660 | axisX_data(); | ||
Michal Klocek
|
r896 | } | ||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | void tst_QChart::axisY() | ||
{ | ||||
Michal Klocek
|
r1660 | QFETCH(QAbstractAxis*, axis); | ||
QFETCH(QAbstractSeries*, series); | ||||
QVERIFY(!m_chart->axisY()); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
m_chart->addSeries(series); | ||||
m_chart->setAxisY(axis,series); | ||||
QVERIFY(m_chart->axisY(series)==axis); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::backgroundBrush_data() | ||||
{ | ||||
QTest::addColumn<QBrush>("backgroundBrush"); | ||||
QTest::newRow("null") << QBrush(); | ||||
Michal Klocek
|
r929 | QTest::newRow("blue") << QBrush(Qt::blue); | ||
QTest::newRow("white") << QBrush(Qt::white); | ||||
QTest::newRow("black") << QBrush(Qt::black); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::backgroundBrush() | ||||
{ | ||||
QFETCH(QBrush, backgroundBrush); | ||||
Michal Klocek
|
r929 | m_chart->setBackgroundBrush(backgroundBrush); | ||
QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::backgroundPen_data() | ||||
{ | ||||
QTest::addColumn<QPen>("backgroundPen"); | ||||
QTest::newRow("null") << QPen(); | ||||
Michal Klocek
|
r929 | QTest::newRow("blue") << QPen(Qt::blue); | ||
QTest::newRow("white") << QPen(Qt::white); | ||||
QTest::newRow("black") << QPen(Qt::black); | ||||
Michal Klocek
|
r896 | } | ||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | void tst_QChart::backgroundPen() | ||
{ | ||||
QFETCH(QPen, backgroundPen); | ||||
Michal Klocek
|
r929 | m_chart->setBackgroundPen(backgroundPen); | ||
QCOMPARE(m_chart->backgroundPen(), backgroundPen); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::isBackgroundVisible_data() | ||||
{ | ||||
QTest::addColumn<bool>("isBackgroundVisible"); | ||||
QTest::newRow("true") << true; | ||||
QTest::newRow("false") << false; | ||||
} | ||||
void tst_QChart::isBackgroundVisible() | ||||
{ | ||||
QFETCH(bool, isBackgroundVisible); | ||||
Michal Klocek
|
r929 | m_chart->setBackgroundVisible(isBackgroundVisible); | ||
QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::legend_data() | ||||
{ | ||||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | } | ||
void tst_QChart::legend() | ||||
{ | ||||
Tero Ahola
|
r1543 | QLegend *legend = m_chart->legend(); | ||
QVERIFY(legend); | ||||
// Colors related signals | ||||
QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); | ||||
QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); | ||||
QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); | ||||
// colorChanged | ||||
legend->setColor(QColor("aliceblue")); | ||||
QCOMPARE(colorSpy.count(), 1); | ||||
QBrush b = legend->brush(); | ||||
b.setColor(QColor("aqua")); | ||||
legend->setBrush(b); | ||||
QCOMPARE(colorSpy.count(), 2); | ||||
// borderColorChanged | ||||
legend->setBorderColor(QColor("aliceblue")); | ||||
QCOMPARE(borderColorSpy.count(), 1); | ||||
QPen p = legend->pen(); | ||||
p.setColor(QColor("aqua")); | ||||
legend->setPen(p); | ||||
QCOMPARE(borderColorSpy.count(), 2); | ||||
// labelColorChanged | ||||
legend->setLabelColor(QColor("lightsalmon")); | ||||
QCOMPARE(labelColorSpy.count(), 1); | ||||
b = legend->labelBrush(); | ||||
b.setColor(QColor("lightseagreen")); | ||||
legend->setLabelBrush(b); | ||||
QCOMPARE(labelColorSpy.count(), 2); | ||||
// fontChanged | ||||
QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); | ||||
QFont f = legend->font(); | ||||
f.setBold(!f.bold()); | ||||
legend->setFont(f); | ||||
QCOMPARE(fontSpy.count(), 1); | ||||
Michal Klocek
|
r896 | } | ||
Michal Klocek
|
r1883 | void tst_QChart::plotArea_data() | ||
Michal Klocek
|
r896 | { | ||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | } | ||
Michal Klocek
|
r1883 | void tst_QChart::plotArea() | ||
Michal Klocek
|
r1082 | { | ||
Michal Klocek
|
r929 | createTestData(); | ||
QRectF rect = m_chart->geometry(); | ||||
Michal Klocek
|
r1883 | QVERIFY(m_chart->plotArea().isValid()); | ||
QVERIFY(m_chart->plotArea().height() < rect.height()); | ||||
QVERIFY(m_chart->plotArea().width() < rect.width()); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::removeAllSeries_data() | ||||
{ | ||||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | } | ||
void tst_QChart::removeAllSeries() | ||||
{ | ||||
Michal Klocek
|
r929 | QLineSeries* series0 = new QLineSeries(this); | ||
QLineSeries* series1 = new QLineSeries(this); | ||||
QLineSeries* series2 = new QLineSeries(this); | ||||
Jani Honkonen
|
r1314 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | ||
QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | ||||
QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | ||||
Michal Klocek
|
r929 | |||
m_chart->addSeries(series0); | ||||
m_chart->addSeries(series1); | ||||
m_chart->addSeries(series2); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
Michal Klocek
|
r1660 | m_chart->createDefaultAxes(); | ||
Michal Klocek
|
r929 | QVERIFY(m_chart->axisY(series0)!=0); | ||
QVERIFY(m_chart->axisY(series1)!=0); | ||||
QVERIFY(m_chart->axisY(series2)!=0); | ||||
Michal Klocek
|
r896 | |||
Michal Klocek
|
r929 | m_chart->removeAllSeries(); | ||
QVERIFY(m_chart->axisY(series0)==0); | ||||
QVERIFY(m_chart->axisY(series1)==0); | ||||
QVERIFY(m_chart->axisY(series2)==0); | ||||
Jani Honkonen
|
r1314 | QCOMPARE(deleteSpy1.count(), 1); | ||
QCOMPARE(deleteSpy2.count(), 1); | ||||
QCOMPARE(deleteSpy3.count(), 1); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::removeSeries_data() | ||||
{ | ||||
Michal Klocek
|
r1660 | axisX_data(); | ||
Michal Klocek
|
r896 | } | ||
void tst_QChart::removeSeries() | ||||
{ | ||||
Michal Klocek
|
r1541 | QFETCH(QAbstractAxis *, axis); | ||
Michal Klocek
|
r1660 | QFETCH(QAbstractSeries *, series); | ||
Jani Honkonen
|
r1314 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | ||
Michal Klocek
|
r929 | m_view->show(); | ||
QTest::qWaitForWindowShown(m_view); | ||||
if(!axis) axis = m_chart->axisY(); | ||||
Michal Klocek
|
r1541 | m_chart->addSeries(series); | ||
Michal Klocek
|
r1577 | m_chart->setAxisY(axis,series); | ||
Michal Klocek
|
r929 | QCOMPARE(m_chart->axisY(series),axis); | ||
m_chart->removeSeries(series); | ||||
QVERIFY(m_chart->axisY(series)==0); | ||||
Jani Honkonen
|
r1314 | QCOMPARE(deleteSpy.count(), 0); | ||
Michal Klocek
|
r896 | } | ||
Michal Klocek
|
r1660 | void tst_QChart::scroll_right_data() | ||
Michal Klocek
|
r896 | { | ||
Michal Klocek
|
r1660 | QTest::addColumn<QAbstractSeries *>("series"); | ||
QLineSeries* series0 = new QLineSeries(this); | ||||
*series0 << QPointF(0, 0) << QPointF(100, 100); | ||||
QTest::newRow("lineSeries") << (QAbstractSeries*) series0; | ||||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | } | ||
Michal Klocek
|
r1660 | void tst_QChart::scroll_right() | ||
Michal Klocek
|
r896 | { | ||
Michal Klocek
|
r1660 | QFETCH(QAbstractSeries *, series); | ||
m_chart->addSeries(series); | ||||
m_chart->createDefaultAxes(); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
QAbstractAxis * axis = m_chart->axisX(); | ||||
QVERIFY(axis!=0); | ||||
switch(axis->type()) | ||||
{ | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeValue:{ | ||
Marek Rosa
|
r1804 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(vaxis!=0); | ||
qreal min = vaxis->min(); | ||||
qreal max = vaxis->max(); | ||||
QVERIFY(max>min); | ||||
m_chart->scroll(50, 0); | ||||
QVERIFY(min<vaxis->min()); | ||||
QVERIFY(max<vaxis->max()); | ||||
break; | ||||
} | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeBarCategory:{ | ||
Marek Rosa
|
r1808 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(caxis!=0); | ||
qreal min = caxis->min().toDouble(); | ||||
qreal max = caxis->max().toDouble(); | ||||
m_chart->scroll(50, 0); | ||||
QVERIFY(min<caxis->min().toDouble()); | ||||
QVERIFY(max<caxis->max().toDouble()); | ||||
break; | ||||
} | ||||
default: | ||||
qFatal("Unsupported type"); | ||||
break; | ||||
} | ||||
} | ||||
void tst_QChart::scroll_left_data() | ||||
{ | ||||
scroll_right_data(); | ||||
} | ||||
void tst_QChart::scroll_left() | ||||
{ | ||||
QFETCH(QAbstractSeries *, series); | ||||
m_chart->addSeries(series); | ||||
m_chart->createDefaultAxes(); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
QAbstractAxis * axis = m_chart->axisX(); | ||||
QVERIFY(axis!=0); | ||||
switch(axis->type()) | ||||
{ | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeValue:{ | ||
Marek Rosa
|
r1804 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(vaxis!=0); | ||
qreal min = vaxis->min(); | ||||
qreal max = vaxis->max(); | ||||
m_chart->scroll(-50, 0); | ||||
QVERIFY(min>vaxis->min()); | ||||
QVERIFY(max>vaxis->max()); | ||||
break; | ||||
} | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeBarCategory:{ | ||
Marek Rosa
|
r1808 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(caxis!=0); | ||
qreal min = caxis->min().toDouble(); | ||||
qreal max = caxis->max().toDouble(); | ||||
m_chart->scroll(-50, 0); | ||||
QVERIFY(min>caxis->min().toDouble()); | ||||
QVERIFY(max>caxis->max().toDouble()); | ||||
break; | ||||
} | ||||
default: | ||||
qFatal("Unsupported type"); | ||||
break; | ||||
} | ||||
} | ||||
void tst_QChart::scroll_up_data() | ||||
{ | ||||
scroll_right_data(); | ||||
} | ||||
void tst_QChart::scroll_up() | ||||
{ | ||||
QFETCH(QAbstractSeries *, series); | ||||
m_chart->addSeries(series); | ||||
m_chart->createDefaultAxes(); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
QAbstractAxis * axis = m_chart->axisY(); | ||||
QVERIFY(axis!=0); | ||||
switch(axis->type()) | ||||
{ | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeValue:{ | ||
Marek Rosa
|
r1804 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(vaxis!=0); | ||
qreal min = vaxis->min(); | ||||
qreal max = vaxis->max(); | ||||
m_chart->scroll(0, 50); | ||||
QVERIFY(min<vaxis->min()); | ||||
QVERIFY(max<vaxis->max()); | ||||
break; | ||||
} | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeBarCategory:{ | ||
Marek Rosa
|
r1808 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(caxis!=0); | ||
qreal min = caxis->min().toDouble(); | ||||
qreal max = caxis->max().toDouble(); | ||||
m_chart->scroll(0, 50); | ||||
QVERIFY(min<caxis->min().toDouble()); | ||||
QVERIFY(max<caxis->max().toDouble()); | ||||
break; | ||||
} | ||||
default: | ||||
qFatal("Unsupported type"); | ||||
break; | ||||
} | ||||
} | ||||
void tst_QChart::scroll_down_data() | ||||
{ | ||||
scroll_right_data(); | ||||
} | ||||
void tst_QChart::scroll_down() | ||||
{ | ||||
QFETCH(QAbstractSeries *, series); | ||||
m_chart->addSeries(series); | ||||
m_chart->createDefaultAxes(); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
QAbstractAxis * axis = m_chart->axisY(); | ||||
QVERIFY(axis!=0); | ||||
switch(axis->type()) | ||||
{ | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeValue:{ | ||
Marek Rosa
|
r1804 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(vaxis!=0); | ||
qreal min = vaxis->min(); | ||||
qreal max = vaxis->max(); | ||||
m_chart->scroll(0, -50); | ||||
QVERIFY(min>vaxis->min()); | ||||
QVERIFY(max>vaxis->max()); | ||||
break; | ||||
} | ||||
Marek Rosa
|
r1818 | case QAbstractAxis::AxisTypeBarCategory:{ | ||
Marek Rosa
|
r1808 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | ||
Michal Klocek
|
r1660 | QVERIFY(caxis!=0); | ||
qreal min = caxis->min().toDouble(); | ||||
qreal max = caxis->max().toDouble(); | ||||
m_chart->scroll(0, -50); | ||||
QVERIFY(min>caxis->min().toDouble()); | ||||
QVERIFY(max>caxis->max().toDouble()); | ||||
break; | ||||
} | ||||
default: | ||||
qFatal("Unsupported type"); | ||||
break; | ||||
} | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::theme_data() | ||||
{ | ||||
QTest::addColumn<QChart::ChartTheme>("theme"); | ||||
Michal Klocek
|
r929 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | ||
QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | ||||
QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | ||||
QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | ||||
QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | ||||
QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | ||||
QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::theme() | ||||
{ | ||||
QFETCH(QChart::ChartTheme, theme); | ||||
Michal Klocek
|
r929 | createTestData(); | ||
m_chart->setTheme(theme); | ||||
QVERIFY(m_chart->theme()==theme); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::title_data() | ||||
{ | ||||
QTest::addColumn<QString>("title"); | ||||
QTest::newRow("null") << QString(); | ||||
QTest::newRow("foo") << QString("foo"); | ||||
} | ||||
void tst_QChart::title() | ||||
{ | ||||
QFETCH(QString, title); | ||||
Michal Klocek
|
r929 | m_chart->setTitle(title); | ||
QCOMPARE(m_chart->title(), title); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::titleBrush_data() | ||||
{ | ||||
QTest::addColumn<QBrush>("titleBrush"); | ||||
QTest::newRow("null") << QBrush(); | ||||
Michal Klocek
|
r929 | QTest::newRow("blue") << QBrush(Qt::blue); | ||
QTest::newRow("white") << QBrush(Qt::white); | ||||
QTest::newRow("black") << QBrush(Qt::black); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::titleBrush() | ||||
{ | ||||
QFETCH(QBrush, titleBrush); | ||||
Michal Klocek
|
r929 | m_chart->setTitleBrush(titleBrush); | ||
QCOMPARE(m_chart->titleBrush(), titleBrush); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::titleFont_data() | ||||
{ | ||||
QTest::addColumn<QFont>("titleFont"); | ||||
QTest::newRow("null") << QFont(); | ||||
Michal Klocek
|
r929 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | ||
Michal Klocek
|
r896 | } | ||
void tst_QChart::titleFont() | ||||
{ | ||||
QFETCH(QFont, titleFont); | ||||
Michal Klocek
|
r929 | m_chart->setTitleFont(titleFont); | ||
QCOMPARE(m_chart->titleFont(), titleFont); | ||||
Michal Klocek
|
r896 | } | ||
void tst_QChart::zoomIn_data() | ||||
{ | ||||
Michal Klocek
|
r929 | QTest::addColumn<QRectF>("rect"); | ||
QTest::newRow("null") << QRectF(); | ||||
QTest::newRow("100x100") << QRectF(10,10,100,100); | ||||
QTest::newRow("200x200") << QRectF(10,10,200,200); | ||||
Michal Klocek
|
r896 | } | ||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | void tst_QChart::zoomIn() | ||
{ | ||||
Michal Klocek
|
r1660 | |||
Michal Klocek
|
r929 | QFETCH(QRectF, rect); | ||
createTestData(); | ||||
Michal Klocek
|
r1660 | m_chart->createDefaultAxes(); | ||
Michal Klocek
|
r1883 | QRectF marigns = m_chart->plotArea(); | ||
Michal Klocek
|
r929 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | ||
Marek Rosa
|
r1804 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | ||
Michal Klocek
|
r1660 | QVERIFY(axisX!=0); | ||
Marek Rosa
|
r1804 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | ||
Michal Klocek
|
r1660 | QVERIFY(axisY!=0); | ||
qreal minX = axisX->min(); | ||||
qreal minY = axisY->min(); | ||||
qreal maxX = axisX->max(); | ||||
qreal maxY = axisY->max(); | ||||
Michal Klocek
|
r929 | m_chart->zoomIn(rect); | ||
if(rect.isValid()){ | ||||
Michal Klocek
|
r1660 | QVERIFY(minX<axisX->min()); | ||
QVERIFY(maxX>axisX->max()); | ||||
QVERIFY(minY<axisY->min()); | ||||
QVERIFY(maxY>axisY->max()); | ||||
Michal Klocek
|
r929 | } | ||
Michal Klocek
|
r1660 | |||
Michal Klocek
|
r896 | } | ||
void tst_QChart::zoomOut_data() | ||||
{ | ||||
Michal Klocek
|
r929 | |||
Michal Klocek
|
r896 | } | ||
void tst_QChart::zoomOut() | ||||
{ | ||||
Michal Klocek
|
r929 | createTestData(); | ||
Michal Klocek
|
r1660 | m_chart->createDefaultAxes(); | ||
Marek Rosa
|
r1804 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | ||
Michal Klocek
|
r1660 | QVERIFY(axisX!=0); | ||
Marek Rosa
|
r1804 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | ||
Michal Klocek
|
r1660 | QVERIFY(axisY!=0); | ||
qreal minX = axisX->min(); | ||||
qreal minY = axisY->min(); | ||||
qreal maxX = axisX->max(); | ||||
qreal maxY = axisY->max(); | ||||
Michal Klocek
|
r929 | |||
m_chart->zoomIn(); | ||||
Michal Klocek
|
r896 | |||
Michal Klocek
|
r1660 | QVERIFY(minX < axisX->min()); | ||
QVERIFY(maxX > axisX->max()); | ||||
QVERIFY(minY < axisY->min()); | ||||
QVERIFY(maxY > axisY->max()); | ||||
Michal Klocek
|
r929 | |||
m_chart->zoomOut(); | ||||
Michal Klocek
|
r896 | |||
Tero Ahola
|
r1115 | // min x may be a zero value | ||
if (qFuzzyIsNull(minX)) | ||||
Michal Klocek
|
r1660 | QVERIFY(qFuzzyIsNull(axisX->min())); | ||
Tero Ahola
|
r1115 | else | ||
Michal Klocek
|
r1660 | QCOMPARE(minX, axisX->min()); | ||
Tero Ahola
|
r1115 | |||
// min y may be a zero value | ||||
if (qFuzzyIsNull(minY)) | ||||
Michal Klocek
|
r1660 | QVERIFY(qFuzzyIsNull(axisY->min())); | ||
Tero Ahola
|
r1115 | else | ||
Michal Klocek
|
r1660 | QCOMPARE(minY, axisY->min()); | ||
QVERIFY(maxX == axisX->max()); | ||||
QVERIFY(maxY == axisY->max()); | ||||
Tero Ahola
|
r1115 | |||
Michal Klocek
|
r896 | } | ||
QTEST_MAIN(tst_QChart) | ||||
#include "tst_qchart.moc" | ||||