##// END OF EJS Templates
Makes theming axis title aware
Makes theming axis title aware

File last commit:

r2110:a93a773ef512
r2153:cd956b4e0b4d
Show More
tst_qpercentbarseries.cpp
344 lines | 11.2 KiB | text/x-c | CppLexer
/ tests / auto / qpercentbarseries / tst_qpercentbarseries.cpp
sauimone
stacked and percent bar unit tests
r1116 /****************************************************************************
**
** 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$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <qpercentbarseries.h>
#include <qbarset.h>
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 #include <qchartview.h>
#include <qchart.h>
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 #include "tst_definitions.h"
sauimone
stacked and percent bar unit tests
r1116
QTCOMMERCIALCHART_USE_NAMESPACE
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 Q_DECLARE_METATYPE(QBarSet*)
sauimone
stacked and percent bar unit tests
r1116 class tst_QPercentBarSeries : public QObject
{
Q_OBJECT
public slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
private slots:
void qpercentbarseries_data();
void qpercentbarseries();
void type_data();
void type();
sauimone
mouse hover test cases for barcharts
r1146 void mouseclicked_data();
void mouseclicked();
void mousehovered_data();
void mousehovered();
sauimone
stacked and percent bar unit tests
r1116
private:
QPercentBarSeries* m_barseries;
};
void tst_QPercentBarSeries::initTestCase()
{
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 qRegisterMetaType<QBarSet*>("QBarSet*");
sauimone
stacked and percent bar unit tests
r1116 }
void tst_QPercentBarSeries::cleanupTestCase()
{
}
void tst_QPercentBarSeries::init()
{
m_barseries = new QPercentBarSeries();
}
void tst_QPercentBarSeries::cleanup()
{
delete m_barseries;
m_barseries = 0;
}
void tst_QPercentBarSeries::qpercentbarseries_data()
{
}
void tst_QPercentBarSeries::qpercentbarseries()
{
QPercentBarSeries *barseries = new QPercentBarSeries();
QVERIFY(barseries != 0);
}
void tst_QPercentBarSeries::type_data()
{
}
void tst_QPercentBarSeries::type()
{
QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar);
}
sauimone
mouse hover test cases for barcharts
r1146 void tst_QPercentBarSeries::mouseclicked_data()
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 {
}
sauimone
mouse hover test cases for barcharts
r1146 void tst_QPercentBarSeries::mouseclicked()
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 {
sauimone
added SKIP_IF_CANNOT_TEST_MOUSE_EVENTS macro to barseries tests
r2066 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QPercentBarSeries* series = new QPercentBarSeries();
QBarSet* set1 = new QBarSet(QString("set 1"));
*set1 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set1);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
QBarSet* set2 = new QBarSet(QString("set 2"));
*set2 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set2);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QList<QBarSet*> barSets = series->barSets();
Jani Honkonen
normalize signal/slot signatures
r2110 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
QChartView view(new QChart());
view.resize(400,300);
view.chart()->addSeries(series);
view.show();
QTest::qWaitForWindowShown(&view);
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // Calculate expected layout for bars
QRectF plotArea = view.chart()->plotArea();
qreal width = plotArea.width();
qreal height = plotArea.height();
qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
qreal rangeX = 3; // 3 values per set
qreal scaleY = (height / rangeY);
qreal scaleX = (width / rangeX);
qreal setCount = series->count();
qreal domainMinY = 0; // These come from internal domain used by barseries.
qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
qreal rectWidth = scaleX * series->barWidth();
QVector<QRectF> layout;
// 3 = count of values in set
// Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
for (int i = 0; i < 3; i++) {
qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
qreal percentage = (100 / colSum);
qreal yPos = height + scaleY * domainMinY + plotArea.top();
for (int set = 0; set < setCount; set++) {
qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
qreal rectHeigth = barSets.at(set)->at(i) * percentage * scaleY;
QRectF rect(xPos, yPos-rectHeigth, rectWidth, rectHeigth);
layout.append(rect);
yPos -= rectHeigth;
}
}
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 //====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 1, bar 0
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 0);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 1, bar 1
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 1);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 1, bar 2
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 2);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 2, bar 0
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 0);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 2, bar 1
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 1);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 2, bar 2
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 2);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 }
sauimone
stacked and percent bar unit tests
r1116
sauimone
mouse hover test cases for barcharts
r1146 void tst_QPercentBarSeries::mousehovered_data()
{
}
void tst_QPercentBarSeries::mousehovered()
{
sauimone
added SKIP_IF_CANNOT_TEST_MOUSE_EVENTS macro to barseries tests
r2066 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
sauimone
mouse hover test cases for barcharts
r1146 QPercentBarSeries* series = new QPercentBarSeries();
QBarSet* set1 = new QBarSet(QString("set 1"));
*set1 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set1);
sauimone
mouse hover test cases for barcharts
r1146
QBarSet* set2 = new QBarSet(QString("set 2"));
*set2 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set2);
sauimone
mouse hover test cases for barcharts
r1146
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QList<QBarSet*> barSets = series->barSets();
Jani Honkonen
normalize signal/slot signatures
r2110 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
sauimone
mouse hover test cases for barcharts
r1146
QChartView view(new QChart());
view.resize(400,300);
view.chart()->addSeries(series);
view.show();
QTest::qWaitForWindowShown(&view);
sauimone
barseries autotest update
r1287 //this is hack since view does not get events otherwise
view.setMouseTracking(true);
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // Calculate expected layout for bars
QRectF plotArea = view.chart()->plotArea();
qreal width = plotArea.width();
qreal height = plotArea.height();
qreal rangeY = 100; // From 0 to 100 because range is scaled to 100%
qreal rangeX = 3; // 3 values per set
qreal scaleY = (height / rangeY);
qreal scaleX = (width / rangeX);
qreal setCount = series->count();
qreal domainMinY = 0; // These come from internal domain used by barseries.
qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values.
qreal rectWidth = scaleX * series->barWidth();
QVector<QRectF> layout;
// 3 = count of values in set
// Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.)
for (int i = 0; i < 3; i++) {
qreal colSum = 20; // Sum of values in column (10 + 10 in our test case)
qreal percentage = (100 / colSum);
qreal yPos = height + scaleY * domainMinY + plotArea.top();
for (int set = 0; set < setCount; set++) {
qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2;
qreal rectHeight = barSets.at(set)->at(i) * percentage * scaleY;
QRectF rect(xPos, yPos-rectHeight, rectWidth, rectHeight);
layout.append(rect);
yPos -= rectHeight;
}
}
sauimone
mouse hover test cases for barcharts
r1146 //=======================================================================
// move mouse to left border
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
TRY_COMPARE(seriesSpy.count(), 0);
sauimone
mouse hover test cases for barcharts
r1146
//=======================================================================
// move mouse on top of set1
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 TRY_COMPARE(seriesSpy.count(), 1);
sauimone
mouse hover test cases for barcharts
r1146
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == true);
sauimone
mouse hover test cases for barcharts
r1146
//=======================================================================
// move mouse from top of set1 to top of set2
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 TRY_COMPARE(seriesSpy.count(), 2);
sauimone
mouse hover test cases for barcharts
r1146
// should leave set1
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == false);
sauimone
mouse hover test cases for barcharts
r1146
// should enter set2
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == true);
sauimone
mouse hover test cases for barcharts
r1146
//=======================================================================
// move mouse from top of set2 to background
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 TRY_COMPARE(seriesSpy.count(), 1);
sauimone
mouse hover test cases for barcharts
r1146
sauimone
barseries autotest update
r1287 // should leave set2
sauimone
mouse hover test cases for barcharts
r1146 seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == false);
sauimone
mouse hover test cases for barcharts
r1146 }
sauimone
stacked and percent bar unit tests
r1116 QTEST_MAIN(tst_QPercentBarSeries)
#include "tst_qpercentbarseries.moc"