##// END OF EJS Templates
barseries unit testing
sauimone -
r1100:63e0c277c9b2
parent child
Show More
@@ -0,0 +1,6
1 !include( ../auto.pri ) {
2 error( "Couldn't find the auto.pri file!" )
3 }
4 SOURCES += tst_qbarseries.cpp
5
6 !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR"
@@ -0,0 +1,133
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QtTest/QtTest>
22 #include <qbarseries.h>
23 #include <qbarset>
24
25 QTCOMMERCIALCHART_USE_NAMESPACE
26
27 class tst_QBarSeries : public QObject
28 {
29 Q_OBJECT
30
31 public slots:
32 void initTestCase();
33 void cleanupTestCase();
34 void init();
35 void cleanup();
36
37 private slots:
38 void qbarseries_data();
39 void qbarseries();
40 void type_data();
41 void type();
42 void appendBarSet_data();
43 void appendBarSet();
44
45 private:
46 QBarSeries* m_barseries;
47 };
48
49 void tst_QBarSeries::initTestCase()
50 {
51 }
52
53 void tst_QBarSeries::cleanupTestCase()
54 {
55 }
56
57 void tst_QBarSeries::init()
58 {
59 QBarCategories categories;
60 categories << "category0" << "category1" << "category2";
61 m_barseries = new QBarSeries(categories);
62 }
63
64 void tst_QBarSeries::cleanup()
65 {
66 delete m_barseries;
67 m_barseries = 0;
68 }
69
70 void tst_QBarSeries::qbarseries_data()
71 {
72 QTest::addColumn<QBarCategories> ("categories");
73 QBarCategories c;
74 c << "category0" << "category1" << "category2";
75 QTest::newRow("categories") << c;
76 }
77
78 void tst_QBarSeries::qbarseries()
79 {
80 QFETCH(QBarCategories, categories);
81 QBarSeries *barseries = new QBarSeries(categories);
82 QVERIFY(barseries != 0);
83 QBarCategories verifyCategories = barseries->categories();
84
85 QVERIFY(verifyCategories.count() == categories.count());
86 for (int i=0; i<categories.count(); i++) {
87 QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0);
88 }
89 }
90
91 void tst_QBarSeries::type_data()
92 {
93
94 }
95
96 void tst_QBarSeries::type()
97 {
98 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
99 }
100
101 void tst_QBarSeries::appendBarSet_data()
102 {
103 }
104
105 void tst_QBarSeries::appendBarSet()
106 {
107 QVERIFY(m_barseries->barsetCount() == 0);
108
109 QBarSet *barset = new QBarSet("testset");
110 m_barseries->appendBarSet(barset);
111
112 QVERIFY(m_barseries->barsetCount() == 1);
113 }
114
115 /*
116 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
117 void appendBarSets(QList<QBarSet* > sets);
118 void removeBarSets(QList<QBarSet* > sets);
119 int barsetCount() const;
120 int categoryCount() const;
121 QList<QBarSet*> barSets() const;
122 QBarCategories categories() const;
123
124 void setLabelsVisible(bool visible = true);
125
126 bool setModel(QAbstractItemModel *model);
127 void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
128 void setModelMappingRange(int first, int count = -1);
129 */
130 QTEST_MAIN(tst_QBarSeries)
131
132 #include "tst_qbarseries.moc"
133
@@ -3,7 +3,7
3 3 }
4 4
5 5 TEMPLATE = subdirs
6 SUBDIRS += qchartview qchart qlineseries #qbarset
6 SUBDIRS += qchartview qchart qlineseries qbarset qbarseries
7 7
8 8 test_private:{
9 9 SUBDIRS += chartdataset domain
@@ -56,9 +56,6 private slots:
56 56 void count();
57 57 void sum_data();
58 58 void sum();
59
60 private:
61
62 59 private:
63 60 QBarSet* m_barset;
64 61 };
@@ -96,24 +93,28 void tst_QBarSet::qbarset()
96 93
97 94 void tst_QBarSet::name_data()
98 95 {
99 QTest::addColumn<QString> ("names");
100 QTest::newRow("name0, name1") << QString("name0") << QString("name1");
96 QTest::addColumn<QString> ("name");
97 QTest::addColumn<QString> ("result");
98 QTest::newRow("name0") << QString("name0") << QString("name0");
99 QTest::newRow("name1") << QString("name1") << QString("name1");
101 100 }
102 101
103 102 void tst_QBarSet::name()
104 103 {
105 QFETCH(QString, names);
104 QFETCH(QString, name);
105 QFETCH(QString, result);
106 106
107 m_barset->setName(names);
108 QCOMPARE(m_barset->name(), names);
107 m_barset->setName(name);
108 QCOMPARE(m_barset->name(), result);
109 109 }
110 110
111 111 void tst_QBarSet::append_data()
112 112 {
113 // QTest::addColumn<QList<qreal> >("values");
114 // QTest::newRow("0.0 1.0 2.0 3.0 4.0") << (QList<qreal>(0.0) << qreal(1.0) << qreal(2.0) << qreal(3.0) << qreal(4.0));
115 113 QTest::addColumn<int> ("count");
116 QTest::newRow("0 1 2 3 4") << 0 << 1 << 2 << 3 << 4;
114 QTest::newRow("0") << 0;
115 QTest::newRow("5") << 5;
116 QTest::newRow("100") << 100;
117 QTest::newRow("1000") << 1000;
117 118 }
118 119
119 120 void tst_QBarSet::append()
@@ -165,7 +166,6 void tst_QBarSet::appendOperator()
165 166
166 167 void tst_QBarSet::insert_data()
167 168 {
168 // TODO?
169 169 }
170 170
171 171 void tst_QBarSet::insert()
@@ -176,25 +176,24 void tst_QBarSet::insert()
176 176 m_barset->insert(0, 1.0); // 1.0
177 177 QCOMPARE(m_barset->at(0), 1.0);
178 178 QCOMPARE(m_barset->count(), 1);
179 QCOMPARE(m_barset->sum(), 1.0);
179 QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0));
180 180
181 181 m_barset->insert(0, 2.0); // 2.0 1.0
182 182 QCOMPARE(m_barset->at(0), 2.0);
183 183 QCOMPARE(m_barset->at(1), 1.0);
184 184 QCOMPARE(m_barset->count(), 2);
185 QCOMPARE(m_barset->sum(), 3.0);
185 QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0));
186 186
187 187 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
188 188 QCOMPARE(m_barset->at(1), 3.0);
189 189 QCOMPARE(m_barset->at(0), 2.0);
190 190 QCOMPARE(m_barset->at(2), 1.0);
191 191 QCOMPARE(m_barset->count(), 3);
192 QCOMPARE(m_barset->sum(), 6.0);
192 QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0));
193 193 }
194 194
195 195 void tst_QBarSet::remove_data()
196 196 {
197 // TODO?
198 197 }
199 198
200 199 void tst_QBarSet::remove()
@@ -329,16 +328,15 void tst_QBarSet::sum()
329 328 QVERIFY(qFuzzyIsNull(m_barset->sum()));
330 329
331 330 m_barset->append(1.0);
332 QCOMPARE(m_barset->sum(),1.0);
331 QVERIFY(qFuzzyCompare(m_barset->sum(),1.0));
333 332 m_barset->append(2.0);
334 QCOMPARE(m_barset->sum(),3.0);
333 QVERIFY(qFuzzyCompare(m_barset->sum(),3.0));
335 334 m_barset->append(3.0);
336 QCOMPARE(m_barset->sum(),6.0);
335 QVERIFY(qFuzzyCompare(m_barset->sum(),6.0));
337 336 m_barset->append(4.0);
338 QCOMPARE(m_barset->sum(),10.0);
337 QVERIFY(qFuzzyCompare(m_barset->sum(),10.0));
339 338 }
340 339
341
342 340 QTEST_MAIN(tst_QBarSet)
343 341
344 342 #include "tst_qbarset.moc"
General Comments 0
You need to be logged in to leave comments. Login now