From fc38b75b444ab526d65d65600f8446525c514e4d 2012-05-02 13:32:15 From: Jani Honkonen Date: 2012-05-02 13:32:15 Subject: [PATCH] Add basic auto tests for pie --- diff --git a/test/auto/auto.pro b/test/auto/auto.pro index 1a3cd60..8121e34 100644 --- a/test/auto/auto.pro +++ b/test/auto/auto.pro @@ -3,7 +3,7 @@ } TEMPLATE = subdirs -SUBDIRS += qchartview qchart qlineseries qbarset qbarseries +SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qpieslice qpieseries test_private:{ SUBDIRS += chartdataset domain diff --git a/test/auto/qpieseries/qpieseries.pro b/test/auto/qpieseries/qpieseries.pro new file mode 100644 index 0000000..eebc7a0 --- /dev/null +++ b/test/auto/qpieseries/qpieseries.pro @@ -0,0 +1,6 @@ +!include( ../auto.pri ) { + error( "Couldn't find the auto.pri file!" ) +} +SOURCES += tst_qpieseries.cpp + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" diff --git a/test/auto/qpieseries/tst_qpieseries.cpp b/test/auto/qpieseries/tst_qpieseries.cpp new file mode 100644 index 0000000..27835a0 --- /dev/null +++ b/test/auto/qpieseries/tst_qpieseries.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +class tst_qpieseries : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void construction(); + void append(); + void insert(); + void remove(); + //void calculatedValues(); + //void themes(); + //void clickedSignal(); + //void hoverSignal(); + +private: + + +private: + +}; + +void tst_qpieseries::initTestCase() +{ +} + +void tst_qpieseries::cleanupTestCase() +{ +} + +void tst_qpieseries::init() +{ + +} + +void tst_qpieseries::cleanup() +{ + +} + +void tst_qpieseries::construction() +{ + // verify default values + QPieSeries s; + QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); + QVERIFY(s.count() == 0); + QVERIFY(s.isEmpty()); + QVERIFY(qFuzzyIsNull(s.sum())); + QVERIFY(qFuzzyCompare(s.horizontalPosition(), 0.5)); + QVERIFY(qFuzzyCompare(s.verticalPosition(), 0.5)); + QVERIFY(qFuzzyCompare(s.pieSize(), 0.7)); + QVERIFY(qFuzzyIsNull(s.pieStartAngle())); + QVERIFY(qFuzzyCompare(s.pieEndAngle(), 360)); +} + +void tst_qpieseries::append() +{ + QPieSeries s; + + // append pointer + QPieSlice *slice1 = 0; + QVERIFY(!s.append(slice1)); + slice1 = new QPieSlice(1, "slice 1"); + QVERIFY(s.append(slice1)); + QVERIFY(!s.append(slice1)); + QCOMPARE(s.count(), 1); + + // append pointer list + QList list; + QVERIFY(!s.append(list)); + list << (QPieSlice *) 0; + QVERIFY(!s.append(list)); + list.clear(); + list << new QPieSlice(2, "slice 2"); + list << new QPieSlice(3, "slice 3"); + QVERIFY(s.append(list)); + QVERIFY(!s.append(list)); + QCOMPARE(s.count(), 3); + + // append operator + s << new QPieSlice(4, "slice 4"); + s << slice1; // fails because already added + QCOMPARE(s.count(), 4); + + // append with params + QPieSlice *slice5 = s.append(5, "slice 5"); + QVERIFY(slice5 != 0); + QVERIFY(qFuzzyCompare(slice5->value(), 5.0)); + QCOMPARE(slice5->label(), QString("slice 5")); + QCOMPARE(s.count(), 5); + + // check slices + QVERIFY(!s.isEmpty()); + for (int i=0; ivalue(), (qreal) i+1)); + QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); + } +} + +void tst_qpieseries::insert() +{ + QPieSeries s; + + // insert one slice + QPieSlice *slice1 = 0; + QVERIFY(!s.insert(0, slice1)); + slice1 = new QPieSlice(1, "slice 1"); + QVERIFY(!s.insert(-1, slice1)); + QVERIFY(!s.insert(5, slice1)); + QVERIFY(s.insert(0, slice1)); + QVERIFY(!s.insert(0, slice1)); + QCOMPARE(s.count(), 1); + + // add some more slices + s.append(2, "slice 2"); + s.append(4, "slice 4"); + QCOMPARE(s.count(), 3); + + // insert between slices + s.insert(2, new QPieSlice(3, "slice 3")); + QCOMPARE(s.count(), 4); + + // check slices + for (int i=0; ivalue(), (qreal) i+1)); + QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); + } +} + +void tst_qpieseries::remove() +{ + QPieSeries s; + + // add some slices + QPieSlice *slice1 = s.append(1, "slice 1"); + QPieSlice *slice2 = s.append(2, "slice 2"); + QPieSlice *slice3 = s.append(3, "slice 3"); + QSignalSpy spy1(slice1, SIGNAL(destroyed())); + QSignalSpy spy2(slice2, SIGNAL(destroyed())); + QSignalSpy spy3(slice3, SIGNAL(destroyed())); + QCOMPARE(s.count(), 3); + + // null pointer remove + QVERIFY(!s.remove(0)); + + // remove first + QVERIFY(s.remove(slice1)); + QVERIFY(!s.remove(slice1)); + QCOMPARE(s.count(), 2); + QCOMPARE(s.slices().at(0)->label(), slice2->label()); + + // remove all + s.clear(); + QVERIFY(s.isEmpty()); + QVERIFY(s.slices().isEmpty()); + QCOMPARE(s.count(), 0); + + // check that slices were actually destroyed + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); + QCOMPARE(spy3.count(), 1); +} + +/* +void tst_qpieseries::calculatedValues() +{ + +} + +void tst_qpieseries::themes() +{ + +} + +void tst_qpieseries::clickedSignal() +{ + +} + +void tst_qpieseries::hoverSignal() +{ + +} +*/ + +QTEST_MAIN(tst_qpieseries) + +#include "tst_qpieseries.moc" + diff --git a/test/auto/qpieslice/qpieslice.pro b/test/auto/qpieslice/qpieslice.pro new file mode 100644 index 0000000..92acdbe --- /dev/null +++ b/test/auto/qpieslice/qpieslice.pro @@ -0,0 +1,6 @@ +!include( ../auto.pri ) { + error( "Couldn't find the auto.pri file!" ) +} +SOURCES += tst_qpieslice.cpp + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" diff --git a/test/auto/qpieslice/tst_qpieslice.cpp b/test/auto/qpieslice/tst_qpieslice.cpp new file mode 100644 index 0000000..cd92d85 --- /dev/null +++ b/test/auto/qpieslice/tst_qpieslice.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +class tst_qpieslice : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void construction(); + void changedSignals(); + +private: + + +private: + +}; + +void tst_qpieslice::initTestCase() +{ +} + +void tst_qpieslice::cleanupTestCase() +{ +} + +void tst_qpieslice::init() +{ + +} + +void tst_qpieslice::cleanup() +{ + +} + +void tst_qpieslice::construction() +{ + // no params + QPieSlice slice1; + QVERIFY(qFuzzyIsNull(slice1.value())); + QVERIFY(slice1.label().isEmpty()); + QVERIFY(!slice1.isLabelVisible()); + QVERIFY(!slice1.isExploded()); + QCOMPARE(slice1.pen(), QPen()); + QCOMPARE(slice1.brush(), QBrush()); + QCOMPARE(slice1.labelPen(), QPen()); + QCOMPARE(slice1.labelFont(), QFont()); + QVERIFY(qFuzzyCompare(slice1.labelArmLengthFactor(), 0.15)); // default value + QVERIFY(qFuzzyCompare(slice1.explodeDistanceFactor(), 0.15)); // default value + QVERIFY(qFuzzyIsNull(slice1.percentage())); + QVERIFY(qFuzzyIsNull(slice1.startAngle())); + QVERIFY(qFuzzyIsNull(slice1.endAngle())); + + // value and label params + QPieSlice slice2(1.0, "foobar"); + QVERIFY(qFuzzyCompare(slice2.value(), 1.0)); + QCOMPARE(slice2.label(), QString("foobar")); + QVERIFY(!slice2.isLabelVisible()); + QVERIFY(!slice2.isExploded()); + QCOMPARE(slice2.pen(), QPen()); + QCOMPARE(slice2.brush(), QBrush()); + QCOMPARE(slice2.labelPen(), QPen()); + QCOMPARE(slice2.labelFont(), QFont()); + QVERIFY(qFuzzyCompare(slice2.labelArmLengthFactor(), 0.15)); // default value + QVERIFY(qFuzzyCompare(slice2.explodeDistanceFactor(), 0.15)); // default value + QVERIFY(qFuzzyIsNull(slice2.percentage())); + QVERIFY(qFuzzyIsNull(slice2.startAngle())); + QVERIFY(qFuzzyIsNull(slice2.endAngle())); +} + +void tst_qpieslice::changedSignals() +{ + // set everything twice to see we do not get unnecessary signals + QPieSlice slice; + QSignalSpy spy(&slice, SIGNAL(changed())); // TODO: this will be changed to something more refined + slice.setValue(1); + slice.setValue(1); + slice.setLabel("foobar"); + slice.setLabel("foobar"); + slice.setLabelVisible(); + slice.setLabelVisible(); + slice.setExploded(); + slice.setExploded(); + slice.setPen(QPen(Qt::red)); + slice.setPen(QPen(Qt::red)); + slice.setBrush(QBrush(Qt::red)); + slice.setBrush(QBrush(Qt::red)); + slice.setLabelPen(QPen(Qt::green)); + slice.setLabelPen(QPen(Qt::green)); + slice.setLabelFont(QFont("Tahoma")); + slice.setLabelFont(QFont("Tahoma")); + slice.setLabelArmLengthFactor(0.1); + slice.setLabelArmLengthFactor(0.1); + slice.setExplodeDistanceFactor(0.1); + slice.setExplodeDistanceFactor(0.1); + QCOMPARE(spy.count(), 10); +} + +QTEST_MAIN(tst_qpieslice) + +#include "tst_qpieslice.moc" +