From 5d7dfff0c2e815ce13c7929525a4df7ddcaafc78 2012-05-02 12:52:06 From: sauimone Date: 2012-05-02 12:52:06 Subject: [PATCH] updated barseries unit test. fixed found errors. --- diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 95c7d05..13dac90 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -115,7 +115,7 @@ void QBarSeries::removeBarSet(QBarSet *set) Q_D(QBarSeries); if (d->m_barSets.contains(set)) { d->m_barSets.removeOne(set); - QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); + QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); emit d->restructuredBars(); } } @@ -128,7 +128,7 @@ void QBarSeries::appendBarSets(QList sets) Q_D(QBarSeries); foreach (QBarSet* set, sets) { d->m_barSets.append(set); - QObject::connect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); } emit d->restructuredBars(); } @@ -143,7 +143,7 @@ void QBarSeries::removeBarSets(QList sets) foreach (QBarSet* set, sets) { if (d->m_barSets.contains(set)) { d->m_barSets.removeOne(set); - QObject::disconnect(set, SIGNAL(updatedBars()), this, SLOT(barsetChanged())); + QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); } } emit d->restructuredBars(); diff --git a/test/auto/qbarseries/tst_qbarseries.cpp b/test/auto/qbarseries/tst_qbarseries.cpp index da939ea..c3b174a 100644 --- a/test/auto/qbarseries/tst_qbarseries.cpp +++ b/test/auto/qbarseries/tst_qbarseries.cpp @@ -41,9 +41,30 @@ private slots: void type(); void appendBarSet_data(); void appendBarSet(); + void removeBarSet_data(); + void removeBarSet(); + void appendBarSets_data(); + void appendBarSets(); + void removeBarSets_data(); + void removeBarSets(); + void barsetCount_data(); + void barsetCount(); + void categoryCount_data(); + void categoryCount(); + void barSets_data(); + void barSets(); + void categories_data(); + void categories(); + void setLabelsVisible_data(); + void setLabelsVisible(); private: QBarSeries* m_barseries; + QBarSeries* m_barseries_with_sets; + + QList m_testSets; + + QBarCategories m_categories; }; void tst_QBarSeries::initTestCase() @@ -56,15 +77,29 @@ void tst_QBarSeries::cleanupTestCase() void tst_QBarSeries::init() { - QBarCategories categories; - categories << "category0" << "category1" << "category2"; - m_barseries = new QBarSeries(categories); + m_categories << "category0" << "category1" << "category2"; + m_barseries = new QBarSeries(m_categories); + m_barseries_with_sets = new QBarSeries(m_categories); + + for (int i=0; i<5; i++) { + m_testSets.append(new QBarSet("testset")); + m_barseries_with_sets->appendBarSet(m_testSets.at(i)); + } } void tst_QBarSeries::cleanup() { + foreach(QBarSet* s, m_testSets) { + m_barseries_with_sets->removeBarSet(s); + delete s; + } + m_testSets.clear(); + delete m_barseries; m_barseries = 0; + delete m_barseries_with_sets; + m_barseries_with_sets = 0; + m_categories.clear(); } void tst_QBarSeries::qbarseries_data() @@ -110,16 +145,166 @@ void tst_QBarSeries::appendBarSet() m_barseries->appendBarSet(barset); QVERIFY(m_barseries->barsetCount() == 1); + + QBarSet *barset2 = new QBarSet("testset2"); + m_barseries->appendBarSet(barset2); + + QVERIFY(m_barseries->barsetCount() == 2); +} + +void tst_QBarSeries::removeBarSet_data() +{ +} + +void tst_QBarSeries::removeBarSet() +{ + int count = m_testSets.count(); + QVERIFY(m_barseries_with_sets->barsetCount() == count); + + // remove some sets + m_barseries_with_sets->removeBarSet(m_testSets.at(2)); + m_barseries_with_sets->removeBarSet(m_testSets.at(3)); + m_barseries_with_sets->removeBarSet(m_testSets.at(4)); + + QVERIFY(m_barseries_with_sets->barsetCount() == 2); + + QList verifysets = m_barseries_with_sets->barSets(); + + QVERIFY(verifysets.at(0) == m_testSets.at(0)); + QVERIFY(verifysets.at(1) == m_testSets.at(1)); + + // Try removing all sets again + for (int i=0; iremoveBarSet(m_testSets.at(i)); + } + + QVERIFY(m_barseries_with_sets->barsetCount() == 0); +} + +void tst_QBarSeries::appendBarSets_data() +{ + +} + +void tst_QBarSeries::appendBarSets() +{ + int count = 5; + QVERIFY(m_barseries->barsetCount() == 0); + + QList sets; + for (int i=0; iappendBarSets(sets); + QVERIFY(m_barseries->barsetCount() == count); +} + +void tst_QBarSeries::removeBarSets_data() +{ + +} + +void tst_QBarSeries::removeBarSets() +{ + int count = m_testSets.count(); + QVERIFY(m_barseries_with_sets->barsetCount() == count); + + // Try removing empty list of sets + QList empty; + m_barseries_with_sets->removeBarSets(empty); + QVERIFY(m_barseries_with_sets->barsetCount() == count); + + // remove all sets + m_barseries_with_sets->removeBarSets(m_testSets); + QVERIFY(m_barseries_with_sets->barsetCount() == 0); + + // Try removing empty list again + m_barseries_with_sets->removeBarSets(empty); + QVERIFY(m_barseries_with_sets->barsetCount() == 0); + + // remove all sets again + m_barseries_with_sets->removeBarSets(m_testSets); + QVERIFY(m_barseries_with_sets->barsetCount() == 0); +} + +void tst_QBarSeries::barsetCount_data() +{ + +} + +void tst_QBarSeries::barsetCount() +{ + QVERIFY(m_barseries->barsetCount() == 0); + QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); +} + +void tst_QBarSeries::categoryCount_data() +{ + +} + +void tst_QBarSeries::categoryCount() +{ + QVERIFY(m_barseries->categoryCount() == m_categories.count()); + QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); +} + +void tst_QBarSeries::barSets_data() +{ + +} + +void tst_QBarSeries::barSets() +{ + QVERIFY(m_barseries->barSets().count() == 0); + + QList sets = m_barseries_with_sets->barSets(); + QVERIFY(sets.count() == m_testSets.count()); + + for (int i=0; icategories(); + + QVERIFY(categories.count() == m_categories.count()); + for (int i=0; ilabelsVisible() == false); + } + + m_barseries_with_sets->setLabelsVisible(true); + foreach (QBarSet* s, m_testSets) { + QVERIFY(s->labelsVisible() == true); + } + + m_barseries_with_sets->setLabelsVisible(false); + foreach (QBarSet* s, m_testSets) { + QVERIFY(s->labelsVisible() == false); + } } /* -void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set -void appendBarSets(QList sets); -void removeBarSets(QList sets); -int barsetCount() const; -int categoryCount() const; -QList barSets() const; -QBarCategories categories() const; void setLabelsVisible(bool visible = true);