diff --git a/test/auto/auto.pri b/test/auto/auto.pri index a1a846f..0a7c3ea 100644 --- a/test/auto/auto.pri +++ b/test/auto/auto.pri @@ -4,3 +4,6 @@ CONFIG += qtestlib !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") + +INCLUDEPATH += ../inc +HEADERS += ../inc/tst_definitions.h diff --git a/test/auto/chartdataset/tst_chartdataset.cpp b/test/auto/chartdataset/tst_chartdataset.cpp index 0876c86..a585d87 100644 --- a/test/auto/chartdataset/tst_chartdataset.cpp +++ b/test/auto/chartdataset/tst_chartdataset.cpp @@ -23,6 +23,7 @@ #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -151,10 +152,10 @@ void tst_ChartDataSet::addSeries() m_dataset->addSeries(series1,axis1); m_dataset->addSeries(series2,axis2); - QCOMPARE(spy0.count(), axisCount); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 3); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), axisCount); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 3); + TRY_COMPARE(spy3.count(), 0); if(axis0==0) axis0 = m_dataset->axisY(); if(axis1==0) axis1 = m_dataset->axisY(); @@ -193,10 +194,10 @@ void tst_ChartDataSet::removeSeries() m_dataset->removeSeries(series1); m_dataset->removeSeries(series2); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), axisCount); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 3); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), axisCount); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 3); } void tst_ChartDataSet::removeAllSeries_data() @@ -225,10 +226,10 @@ void tst_ChartDataSet::removeAllSeries() m_dataset->removeAllSeries(); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 4); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 3); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 4); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 3); } @@ -296,10 +297,10 @@ void tst_ChartDataSet::seriesCount() QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); QCOMPARE(m_dataset->seriesCount(series0->type()),3); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 0); } void tst_ChartDataSet::seriesIndex_data() @@ -333,10 +334,10 @@ void tst_ChartDataSet::seriesIndex() QCOMPARE(m_dataset->seriesIndex(series1),1); QCOMPARE(m_dataset->seriesIndex(series2),2); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 0); m_dataset->removeSeries(series0); m_dataset->removeSeries(series1); @@ -414,10 +415,10 @@ void tst_ChartDataSet::domain() QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 0); } void tst_ChartDataSet::zoomInDomain_data() @@ -450,9 +451,9 @@ void tst_ChartDataSet::zoomInDomain() m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } void tst_ChartDataSet::zoomOutDomain_data() @@ -486,9 +487,9 @@ void tst_ChartDataSet::zoomOutDomain() m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } void tst_ChartDataSet::scrollDomain_data() @@ -522,9 +523,9 @@ void tst_ChartDataSet::scrollDomain() m_dataset->scrollDomain(10,10,QSize(1000,1000)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } QTEST_MAIN(tst_ChartDataSet) diff --git a/test/auto/domain/tst_domain.cpp b/test/auto/domain/tst_domain.cpp index dcf5352..ee5dacc 100644 --- a/test/auto/domain/tst_domain.cpp +++ b/test/auto/domain/tst_domain.cpp @@ -21,6 +21,7 @@ #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -132,9 +133,9 @@ void tst_Domain::handleAxisRangeXChanged() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 0); } @@ -168,9 +169,9 @@ void tst_Domain::handleAxisRangeYChanged() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 1); } void tst_Domain::isEmpty_data() @@ -226,9 +227,9 @@ void tst_Domain::maxX() domain.setMaxX(maxX2); QCOMPARE(domain.maxX(), maxX2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), count); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), count); + TRY_COMPARE(spy2.count(), 0); } @@ -259,9 +260,9 @@ void tst_Domain::maxY() domain.setMaxY(maxY2); QCOMPARE(domain.maxY(), maxY2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), count); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), count); } void tst_Domain::minX_data() @@ -291,9 +292,9 @@ void tst_Domain::minX() domain.setMinX(minX2); QCOMPARE(domain.minX(), minX2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), count); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), count); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::minY_data() @@ -323,9 +324,9 @@ void tst_Domain::minY() domain.setMinY(minY2); QCOMPARE(domain.minY(), minY2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), count); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), count); } void tst_Domain::operatorEquals_data() @@ -371,9 +372,9 @@ void tst_Domain::operatorEquals() QCOMPARE(*domain1==*domain2, equals); QCOMPARE(*domain1!=*domain2, notEquals); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::setRange_data() @@ -407,9 +408,9 @@ void tst_Domain::setRange() QCOMPARE(domain.minY(), minY); QCOMPARE(domain.maxY(), maxY); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } @@ -443,9 +444,9 @@ void tst_Domain::setRangeX() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::setRangeY_data() @@ -478,9 +479,9 @@ void tst_Domain::setRangeY() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 1); } void tst_Domain::spanX_data() @@ -508,9 +509,9 @@ void tst_Domain::spanX() QCOMPARE(domain.spanX(), spanX); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::spanY_data() @@ -538,9 +539,9 @@ void tst_Domain::spanY() QCOMPARE(domain.spanY(), spanY); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::zoom_data() @@ -593,9 +594,9 @@ void tst_Domain::zoom() QCOMPARE(domain == domain1, true); domain.zoomOut(rect0, size0); QCOMPARE(domain == domain0, true); - QCOMPARE(spy0.count(), 6); - QCOMPARE(spy1.count(), 6); - QCOMPARE(spy2.count(), 6); + TRY_COMPARE(spy0.count(), 6); + TRY_COMPARE(spy1.count(), 6); + TRY_COMPARE(spy2.count(), 6); } @@ -631,9 +632,9 @@ void tst_Domain::move() result.setRange(dx, size.width() + dx, dy, size.height() + dy); QCOMPARE(domain == result, true); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), dx!=0?1:0); - QCOMPARE(spy2.count(), dy!=0?1:0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), dx!=0?1:0); + TRY_COMPARE(spy2.count(), dy!=0?1:0); } void tst_Domain::handleAxisXChanged_data() @@ -671,9 +672,9 @@ void tst_Domain::handleAxisXChanged() QCOMPARE(resultMin, domain.minX()); QCOMPARE(resultMax, domain.maxX()); QCOMPARE(resultTickCount, domain.tickXCount()); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 0); } @@ -702,9 +703,9 @@ void tst_Domain::handleAxisYChanged() QCOMPARE(resultMin, domain.minY()); QCOMPARE(resultMax, domain.maxY()); QCOMPARE(resultTickCount, domain.tickYCount()); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 1); } QTEST_MAIN(tst_Domain) diff --git a/test/auto/inc/tst_definitions.h b/test/auto/inc/tst_definitions.h new file mode 100644 index 0000000..bac89c4 --- /dev/null +++ b/test/auto/inc/tst_definitions.h @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef TST_DEFINITIONS_H +#define TST_DEFINITIONS_H + +#include + +#define TRY_COMPARE(actual, expected) { \ + do { \ + const int timeout(1000); \ + const int waitStep(30); \ + /* always wait before comparing to catch possible extra signals */ \ + QTest::qWait(waitStep); \ + for (int time(0); actual != expected && time < timeout; time += waitStep) \ + QTest::qWait(waitStep); \ + QCOMPARE(actual, expected); \ + } while (0); \ +} + +#endif // TST_DEFINITIONS_H diff --git a/test/auto/qchartview/tst_qchartview.cpp b/test/auto/qchartview/tst_qchartview.cpp index 7d58e31..6390b69 100644 --- a/test/auto/qchartview/tst_qchartview.cpp +++ b/test/auto/qchartview/tst_qchartview.cpp @@ -22,6 +22,7 @@ #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -153,8 +154,8 @@ void tst_QChartView::rubberBand() QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); - QCOMPARE(spy0.count(), Xcount); - QCOMPARE(spy1.count(), Ycount); + TRY_COMPARE(spy0.count(), Xcount); + TRY_COMPARE(spy1.count(), Ycount); //this is hack since view does not get events otherwise m_view->setMouseTracking(false); diff --git a/test/auto/qlineseries/tst_qlineseries.cpp b/test/auto/qlineseries/tst_qlineseries.cpp index e2f0515..4c516f7 100644 --- a/test/auto/qlineseries/tst_qlineseries.cpp +++ b/test/auto/qlineseries/tst_qlineseries.cpp @@ -22,6 +22,7 @@ #include #include #include +#include Q_DECLARE_METATYPE(QList) @@ -173,10 +174,8 @@ void tst_QLineSeries::append_raw() { QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); - QTest::qWait(200); m_series->append(points); - QTest::qWait(200); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); } @@ -240,7 +239,7 @@ void tst_QLineSeries::count_raw() for(int i=0 ; i< count; ++i) m_series->append(i,i); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->count(), count); } @@ -262,7 +261,7 @@ void tst_QLineSeries::oper() } QCOMPARE(series.points(), points); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); } @@ -283,7 +282,7 @@ void tst_QLineSeries::pen() QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); series.setPen(pen); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(series.pen(), pen); m_chart->addSeries(&series); @@ -308,7 +307,7 @@ void tst_QLineSeries::pointsVisible_raw() QFETCH(bool, pointsVisible); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->setPointsVisible(pointsVisible); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->pointsVisible(), pointsVisible); } @@ -322,17 +321,13 @@ void tst_QLineSeries::remove_raw() QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->append(points); - QTest::qWait(200); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); foreach(const QPointF& point,points) - { m_series->remove(point); - QTest::qWait(200); - } - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points().count(), 0); } @@ -371,12 +366,10 @@ void tst_QLineSeries::removeAll_raw() QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->append(points); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); - QTest::qWait(200); m_series->removeAll(); - QTest::qWait(200); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points().count(), 0); } @@ -414,15 +407,11 @@ void tst_QLineSeries::replace_raw() QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->append(points); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); - QTest::qWait(200); foreach(const QPointF& point,points) - { - m_series->replace(point.x(),point.y(),point.x(),0); - QTest::qWait(200); - } + m_series->replace(point.x(),point.y(),point.x(),0); QList newPoints = m_series->points(); diff --git a/test/auto/qpieseries/tst_qpieseries.cpp b/test/auto/qpieseries/tst_qpieseries.cpp index 27835a0..78eded3 100644 --- a/test/auto/qpieseries/tst_qpieseries.cpp +++ b/test/auto/qpieseries/tst_qpieseries.cpp @@ -21,6 +21,7 @@ #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -187,9 +188,9 @@ void tst_qpieseries::remove() QCOMPARE(s.count(), 0); // check that slices were actually destroyed - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); - QCOMPARE(spy3.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); + TRY_COMPARE(spy3.count(), 1); } /* diff --git a/test/auto/qpieslice/tst_qpieslice.cpp b/test/auto/qpieslice/tst_qpieslice.cpp index cd92d85..42738e0 100644 --- a/test/auto/qpieslice/tst_qpieslice.cpp +++ b/test/auto/qpieslice/tst_qpieslice.cpp @@ -20,6 +20,7 @@ #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -122,7 +123,7 @@ void tst_qpieslice::changedSignals() slice.setLabelArmLengthFactor(0.1); slice.setExplodeDistanceFactor(0.1); slice.setExplodeDistanceFactor(0.1); - QCOMPARE(spy.count(), 10); + TRY_COMPARE(spy.count(), 10); } QTEST_MAIN(tst_qpieslice)