##// END OF EJS Templates
Add autoscale testcases to tst_qvaluesaxis
Add autoscale testcases to tst_qvaluesaxis

File last commit:

r1494:0e4d11fde6b8
r1705:253f5c2017da
Show More
tst_qpieslice.cpp
296 lines | 9.0 KiB | text/x-c | CppLexer
Jani Honkonen
Add basic auto tests for pie
r1105 /****************************************************************************
**
** 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>
Tero Ahola
Auto tests involving signal spys to wait before comparisons
r1109 #include <tst_definitions.h>
Jani Honkonen
Adding more tests for pie...
r1119 #include <qchartview.h>
#include <qchart.h>
#include <qpieslice.h>
#include <qpieseries.h>
Jani Honkonen
Add basic auto tests for pie
r1105
QTCOMMERCIALCHART_USE_NAMESPACE
class tst_qpieslice : public QObject
{
Q_OBJECT
public slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
private slots:
void construction();
void changedSignals();
Jani Honkonen
Adding more tests for pie...
r1119 void customize();
void mouseClick();
void mouseHover();
Jani Honkonen
Add basic auto tests for pie
r1105
private:
private:
};
void tst_qpieslice::initTestCase()
{
}
void tst_qpieslice::cleanupTestCase()
{
}
void tst_qpieslice::init()
{
}
void tst_qpieslice::cleanup()
{
}
void tst_qpieslice::construction()
{
// no params
QPieSlice slice1;
Jani Honkonen
Remove qFuzzyXXX functions from pie tests...
r1125 QCOMPARE(slice1.value(), 0.0);
Jani Honkonen
Add basic auto tests for pie
r1105 QVERIFY(slice1.label().isEmpty());
QVERIFY(!slice1.isLabelVisible());
QVERIFY(!slice1.isExploded());
QCOMPARE(slice1.pen(), QPen());
QCOMPARE(slice1.brush(), QBrush());
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QCOMPARE(slice1.labelBrush(), QBrush());
Jani Honkonen
Add basic auto tests for pie
r1105 QCOMPARE(slice1.labelFont(), QFont());
Jani Honkonen
Remove qFuzzyXXX functions from pie tests...
r1125 QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value
QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value
QCOMPARE(slice1.percentage(), 0.0);
QCOMPARE(slice1.startAngle(), 0.0);
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 QCOMPARE(slice1.angleSpan(), 0.0);
Jani Honkonen
Add basic auto tests for pie
r1105
// value and label params
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 QPieSlice slice2("foobar", 1.0);
Jani Honkonen
Remove qFuzzyXXX functions from pie tests...
r1125 QCOMPARE(slice2.value(), 1.0);
Jani Honkonen
Add basic auto tests for pie
r1105 QCOMPARE(slice2.label(), QString("foobar"));
QVERIFY(!slice2.isLabelVisible());
QVERIFY(!slice2.isExploded());
QCOMPARE(slice2.pen(), QPen());
QCOMPARE(slice2.brush(), QBrush());
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QCOMPARE(slice2.labelBrush(), QBrush());
Jani Honkonen
Add basic auto tests for pie
r1105 QCOMPARE(slice2.labelFont(), QFont());
Jani Honkonen
Remove qFuzzyXXX functions from pie tests...
r1125 QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value
QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value
QCOMPARE(slice2.percentage(), 0.0);
QCOMPARE(slice2.startAngle(), 0.0);
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 QCOMPARE(slice2.angleSpan(), 0.0);
Jani Honkonen
Add basic auto tests for pie
r1105 }
void tst_qpieslice::changedSignals()
{
QPieSlice slice;
Jani Honkonen
pie: remove changed() signal and replace it with more refined signals...
r1224
QSignalSpy valueSpy(&slice, SIGNAL(valueChanged()));
QSignalSpy labelSpy(&slice, SIGNAL(labelChanged()));
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 QSignalSpy penSpy(&slice, SIGNAL(penChanged()));
QSignalSpy brushSpy(&slice, SIGNAL(brushChanged()));
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QSignalSpy labelBrushSpy(&slice, SIGNAL(labelBrushChanged()));
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged()));
Tero Ahola
Auto tests for new QPieSlice signals
r1334 QSignalSpy colorSpy(&slice, SIGNAL(colorChanged()));
QSignalSpy borderColorSpy(&slice, SIGNAL(borderColorChanged()));
QSignalSpy borderWidthSpy(&slice, SIGNAL(borderWidthChanged()));
QSignalSpy labelColorSpy(&slice, SIGNAL(labelColorChanged()));
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274
// percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
Jani Honkonen
pie: remove changed() signal and replace it with more refined signals...
r1224
// set everything twice to see we do not get unnecessary signals
Jani Honkonen
pie: make it impossible to add negative slice values
r1280 slice.setValue(1.0);
slice.setValue(-1.0);
QCOMPARE(slice.value(), 1.0);
Jani Honkonen
Add basic auto tests for pie
r1105 slice.setLabel("foobar");
slice.setLabel("foobar");
slice.setLabelVisible();
slice.setLabelVisible();
slice.setExploded();
slice.setExploded();
slice.setPen(QPen(Qt::red));
Tero Ahola
Auto tests for new QPieSlice signals
r1334 slice.setPen(QPen(QBrush(Qt::red), 3));
Jani Honkonen
Add basic auto tests for pie
r1105 slice.setBrush(QBrush(Qt::red));
slice.setBrush(QBrush(Qt::red));
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 slice.setLabelBrush(QBrush(Qt::green));
slice.setLabelBrush(QBrush(Qt::green));
Jani Honkonen
Add basic auto tests for pie
r1105 slice.setLabelFont(QFont("Tahoma"));
slice.setLabelFont(QFont("Tahoma"));
Jani Honkonen
pie: add label position to slice
r1450 slice.setLabelPosition(QPieSlice::LabelInside);
slice.setLabelPosition(QPieSlice::LabelInside);
Jani Honkonen
Add basic auto tests for pie
r1105 slice.setLabelArmLengthFactor(0.1);
slice.setLabelArmLengthFactor(0.1);
slice.setExplodeDistanceFactor(0.1);
slice.setExplodeDistanceFactor(0.1);
Jani Honkonen
pie: remove changed() signal and replace it with more refined signals...
r1224
TRY_COMPARE(valueSpy.count(), 1);
TRY_COMPARE(labelSpy.count(), 1);
Tero Ahola
Auto tests for new QPieSlice signals
r1334 TRY_COMPARE(penSpy.count(), 2);
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 TRY_COMPARE(brushSpy.count(), 1);
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 TRY_COMPARE(labelBrushSpy.count(), 1);
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 TRY_COMPARE(labelFontSpy.count(), 1);
Tero Ahola
Auto tests for new QPieSlice signals
r1334 TRY_COMPARE(colorSpy.count(), 1);
TRY_COMPARE(borderColorSpy.count(), 1);
TRY_COMPARE(borderWidthSpy.count(), 1);
TRY_COMPARE(labelColorSpy.count(), 1);
Jani Honkonen
Add basic auto tests for pie
r1105 }
Jani Honkonen
Adding more tests for pie...
r1119 void tst_qpieslice::customize()
{
// create a pie series
QPieSeries *series = new QPieSeries();
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 QPieSlice *s1 = series->append("slice 1", 1);
QPieSlice *s2 = series->append("slice 2", 2);
series->append("slice 3", 3);
Jani Honkonen
Adding more tests for pie...
r1119
// customize a slice
QPen p1(Qt::red);
s1->setPen(p1);
QBrush b1(Qt::red);
s1->setBrush(b1);
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 s1->setLabelBrush(b1);
Jani Honkonen
Adding more tests for pie...
r1119 QFont f1("Consolas");
s1->setLabelFont(f1);
// add series to the chart
QChartView view(new QChart());
view.resize(200, 200);
view.chart()->addSeries(series);
view.show();
QTest::qWaitForWindowShown(&view);
//QTest::qWait(1000);
// check that customizations persist
QCOMPARE(s1->pen(), p1);
QCOMPARE(s1->brush(), b1);
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QCOMPARE(s1->labelBrush(), b1);
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(s1->labelFont(), f1);
// remove a slice
series->remove(s2);
QCOMPARE(s1->pen(), p1);
QCOMPARE(s1->brush(), b1);
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QCOMPARE(s1->labelBrush(), b1);
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(s1->labelFont(), f1);
// add a slice
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 series->append("slice 4", 4);
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(s1->pen(), p1);
QCOMPARE(s1->brush(), b1);
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QCOMPARE(s1->labelBrush(), b1);
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(s1->labelFont(), f1);
// insert a slice
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 series->insert(0, new QPieSlice("slice 5", 5));
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(s1->pen(), p1);
QCOMPARE(s1->brush(), b1);
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QCOMPARE(s1->labelBrush(), b1);
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(s1->labelFont(), f1);
// change theme
// theme will overwrite customizations
view.chart()->setTheme(QChart::ChartThemeHighContrast);
QVERIFY(s1->pen() != p1);
QVERIFY(s1->brush() != b1);
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 QVERIFY(s1->labelBrush() != b1);
Jani Honkonen
Adding more tests for pie...
r1119 QVERIFY(s1->labelFont() != f1);
}
void tst_qpieslice::mouseClick()
{
// create a pie series
QPieSeries *series = new QPieSeries();
series->setPieSize(1.0);
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 QPieSlice *s1 = series->append("slice 1", 1);
QPieSlice *s2 = series->append("slice 2", 2);
QPieSlice *s3 = series->append("slice 3", 3);
Jani Honkonen
Adding more tests for pie...
r1119 QSignalSpy clickSpy1(s1, SIGNAL(clicked()));
QSignalSpy clickSpy2(s2, SIGNAL(clicked()));
QSignalSpy clickSpy3(s3, SIGNAL(clicked()));
// add series to the chart
QChartView view(new QChart());
Jani Honkonen
Fix pie autotests...
r1192 view.chart()->legend()->setVisible(false);
Jani Honkonen
Adding more tests for pie...
r1119 view.resize(200, 200);
view.chart()->addSeries(series);
view.show();
QTest::qWaitForWindowShown(&view);
// simulate clicks
// pie rectangle: QRectF(60,60 121x121)
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(clickSpy1.count(), 1);
QCOMPARE(clickSpy2.count(), 1);
QCOMPARE(clickSpy3.count(), 1);
}
void tst_qpieslice::mouseHover()
{
// create a pie series
QPieSeries *series = new QPieSeries();
series->setPieSize(1.0);
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 QPieSlice *s1 = series->append("slice 1", 1);
series->append("slice 2", 2);
series->append("slice 3", 3);
Jani Honkonen
Adding more tests for pie...
r1119
// add series to the chart
QChartView view(new QChart());
Jani Honkonen
Fix pie autotests...
r1192 view.chart()->legend()->setVisible(false);
Jani Honkonen
Adding more tests for pie...
r1119 view.resize(200, 200);
view.chart()->addSeries(series);
view.show();
QTest::qWaitForWindowShown(&view);
// first move to right top corner
QTest::mouseMove(view.viewport(), QPoint(200, 0));
Jani Honkonen
Try to fix pie hover test errors when running in bamboo...
r1128 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
Jani Honkonen
Adding more tests for pie...
r1119
// move inside slice rectangle but NOT the actual slice
// pie rectangle: QRectF(60,60 121x121)
QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool)));
QTest::mouseMove(view.viewport(), QPoint(170, 70));
Jani Honkonen
Another miserable attempt to fix pie hover auto tests in bamboo
r1129 TRY_COMPARE(hoverSpy.count(), 0);
Jani Honkonen
Adding more tests for pie...
r1119
// move inside the slice
QTest::mouseMove(view.viewport(), QPoint(139, 85));
Jani Honkonen
Another miserable attempt to fix pie hover auto tests in bamboo
r1129 TRY_COMPARE(hoverSpy.count(), 1);
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true);
// move outside the slice
QTest::mouseMove(view.viewport(), QPoint(200, 0));
Jani Honkonen
Another miserable attempt to fix pie hover auto tests in bamboo
r1129 TRY_COMPARE(hoverSpy.count(), 2);
Jani Honkonen
Adding more tests for pie...
r1119 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false);
}
Jani Honkonen
Add basic auto tests for pie
r1105 QTEST_MAIN(tst_qpieslice)
#include "tst_qpieslice.moc"