From d9d98bcd2ec457230bfb1bca73ba153aeaa8c5b7 2012-10-23 11:33:16 From: sauimone Date: 2012-10-23 11:33:16 Subject: [PATCH] qlegend unit test started --- diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9cb588d..45ad45a 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -24,7 +24,8 @@ SUBDIRS += \ qcategoryaxis \ qbarcategoryaxis \ domain \ - chartdataset + chartdataset \ + qlegend contains(QT_VERSION, ^4\\.[0-7]\\.[0-3]\\s*$) | contains(QT_VERSION, ^4\\.[0-6]\\..*) { warning("QtCommercial.Charts QML API requires at least Qt 4.7.4. You are using $${QT_VERSION} so the QML API is disabled.") diff --git a/tests/auto/qlegend/qlegend.pro b/tests/auto/qlegend/qlegend.pro new file mode 100644 index 0000000..26dbf50 --- /dev/null +++ b/tests/auto/qlegend/qlegend.pro @@ -0,0 +1,4 @@ +!include( ../auto.pri ) { + error( "Couldn't find the auto.pri file!" ) +} +SOURCES += tst_qlegend.cpp diff --git a/tests/auto/qlegend/tst_qlegend.cpp b/tests/auto/qlegend/tst_qlegend.cpp new file mode 100644 index 0000000..22cb1a7 --- /dev/null +++ b/tests/auto/qlegend/tst_qlegend.cpp @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +class tst_QLegend : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void qlegend(); + void qpieLegendMarker(); + void qareaLegendMarker(); + void qxyLegendMarker(); + void qbarLegendMarker(); + +private: + + QChart *m_chart; + +}; + +void tst_QLegend::initTestCase() +{ +} + +void tst_QLegend::cleanupTestCase() +{ +} + +void tst_QLegend::init() +{ + m_chart = new QChart(); +} + +void tst_QLegend::cleanup() +{ + delete m_chart; + m_chart = 0; +} + +void tst_QLegend::qlegend() +{ + QVERIFY(m_chart); + + QLegend *legend = m_chart->legend(); + QVERIFY(legend); + + QList markers = legend->markers(); + QVERIFY(markers.count() == 0); +} + +void tst_QLegend::qpieLegendMarker() +{ + QVERIFY(m_chart); + QLegend *legend = m_chart->legend(); + + QPieSeries *series = new QPieSeries(); + QPieSlice *s1 = new QPieSlice(QString("s1"), 111.0); + series->append(s1); + m_chart->addSeries(series); + + // Should have one marker + QList markers = legend->markers(); + QVERIFY(markers.count() == 1); + QLegendMarker *m = markers.at(0); + + // Should be piemarker + QVERIFY(m->type() == QLegendMarker::LegendMarkerTypePie); + + // Related series and slice must match + QPieLegendMarker *pm = qobject_cast (m); + QVERIFY(pm); + QVERIFY(pm->series() == series); + QVERIFY(pm->slice() == s1); + + // Add another slice + QPieSlice *s2 = new QPieSlice(QString("s2"), 111.0); + series->append(s2); + + markers = legend->markers(); + QVERIFY(markers.count() == 2); + m = markers.at(1); + + QVERIFY(m->type() == QLegendMarker::LegendMarkerTypePie); + + // Related series and slice must match + pm = qobject_cast (m); + QVERIFY(pm); + QVERIFY(pm->series() == series); + QVERIFY(pm->slice() == s2); +} + +void tst_QLegend::qareaLegendMarker() +{ + QVERIFY(m_chart); + QLegend *legend = m_chart->legend(); + QAreaSeries *series = new QAreaSeries(); + + QLineSeries *upper = new QLineSeries(); + QLineSeries *lower = new QLineSeries(); + + upper->append(1,1); + lower->append(1,0); + + series->setUpperSeries(upper); + series->setLowerSeries(lower); + + m_chart->addSeries(series); + + // Should have one marker + QList markers = legend->markers(); + QVERIFY(markers.count() == 1); + QLegendMarker *m = markers.at(0); + + QVERIFY(m->series() == series); + QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeArea); + + QAreaLegendMarker *pm = qobject_cast (m); + QVERIFY(pm); + QVERIFY(pm->series() == series); +} + +void tst_QLegend::qxyLegendMarker() +{ + QVERIFY(m_chart); + QLegend *legend = m_chart->legend(); + + QLineSeries *series = new QLineSeries(); + m_chart->addSeries(series); + + // Should have one marker + QList markers = legend->markers(); + QVERIFY(markers.count() == 1); + QLegendMarker *m = markers.at(0); + + QVERIFY(m->series() == series); + QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeXY); + + QXYLegendMarker *pm = qobject_cast (m); + QVERIFY(pm); + QVERIFY(pm->series() == series); +} + +void tst_QLegend::qbarLegendMarker() +{ + QVERIFY(m_chart); + QLegend *legend = m_chart->legend(); + + QBarSeries *series = new QBarSeries(); + QBarSet *set0 = new QBarSet(QString("set0")); + series->append(set0); + m_chart->addSeries(series); + + // Should have one marker + QList markers = legend->markers(); + QVERIFY(markers.count() == 1); + QLegendMarker *m = markers.at(0); + + QVERIFY(m->series() == series); + QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeBar); + + QBarLegendMarker *pm = qobject_cast (m); + QVERIFY(pm); + QVERIFY(pm->series() == series); + QVERIFY(pm->barset() == set0); + + // Add another barset + QBarSet *set1 = new QBarSet(QString("set0")); + series->append(set1); + + markers = legend->markers(); + QVERIFY(markers.count() == 2); + m = markers.at(1); + + QVERIFY(m->series() == series); + QVERIFY(m->type() == QLegendMarker::LegendMarkerTypeBar); + + pm = qobject_cast (m); + QVERIFY(pm); + QVERIFY(pm->series() == series); + QVERIFY(pm->barset() == set1); +} + +QTEST_MAIN(tst_QLegend) + +#include "tst_qlegend.moc" +