diff --git a/test/auto/domain/tst_domain.cpp b/test/auto/domain/tst_domain.cpp index 9e96f35..c2b8444 100644 --- a/test/auto/domain/tst_domain.cpp +++ b/test/auto/domain/tst_domain.cpp @@ -7,9 +7,9 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(Domain*) Q_DECLARE_METATYPE(QSizeF) -class tst_Domain : public QObject +class tst_Domain: public QObject { - Q_OBJECT +Q_OBJECT public slots: void initTestCase(); @@ -47,6 +47,12 @@ private slots: void spanY(); void zoom_data(); void zoom(); + void move_data(); + void move(); + void handleAxisXChanged_data(); + void handleAxisXChanged(); + void handleAxisYChanged_data(); + void handleAxisYChanged(); }; void tst_Domain::initTestCase() @@ -93,8 +99,8 @@ void tst_Domain::handleAxisRangeXChanged() Domain domain; QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); domain.handleAxisXChanged(min, max); @@ -121,7 +127,6 @@ void tst_Domain::handleAxisRangeYChanged_data() QTest::newRow("-1 0") << -1.0 << 0.0; } - void tst_Domain::handleAxisRangeYChanged() { QFETCH(qreal, min); @@ -130,10 +135,10 @@ void tst_Domain::handleAxisRangeYChanged() Domain domain; QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); - domain.handleAxisYChanged(min, max,5); + domain.handleAxisYChanged(min, max, 5); QList arg0 = spy0.first(); QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); @@ -163,14 +168,14 @@ void tst_Domain::isEmpty_data() void tst_Domain::isEmpty() { - QFETCH(qreal, minX); - QFETCH(qreal, maxX); - QFETCH(qreal, minY); - QFETCH(qreal, maxY); + QFETCH(qreal, minX); + QFETCH(qreal, maxX); + QFETCH(qreal, minY); + QFETCH(qreal, maxY); QFETCH(bool, isEmpty); Domain domain; - domain.setRange(minX,maxX,minY,maxY); + domain.setRange(minX, maxX, minY, maxY); QCOMPARE(domain.isEmpty(), isEmpty); } @@ -193,15 +198,14 @@ void tst_Domain::maxX() Domain domain; QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); domain.setMaxX(maxX1); QCOMPARE(domain.maxX(), maxX1); domain.setMaxX(maxX2); QCOMPARE(domain.maxX(), maxX2); - QCOMPARE(spy0.count(), count); QCOMPARE(spy1.count(), count); QCOMPARE(spy2.count(), 0); @@ -210,100 +214,98 @@ void tst_Domain::maxX() void tst_Domain::maxY_data() { - QTest::addColumn("maxY1"); - QTest::addColumn("maxY2"); - QTest::addColumn("count"); - QTest::newRow("1") << 0.0 << 1.0 << 1; - QTest::newRow("1.0") << 1.0 << 1.0 << 1; - QTest::newRow("2.0") << 1.0 << 0.0 << 2; + QTest::addColumn("maxY1"); + QTest::addColumn("maxY2"); + QTest::addColumn("count"); + QTest::newRow("1") << 0.0 << 1.0 << 1; + QTest::newRow("1.0") << 1.0 << 1.0 << 1; + QTest::newRow("2.0") << 1.0 << 0.0 << 2; } - void tst_Domain::maxY() { - QFETCH(qreal, maxY1); - QFETCH(qreal, maxY2); - QFETCH(int, count); + QFETCH(qreal, maxY1); + QFETCH(qreal, maxY2); + QFETCH(int, count); - Domain domain; + Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); - domain.setMaxY(maxY1); - QCOMPARE(domain.maxY(), maxY1); - domain.setMaxY(maxY2); - QCOMPARE(domain.maxY(), maxY2); + domain.setMaxY(maxY1); + QCOMPARE(domain.maxY(), maxY1); + domain.setMaxY(maxY2); + QCOMPARE(domain.maxY(), maxY2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), count); + QCOMPARE(spy0.count(), count); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), count); } void tst_Domain::minX_data() { - QTest::addColumn("minX1"); - QTest::addColumn("minX2"); - QTest::addColumn("count"); - QTest::newRow("1") << 0.0 << 1.0 << 1; - QTest::newRow("1.0") << 1.0 << 1.0 << 1; - QTest::newRow("2.0") << 1.0 << 0.0 << 2; + QTest::addColumn("minX1"); + QTest::addColumn("minX2"); + QTest::addColumn("count"); + QTest::newRow("1") << 0.0 << 1.0 << 1; + QTest::newRow("1.0") << 1.0 << 1.0 << 1; + QTest::newRow("2.0") << 1.0 << 0.0 << 2; } - void tst_Domain::minX() { - QFETCH(qreal, minX1); - QFETCH(qreal, minX2); - QFETCH(int, count); + QFETCH(qreal, minX1); + QFETCH(qreal, minX2); + QFETCH(int, count); - Domain domain; + Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); - domain.setMinX(minX1); - QCOMPARE(domain.minX(), minX1); - domain.setMinX(minX2); - QCOMPARE(domain.minX(), minX2); + domain.setMinX(minX1); + QCOMPARE(domain.minX(), minX1); + domain.setMinX(minX2); + QCOMPARE(domain.minX(), minX2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), count); - QCOMPARE(spy2.count(), 0); + QCOMPARE(spy0.count(), count); + QCOMPARE(spy1.count(), count); + QCOMPARE(spy2.count(), 0); } void tst_Domain::minY_data() { - QTest::addColumn("minY1"); - QTest::addColumn("minY2"); - QTest::addColumn("count"); - QTest::newRow("1") << 0.0 << 1.0 << 1; - QTest::newRow("1.0") << 1.0 << 1.0 << 1; - QTest::newRow("2.0") << 1.0 << 0.0 << 2; + QTest::addColumn("minY1"); + QTest::addColumn("minY2"); + QTest::addColumn("count"); + QTest::newRow("1") << 0.0 << 1.0 << 1; + QTest::newRow("1.0") << 1.0 << 1.0 << 1; + QTest::newRow("2.0") << 1.0 << 0.0 << 2; } void tst_Domain::minY() { - QFETCH(qreal, minY1); - QFETCH(qreal, minY2); - QFETCH(int, count); + QFETCH(qreal, minY1); + QFETCH(qreal, minY2); + QFETCH(int, count); - Domain domain; + Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); - domain.setMinY(minY1); - QCOMPARE(domain.minY(), minY1); - domain.setMinY(minY2); - QCOMPARE(domain.minY(), minY2); + domain.setMinY(minY1); + QCOMPARE(domain.minY(), minY1); + domain.setMinY(minY2); + QCOMPARE(domain.minY(), minY2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), count); + QCOMPARE(spy0.count(), count); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), count); } void tst_Domain::operatorEquals_data() @@ -316,19 +318,19 @@ void tst_Domain::operatorEquals_data() Domain* a; Domain* b; a = new Domain(); - a->setRange(0,100,0,100); + a->setRange(0, 100, 0, 100); b = new Domain(); - b->setRange(0,100,0,100); - QTest::newRow("equals") << a << b << true <setRange(0, 100, 0, 100); + QTest::newRow("equals") << a << b << true << false; a = new Domain(); - a->setRange(0,100,0,100); + a->setRange(0, 100, 0, 100); b = new Domain(); - b->setRange(0,100,0,1); + b->setRange(0, 100, 0, 1); QTest::newRow("equals") << a << b << false << true; a = new Domain(); - a->setRange(0,100,0,100); + a->setRange(0, 100, 0, 100); b = new Domain(); - b->setRange(0,1,0,100); + b->setRange(0, 1, 0, 100); QTest::newRow("equals") << a << b << false << true; } @@ -343,8 +345,8 @@ void tst_Domain::operatorEquals() Domain domain; QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); QCOMPARE(*domain1==*domain2, equals); QCOMPARE(*domain1!=*domain2, notEquals); @@ -375,8 +377,8 @@ void tst_Domain::setRange() Domain domain; QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); domain.setRange(minX, maxX, minY, maxY); @@ -389,83 +391,82 @@ void tst_Domain::setRange() QCOMPARE(spy1.count(), 1); QCOMPARE(spy2.count(), 1); - } void tst_Domain::setRangeX_data() { - QTest::addColumn("min"); - QTest::addColumn("max"); - QTest::newRow("-1 1") << -1.0 << 1.0; - QTest::newRow("0 1") << 0.0 << 1.0; - QTest::newRow("-1 0") << -1.0 << 0.0; + QTest::addColumn("min"); + QTest::addColumn("max"); + QTest::newRow("-1 1") << -1.0 << 1.0; + QTest::newRow("0 1") << 0.0 << 1.0; + QTest::newRow("-1 0") << -1.0 << 0.0; } void tst_Domain::setRangeX() { - QFETCH(qreal, min); - QFETCH(qreal, max); + QFETCH(qreal, min); + QFETCH(qreal, max); - Domain domain; + Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); - domain.setRangeX(min, max); + domain.setRangeX(min, max); - QList arg0 = spy0.first(); + QList arg0 = spy0.first(); QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); - QList arg1 = spy1.first(); + QList arg1 = spy1.first(); 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); + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 0); } void tst_Domain::setRangeY_data() { - QTest::addColumn("min"); - QTest::addColumn("max"); - QTest::newRow("-1 1") << -1.0 << 1.0; - QTest::newRow("0 1") << 0.0 << 1.0; - QTest::newRow("-1 0") << -1.0 << 0.0; + QTest::addColumn("min"); + QTest::addColumn("max"); + QTest::newRow("-1 1") << -1.0 << 1.0; + QTest::newRow("0 1") << 0.0 << 1.0; + QTest::newRow("-1 0") << -1.0 << 0.0; } void tst_Domain::setRangeY() { - QFETCH(qreal, min); - QFETCH(qreal, max); + QFETCH(qreal, min); + QFETCH(qreal, max); - Domain domain; + Domain domain; - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); - domain.setRangeY(min, max); + domain.setRangeY(min, max); - QList arg0 = spy0.first(); + QList arg0 = spy0.first(); QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); - QList arg1 = spy2.first(); + QList arg1 = spy2.first(); 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); + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 1); } void tst_Domain::spanX_data() { - QTest::addColumn("minX"); - QTest::addColumn("maxX"); + QTest::addColumn("minX"); + QTest::addColumn("maxX"); QTest::addColumn("spanX"); QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; @@ -479,11 +480,11 @@ void tst_Domain::spanX() Domain domain; - domain.setRangeX(minX,maxX); + domain.setRangeX(minX, maxX); QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); QCOMPARE(domain.spanX(), spanX); @@ -494,35 +495,34 @@ void tst_Domain::spanX() void tst_Domain::spanY_data() { - QTest::addColumn("minY"); - QTest::addColumn("maxY"); - QTest::addColumn("spanY"); - QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; - QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; + QTest::addColumn("minY"); + QTest::addColumn("maxY"); + QTest::addColumn("spanY"); + QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; + QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; } void tst_Domain::spanY() { - QFETCH(qreal, minY); - QFETCH(qreal, maxY); - QFETCH(qreal, spanY); + QFETCH(qreal, minY); + QFETCH(qreal, maxY); + QFETCH(qreal, spanY); - Domain domain; + Domain domain; - domain.setRangeY(minY,maxY); + domain.setRangeY(minY, maxY); - QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); - QCOMPARE(domain.spanY(), spanY); + QCOMPARE(domain.spanY(), spanY); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); } - void tst_Domain::zoom_data() { QTest::addColumn("rect0"); @@ -531,9 +531,14 @@ void tst_Domain::zoom_data() QTest::addColumn("size1"); QTest::addColumn("rect2"); QTest::addColumn("size2"); - QTest::newRow("first") << QRectF(10,10,100,100) << QSizeF(1000,1000) << QRectF(20,20,100,100) << QSizeF(1000,1000) << QRectF(50,50,100,100) << QSizeF(1000,1000); - QTest::newRow("scound") << QRectF(10,10,50,50) << QSizeF(1000,1000) << QRectF(20,20,100,100) << QSizeF(1000,1000) << QRectF(50,50,100,100) << QSizeF(1000,1000); - QTest::newRow("third") << QRectF(10,10,10,10) << QSizeF(100,100) << QRectF(20,20,20,20) << QSizeF(100,100) << QRectF(50,50,50,50) << QSizeF(100,100); + QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) + << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) + << QSizeF(1000, 1000); + QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) + << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) + << QSizeF(1000, 1000); + QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) + << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); } void tst_Domain::zoom() @@ -547,33 +552,141 @@ void tst_Domain::zoom() Domain domain; - domain.setRange(0,1000,0,1000); + domain.setRange(0, 1000, 0, 1000); QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); - QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); - QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); Domain domain0; - domain0.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); + domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); domain.zoomIn(rect0, size0); Domain domain1; - domain1.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); + domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); domain.zoomIn(rect1, size1); Domain domain2; - domain2.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); + domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); domain.zoomIn(rect2, size2); domain.zoomOut(rect2, size2); - QCOMPARE(domain == domain2,true); + QCOMPARE(domain == domain2, true); domain.zoomOut(rect1, size1); - QCOMPARE(domain == domain1,true); + QCOMPARE(domain == domain1, true); domain.zoomOut(rect0, size0); - QCOMPARE(domain == domain0,true); + QCOMPARE(domain == domain0, true); QCOMPARE(spy0.count(), 6); QCOMPARE(spy1.count(), 6); QCOMPARE(spy2.count(), 6); } +void tst_Domain::move_data() +{ + QTest::addColumn("dx"); + QTest::addColumn("dy"); + QTest::addColumn("size"); + QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); + QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); + QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); + QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); + QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); + QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); +} + +void tst_Domain::move() +{ + QFETCH(int, dx); + QFETCH(int, dy); + QFETCH(QSizeF, size); + Domain domain; + + domain.setRange(0, size.width(), 0, size.height()); + + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); + + domain.move(dx, dy, size); + + Domain result; + 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); +} + +void tst_Domain::handleAxisXChanged_data() +{ + QTest::addColumn("min"); + QTest::addColumn("max"); + QTest::addColumn("tickCount"); + QTest::addColumn("niceNumbers"); + QTest::addColumn("resultMin"); + QTest::addColumn("resultMax"); + QTest::addColumn("resultTickCount"); + QTest::newRow("0,100,5,false") << 0.0 << 100.0 << 5 << false << 0.0 << 100.0 << 5; + QTest::newRow("0,100,5,true") << 0.0 << 100.0 << 5 << true << 0.0 << 100.0 << 6; + QTest::newRow("0.1,99,5,true") << 0.1 << 99.0 << 5 << true << 0.0 << 100.0 << 6; + QTest::newRow("5,93.5,true") << 5.0 << 93.5 << 5 << true << 0.0 << 100.0 << 6; +} + +void tst_Domain::handleAxisXChanged() +{ + QFETCH(qreal, min); + QFETCH(qreal, max); + QFETCH(int, tickCount); + QFETCH(bool, niceNumbers); + QFETCH(qreal, resultMin); + QFETCH(qreal, resultMax); + QFETCH(int, resultTickCount); + + Domain domain; + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); + + domain.handleAxisXChanged(min, max, tickCount, niceNumbers); + + QCOMPARE(resultMin, domain.minX()); + QCOMPARE(resultMax, domain.maxX()); + QCOMPARE(resultTickCount, domain.tickXCount()); + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 0); + +} + +void tst_Domain::handleAxisYChanged_data() +{ + handleAxisXChanged_data(); +} + +void tst_Domain::handleAxisYChanged() +{ + QFETCH(qreal, min); + QFETCH(qreal, max); + QFETCH(int, tickCount); + QFETCH(bool, niceNumbers); + QFETCH(qreal, resultMin); + QFETCH(qreal, resultMax); + QFETCH(int, resultTickCount); + + Domain domain; + QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); + QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal,int ))); + QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal,int ))); + + domain.handleAxisYChanged(min, max, tickCount, niceNumbers); + + QCOMPARE(resultMin, domain.minY()); + QCOMPARE(resultMax, domain.maxY()); + QCOMPARE(resultTickCount, domain.tickYCount()); + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 1); +} + QTEST_MAIN(tst_Domain) #include "tst_domain.moc"