tst_domain.cpp
745 lines
| 19.6 KiB
| text/x-c
|
CppLexer
|
r774 | /**************************************************************************** | ||
** | ||||
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
|
r774 | ** All rights reserved. | ||
|
r2740 | ** For any questions to Digia, please use contact form at http://qt.io | ||
|
r774 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r774 | ** | ||
|
r2740 | ** Licensees holding valid commercial license for Qt may use this file in | ||
** accordance with the Qt License Agreement provided with the Software | ||||
** or, alternatively, in accordance with the terms contained in a written | ||||
** agreement between you and Digia. | ||||
|
r774 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r774 | ** | ||
****************************************************************************/ | ||||
|
r1977 | #ifndef BUILD_PRIVATE_UNIT_TESTS | ||
#include <QtTest/QtTest> | ||||
class tst_Domain: public QObject { | ||||
Q_OBJECT | ||||
private Q_SLOTS: | ||||
void skip(); | ||||
}; | ||||
void tst_Domain::skip() | ||||
{ | ||||
|
r2367 | QSKIP("This test requires the debug version of library"); | ||
|
r1977 | } | ||
QTEST_MAIN(tst_Domain) | ||||
#include "tst_domain.moc" | ||||
#else | ||||
|
r774 | |||
|
r439 | #include <QtTest/QtTest> | ||
|
r2275 | #include <private/xydomain_p.h> | ||
|
r1698 | #include <private/qabstractaxis_p.h> | ||
|
r1109 | #include <tst_definitions.h> | ||
|
r439 | |||
|
r2712 | QT_CHARTS_USE_NAMESPACE | ||
|
r439 | |||
|
r2275 | Q_DECLARE_METATYPE(XYDomain*) | ||
|
r439 | Q_DECLARE_METATYPE(QSizeF) | ||
|
r2273 | Q_DECLARE_METATYPE(QMargins) | ||
|
r439 | |||
|
r1698 | |||
class AxisMock: public QAbstractAxisPrivate | ||||
{ | ||||
Q_OBJECT | ||||
public: | ||||
|
r2273 | AxisMock(Qt::Alignment alignment):QAbstractAxisPrivate(0){ setAlignment(alignment);}; | ||
void initializeGraphics(QGraphicsItem* item) | ||||
|
r1726 | { | ||
|
r2273 | Q_UNUSED(item); | ||
|
r1726 | }; | ||
|
r2275 | |||
void initializeDomain(AbstractDomain* domain) | ||||
|
r1726 | { | ||
Q_UNUSED(domain); | ||||
}; | ||||
void setMin(const QVariant &min) | ||||
{ | ||||
Q_UNUSED(min); | ||||
} | ||||
|
r1698 | qreal min() { return m_min;} | ||
|
r1726 | void setMax(const QVariant &max) | ||
{ | ||||
Q_UNUSED(max); | ||||
} | ||||
|
r1698 | qreal max() { return m_max; } | ||
|
r1726 | void setRange(const QVariant &min, const QVariant &max) | ||
{ | ||||
Q_UNUSED(min); | ||||
Q_UNUSED(max); | ||||
}; | ||||
|
r2273 | void setRange(qreal min, qreal max) | ||
{ | ||||
m_min=min; | ||||
m_max=max; | ||||
emit rangeChanged(min,max); | ||||
}; | ||||
|
r1726 | int count () const { return m_count; } | ||
|
r1698 | |||
void handleDomainUpdated(){}; | ||||
public: | ||||
|
r1726 | int m_count; | ||
|
r1698 | qreal m_min; | ||
qreal m_max; | ||||
}; | ||||
|
r773 | class tst_Domain: public QObject | ||
|
r439 | { | ||
|
r773 | Q_OBJECT | ||
|
r439 | |||
|
r774 | public Q_SLOTS: | ||
|
r439 | void initTestCase(); | ||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
|
r774 | private Q_SLOTS: | ||
|
r439 | void domain(); | ||
|
r2273 | void handleHorizontalAxisRangeChanged_data(); | ||
void handleHorizontalAxisRangeChanged(); | ||||
void handleVerticalAxisRangeChanged_data(); | ||||
void handleVerticalAxisRangeChanged(); | ||||
|
r439 | void isEmpty_data(); | ||
void isEmpty(); | ||||
void maxX_data(); | ||||
void maxX(); | ||||
void maxY_data(); | ||||
void maxY(); | ||||
void minX_data(); | ||||
void minX(); | ||||
void minY_data(); | ||||
void minY(); | ||||
void operatorEquals_data(); | ||||
void operatorEquals(); | ||||
void setRange_data(); | ||||
void setRange(); | ||||
void setRangeX_data(); | ||||
void setRangeX(); | ||||
void setRangeY_data(); | ||||
void setRangeY(); | ||||
void spanX_data(); | ||||
void spanX(); | ||||
void spanY_data(); | ||||
void spanY(); | ||||
|
r2273 | void zoomIn_data(); | ||
void zoomIn(); | ||||
void zoomOut_data(); | ||||
void zoomOut(); | ||||
|
r773 | void move_data(); | ||
void move(); | ||||
|
r439 | }; | ||
void tst_Domain::initTestCase() | ||||
{ | ||||
} | ||||
void tst_Domain::cleanupTestCase() | ||||
{ | ||||
|
r2733 | QTest::qWait(1); // Allow final deleteLaters to run | ||
|
r439 | } | ||
void tst_Domain::init() | ||||
{ | ||||
} | ||||
void tst_Domain::cleanup() | ||||
{ | ||||
} | ||||
void tst_Domain::domain() | ||||
{ | ||||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
QCOMPARE(domain.isEmpty(), true); | ||||
QCOMPARE(domain.maxX(), 0.0); | ||||
QCOMPARE(domain.maxY(), 0.0); | ||||
QCOMPARE(domain.minX(), 0.0); | ||||
QCOMPARE(domain.minY(), 0.0); | ||||
} | ||||
|
r2273 | void tst_Domain::handleHorizontalAxisRangeChanged_data() | ||
|
r439 | { | ||
QTest::addColumn<qreal>("min"); | ||||
QTest::addColumn<qreal>("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; | ||||
} | ||||
|
r2273 | void tst_Domain::handleHorizontalAxisRangeChanged() | ||
|
r439 | { | ||
QFETCH(qreal, min); | ||||
QFETCH(qreal, max); | ||||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r2273 | AxisMock axis(Qt::AlignBottom); | ||
QObject::connect(&axis,SIGNAL(rangeChanged(qreal,qreal)),&domain,SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | ||||
axis.setRange(min,max); | ||||
|
r439 | |||
|
r2242 | QVERIFY(qFuzzyCompare(domain.minX(), min)); | ||
QVERIFY(qFuzzyCompare(domain.maxX(), max)); | ||||
|
r439 | |||
QList<QVariant> arg1 = spy1.first(); | ||||
|
r2242 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); | ||
QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); | ||||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), 1); | ||
TRY_COMPARE(spy1.count(), 1); | ||||
TRY_COMPARE(spy2.count(), 0); | ||||
|
r439 | |||
} | ||||
|
r2273 | void tst_Domain::handleVerticalAxisRangeChanged_data() | ||
|
r439 | { | ||
QTest::addColumn<qreal>("min"); | ||||
QTest::addColumn<qreal>("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; | ||||
} | ||||
|
r2273 | void tst_Domain::handleVerticalAxisRangeChanged() | ||
|
r439 | { | ||
QFETCH(qreal, min); | ||||
QFETCH(qreal, max); | ||||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r2273 | AxisMock axis(Qt::AlignLeft); | ||
QObject::connect(&axis, SIGNAL(rangeChanged(qreal,qreal)), &domain, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | ||||
axis.setRange(min,max); | ||||
|
r439 | |||
|
r2242 | QVERIFY(qFuzzyCompare(domain.minY(), min)); | ||
QVERIFY(qFuzzyCompare(domain.maxY(), max)); | ||||
|
r439 | |||
QList<QVariant> arg1 = spy2.first(); | ||||
|
r2242 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); | ||
QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); | ||||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), 1); | ||
TRY_COMPARE(spy1.count(), 0); | ||||
TRY_COMPARE(spy2.count(), 1); | ||||
|
r439 | } | ||
void tst_Domain::isEmpty_data() | ||||
{ | ||||
QTest::addColumn<qreal>("minX"); | ||||
QTest::addColumn<qreal>("maxX"); | ||||
QTest::addColumn<qreal>("minY"); | ||||
QTest::addColumn<qreal>("maxY"); | ||||
|
r2273 | QTest::addColumn<QSizeF>("size"); | ||
|
r439 | QTest::addColumn<bool>("isEmpty"); | ||
|
r2273 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << QSizeF(1,1) << true; | ||
QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; | ||||
QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; | ||||
QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(1,1) << false; | ||||
QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(-11,1) << true; | ||||
|
r439 | } | ||
void tst_Domain::isEmpty() | ||||
{ | ||||
|
r773 | QFETCH(qreal, minX); | ||
QFETCH(qreal, maxX); | ||||
QFETCH(qreal, minY); | ||||
QFETCH(qreal, maxY); | ||||
|
r2273 | QFETCH(QSizeF, size); | ||
|
r439 | QFETCH(bool, isEmpty); | ||
|
r2275 | XYDomain domain; | ||
|
r773 | domain.setRange(minX, maxX, minY, maxY); | ||
|
r2273 | domain.setSize(size); | ||
|
r439 | QCOMPARE(domain.isEmpty(), isEmpty); | ||
} | ||||
void tst_Domain::maxX_data() | ||||
{ | ||||
QTest::addColumn<qreal>("maxX1"); | ||||
QTest::addColumn<qreal>("maxX2"); | ||||
QTest::addColumn<int>("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::maxX() | ||||
{ | ||||
QFETCH(qreal, maxX1); | ||||
QFETCH(qreal, maxX2); | ||||
QFETCH(int, count); | ||||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
domain.setMaxX(maxX1); | ||||
QCOMPARE(domain.maxX(), maxX1); | ||||
domain.setMaxX(maxX2); | ||||
QCOMPARE(domain.maxX(), maxX2); | ||||
|
r1109 | TRY_COMPARE(spy0.count(), count); | ||
TRY_COMPARE(spy1.count(), count); | ||||
TRY_COMPARE(spy2.count(), 0); | ||||
|
r439 | |||
} | ||||
void tst_Domain::maxY_data() | ||||
{ | ||||
|
r773 | QTest::addColumn<qreal>("maxY1"); | ||
QTest::addColumn<qreal>("maxY2"); | ||||
QTest::addColumn<int>("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; | ||||
|
r439 | } | ||
void tst_Domain::maxY() | ||||
{ | ||||
|
r773 | QFETCH(qreal, maxY1); | ||
QFETCH(qreal, maxY2); | ||||
QFETCH(int, count); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r773 | domain.setMaxY(maxY1); | ||
QCOMPARE(domain.maxY(), maxY1); | ||||
domain.setMaxY(maxY2); | ||||
QCOMPARE(domain.maxY(), maxY2); | ||||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), count); | ||
TRY_COMPARE(spy1.count(), 0); | ||||
TRY_COMPARE(spy2.count(), count); | ||||
|
r439 | } | ||
void tst_Domain::minX_data() | ||||
{ | ||||
|
r773 | QTest::addColumn<qreal>("minX1"); | ||
QTest::addColumn<qreal>("minX2"); | ||||
QTest::addColumn<int>("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; | ||||
|
r439 | } | ||
void tst_Domain::minX() | ||||
{ | ||||
|
r773 | QFETCH(qreal, minX1); | ||
QFETCH(qreal, minX2); | ||||
QFETCH(int, count); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r773 | domain.setMinX(minX1); | ||
QCOMPARE(domain.minX(), minX1); | ||||
domain.setMinX(minX2); | ||||
QCOMPARE(domain.minX(), minX2); | ||||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), count); | ||
TRY_COMPARE(spy1.count(), count); | ||||
TRY_COMPARE(spy2.count(), 0); | ||||
|
r439 | } | ||
void tst_Domain::minY_data() | ||||
{ | ||||
|
r773 | QTest::addColumn<qreal>("minY1"); | ||
QTest::addColumn<qreal>("minY2"); | ||||
QTest::addColumn<int>("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; | ||||
|
r439 | } | ||
void tst_Domain::minY() | ||||
{ | ||||
|
r773 | QFETCH(qreal, minY1); | ||
QFETCH(qreal, minY2); | ||||
QFETCH(int, count); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r773 | domain.setMinY(minY1); | ||
QCOMPARE(domain.minY(), minY1); | ||||
domain.setMinY(minY2); | ||||
QCOMPARE(domain.minY(), minY2); | ||||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), count); | ||
TRY_COMPARE(spy1.count(), 0); | ||||
TRY_COMPARE(spy2.count(), count); | ||||
|
r439 | } | ||
void tst_Domain::operatorEquals_data() | ||||
{ | ||||
|
r2275 | QTest::addColumn<XYDomain*>("domain1"); | ||
QTest::addColumn<XYDomain*>("domain2"); | ||||
|
r439 | QTest::addColumn<bool>("equals"); | ||
QTest::addColumn<bool>("notEquals"); | ||||
|
r2275 | XYDomain* a; | ||
XYDomain* b; | ||||
a = new XYDomain(); | ||||
|
r773 | a->setRange(0, 100, 0, 100); | ||
|
r2275 | b = new XYDomain(); | ||
|
r773 | b->setRange(0, 100, 0, 100); | ||
QTest::newRow("equals") << a << b << true << false; | ||||
|
r2275 | a = new XYDomain(); | ||
|
r773 | a->setRange(0, 100, 0, 100); | ||
|
r2275 | b = new XYDomain(); | ||
|
r773 | b->setRange(0, 100, 0, 1); | ||
|
r439 | QTest::newRow("equals") << a << b << false << true; | ||
|
r2275 | a = new XYDomain(); | ||
|
r773 | a->setRange(0, 100, 0, 100); | ||
|
r2275 | b = new XYDomain(); | ||
|
r773 | b->setRange(0, 1, 0, 100); | ||
|
r439 | QTest::newRow("equals") << a << b << false << true; | ||
} | ||||
void tst_Domain::operatorEquals() | ||||
{ | ||||
|
r2275 | QFETCH(XYDomain*, domain1); | ||
QFETCH(XYDomain*, domain2); | ||||
|
r439 | QFETCH(bool, equals); | ||
QFETCH(bool, notEquals); | ||||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
QCOMPARE(*domain1==*domain2, equals); | ||||
QCOMPARE(*domain1!=*domain2, notEquals); | ||||
|
r1109 | TRY_COMPARE(spy0.count(), 0); | ||
TRY_COMPARE(spy1.count(), 0); | ||||
TRY_COMPARE(spy2.count(), 0); | ||||
|
r2733 | |||
delete domain1; | ||||
delete domain2; | ||||
|
r439 | } | ||
void tst_Domain::setRange_data() | ||||
{ | ||||
QTest::addColumn<qreal>("minX"); | ||||
QTest::addColumn<qreal>("maxX"); | ||||
QTest::addColumn<qreal>("minY"); | ||||
QTest::addColumn<qreal>("maxY"); | ||||
QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; | ||||
QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; | ||||
QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; | ||||
} | ||||
void tst_Domain::setRange() | ||||
{ | ||||
QFETCH(qreal, minX); | ||||
QFETCH(qreal, maxX); | ||||
QFETCH(qreal, minY); | ||||
QFETCH(qreal, maxY); | ||||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
domain.setRange(minX, maxX, minY, maxY); | ||||
QCOMPARE(domain.minX(), minX); | ||||
QCOMPARE(domain.maxX(), maxX); | ||||
QCOMPARE(domain.minY(), minY); | ||||
QCOMPARE(domain.maxY(), maxY); | ||||
|
r1109 | TRY_COMPARE(spy0.count(), 1); | ||
TRY_COMPARE(spy1.count(), 1); | ||||
TRY_COMPARE(spy2.count(), 1); | ||||
|
r439 | |||
} | ||||
void tst_Domain::setRangeX_data() | ||||
{ | ||||
|
r773 | QTest::addColumn<qreal>("min"); | ||
QTest::addColumn<qreal>("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; | ||||
|
r439 | } | ||
void tst_Domain::setRangeX() | ||||
{ | ||||
|
r773 | QFETCH(qreal, min); | ||
QFETCH(qreal, max); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r773 | domain.setRangeX(min, max); | ||
|
r439 | |||
|
r2242 | QVERIFY(qFuzzyCompare(domain.minX(), min)); | ||
QVERIFY(qFuzzyCompare(domain.maxX(), max)); | ||||
|
r439 | |||
|
r773 | QList<QVariant> arg1 = spy1.first(); | ||
|
r2242 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); | ||
QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); | ||||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), 1); | ||
TRY_COMPARE(spy1.count(), 1); | ||||
TRY_COMPARE(spy2.count(), 0); | ||||
|
r439 | } | ||
void tst_Domain::setRangeY_data() | ||||
{ | ||||
|
r773 | QTest::addColumn<qreal>("min"); | ||
QTest::addColumn<qreal>("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; | ||||
|
r439 | } | ||
void tst_Domain::setRangeY() | ||||
{ | ||||
|
r773 | QFETCH(qreal, min); | ||
QFETCH(qreal, max); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r773 | domain.setRangeY(min, max); | ||
|
r439 | |||
|
r2242 | QVERIFY(qFuzzyCompare(domain.minY(), min)); | ||
QVERIFY(qFuzzyCompare(domain.maxY(), max)); | ||||
|
r439 | |||
|
r773 | QList<QVariant> arg1 = spy2.first(); | ||
|
r2242 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); | ||
QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); | ||||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), 1); | ||
TRY_COMPARE(spy1.count(), 0); | ||||
TRY_COMPARE(spy2.count(), 1); | ||||
|
r439 | } | ||
void tst_Domain::spanX_data() | ||||
{ | ||||
|
r773 | QTest::addColumn<qreal>("minX"); | ||
QTest::addColumn<qreal>("maxX"); | ||||
|
r439 | QTest::addColumn<qreal>("spanX"); | ||
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::spanX() | ||||
{ | ||||
QFETCH(qreal, minX); | ||||
QFETCH(qreal, maxX); | ||||
QFETCH(qreal, spanX); | ||||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r773 | domain.setRangeX(minX, maxX); | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
QCOMPARE(domain.spanX(), spanX); | ||||
|
r1109 | TRY_COMPARE(spy0.count(), 0); | ||
TRY_COMPARE(spy1.count(), 0); | ||||
TRY_COMPARE(spy2.count(), 0); | ||||
|
r439 | } | ||
void tst_Domain::spanY_data() | ||||
{ | ||||
|
r773 | QTest::addColumn<qreal>("minY"); | ||
QTest::addColumn<qreal>("maxY"); | ||||
QTest::addColumn<qreal>("spanY"); | ||||
QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; | ||||
QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; | ||||
|
r439 | } | ||
void tst_Domain::spanY() | ||||
{ | ||||
|
r773 | QFETCH(qreal, minY); | ||
QFETCH(qreal, maxY); | ||||
QFETCH(qreal, spanY); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r439 | |||
|
r773 | domain.setRangeY(minY, maxY); | ||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r439 | |||
|
r773 | QCOMPARE(domain.spanY(), spanY); | ||
|
r439 | |||
|
r1109 | TRY_COMPARE(spy0.count(), 0); | ||
TRY_COMPARE(spy1.count(), 0); | ||||
TRY_COMPARE(spy2.count(), 0); | ||||
|
r439 | } | ||
|
r2273 | void tst_Domain::zoomIn_data() | ||
|
r439 | { | ||
|
r2273 | QTest::addColumn<QMargins>("range"); | ||
QTest::addColumn<QSizeF>("size"); | ||||
QTest::addColumn<QMargins>("zoom"); | ||||
QTest::addColumn<QMargins>("result"); | ||||
QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << | ||||
QMargins(100, 100, 900, 900) << QMargins(100,100,900,900); | ||||
QTest::newRow("second") << QMargins(0,0,2000,2000) << QSizeF(1000, 1000) << | ||||
QMargins(100, 100, 900, 900) << QMargins(200,200,1800,1800); | ||||
|
r439 | } | ||
|
r2273 | void tst_Domain::zoomIn() | ||
|
r439 | { | ||
|
r2273 | QFETCH(QMargins, range); | ||
QFETCH(QSizeF, size); | ||||
QFETCH(QMargins, zoom); | ||||
QFETCH(QMargins, result); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r2273 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); | ||
domain.setSize(size); | ||||
QSignalSpy spy0(&domain, SIGNAL(updated())); | ||||
QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
domain.zoomIn(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); | ||||
QCOMPARE(domain.minX(),qreal(result.left())); | ||||
QCOMPARE(domain.maxX(),qreal(result.right())); | ||||
QCOMPARE(domain.minY(),qreal(result.top())); | ||||
QCOMPARE(domain.maxY(),qreal(result.bottom())); | ||||
TRY_COMPARE(spy0.count(), 1); | ||||
TRY_COMPARE(spy1.count(), 1); | ||||
TRY_COMPARE(spy2.count(), 1); | ||||
} | ||||
void tst_Domain::zoomOut_data() | ||||
{ | ||||
QTest::addColumn<QMargins>("range"); | ||||
QTest::addColumn<QSizeF>("size"); | ||||
QTest::addColumn<QMargins>("zoom"); | ||||
QTest::addColumn<QMargins>("result"); | ||||
QTest::newRow("first") << QMargins(100,100,900,900) << QSizeF(1000, 1000) << | ||||
QMargins(100, 100, 900, 900) << QMargins(0,0,1000,1000); | ||||
QTest::newRow("second") << QMargins(200,200,1800,1800) << QSizeF(1000, 1000) << | ||||
QMargins(100, 100, 900, 900) << QMargins(0,0,2000,2000); | ||||
} | ||||
void tst_Domain::zoomOut() | ||||
{ | ||||
QFETCH(QMargins, range); | ||||
QFETCH(QSizeF, size); | ||||
QFETCH(QMargins, zoom); | ||||
QFETCH(QMargins, result); | ||||
|
r439 | |||
|
r2275 | XYDomain domain; | ||
|
r2273 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); | ||
domain.setSize(size); | ||||
|
r439 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
domain.zoomOut(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); | ||||
QCOMPARE(domain.minX(),qreal(result.left())); | ||||
QCOMPARE(domain.maxX(),qreal(result.right())); | ||||
QCOMPARE(domain.minY(),qreal(result.top())); | ||||
QCOMPARE(domain.maxY(),qreal(result.bottom())); | ||||
TRY_COMPARE(spy0.count(), 1); | ||||
TRY_COMPARE(spy1.count(), 1); | ||||
TRY_COMPARE(spy2.count(), 1); | ||||
|
r439 | } | ||
|
r773 | void tst_Domain::move_data() | ||
{ | ||||
|
r2273 | QTest::addColumn<QMargins>("range"); | ||
QTest::addColumn<QSizeF>("size"); | ||||
|
r773 | QTest::addColumn<int>("dx"); | ||
QTest::addColumn<int>("dy"); | ||||
|
r2273 | QTest::addColumn<QMargins>("result"); | ||
QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << | ||||
10 << 10 << QMargins(10,10,1010,1010); | ||||
QTest::newRow("second") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << | ||||
-10 << -10 << QMargins(-10,-10,990,990); | ||||
|
r773 | } | ||
void tst_Domain::move() | ||||
{ | ||||
|
r2273 | QFETCH(QMargins, range); | ||
QFETCH(QSizeF, size); | ||||
|
r773 | QFETCH(int, dx); | ||
QFETCH(int, dy); | ||||
|
r2273 | QFETCH(QMargins, result); | ||
|
r773 | |||
|
r2275 | XYDomain domain; | ||
|
r2273 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); | ||
domain.setSize(size); | ||||
|
r773 | |||
|
r1698 | QSignalSpy spy0(&domain, SIGNAL(updated())); | ||
|
r2273 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); | ||
QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); | ||||
|
r773 | |||
|
r2273 | domain.move(dx, dy); | ||
|
r773 | |||
|
r2273 | QCOMPARE(domain.minX(),qreal(result.left())); | ||
QCOMPARE(domain.maxX(),qreal(result.right())); | ||||
QCOMPARE(domain.minY(),qreal(result.top())); | ||||
QCOMPARE(domain.maxY(),qreal(result.bottom())); | ||||
|
r773 | |||
|
r1109 | TRY_COMPARE(spy0.count(), 1); | ||
|
r1111 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); | ||
TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); | ||||
|
r773 | } | ||
|
r439 | QTEST_MAIN(tst_Domain) | ||
#include "tst_domain.moc" | ||||
|
r1977 | #endif | ||