tst_chartdataset.cpp
614 lines
| 16.6 KiB
| text/x-c
|
CppLexer
|
r224 | #include <QtTest/QtTest> | ||
#include <qchartaxis.h> | ||||
|
r349 | #include <qlineseries.h> | ||
|
r224 | #include <private/chartdataset_p.h> | ||
#include <private/domain_p.h> | ||||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
Q_DECLARE_METATYPE(Domain) | ||||
Q_DECLARE_METATYPE(QChartAxis*) | ||||
|
r360 | Q_DECLARE_METATYPE(QSeries*) | ||
|
r349 | Q_DECLARE_METATYPE(QLineSeries*) | ||
|
r224 | |||
class tst_ChartDataSet: public QObject { | ||||
Q_OBJECT | ||||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
void chartdataset_data(); | ||||
void chartdataset(); | ||||
void addDomain_data(); | ||||
void addDomain(); | ||||
void addSeries_data(); | ||||
void addSeries(); | ||||
void axisY_data(); | ||||
void axisY(); | ||||
void clearDomains_data(); | ||||
void clearDomains(); | ||||
void domain_data(); | ||||
void domain(); | ||||
void nextpreviousDomain_data(); | ||||
void nextpreviousDomain(); | ||||
void removeSeries_data(); | ||||
void removeSeries(); | ||||
|
r258 | void removeAllSeries_data(); | ||
void removeAllSeries(); | ||||
|
r224 | }; | ||
void tst_ChartDataSet::initTestCase() | ||||
{ | ||||
qRegisterMetaType<Domain>("Domain"); | ||||
qRegisterMetaType<QChartAxis*>(); | ||||
|
r360 | qRegisterMetaType<QSeries*>(); | ||
|
r224 | } | ||
void tst_ChartDataSet::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_ChartDataSet::init() | ||||
{ | ||||
} | ||||
void tst_ChartDataSet::cleanup() | ||||
{ | ||||
} | ||||
void tst_ChartDataSet::chartdataset_data() | ||||
{ | ||||
} | ||||
void tst_ChartDataSet::chartdataset() | ||||
{ | ||||
ChartDataSet dataSet; | ||||
QVERIFY2(dataSet.axisX(), "Missing axisX."); | ||||
QVERIFY2(dataSet.axisY(), "Missing axisY."); | ||||
//check if not dangling pointer | ||||
dataSet.axisX()->objectName(); | ||||
dataSet.axisY()->objectName(); | ||||
QVERIFY(dataSet.domain(dataSet.axisX())==Domain()); | ||||
QVERIFY(dataSet.domain(dataSet.axisY())==Domain()); | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
} | ||||
void tst_ChartDataSet::addDomain_data() | ||||
{ | ||||
QTest::addColumn<QRectF>("rect"); | ||||
QTest::addColumn<QRectF>("viewport"); | ||||
QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) | ||||
<< QRectF(0, 0, 1000, 1000); | ||||
QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) | ||||
<< QRectF(0, 0, 1000, 1000); | ||||
QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) | ||||
<< QRectF(0, 0, 1000, 1000); | ||||
} | ||||
void tst_ChartDataSet::addDomain() | ||||
{ | ||||
QFETCH(QRectF, rect); | ||||
QFETCH(QRectF, viewport); | ||||
ChartDataSet dataSet; | ||||
Domain domain1(0, 1000, 0, 1000); | ||||
|
r349 | QLineSeries series; | ||
|
r224 | series.add(0, 0); | ||
series.add(1000, 1000); | ||||
dataSet.addSeries(&series); | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | ||||
QSignalSpy spy1(&dataSet, | ||||
|
r399 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | ||
|
r224 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | ||
|
r360 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | ||
|
r224 | QSignalSpy spy4(&dataSet, | ||
|
r360 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | ||
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | ||||
|
r224 | |||
Domain domain2 = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain1 == domain2); | ||||
dataSet.addDomain(rect, viewport); | ||||
QCOMPARE(dataSet.domainIndex(), 1); | ||||
Domain domain3 = dataSet.domain(dataSet.axisY()); | ||||
Domain domain4 = domain1.subDomain(rect, viewport.width(), | ||||
viewport.height()); | ||||
QVERIFY(domain3 == domain4); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 2); | ||||
QCOMPARE(spy2.count(), 0); | ||||
QCOMPARE(spy3.count(), 0); | ||||
QCOMPARE(spy4.count(), 1); | ||||
QCOMPARE(spy5.count(), 0); | ||||
} | ||||
void tst_ChartDataSet::addSeries_data() | ||||
{ | ||||
|
r411 | QTest::addColumn<int>("defaultAxisCount"); | ||
QTest::addColumn<int>("firstAxisCount"); | ||||
QTest::addColumn<int>("secoundAxisCount"); | ||||
QTest::newRow("2 ,1 ,0") << 2 << 1 << 0; | ||||
QTest::newRow("2 series, 2 new axis") << 2 << 0 << 2; | ||||
QTest::newRow("2 series, 1 new axis") << 2 << 0 << 2; | ||||
QTest::newRow("3 series, 3 new axis") << 3 << 0 << 3; | ||||
QTest::newRow("3 series, 2 new axis") << 3 << 0 << 2; | ||||
QTest::newRow("3 series, 1 new axis") << 3 << 0 << 1; | ||||
QTest::newRow("3 series, default + 1 new axis") << 3 << 0 << 1; | ||||
|
r224 | } | ||
void tst_ChartDataSet::addSeries() | ||||
{ | ||||
|
r411 | QFETCH(int, defaultAxisCount); | ||
QFETCH(int, firstAxisCount); | ||||
QFETCH(int, secoundAxisCount); | ||||
ChartDataSet dataSet; | ||||
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | ||||
QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | ||||
QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | ||||
QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | ||||
QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | ||||
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | ||||
for (int i = 0; i < defaultAxisCount; i++) { | ||||
QLineSeries* series = new QLineSeries(); | ||||
dataSet.addSeries(series); | ||||
} | ||||
QChartAxis* firstAxis = new QChartAxis(); | ||||
for (int i = 0; i < firstAxisCount; i++) { | ||||
QLineSeries* series = new QLineSeries(); | ||||
dataSet.addSeries(series, firstAxis); | ||||
} | ||||
QChartAxis* secoundAxis = new QChartAxis(); | ||||
for (int i = 0; i < secoundAxisCount; i++) { | ||||
QLineSeries* series = new QLineSeries(); | ||||
dataSet.addSeries(series, secoundAxis); | ||||
} | ||||
int axisCount = 1; | ||||
if (defaultAxisCount > 0) | ||||
axisCount++; | ||||
if (firstAxisCount > 0) | ||||
axisCount++; | ||||
if (secoundAxisCount > 0) | ||||
axisCount++; | ||||
QCOMPARE(spy0.count(), axisCount); | ||||
QCOMPARE(spy1.count(), (defaultAxisCount + firstAxisCount + secoundAxisCount)*2); | ||||
QCOMPARE(spy2.count(), 0); | ||||
QCOMPARE(spy3.count(), defaultAxisCount + firstAxisCount + secoundAxisCount); | ||||
int i = 0; | ||||
while (defaultAxisCount) { | ||||
i+=defaultAxisCount; | ||||
defaultAxisCount--; | ||||
} | ||||
int j = 0; | ||||
while (firstAxisCount>0) { | ||||
j += firstAxisCount; | ||||
firstAxisCount--; | ||||
} | ||||
int k = 0; | ||||
while (secoundAxisCount>0) { | ||||
k += secoundAxisCount; | ||||
secoundAxisCount--; | ||||
} | ||||
QCOMPARE(spy4.count(),i + j + k); | ||||
QCOMPARE(spy5.count(), 0); | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
|
r224 | } | ||
void tst_ChartDataSet::axisY_data() | ||||
{ | ||||
QTest::addColumn<QChartAxis*>("axisY"); | ||||
QTest::newRow("axisY1") << new QChartAxis(); | ||||
QTest::newRow("axisY2") << new QChartAxis(); | ||||
} | ||||
void tst_ChartDataSet::axisY() | ||||
{ | ||||
QFETCH(QChartAxis*, axisY); | ||||
ChartDataSet dataSet; | ||||
QChartAxis* defaultAxisY = dataSet.axisY(); | ||||
QVERIFY2(defaultAxisY, "Missing axisY."); | ||||
|
r349 | QLineSeries* series1 = new QLineSeries(); | ||
|
r251 | dataSet.addSeries(series1); | ||
|
r349 | QLineSeries* series2 = new QLineSeries(); | ||
|
r251 | dataSet.addSeries(series2, axisY); | ||
QVERIFY(dataSet.axisY(series1) == defaultAxisY); | ||||
QVERIFY(dataSet.axisY(series2) == axisY); | ||||
|
r224 | |||
} | ||||
void tst_ChartDataSet::clearDomains_data() | ||||
{ | ||||
QTest::addColumn<int>("indexCount"); | ||||
QTest::newRow("0") << 0; | ||||
QTest::newRow("1") << 1; | ||||
QTest::newRow("5") << 2; | ||||
QTest::newRow("8") << 3; | ||||
} | ||||
void tst_ChartDataSet::clearDomains() | ||||
{ | ||||
QFETCH(int, indexCount); | ||||
Domain domain1(0, 100, 0, 100); | ||||
|
r349 | QLineSeries* series = new QLineSeries(); | ||
|
r251 | series->add(0, 0); | ||
series->add(100, 100); | ||||
|
r224 | |||
ChartDataSet dataSet; | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
|
r251 | dataSet.addSeries(series); | ||
|
r224 | |||
Domain domain2 = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain2 == domain1); | ||||
QList<Domain> domains; | ||||
domains << domain1; | ||||
for (int i = 0; i < indexCount; i++) { | ||||
dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100)); | ||||
domains << dataSet.domain(dataSet.axisY()); | ||||
} | ||||
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | ||||
QSignalSpy spy1(&dataSet, | ||||
|
r399 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | ||
|
r224 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | ||
|
r360 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | ||
|
r224 | QSignalSpy spy4(&dataSet, | ||
|
r360 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | ||
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | ||||
|
r224 | |||
dataSet.clearDomains(indexCount); | ||||
QCOMPARE(dataSet.domainIndex(), indexCount); | ||||
domain2 = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain2 == domains.at(indexCount)); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), 0); | ||||
QCOMPARE(spy3.count(), 0); | ||||
QCOMPARE(spy4.count(), 0); | ||||
QCOMPARE(spy5.count(), 0); | ||||
} | ||||
void tst_ChartDataSet::domain_data() | ||||
{ | ||||
QTest::addColumn<Domain>("domain1"); | ||||
QTest::addColumn<Domain>("domain2"); | ||||
QTest::addColumn<Domain>("domain3"); | ||||
QTest::addColumn<Domain>("domain"); | ||||
QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10) | ||||
<< Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10); | ||||
QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10) | ||||
<< Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3) | ||||
<< Domain(-1, 11, 0, 11); | ||||
QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1) | ||||
<< Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8); | ||||
} | ||||
void tst_ChartDataSet::domain() | ||||
{ | ||||
QFETCH(Domain, domain1); | ||||
QFETCH(Domain, domain2); | ||||
QFETCH(Domain, domain3); | ||||
QFETCH(Domain, domain); | ||||
ChartDataSet dataSet; | ||||
|
r349 | QLineSeries* series1 = new QLineSeries(); | ||
|
r251 | series1->add(domain1.m_minX, domain1.m_minY); | ||
series1->add(domain1.m_maxX, domain1.m_maxY); | ||||
|
r349 | QLineSeries* series2 = new QLineSeries(); | ||
|
r251 | series2->add(domain2.m_minX, domain2.m_minY); | ||
series2->add(domain2.m_maxX, domain2.m_maxY); | ||||
|
r349 | QLineSeries* series3 = new QLineSeries(); | ||
|
r251 | series3->add(domain3.m_minX, domain3.m_minY); | ||
series3->add(domain3.m_maxX, domain3.m_maxY); | ||||
|
r224 | |||
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | ||||
QSignalSpy spy1(&dataSet, | ||||
|
r399 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | ||
|
r224 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | ||
|
r360 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | ||
|
r224 | QSignalSpy spy4(&dataSet, | ||
|
r360 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | ||
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | ||||
|
r224 | |||
|
r251 | dataSet.addSeries(series1); | ||
dataSet.addSeries(series2); | ||||
dataSet.addSeries(series3); | ||||
|
r224 | |||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal"); | ||||
QCOMPARE(spy0.count(), 2); | ||||
QCOMPARE(spy1.count(), 6); | ||||
QCOMPARE(spy2.count(), 0); | ||||
QCOMPARE(spy3.count(), 3); | ||||
|
r411 | QCOMPARE(spy4.count(), 6); | ||
|
r224 | QCOMPARE(spy5.count(), 0); | ||
} | ||||
void tst_ChartDataSet::nextpreviousDomain_data() | ||||
{ | ||||
QTest::addColumn<QRectF>("rect"); | ||||
QTest::addColumn<QRectF>("viewport"); | ||||
QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) | ||||
<< QRectF(0, 0, 1000, 1000); | ||||
QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) | ||||
<< QRectF(0, 0, 1000, 1000); | ||||
QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) | ||||
<< QRectF(0, 0, 1000, 1000); | ||||
} | ||||
void tst_ChartDataSet::nextpreviousDomain() | ||||
{ | ||||
QFETCH(QRectF, rect); | ||||
QFETCH(QRectF, viewport); | ||||
ChartDataSet dataSet; | ||||
Domain domain1(0, 1000, 0, 1000); | ||||
|
r349 | QLineSeries* series = new QLineSeries(); | ||
|
r251 | series->add(0, 0); | ||
series->add(1000, 1000); | ||||
|
r224 | |||
|
r251 | dataSet.addSeries(series); | ||
|
r224 | |||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
Domain domain2 = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain1 == domain2); | ||||
dataSet.addDomain(rect, viewport); | ||||
QCOMPARE(dataSet.domainIndex(), 1); | ||||
Domain domain3 = dataSet.domain(dataSet.axisY()); | ||||
Domain domain4 = domain1.subDomain(rect, viewport.width(), | ||||
viewport.height()); | ||||
QVERIFY(domain3 == domain4); | ||||
dataSet.addDomain(rect, viewport); | ||||
QCOMPARE(dataSet.domainIndex(), 2); | ||||
Domain domain5 = dataSet.domain(dataSet.axisY()); | ||||
Domain domain6 = domain3.subDomain(rect, viewport.width(), | ||||
viewport.height()); | ||||
QVERIFY(domain5 == domain6); | ||||
dataSet.addDomain(rect, viewport); | ||||
QCOMPARE(dataSet.domainIndex(), 3); | ||||
Domain domain7 = dataSet.domain(dataSet.axisY()); | ||||
Domain domain8 = domain5.subDomain(rect, viewport.width(), | ||||
viewport.height()); | ||||
QVERIFY(domain7 == domain8); | ||||
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | ||||
QSignalSpy spy1(&dataSet, | ||||
|
r399 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | ||
|
r224 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | ||
|
r360 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | ||
|
r224 | QSignalSpy spy4(&dataSet, | ||
|
r360 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | ||
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | ||||
|
r224 | |||
Domain domain; | ||||
bool previous = dataSet.previousDomain(); | ||||
QCOMPARE(previous, true); | ||||
QCOMPARE(dataSet.domainIndex(), 2); | ||||
domain = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain == domain5); | ||||
previous = dataSet.previousDomain(); | ||||
QCOMPARE(previous, true); | ||||
QCOMPARE(dataSet.domainIndex(), 1); | ||||
domain = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain == domain3); | ||||
previous = dataSet.previousDomain(); | ||||
QCOMPARE(previous, true); | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
domain = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain == domain1); | ||||
previous = dataSet.previousDomain(); | ||||
QCOMPARE(previous, false); | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
domain = dataSet.domain(dataSet.axisY()); | ||||
QVERIFY(domain == domain1); | ||||
bool next = dataSet.nextDomain(); | ||||
QCOMPARE(next, true); | ||||
QCOMPARE(dataSet.domainIndex(),1); | ||||
next = dataSet.nextDomain(); | ||||
QCOMPARE(next, true); | ||||
QCOMPARE(dataSet.domainIndex(),2); | ||||
next = dataSet.nextDomain(); | ||||
QCOMPARE(next, true); | ||||
QCOMPARE(dataSet.domainIndex(),3); | ||||
next = dataSet.nextDomain(); | ||||
QCOMPARE(next, false); | ||||
QCOMPARE(dataSet.domainIndex(),3); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 12); | ||||
QCOMPARE(spy2.count(), 0); | ||||
QCOMPARE(spy3.count(), 0); | ||||
QCOMPARE(spy4.count(), 6); | ||||
QCOMPARE(spy5.count(), 0); | ||||
} | ||||
void tst_ChartDataSet::removeSeries_data() | ||||
{ | ||||
QTest::addColumn<int>("seriesCount"); | ||||
QTest::addColumn<int>("axisYCount"); | ||||
QTest::newRow("2 series, default axis") << 2 << 0; | ||||
QTest::newRow("2 series, 2 new axis") << 2 << 2; | ||||
QTest::newRow("2 series, 1 new axis") << 2 << 2; | ||||
QTest::newRow("3 series, 3 new axis") << 3 << 3; | ||||
QTest::newRow("3 series, 2 new axis") << 3 << 2; | ||||
QTest::newRow("3 series, 1 new axis") << 3 << 1; | ||||
} | ||||
void tst_ChartDataSet::removeSeries() | ||||
{ | ||||
QFETCH(int, seriesCount); | ||||
QFETCH(int, axisYCount); | ||||
ChartDataSet dataSet; | ||||
QList<QChartAxis*> axisList; | ||||
|
r360 | QList<QSeries*> seriesList; | ||
|
r224 | |||
for (int i = 0; i < axisYCount; i++) { | ||||
QChartAxis* axis = new QChartAxis(); | ||||
axisList << axis; | ||||
} | ||||
QList<QChartAxis*>::iterator iterator = axisList.begin(); | ||||
for (int i = 0; i < seriesCount; i++) { | ||||
QChartAxis* axisY = 0; | ||||
|
r349 | QLineSeries* series = new QLineSeries(); | ||
|
r224 | if (iterator != axisList.end()) { | ||
axisY = *iterator; | ||||
iterator++; | ||||
} else if (axisList.count() > 0) { | ||||
iterator--; | ||||
axisY = *iterator; | ||||
iterator++; | ||||
} | ||||
dataSet.addSeries(series, axisY); | ||||
seriesList << series; | ||||
} | ||||
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | ||||
QSignalSpy spy1(&dataSet, | ||||
|
r399 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | ||
|
r224 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | ||
|
r360 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | ||
|
r224 | QSignalSpy spy4(&dataSet, | ||
|
r360 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | ||
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | ||||
|
r224 | |||
for (int i = 0; i < seriesCount; i++) { | ||||
dataSet.removeSeries(seriesList.at(i)); | ||||
} | ||||
|
r258 | //default axis | ||
if (axisYCount == 0) | ||||
axisYCount++; | ||||
|
r224 | QCOMPARE(spy0.count(), 0); | ||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), axisYCount); | ||||
QCOMPARE(spy3.count(), 0); | ||||
QCOMPARE(spy4.count(), 0); | ||||
QCOMPARE(spy5.count(), seriesCount); | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
|
r258 | |||
qDeleteAll(seriesList); | ||||
|
r224 | } | ||
|
r258 | void tst_ChartDataSet::removeAllSeries_data() | ||
{ | ||||
QTest::addColumn<int>("seriesCount"); | ||||
QTest::addColumn<int>("axisYCount"); | ||||
QTest::newRow("2 series, default axis") << 2 << 0; | ||||
QTest::newRow("2 series, 2 new axis") << 2 << 2; | ||||
QTest::newRow("2 series, 1 new axis") << 2 << 2; | ||||
QTest::newRow("3 series, 3 new axis") << 3 << 3; | ||||
QTest::newRow("3 series, 2 new axis") << 3 << 2; | ||||
QTest::newRow("3 series, 1 new axis") << 3 << 1; | ||||
} | ||||
void tst_ChartDataSet::removeAllSeries() | ||||
{ | ||||
QFETCH(int, seriesCount); | ||||
QFETCH(int, axisYCount); | ||||
ChartDataSet dataSet; | ||||
QList<QChartAxis*> axisList; | ||||
for (int i = 0; i < axisYCount; i++) { | ||||
QChartAxis* axis = new QChartAxis(); | ||||
axisList << axis; | ||||
} | ||||
QList<QChartAxis*>::iterator iterator = axisList.begin(); | ||||
for (int i = 0; i < seriesCount; i++) { | ||||
QChartAxis* axisY = 0; | ||||
|
r349 | QLineSeries* series = new QLineSeries(); | ||
|
r258 | if (iterator != axisList.end()) { | ||
axisY = *iterator; | ||||
iterator++; | ||||
} else if (axisList.count() > 0) { | ||||
iterator--; | ||||
axisY = *iterator; | ||||
iterator++; | ||||
} | ||||
dataSet.addSeries(series, axisY); | ||||
} | ||||
QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | ||||
|
r399 | QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | ||
|
r258 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | ||
|
r360 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | ||
QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | ||||
QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | ||||
|
r258 | |||
dataSet.removeAllSeries(); | ||||
//default axis | ||||
if (axisYCount == 0) | ||||
axisYCount++; | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(spy1.count(), 0); | ||||
QCOMPARE(spy2.count(), axisYCount); | ||||
QCOMPARE(spy3.count(), 0); | ||||
QCOMPARE(spy4.count(), 0); | ||||
QCOMPARE(spy5.count(), seriesCount); | ||||
QCOMPARE(dataSet.domainIndex(), 0); | ||||
} | ||||
|
r224 | QTEST_MAIN(tst_ChartDataSet) | ||
#include "tst_chartdataset.moc" | ||||