##// END OF EJS Templates
Removes test_private form qmake, adds chaeck in soruce file of private tests
Michal Klocek -
r1977:0c7165b201ff
parent child
Show More
@@ -1,103 +1,102
1 ##################### LIB #################################################
1 ##################### LIB #################################################
2
2
3 LIBRARY_NAME = QtCommercialChart
3 LIBRARY_NAME = QtCommercialChart
4 CONFIG(debug, debug|release) {
4 CONFIG(debug, debug|release) {
5 mac: LIBRARY_NAME = $$join(LIBRARY_NAME,,,_debug)
5 mac: LIBRARY_NAME = $$join(LIBRARY_NAME,,,_debug)
6 win32: LIBRARY_NAME = $$join(LIBRARY_NAME,,,d)
6 win32: LIBRARY_NAME = $$join(LIBRARY_NAME,,,d)
7 }
7 }
8
8
9 LIBS += -l$$LIBRARY_NAME
9 LIBS += -l$$LIBRARY_NAME
10
10
11 # This will undefine Q_DECL_EXPORT/Q_DECL_IMPORT at qchartglobal.h
11 # This will undefine Q_DECL_EXPORT/Q_DECL_IMPORT at qchartglobal.h
12 # They should not be used for staticlib builds.
12 # They should not be used for staticlib builds.
13 staticlib:DEFINES+=QTCOMMERCIALCHART_STATICLIB
13 staticlib:DEFINES+=QTCOMMERCIALCHART_STATICLIB
14
14
15 ##################### SHADOW CONFIG #################################################
15 ##################### SHADOW CONFIG #################################################
16
16
17 !contains($${PWD}, $${OUT_PWD}){
17 !contains($${PWD}, $${OUT_PWD}){
18 search = "$$PWD:::"
18 search = "$$PWD:::"
19 temp = $$split(search,"/")
19 temp = $$split(search,"/")
20 temp = $$last(temp)
20 temp = $$last(temp)
21 path = $$replace(search,$$temp,'')
21 path = $$replace(search,$$temp,'')
22 temp = $$split(OUT_PWD,$$path)
22 temp = $$split(OUT_PWD,$$path)
23 temp = $$split(temp,'/')
23 temp = $$split(temp,'/')
24 temp = $$first(temp)
24 temp = $$first(temp)
25 path = "$${path}$${temp}"
25 path = "$${path}$${temp}"
26 SHADOW=$$path
26 SHADOW=$$path
27 }else{
27 }else{
28 SHADOW=$$PWD
28 SHADOW=$$PWD
29 CONFIG-=development_build
29 CONFIG-=development_build
30 }
30 }
31
31
32 ##################### BUILD PATHS ##################################################
32 ##################### BUILD PATHS ##################################################
33
33
34 CHART_BUILD_PUBLIC_HEADER_DIR = $$SHADOW/include
34 CHART_BUILD_PUBLIC_HEADER_DIR = $$SHADOW/include
35 CHART_BUILD_PRIVATE_HEADER_DIR = $$CHART_BUILD_PUBLIC_HEADER_DIR/private
35 CHART_BUILD_PRIVATE_HEADER_DIR = $$CHART_BUILD_PUBLIC_HEADER_DIR/private
36 CHART_BUILD_LIB_DIR = $$SHADOW/lib
36 CHART_BUILD_LIB_DIR = $$SHADOW/lib
37 CHART_BUILD_DIR = $$SHADOW/build
37 CHART_BUILD_DIR = $$SHADOW/build
38 CHART_BUILD_BIN_DIR = $$SHADOW/bin
38 CHART_BUILD_BIN_DIR = $$SHADOW/bin
39 CHART_BUILD_PLUGIN_DIR = $$CHART_BUILD_BIN_DIR/QtCommercial/Chart
39 CHART_BUILD_PLUGIN_DIR = $$CHART_BUILD_BIN_DIR/QtCommercial/Chart
40 CHART_BUILD_DOC_DIR = $$SHADOW/doc
40 CHART_BUILD_DOC_DIR = $$SHADOW/doc
41
41
42 # Use own folders for debug and release builds
42 # Use own folders for debug and release builds
43
43
44 CONFIG(debug, debug|release):CHART_BUILD_DIR = $$join(CHART_BUILD_DIR,,,/debug)
44 CONFIG(debug, debug|release):CHART_BUILD_DIR = $$join(CHART_BUILD_DIR,,,/debug)
45 CONFIG(release, debug|release): CHART_BUILD_DIR = $$join(CHART_BUILD_DIR,,,/release)
45 CONFIG(release, debug|release): CHART_BUILD_DIR = $$join(CHART_BUILD_DIR,,,/release)
46
46
47
47
48 win32:{
48 win32:{
49 CHART_BUILD_PUBLIC_HEADER_DIR = $$replace(CHART_BUILD_PUBLIC_HEADER_DIR, "/","\\")
49 CHART_BUILD_PUBLIC_HEADER_DIR = $$replace(CHART_BUILD_PUBLIC_HEADER_DIR, "/","\\")
50 CHART_BUILD_PRIVATE_HEADER_DIR = $$replace(CHART_BUILD_PRIVATE_HEADER_DIR, "/","\\")
50 CHART_BUILD_PRIVATE_HEADER_DIR = $$replace(CHART_BUILD_PRIVATE_HEADER_DIR, "/","\\")
51 CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\")
51 CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\")
52 CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\")
52 CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\")
53 CHART_BUILD_PLUGIN_DIR = $$replace(CHART_BUILD_PLUGIN_DIR, "/","\\")
53 CHART_BUILD_PLUGIN_DIR = $$replace(CHART_BUILD_PLUGIN_DIR, "/","\\")
54 CHART_BUILD_DOC_DIR = $$replace(CHART_BUILD_DOC_DIR, "/","\\")
54 CHART_BUILD_DOC_DIR = $$replace(CHART_BUILD_DOC_DIR, "/","\\")
55 CHART_BUILD_LIB_DIR = $$replace(CHART_BUILD_LIB_DIR, "/","\\")
55 CHART_BUILD_LIB_DIR = $$replace(CHART_BUILD_LIB_DIR, "/","\\")
56 }
56 }
57
57
58 mac: {
58 mac: {
59 # Some Qt versions use an incompatible configuration on OSX which makes the build fail.
59 # Some Qt versions use an incompatible configuration on OSX which makes the build fail.
60 # As a work-around, set the minimum OSX version to 10.5.
60 # As a work-around, set the minimum OSX version to 10.5.
61 QMAKE_CXXFLAGS *= -mmacosx-version-min=10.5
61 QMAKE_CXXFLAGS *= -mmacosx-version-min=10.5
62 QMAKE_LFLAGS *= -mmacosx-version-min=10.5
62 QMAKE_LFLAGS *= -mmacosx-version-min=10.5
63 }
63 }
64
64
65 linux-arm*: {
65 linux-arm*: {
66 DEFINES+=QT_ON_ARM
66 DEFINES+=QT_ON_ARM
67 }
67 }
68
68
69 ##################### INCLUDES ############################################################
69 ##################### INCLUDES ############################################################
70
70
71
71
72 INCLUDEPATH += $$CHART_BUILD_PUBLIC_HEADER_DIR
72 INCLUDEPATH += $$CHART_BUILD_PUBLIC_HEADER_DIR
73
73
74 !win32: {
74 !win32: {
75 LIBS += -L$$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR
75 LIBS += -L$$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR
76 } else {
76 } else {
77 win32-msvc*: {
77 win32-msvc*: {
78 # hack fix for error:
78 # hack fix for error:
79 # "LINK : fatal error LNK1146: no argument specified with option '/LIBPATH:'"
79 # "LINK : fatal error LNK1146: no argument specified with option '/LIBPATH:'"
80 QMAKE_LIBDIR += $$CHART_BUILD_LIB_DIR
80 QMAKE_LIBDIR += $$CHART_BUILD_LIB_DIR
81 } else {
81 } else {
82 LIBS += -L$$CHART_BUILD_LIB_DIR
82 LIBS += -L$$CHART_BUILD_LIB_DIR
83 }
83 }
84 }
84 }
85
85
86 ##################### DEVELOPMENT BUILD ###################################################
86 ##################### DEVELOPMENT BUILD ###################################################
87
87
88 development_build: {
88 development_build: {
89 DEFINES+=DEVELOPMENT_BUILD
89 DEFINES+=DEVELOPMENT_BUILD
90 CONFIG+=debug_and_release
90 CONFIG+=debug_and_release
91 CONFIG+=build_all
91 CONFIG+=build_all
92 }
92 }
93
93
94 #################### COVERAGE #################################################################
94 #################### COVERAGE #################################################################
95 coverage: CONFIG += debug
95 coverage: CONFIG += debug
96
96
97 ##################### UNIT TESTS ##############################################################
97 ##################### UNIT TESTS ##############################################################
98
98
99 CONFIG(debug, debug|release) {
99 CONFIG(debug, debug|release) {
100 CONFIG+=test_private
101 DEFINES+=BUILD_PRIVATE_UNIT_TESTS
100 DEFINES+=BUILD_PRIVATE_UNIT_TESTS
102 }
101 }
103
102
@@ -1,34 +1,35
1 !include( ../tests.pri ) {
1 !include( ../tests.pri ) {
2 error( "Couldn't find the tests.pri file!" )
2 error( "Couldn't find the tests.pri file!" )
3 }
3 }
4
4
5 TEMPLATE = subdirs
5 TEMPLATE = subdirs
6 SUBDIRS += \
6 SUBDIRS += \
7 qchartview \
7 qchartview \
8 qchart \
8 qchart \
9 qlineseries \
9 qlineseries \
10 qbarset \
10 qbarset \
11 qbarseries \
11 qbarseries \
12 qstackedbarseries \
12 qstackedbarseries \
13 qpercentbarseries \
13 qpercentbarseries \
14 qpieslice qpieseries \
14 qpieslice qpieseries \
15 qpiemodelmapper \
15 qpiemodelmapper \
16 qsplineseries \
16 qsplineseries \
17 qscatterseries \
17 qscatterseries \
18 qxymodelmapper \
18 qxymodelmapper \
19 qbarmodelmapper \
19 qbarmodelmapper \
20 qhorizontalbarseries \
20 qhorizontalbarseries \
21 qhorizontalstackedbarseries \
21 qhorizontalstackedbarseries \
22 qhorizontalpercentbarseries \
22 qhorizontalpercentbarseries \
23 qvalueaxis \
23 qvalueaxis \
24 qcategoryaxis \
24 qcategoryaxis \
25 qbarcategoryaxis
25 qbarcategoryaxis \
26 domain \
27 chartdataset
26
28
27 !linux-arm*: {
29 !linux-arm*: {
28 SUBDIRS += \
30 SUBDIRS += \
29 qdatetimeaxis
31 qdatetimeaxis
30 }
32 }
31
33
32 test_private:{
34
33 SUBDIRS += domain chartdataset
35
34 }
@@ -1,623 +1,644
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #ifndef BUILD_PRIVATE_UNIT_TESTS
21 #include <QtTest/QtTest>
22
23 class tst_ChartDataSet: public QObject {
24
25 Q_OBJECT
26
27 private Q_SLOTS:
28 void skip();
29
30 };
31
32 void tst_ChartDataSet::skip()
33 {
34 QSKIP("This test requires the debug version of library", SkipAll);
35 }
36
37 QTEST_MAIN(tst_ChartDataSet)
38 #include "tst_chartdataset.moc"
39
40 #else
20
41
21 #include <QtTest/QtTest>
42 #include <QtTest/QtTest>
22 #include <qabstractaxis.h>
43 #include <qabstractaxis.h>
23 #include <qvalueaxis.h>
44 #include <qvalueaxis.h>
24 #include <qbarcategoryaxis.h>
45 #include <qbarcategoryaxis.h>
25 #include <qlineseries.h>
46 #include <qlineseries.h>
26 #include <qareaseries.h>
47 #include <qareaseries.h>
27 #include <qscatterseries.h>
48 #include <qscatterseries.h>
28 #include <qsplineseries.h>
49 #include <qsplineseries.h>
29 #include <qpieseries.h>
50 #include <qpieseries.h>
30 #include <qbarseries.h>
51 #include <qbarseries.h>
31 #include <qpercentbarseries.h>
52 #include <qpercentbarseries.h>
32 #include <qstackedbarseries.h>
53 #include <qstackedbarseries.h>
33 #include <private/chartdataset_p.h>
54 #include <private/chartdataset_p.h>
34 #include <private/domain_p.h>
55 #include <private/domain_p.h>
35 #include <tst_definitions.h>
56 #include <tst_definitions.h>
36
57
37 QTCOMMERCIALCHART_USE_NAMESPACE
58 QTCOMMERCIALCHART_USE_NAMESPACE
38
59
39 Q_DECLARE_METATYPE(Domain *)
60 Q_DECLARE_METATYPE(Domain *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
61 Q_DECLARE_METATYPE(QAbstractAxis *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
62 Q_DECLARE_METATYPE(QAbstractSeries *)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
63 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
64 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
44 Q_DECLARE_METATYPE(QLineSeries *)
65 Q_DECLARE_METATYPE(QLineSeries *)
45
66
46 class tst_ChartDataSet: public QObject {
67 class tst_ChartDataSet: public QObject {
47
68
48 Q_OBJECT
69 Q_OBJECT
49
70
50 public Q_SLOTS:
71 public Q_SLOTS:
51 void initTestCase();
72 void initTestCase();
52 void cleanupTestCase();
73 void cleanupTestCase();
53 void init();
74 void init();
54 void cleanup();
75 void cleanup();
55
76
56 private Q_SLOTS:
77 private Q_SLOTS:
57 void chartdataset_data();
78 void chartdataset_data();
58 void chartdataset();
79 void chartdataset();
59 void addSeries_data();
80 void addSeries_data();
60 void addSeries();
81 void addSeries();
61 void setAxisX_data();
82 void setAxisX_data();
62 void setAxisX();
83 void setAxisX();
63 void setAxisY_data();
84 void setAxisY_data();
64 void setAxisY();
85 void setAxisY();
65 void removeSeries_data();
86 void removeSeries_data();
66 void removeSeries();
87 void removeSeries();
67 void removeAllSeries_data();
88 void removeAllSeries_data();
68 void removeAllSeries();
89 void removeAllSeries();
69 void seriesCount_data();
90 void seriesCount_data();
70 void seriesCount();
91 void seriesCount();
71 void seriesIndex_data();
92 void seriesIndex_data();
72 void seriesIndex();
93 void seriesIndex();
73 void domain_data();
94 void domain_data();
74 void domain();
95 void domain();
75 void zoomInDomain_data();
96 void zoomInDomain_data();
76 void zoomInDomain();
97 void zoomInDomain();
77 void zoomOutDomain_data();
98 void zoomOutDomain_data();
78 void zoomOutDomain();
99 void zoomOutDomain();
79 void scrollDomain_data();
100 void scrollDomain_data();
80 void scrollDomain();
101 void scrollDomain();
81
102
82 private:
103 private:
83 ChartDataSet* m_dataset;
104 ChartDataSet* m_dataset;
84 };
105 };
85
106
86 void tst_ChartDataSet::initTestCase()
107 void tst_ChartDataSet::initTestCase()
87 {
108 {
88 qRegisterMetaType<Domain*>();
109 qRegisterMetaType<Domain*>();
89 qRegisterMetaType<QAbstractAxis*>();
110 qRegisterMetaType<QAbstractAxis*>();
90 qRegisterMetaType<QAbstractSeries*>();
111 qRegisterMetaType<QAbstractSeries*>();
91 }
112 }
92
113
93 void tst_ChartDataSet::cleanupTestCase()
114 void tst_ChartDataSet::cleanupTestCase()
94 {
115 {
95 }
116 }
96
117
97 void tst_ChartDataSet::init()
118 void tst_ChartDataSet::init()
98 {
119 {
99 m_dataset = new ChartDataSet();
120 m_dataset = new ChartDataSet();
100 }
121 }
101
122
102
123
103 void tst_ChartDataSet::cleanup()
124 void tst_ChartDataSet::cleanup()
104 {
125 {
105 QList<QAbstractSeries*> series = m_dataset->series();
126 QList<QAbstractSeries*> series = m_dataset->series();
106 foreach(QAbstractSeries* serie, series)
127 foreach(QAbstractSeries* serie, series)
107 {
128 {
108 m_dataset->removeSeries(serie);
129 m_dataset->removeSeries(serie);
109 }
130 }
110 }
131 }
111
132
112 void tst_ChartDataSet::chartdataset_data()
133 void tst_ChartDataSet::chartdataset_data()
113 {
134 {
114 }
135 }
115
136
116 void tst_ChartDataSet::chartdataset()
137 void tst_ChartDataSet::chartdataset()
117 {
138 {
118 QVERIFY(m_dataset->axisX(0) == 0);
139 QVERIFY(m_dataset->axisX(0) == 0);
119 QVERIFY(m_dataset->axisY(0) == 0);
140 QVERIFY(m_dataset->axisY(0) == 0);
120 QLineSeries* series = new QLineSeries(this);
141 QLineSeries* series = new QLineSeries(this);
121 QCOMPARE(m_dataset->seriesIndex(series),-1);
142 QCOMPARE(m_dataset->seriesIndex(series),-1);
122 QVERIFY(m_dataset->domain(series) == 0);
143 QVERIFY(m_dataset->domain(series) == 0);
123 QVERIFY(m_dataset->axisX(series) == 0);
144 QVERIFY(m_dataset->axisX(series) == 0);
124 QVERIFY(m_dataset->axisY(series) == 0);
145 QVERIFY(m_dataset->axisY(series) == 0);
125 m_dataset->createDefaultAxes();
146 m_dataset->createDefaultAxes();
126 }
147 }
127
148
128
149
129 void tst_ChartDataSet::addSeries_data()
150 void tst_ChartDataSet::addSeries_data()
130 {
151 {
131 QTest::addColumn<QAbstractSeries*>("series");
152 QTest::addColumn<QAbstractSeries*>("series");
132
153
133 QAbstractSeries* line = new QLineSeries(this);
154 QAbstractSeries* line = new QLineSeries(this);
134 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
155 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
135 QAbstractSeries* scatter = new QScatterSeries(this);
156 QAbstractSeries* scatter = new QScatterSeries(this);
136 QAbstractSeries* spline = new QSplineSeries(this);
157 QAbstractSeries* spline = new QSplineSeries(this);
137 QAbstractSeries* pie = new QPieSeries(this);
158 QAbstractSeries* pie = new QPieSeries(this);
138 QAbstractSeries* bar = new QBarSeries(this);
159 QAbstractSeries* bar = new QBarSeries(this);
139 QAbstractSeries* percent = new QPercentBarSeries(this);
160 QAbstractSeries* percent = new QPercentBarSeries(this);
140 QAbstractSeries* stacked = new QStackedBarSeries(this);
161 QAbstractSeries* stacked = new QStackedBarSeries(this);
141
162
142 QTest::newRow("line") << line;
163 QTest::newRow("line") << line;
143 QTest::newRow("area") << area;
164 QTest::newRow("area") << area;
144 QTest::newRow("scatter") << scatter;
165 QTest::newRow("scatter") << scatter;
145 QTest::newRow("spline") << spline;
166 QTest::newRow("spline") << spline;
146 QTest::newRow("pie") << pie;
167 QTest::newRow("pie") << pie;
147 QTest::newRow("bar") << bar;
168 QTest::newRow("bar") << bar;
148 QTest::newRow("percent") << percent;
169 QTest::newRow("percent") << percent;
149 QTest::newRow("stacked") << stacked;
170 QTest::newRow("stacked") << stacked;
150 }
171 }
151
172
152 void tst_ChartDataSet::addSeries()
173 void tst_ChartDataSet::addSeries()
153 {
174 {
154
175
155 QFETCH(QAbstractSeries*, series);
176 QFETCH(QAbstractSeries*, series);
156
177
157 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
178 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
158 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
179 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
159 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
180 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
181 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161
182
162 m_dataset->addSeries(series);
183 m_dataset->addSeries(series);
163 m_dataset->createDefaultAxes();
184 m_dataset->createDefaultAxes();
164 if(series->type()==QAbstractSeries::SeriesTypePie){
185 if(series->type()==QAbstractSeries::SeriesTypePie){
165 TRY_COMPARE(spy0.count(), 0);
186 TRY_COMPARE(spy0.count(), 0);
166 }else{
187 }else{
167 TRY_COMPARE(spy0.count(), 2);
188 TRY_COMPARE(spy0.count(), 2);
168 }
189 }
169 TRY_COMPARE(spy1.count(), 0);
190 TRY_COMPARE(spy1.count(), 0);
170 TRY_COMPARE(spy2.count(), 1);
191 TRY_COMPARE(spy2.count(), 1);
171 TRY_COMPARE(spy3.count(), 0);
192 TRY_COMPARE(spy3.count(), 0);
172 }
193 }
173
194
174
195
175 void tst_ChartDataSet::setAxisX_data()
196 void tst_ChartDataSet::setAxisX_data()
176 {
197 {
177 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
198 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
178 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
199 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
179 QTest::addColumn<int>("axisCount");
200 QTest::addColumn<int>("axisCount");
180
201
181 QAbstractSeries* line = new QLineSeries(this);
202 QAbstractSeries* line = new QLineSeries(this);
182 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
203 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
183 QAbstractSeries* scatter = new QScatterSeries(this);
204 QAbstractSeries* scatter = new QScatterSeries(this);
184 QAbstractSeries* spline = new QSplineSeries(this);
205 QAbstractSeries* spline = new QSplineSeries(this);
185 /*QAbstractSeries* pie = */new QPieSeries(this);
206 /*QAbstractSeries* pie = */new QPieSeries(this);
186 /*QAbstractSeries* bar = */new QBarSeries(this);
207 /*QAbstractSeries* bar = */new QBarSeries(this);
187 /*QAbstractSeries* percent = */new QPercentBarSeries(this);
208 /*QAbstractSeries* percent = */new QPercentBarSeries(this);
188 /*QAbstractSeries* stacked = */new QStackedBarSeries(this);
209 /*QAbstractSeries* stacked = */new QStackedBarSeries(this);
189
210
190 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
211 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
191 << (QList<QAbstractSeries*>() << line << spline << scatter)
212 << (QList<QAbstractSeries*>() << line << spline << scatter)
192 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3;
213 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3;
193
214
194 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
215 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
195 << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1;
216 << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1;
196
217
197 QList<QAbstractAxis*> axes0;
218 QList<QAbstractAxis*> axes0;
198 axes0 << new QValueAxis(this) << new QValueAxis(this);
219 axes0 << new QValueAxis(this) << new QValueAxis(this);
199 axes0 << axes0.last();
220 axes0 << axes0.last();
200 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
221 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
201 << (QList<QAbstractSeries*>() << line << spline << scatter)
222 << (QList<QAbstractSeries*>() << line << spline << scatter)
202 << axes0 << 2;
223 << axes0 << 2;
203 //TODO: add more test cases
224 //TODO: add more test cases
204 }
225 }
205
226
206 void tst_ChartDataSet::setAxisX()
227 void tst_ChartDataSet::setAxisX()
207 {
228 {
208 QFETCH(QList<QAbstractSeries*>, seriesList);
229 QFETCH(QList<QAbstractSeries*>, seriesList);
209 QFETCH(QList<QAbstractAxis*>, axisList);
230 QFETCH(QList<QAbstractAxis*>, axisList);
210 QFETCH(int, axisCount);
231 QFETCH(int, axisCount);
211
232
212 Q_ASSERT(seriesList.count() == axisList.count());
233 Q_ASSERT(seriesList.count() == axisList.count());
213
234
214 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
235 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
215 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
236 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
216 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
237 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
217 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
238 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
218
239
219 foreach(QAbstractSeries* series, seriesList){
240 foreach(QAbstractSeries* series, seriesList){
220 m_dataset->addSeries(series);
241 m_dataset->addSeries(series);
221 }
242 }
222
243
223 TRY_COMPARE(spy0.count(), 0);
244 TRY_COMPARE(spy0.count(), 0);
224 TRY_COMPARE(spy1.count(), 0);
245 TRY_COMPARE(spy1.count(), 0);
225 TRY_COMPARE(spy2.count(), seriesList.count());
246 TRY_COMPARE(spy2.count(), seriesList.count());
226 TRY_COMPARE(spy3.count(), 0);
247 TRY_COMPARE(spy3.count(), 0);
227
248
228 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
249 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
229 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
250 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
230 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
251 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
231 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
252 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
232
253
233 for(int i=0 ; i < seriesList.count(); i++){
254 for(int i=0 ; i < seriesList.count(); i++){
234 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal);
255 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal);
235 }
256 }
236
257
237 TRY_COMPARE(spy4.count(), axisCount);
258 TRY_COMPARE(spy4.count(), axisCount);
238 TRY_COMPARE(spy5.count(), 0);
259 TRY_COMPARE(spy5.count(), 0);
239 TRY_COMPARE(spy6.count(), 0);
260 TRY_COMPARE(spy6.count(), 0);
240 TRY_COMPARE(spy7.count(), 0);
261 TRY_COMPARE(spy7.count(), 0);
241
262
242 for(int i=0 ; i < seriesList.count(); i++){
263 for(int i=0 ; i < seriesList.count(); i++){
243 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
264 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
244 }
265 }
245 }
266 }
246
267
247 void tst_ChartDataSet::setAxisY_data()
268 void tst_ChartDataSet::setAxisY_data()
248 {
269 {
249 setAxisX_data();
270 setAxisX_data();
250 }
271 }
251
272
252 void tst_ChartDataSet::setAxisY()
273 void tst_ChartDataSet::setAxisY()
253 {
274 {
254 QFETCH(QList<QAbstractSeries*>, seriesList);
275 QFETCH(QList<QAbstractSeries*>, seriesList);
255 QFETCH(QList<QAbstractAxis*>, axisList);
276 QFETCH(QList<QAbstractAxis*>, axisList);
256 QFETCH(int, axisCount);
277 QFETCH(int, axisCount);
257
278
258 Q_ASSERT(seriesList.count() == axisList.count());
279 Q_ASSERT(seriesList.count() == axisList.count());
259
280
260 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
281 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
261 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
282 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
262 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
283 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
263 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
284 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
264
285
265 foreach(QAbstractSeries* series, seriesList){
286 foreach(QAbstractSeries* series, seriesList){
266 m_dataset->addSeries(series);
287 m_dataset->addSeries(series);
267 }
288 }
268
289
269 TRY_COMPARE(spy0.count(), 0);
290 TRY_COMPARE(spy0.count(), 0);
270 TRY_COMPARE(spy1.count(), 0);
291 TRY_COMPARE(spy1.count(), 0);
271 TRY_COMPARE(spy2.count(), seriesList.count());
292 TRY_COMPARE(spy2.count(), seriesList.count());
272 TRY_COMPARE(spy3.count(), 0);
293 TRY_COMPARE(spy3.count(), 0);
273
294
274 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
295 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
275 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
296 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
276 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
297 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
277 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
298 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
278
299
279 for(int i=0 ; i < seriesList.count(); i++){
300 for(int i=0 ; i < seriesList.count(); i++){
280 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical);
301 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical);
281 }
302 }
282
303
283 TRY_COMPARE(spy4.count(), axisCount);
304 TRY_COMPARE(spy4.count(), axisCount);
284 TRY_COMPARE(spy5.count(), 0);
305 TRY_COMPARE(spy5.count(), 0);
285 TRY_COMPARE(spy6.count(), 0);
306 TRY_COMPARE(spy6.count(), 0);
286 TRY_COMPARE(spy7.count(), 0);
307 TRY_COMPARE(spy7.count(), 0);
287
308
288 for(int i=0 ; i < seriesList.count(); i++){
309 for(int i=0 ; i < seriesList.count(); i++){
289 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
310 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
290 }
311 }
291 }
312 }
292
313
293 void tst_ChartDataSet::removeSeries_data()
314 void tst_ChartDataSet::removeSeries_data()
294 {
315 {
295 addSeries_data();
316 addSeries_data();
296 }
317 }
297
318
298 void tst_ChartDataSet::removeSeries()
319 void tst_ChartDataSet::removeSeries()
299 {
320 {
300 QFETCH(QAbstractSeries*, series);
321 QFETCH(QAbstractSeries*, series);
301
322
302 m_dataset->addSeries(series);
323 m_dataset->addSeries(series);
303 m_dataset->createDefaultAxes();
324 m_dataset->createDefaultAxes();
304
325
305 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
326 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
306 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
327 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
307 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
328 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
308 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
329 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
309
330
310 m_dataset->removeSeries(series);
331 m_dataset->removeSeries(series);
311
332
312 TRY_COMPARE(spy0.count(), 0);
333 TRY_COMPARE(spy0.count(), 0);
313 if (series->type() == QAbstractSeries::SeriesTypePie) {
334 if (series->type() == QAbstractSeries::SeriesTypePie) {
314 TRY_COMPARE(spy1.count(), 0);
335 TRY_COMPARE(spy1.count(), 0);
315 }
336 }
316 else {
337 else {
317 TRY_COMPARE(spy1.count(), 2);
338 TRY_COMPARE(spy1.count(), 2);
318 }
339 }
319 TRY_COMPARE(spy2.count(), 0);
340 TRY_COMPARE(spy2.count(), 0);
320 TRY_COMPARE(spy3.count(), 1);
341 TRY_COMPARE(spy3.count(), 1);
321 }
342 }
322
343
323 void tst_ChartDataSet::removeAllSeries_data()
344 void tst_ChartDataSet::removeAllSeries_data()
324 {
345 {
325 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
346 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
326 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
347 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
327 QTest::addColumn<int>("axisCount");
348 QTest::addColumn<int>("axisCount");
328
349
329 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
350 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
330 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
351 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
331 << new QScatterSeries(this))
352 << new QScatterSeries(this))
332 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this)
353 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this)
333 << new QValueAxis(this)) << 3;
354 << new QValueAxis(this)) << 3;
334 //TODO:
355 //TODO:
335 }
356 }
336
357
337 void tst_ChartDataSet::removeAllSeries()
358 void tst_ChartDataSet::removeAllSeries()
338 {
359 {
339 QFETCH(QList<QAbstractSeries*>, seriesList);
360 QFETCH(QList<QAbstractSeries*>, seriesList);
340 QFETCH(QList<QAbstractAxis*>, axisList);
361 QFETCH(QList<QAbstractAxis*>, axisList);
341 QFETCH(int, axisCount);
362 QFETCH(int, axisCount);
342
363
343 foreach(QAbstractSeries* series, seriesList) {
364 foreach(QAbstractSeries* series, seriesList) {
344 m_dataset->addSeries(series);
365 m_dataset->addSeries(series);
345 }
366 }
346
367
347 for (int i = 0; i < seriesList.count(); i++) {
368 for (int i = 0; i < seriesList.count(); i++) {
348 m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal);
369 m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal);
349 }
370 }
350
371
351 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
372 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
352 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
373 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
353 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
374 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
354 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
375 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
355
376
356 m_dataset->removeAllSeries();
377 m_dataset->removeAllSeries();
357
378
358 TRY_COMPARE(spy0.count(), 0);
379 TRY_COMPARE(spy0.count(), 0);
359 TRY_COMPARE(spy1.count(), axisCount);
380 TRY_COMPARE(spy1.count(), axisCount);
360 TRY_COMPARE(spy2.count(), 0);
381 TRY_COMPARE(spy2.count(), 0);
361 TRY_COMPARE(spy3.count(), seriesList.count());
382 TRY_COMPARE(spy3.count(), seriesList.count());
362 }
383 }
363
384
364
385
365 void tst_ChartDataSet::seriesCount_data()
386 void tst_ChartDataSet::seriesCount_data()
366 {
387 {
367 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
388 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
368 QTest::addColumn<int>("seriesCount");
389 QTest::addColumn<int>("seriesCount");
369
390
370 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
391 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
371 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
392 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
372 }
393 }
373
394
374 void tst_ChartDataSet::seriesCount()
395 void tst_ChartDataSet::seriesCount()
375 {
396 {
376 QFETCH(QList<QAbstractSeries*>, seriesList);
397 QFETCH(QList<QAbstractSeries*>, seriesList);
377 QFETCH(int, seriesCount);
398 QFETCH(int, seriesCount);
378
399
379 foreach(QAbstractSeries* series, seriesList){
400 foreach(QAbstractSeries* series, seriesList){
380 m_dataset->addSeries(series);
401 m_dataset->addSeries(series);
381 }
402 }
382
403
383 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
404 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
384 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
405 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
385 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
406 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
386 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
407 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
387
408
388 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
409 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
389 TRY_COMPARE(spy0.count(), 0);
410 TRY_COMPARE(spy0.count(), 0);
390 TRY_COMPARE(spy1.count(), 0);
411 TRY_COMPARE(spy1.count(), 0);
391 TRY_COMPARE(spy2.count(), 0);
412 TRY_COMPARE(spy2.count(), 0);
392 TRY_COMPARE(spy3.count(), 0);
413 TRY_COMPARE(spy3.count(), 0);
393 }
414 }
394
415
395 void tst_ChartDataSet::seriesIndex_data()
416 void tst_ChartDataSet::seriesIndex_data()
396 {
417 {
397 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
418 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
398
419
399 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
420 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
400 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
421 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
401 }
422 }
402
423
403 void tst_ChartDataSet::seriesIndex()
424 void tst_ChartDataSet::seriesIndex()
404 {
425 {
405
426
406 QFETCH(QList<QAbstractSeries*>, seriesList);
427 QFETCH(QList<QAbstractSeries*>, seriesList);
407
428
408 foreach(QAbstractSeries* series, seriesList) {
429 foreach(QAbstractSeries* series, seriesList) {
409 m_dataset->addSeries(series);
430 m_dataset->addSeries(series);
410 }
431 }
411
432
412 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
433 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
413 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
434 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
414 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
435 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
415 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
436 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
416
437
417 for (int i = 0; i < seriesList.count(); i++) {
438 for (int i = 0; i < seriesList.count(); i++) {
418 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
439 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
419 }
440 }
420
441
421 TRY_COMPARE(spy0.count(), 0);
442 TRY_COMPARE(spy0.count(), 0);
422 TRY_COMPARE(spy1.count(), 0);
443 TRY_COMPARE(spy1.count(), 0);
423 TRY_COMPARE(spy2.count(), 0);
444 TRY_COMPARE(spy2.count(), 0);
424 TRY_COMPARE(spy3.count(), 0);
445 TRY_COMPARE(spy3.count(), 0);
425
446
426 foreach(QAbstractSeries* series, seriesList) {
447 foreach(QAbstractSeries* series, seriesList) {
427 m_dataset->removeSeries(series);
448 m_dataset->removeSeries(series);
428 }
449 }
429
450
430 for (int i = 0; i < seriesList.count(); i++) {
451 for (int i = 0; i < seriesList.count(); i++) {
431 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
452 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
432 }
453 }
433
454
434 foreach(QAbstractSeries* series, seriesList) {
455 foreach(QAbstractSeries* series, seriesList) {
435 m_dataset->addSeries(series);
456 m_dataset->addSeries(series);
436 }
457 }
437
458
438 for (int i = 0; i < seriesList.count(); i++) {
459 for (int i = 0; i < seriesList.count(); i++) {
439 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
460 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
440 }
461 }
441
462
442 m_dataset->removeSeries(seriesList.at(1));
463 m_dataset->removeSeries(seriesList.at(1));
443
464
444 for (int i = 0; i < seriesList.count(); i++) {
465 for (int i = 0; i < seriesList.count(); i++) {
445 if (i != 1)
466 if (i != 1)
446 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
467 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
447 else
468 else
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
469 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
449 }
470 }
450
471
451 m_dataset->addSeries(seriesList.at(1));
472 m_dataset->addSeries(seriesList.at(1));
452
473
453 for (int i = 0; i < seriesList.count(); i++) {
474 for (int i = 0; i < seriesList.count(); i++) {
454 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
475 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
455 }
476 }
456
477
457 m_dataset->removeSeries(seriesList.at(2));
478 m_dataset->removeSeries(seriesList.at(2));
458
479
459 for (int i = 0; i < seriesList.count(); i++) {
480 for (int i = 0; i < seriesList.count(); i++) {
460 if (i != 2)
481 if (i != 2)
461 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
462 else
483 else
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
464 }
485 }
465
486
466 m_dataset->removeSeries(seriesList.at(0));
487 m_dataset->removeSeries(seriesList.at(0));
467
488
468 for (int i = 0; i < seriesList.count(); i++) {
489 for (int i = 0; i < seriesList.count(); i++) {
469 if (i != 2 && i != 0)
490 if (i != 2 && i != 0)
470 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
491 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
471 else
492 else
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
493 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
473 }
494 }
474
495
475 m_dataset->addSeries(seriesList.at(2));
496 m_dataset->addSeries(seriesList.at(2));
476 m_dataset->addSeries(seriesList.at(0));
497 m_dataset->addSeries(seriesList.at(0));
477
498
478 for (int i = 0; i < seriesList.count(); i++) {
499 for (int i = 0; i < seriesList.count(); i++) {
479 if (i == 2)
500 if (i == 2)
480 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
501 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
481 else if (i == 0)
502 else if (i == 0)
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
503 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
483 else
504 else
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
505 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
485 }
506 }
486
507
487 }
508 }
488
509
489 void tst_ChartDataSet::domain_data()
510 void tst_ChartDataSet::domain_data()
490 {
511 {
491 addSeries_data();
512 addSeries_data();
492 }
513 }
493
514
494 void tst_ChartDataSet::domain()
515 void tst_ChartDataSet::domain()
495 {
516 {
496 QFETCH(QAbstractSeries*, series);
517 QFETCH(QAbstractSeries*, series);
497
518
498 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
519 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
499 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
520 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
500 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
521 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
501 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
522 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
502
523
503 m_dataset->addSeries(series);
524 m_dataset->addSeries(series);
504 QVERIFY(m_dataset->domain(series));
525 QVERIFY(m_dataset->domain(series));
505
526
506
527
507 TRY_COMPARE(spy0.count(), 0);
528 TRY_COMPARE(spy0.count(), 0);
508 TRY_COMPARE(spy1.count(), 0);
529 TRY_COMPARE(spy1.count(), 0);
509 TRY_COMPARE(spy2.count(), 1);
530 TRY_COMPARE(spy2.count(), 1);
510
531
511 QList<QVariant> arguments = spy2.takeFirst();
532 QList<QVariant> arguments = spy2.takeFirst();
512 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
533 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
513 QVERIFY(m_dataset->domain(series) == domain);
534 QVERIFY(m_dataset->domain(series) == domain);
514
535
515 TRY_COMPARE(spy3.count(), 0);
536 TRY_COMPARE(spy3.count(), 0);
516
537
517 }
538 }
518
539
519 void tst_ChartDataSet::zoomInDomain_data()
540 void tst_ChartDataSet::zoomInDomain_data()
520 {
541 {
521 QTest::addColumn<bool >("sameAxis");
542 QTest::addColumn<bool >("sameAxis");
522 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
543 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
523 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
544 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
545 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 }
546 }
526
547
527 void tst_ChartDataSet::zoomInDomain()
548 void tst_ChartDataSet::zoomInDomain()
528 {
549 {
529 QFETCH(bool, sameAxis);
550 QFETCH(bool, sameAxis);
530 QFETCH(QList<QAbstractSeries*>, seriesList);
551 QFETCH(QList<QAbstractSeries*>, seriesList);
531
552
532 foreach(QAbstractSeries* series, seriesList) {
553 foreach(QAbstractSeries* series, seriesList) {
533 m_dataset->addSeries(series);
554 m_dataset->addSeries(series);
534 }
555 }
535
556
536 if(sameAxis) m_dataset->createDefaultAxes();
557 if(sameAxis) m_dataset->createDefaultAxes();
537
558
538 QList<QSignalSpy*> spyList;
559 QList<QSignalSpy*> spyList;
539
560
540 foreach(QAbstractSeries* series, seriesList) {
561 foreach(QAbstractSeries* series, seriesList) {
541 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated()));
562 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated()));
542 }
563 }
543
564
544 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
565 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
545
566
546 foreach(QSignalSpy* spy, spyList) {
567 foreach(QSignalSpy* spy, spyList) {
547 TRY_COMPARE(spy->count(), 1);
568 TRY_COMPARE(spy->count(), 1);
548 }
569 }
549
570
550 qDeleteAll(spyList);
571 qDeleteAll(spyList);
551 }
572 }
552
573
553
574
554
575
555 void tst_ChartDataSet::zoomOutDomain_data()
576 void tst_ChartDataSet::zoomOutDomain_data()
556 {
577 {
557 zoomInDomain_data();
578 zoomInDomain_data();
558 }
579 }
559
580
560 void tst_ChartDataSet::zoomOutDomain()
581 void tst_ChartDataSet::zoomOutDomain()
561 {
582 {
562 QFETCH(bool, sameAxis);
583 QFETCH(bool, sameAxis);
563 QFETCH(QList<QAbstractSeries*>, seriesList);
584 QFETCH(QList<QAbstractSeries*>, seriesList);
564
585
565 foreach(QAbstractSeries* series, seriesList) {
586 foreach(QAbstractSeries* series, seriesList) {
566 m_dataset->addSeries(series);
587 m_dataset->addSeries(series);
567 }
588 }
568
589
569 if (sameAxis)
590 if (sameAxis)
570 m_dataset->createDefaultAxes();
591 m_dataset->createDefaultAxes();
571
592
572 QList<QSignalSpy*> spyList;
593 QList<QSignalSpy*> spyList;
573
594
574 foreach(QAbstractSeries* series, seriesList) {
595 foreach(QAbstractSeries* series, seriesList) {
575 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated()));
596 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated()));
576 }
597 }
577
598
578 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
599 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
579
600
580 foreach(QSignalSpy* spy, spyList) {
601 foreach(QSignalSpy* spy, spyList) {
581 TRY_COMPARE(spy->count(), 1);
602 TRY_COMPARE(spy->count(), 1);
582 }
603 }
583
604
584 qDeleteAll (spyList);
605 qDeleteAll (spyList);
585 }
606 }
586
607
587 void tst_ChartDataSet::scrollDomain_data()
608 void tst_ChartDataSet::scrollDomain_data()
588 {
609 {
589 zoomInDomain_data();
610 zoomInDomain_data();
590 }
611 }
591
612
592 void tst_ChartDataSet::scrollDomain()
613 void tst_ChartDataSet::scrollDomain()
593 {
614 {
594 QFETCH(bool, sameAxis);
615 QFETCH(bool, sameAxis);
595 QFETCH(QList<QAbstractSeries*>, seriesList);
616 QFETCH(QList<QAbstractSeries*>, seriesList);
596
617
597 foreach(QAbstractSeries* series, seriesList) {
618 foreach(QAbstractSeries* series, seriesList) {
598 m_dataset->addSeries(series);
619 m_dataset->addSeries(series);
599 }
620 }
600
621
601 if (sameAxis)
622 if (sameAxis)
602 m_dataset->createDefaultAxes();
623 m_dataset->createDefaultAxes();
603
624
604 QList<QSignalSpy*> spyList;
625 QList<QSignalSpy*> spyList;
605
626
606 foreach(QAbstractSeries* series, seriesList) {
627 foreach(QAbstractSeries* series, seriesList) {
607 spyList
628 spyList
608 << new QSignalSpy(m_dataset->domain(series),
629 << new QSignalSpy(m_dataset->domain(series),
609 SIGNAL(updated()));
630 SIGNAL(updated()));
610 }
631 }
611
632
612 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
633 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
613
634
614 foreach(QSignalSpy* spy, spyList) {
635 foreach(QSignalSpy* spy, spyList) {
615 TRY_COMPARE(spy->count(), 1);
636 TRY_COMPARE(spy->count(), 1);
616 }
637 }
617
638
618 qDeleteAll(spyList);
639 qDeleteAll(spyList);
619 }
640 }
620
641
621 QTEST_MAIN(tst_ChartDataSet)
642 QTEST_MAIN(tst_ChartDataSet)
622 #include "tst_chartdataset.moc"
643 #include "tst_chartdataset.moc"
623
644 #endif
@@ -1,4 +1,5
1 !include( ../auto.pri ) {
1 !include( ../auto.pri ) {
2 error( "Couldn't find the auto.pri file!" )
2 error( "Couldn't find the auto.pri file!" )
3 }
3 }
4
4 SOURCES += tst_domain.cpp
5 SOURCES += tst_domain.cpp
@@ -1,681 +1,703
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #ifndef BUILD_PRIVATE_UNIT_TESTS
21
22 #include <QtTest/QtTest>
23
24 class tst_Domain: public QObject {
25
26 Q_OBJECT
27
28 private Q_SLOTS:
29 void skip();
30
31 };
32
33 void tst_Domain::skip()
34 {
35 QSKIP("This test requires the debug version of library", SkipAll);
36 }
37
38 QTEST_MAIN(tst_Domain)
39 #include "tst_domain.moc"
40
41 #else
20
42
21 #include <QtTest/QtTest>
43 #include <QtTest/QtTest>
22 #include <private/domain_p.h>
44 #include <private/domain_p.h>
23 #include <private/qabstractaxis_p.h>
45 #include <private/qabstractaxis_p.h>
24 #include <tst_definitions.h>
46 #include <tst_definitions.h>
25
47
26 QTCOMMERCIALCHART_USE_NAMESPACE
48 QTCOMMERCIALCHART_USE_NAMESPACE
27
49
28 Q_DECLARE_METATYPE(Domain*)
50 Q_DECLARE_METATYPE(Domain*)
29 Q_DECLARE_METATYPE(QSizeF)
51 Q_DECLARE_METATYPE(QSizeF)
30
52
31
53
32 class AxisMock: public QAbstractAxisPrivate
54 class AxisMock: public QAbstractAxisPrivate
33 {
55 {
34 Q_OBJECT
56 Q_OBJECT
35 public:
57 public:
36 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
58 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
37 ChartAxis* createGraphics(ChartPresenter* presenter)
59 ChartAxis* createGraphics(ChartPresenter* presenter)
38 {
60 {
39 Q_UNUSED(presenter);
61 Q_UNUSED(presenter);
40 return 0;
62 return 0;
41 };
63 };
42 void intializeDomain(Domain* domain)
64 void intializeDomain(Domain* domain)
43 {
65 {
44 Q_UNUSED(domain);
66 Q_UNUSED(domain);
45 };
67 };
46 void setMin(const QVariant &min)
68 void setMin(const QVariant &min)
47 {
69 {
48 Q_UNUSED(min);
70 Q_UNUSED(min);
49 }
71 }
50 qreal min() { return m_min;}
72 qreal min() { return m_min;}
51 void setMax(const QVariant &max)
73 void setMax(const QVariant &max)
52 {
74 {
53 Q_UNUSED(max);
75 Q_UNUSED(max);
54 }
76 }
55 qreal max() { return m_max; }
77 qreal max() { return m_max; }
56 void setRange(const QVariant &min, const QVariant &max)
78 void setRange(const QVariant &min, const QVariant &max)
57 {
79 {
58 Q_UNUSED(min);
80 Q_UNUSED(min);
59 Q_UNUSED(max);
81 Q_UNUSED(max);
60 };
82 };
61
83
62 int count () const { return m_count; }
84 int count () const { return m_count; }
63
85
64 void handleDomainUpdated(){};
86 void handleDomainUpdated(){};
65 public:
87 public:
66 int m_count;
88 int m_count;
67 qreal m_min;
89 qreal m_min;
68 qreal m_max;
90 qreal m_max;
69 };
91 };
70
92
71 class tst_Domain: public QObject
93 class tst_Domain: public QObject
72 {
94 {
73 Q_OBJECT
95 Q_OBJECT
74
96
75 public Q_SLOTS:
97 public Q_SLOTS:
76 void initTestCase();
98 void initTestCase();
77 void cleanupTestCase();
99 void cleanupTestCase();
78 void init();
100 void init();
79 void cleanup();
101 void cleanup();
80
102
81 private Q_SLOTS:
103 private Q_SLOTS:
82 void domain();
104 void domain();
83 void handleAxisUpdatedX_data();
105 void handleAxisUpdatedX_data();
84 void handleAxisUpdatedX();
106 void handleAxisUpdatedX();
85 void handleAxisUpdatedY_data();
107 void handleAxisUpdatedY_data();
86 void handleAxisUpdatedY();
108 void handleAxisUpdatedY();
87 void isEmpty_data();
109 void isEmpty_data();
88 void isEmpty();
110 void isEmpty();
89 void maxX_data();
111 void maxX_data();
90 void maxX();
112 void maxX();
91 void maxY_data();
113 void maxY_data();
92 void maxY();
114 void maxY();
93 void minX_data();
115 void minX_data();
94 void minX();
116 void minX();
95 void minY_data();
117 void minY_data();
96 void minY();
118 void minY();
97 void operatorEquals_data();
119 void operatorEquals_data();
98 void operatorEquals();
120 void operatorEquals();
99 void setRange_data();
121 void setRange_data();
100 void setRange();
122 void setRange();
101 void setRangeX_data();
123 void setRangeX_data();
102 void setRangeX();
124 void setRangeX();
103 void setRangeY_data();
125 void setRangeY_data();
104 void setRangeY();
126 void setRangeY();
105 void spanX_data();
127 void spanX_data();
106 void spanX();
128 void spanX();
107 void spanY_data();
129 void spanY_data();
108 void spanY();
130 void spanY();
109 void zoom_data();
131 void zoom_data();
110 void zoom();
132 void zoom();
111 void move_data();
133 void move_data();
112 void move();
134 void move();
113 };
135 };
114
136
115 void tst_Domain::initTestCase()
137 void tst_Domain::initTestCase()
116 {
138 {
117 }
139 }
118
140
119 void tst_Domain::cleanupTestCase()
141 void tst_Domain::cleanupTestCase()
120 {
142 {
121 }
143 }
122
144
123 void tst_Domain::init()
145 void tst_Domain::init()
124 {
146 {
125 }
147 }
126
148
127 void tst_Domain::cleanup()
149 void tst_Domain::cleanup()
128 {
150 {
129 }
151 }
130
152
131 void tst_Domain::domain()
153 void tst_Domain::domain()
132 {
154 {
133 Domain domain;
155 Domain domain;
134
156
135 QCOMPARE(domain.isEmpty(), true);
157 QCOMPARE(domain.isEmpty(), true);
136 QCOMPARE(domain.maxX(), 0.0);
158 QCOMPARE(domain.maxX(), 0.0);
137 QCOMPARE(domain.maxY(), 0.0);
159 QCOMPARE(domain.maxY(), 0.0);
138 QCOMPARE(domain.minX(), 0.0);
160 QCOMPARE(domain.minX(), 0.0);
139 QCOMPARE(domain.minY(), 0.0);
161 QCOMPARE(domain.minY(), 0.0);
140 }
162 }
141
163
142 void tst_Domain::handleAxisUpdatedX_data()
164 void tst_Domain::handleAxisUpdatedX_data()
143 {
165 {
144 QTest::addColumn<qreal>("min");
166 QTest::addColumn<qreal>("min");
145 QTest::addColumn<qreal>("max");
167 QTest::addColumn<qreal>("max");
146 QTest::newRow("-1 1") << -1.0 << 1.0;
168 QTest::newRow("-1 1") << -1.0 << 1.0;
147 QTest::newRow("0 1") << 0.0 << 1.0;
169 QTest::newRow("0 1") << 0.0 << 1.0;
148 QTest::newRow("-1 0") << -1.0 << 0.0;
170 QTest::newRow("-1 0") << -1.0 << 0.0;
149 }
171 }
150
172
151 void tst_Domain::handleAxisUpdatedX()
173 void tst_Domain::handleAxisUpdatedX()
152 {
174 {
153 QFETCH(qreal, min);
175 QFETCH(qreal, min);
154 QFETCH(qreal, max);
176 QFETCH(qreal, max);
155
177
156 Domain domain;
178 Domain domain;
157
179
158 QSignalSpy spy0(&domain, SIGNAL(updated()));
180 QSignalSpy spy0(&domain, SIGNAL(updated()));
159 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
181 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
160 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
182 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
161
183
162 AxisMock axis(Qt::Horizontal);
184 AxisMock axis(Qt::Horizontal);
163 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
185 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
164 axis.m_min=min;
186 axis.m_min=min;
165 axis.m_max=max;
187 axis.m_max=max;
166 axis.emitUpdated();
188 axis.emitUpdated();
167
189
168 QVERIFY(qFuzzyIsNull(domain.minX() - min));
190 QVERIFY(qFuzzyIsNull(domain.minX() - min));
169 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
191 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
170
192
171 QList<QVariant> arg1 = spy1.first();
193 QList<QVariant> arg1 = spy1.first();
172 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
194 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
173 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
195 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
174
196
175 TRY_COMPARE(spy0.count(), 1);
197 TRY_COMPARE(spy0.count(), 1);
176 TRY_COMPARE(spy1.count(), 1);
198 TRY_COMPARE(spy1.count(), 1);
177 TRY_COMPARE(spy2.count(), 0);
199 TRY_COMPARE(spy2.count(), 0);
178
200
179 }
201 }
180
202
181 void tst_Domain::handleAxisUpdatedY_data()
203 void tst_Domain::handleAxisUpdatedY_data()
182 {
204 {
183 QTest::addColumn<qreal>("min");
205 QTest::addColumn<qreal>("min");
184 QTest::addColumn<qreal>("max");
206 QTest::addColumn<qreal>("max");
185 QTest::newRow("-1 1") << -1.0 << 1.0;
207 QTest::newRow("-1 1") << -1.0 << 1.0;
186 QTest::newRow("0 1") << 0.0 << 1.0;
208 QTest::newRow("0 1") << 0.0 << 1.0;
187 QTest::newRow("-1 0") << -1.0 << 0.0;
209 QTest::newRow("-1 0") << -1.0 << 0.0;
188 }
210 }
189
211
190 void tst_Domain::handleAxisUpdatedY()
212 void tst_Domain::handleAxisUpdatedY()
191 {
213 {
192 QFETCH(qreal, min);
214 QFETCH(qreal, min);
193 QFETCH(qreal, max);
215 QFETCH(qreal, max);
194
216
195 Domain domain;
217 Domain domain;
196
218
197 QSignalSpy spy0(&domain, SIGNAL(updated()));
219 QSignalSpy spy0(&domain, SIGNAL(updated()));
198 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
220 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
199 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
221 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
200
222
201 AxisMock axis(Qt::Vertical);
223 AxisMock axis(Qt::Vertical);
202 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
224 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
203 axis.m_min = min;
225 axis.m_min = min;
204 axis.m_max = max;
226 axis.m_max = max;
205 axis.emitUpdated();
227 axis.emitUpdated();
206
228
207 QVERIFY(qFuzzyIsNull(domain.minY() - min));
229 QVERIFY(qFuzzyIsNull(domain.minY() - min));
208 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
230 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
209
231
210 QList<QVariant> arg1 = spy2.first();
232 QList<QVariant> arg1 = spy2.first();
211 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
233 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
212 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
234 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
213
235
214 TRY_COMPARE(spy0.count(), 1);
236 TRY_COMPARE(spy0.count(), 1);
215 TRY_COMPARE(spy1.count(), 0);
237 TRY_COMPARE(spy1.count(), 0);
216 TRY_COMPARE(spy2.count(), 1);
238 TRY_COMPARE(spy2.count(), 1);
217 }
239 }
218
240
219 void tst_Domain::isEmpty_data()
241 void tst_Domain::isEmpty_data()
220 {
242 {
221 QTest::addColumn<qreal>("minX");
243 QTest::addColumn<qreal>("minX");
222 QTest::addColumn<qreal>("maxX");
244 QTest::addColumn<qreal>("maxX");
223 QTest::addColumn<qreal>("minY");
245 QTest::addColumn<qreal>("minY");
224 QTest::addColumn<qreal>("maxY");
246 QTest::addColumn<qreal>("maxY");
225 QTest::addColumn<bool>("isEmpty");
247 QTest::addColumn<bool>("isEmpty");
226 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true;
248 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true;
227 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true;
249 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true;
228 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true;
250 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true;
229 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false;
251 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false;
230 }
252 }
231
253
232 void tst_Domain::isEmpty()
254 void tst_Domain::isEmpty()
233 {
255 {
234 QFETCH(qreal, minX);
256 QFETCH(qreal, minX);
235 QFETCH(qreal, maxX);
257 QFETCH(qreal, maxX);
236 QFETCH(qreal, minY);
258 QFETCH(qreal, minY);
237 QFETCH(qreal, maxY);
259 QFETCH(qreal, maxY);
238 QFETCH(bool, isEmpty);
260 QFETCH(bool, isEmpty);
239
261
240 Domain domain;
262 Domain domain;
241 domain.setRange(minX, maxX, minY, maxY);
263 domain.setRange(minX, maxX, minY, maxY);
242 QCOMPARE(domain.isEmpty(), isEmpty);
264 QCOMPARE(domain.isEmpty(), isEmpty);
243 }
265 }
244
266
245 void tst_Domain::maxX_data()
267 void tst_Domain::maxX_data()
246 {
268 {
247 QTest::addColumn<qreal>("maxX1");
269 QTest::addColumn<qreal>("maxX1");
248 QTest::addColumn<qreal>("maxX2");
270 QTest::addColumn<qreal>("maxX2");
249 QTest::addColumn<int>("count");
271 QTest::addColumn<int>("count");
250 QTest::newRow("1") << 0.0 << 1.0 << 1;
272 QTest::newRow("1") << 0.0 << 1.0 << 1;
251 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
273 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
252 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
274 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
253 }
275 }
254
276
255 void tst_Domain::maxX()
277 void tst_Domain::maxX()
256 {
278 {
257 QFETCH(qreal, maxX1);
279 QFETCH(qreal, maxX1);
258 QFETCH(qreal, maxX2);
280 QFETCH(qreal, maxX2);
259 QFETCH(int, count);
281 QFETCH(int, count);
260
282
261 Domain domain;
283 Domain domain;
262
284
263 QSignalSpy spy0(&domain, SIGNAL(updated()));
285 QSignalSpy spy0(&domain, SIGNAL(updated()));
264 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
286 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
265 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
287 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
266
288
267 domain.setMaxX(maxX1);
289 domain.setMaxX(maxX1);
268 QCOMPARE(domain.maxX(), maxX1);
290 QCOMPARE(domain.maxX(), maxX1);
269 domain.setMaxX(maxX2);
291 domain.setMaxX(maxX2);
270 QCOMPARE(domain.maxX(), maxX2);
292 QCOMPARE(domain.maxX(), maxX2);
271
293
272 TRY_COMPARE(spy0.count(), count);
294 TRY_COMPARE(spy0.count(), count);
273 TRY_COMPARE(spy1.count(), count);
295 TRY_COMPARE(spy1.count(), count);
274 TRY_COMPARE(spy2.count(), 0);
296 TRY_COMPARE(spy2.count(), 0);
275
297
276 }
298 }
277
299
278 void tst_Domain::maxY_data()
300 void tst_Domain::maxY_data()
279 {
301 {
280 QTest::addColumn<qreal>("maxY1");
302 QTest::addColumn<qreal>("maxY1");
281 QTest::addColumn<qreal>("maxY2");
303 QTest::addColumn<qreal>("maxY2");
282 QTest::addColumn<int>("count");
304 QTest::addColumn<int>("count");
283 QTest::newRow("1") << 0.0 << 1.0 << 1;
305 QTest::newRow("1") << 0.0 << 1.0 << 1;
284 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
306 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
285 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
307 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
286 }
308 }
287
309
288 void tst_Domain::maxY()
310 void tst_Domain::maxY()
289 {
311 {
290 QFETCH(qreal, maxY1);
312 QFETCH(qreal, maxY1);
291 QFETCH(qreal, maxY2);
313 QFETCH(qreal, maxY2);
292 QFETCH(int, count);
314 QFETCH(int, count);
293
315
294 Domain domain;
316 Domain domain;
295
317
296 QSignalSpy spy0(&domain, SIGNAL(updated()));
318 QSignalSpy spy0(&domain, SIGNAL(updated()));
297 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
319 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
298 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
320 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
299
321
300 domain.setMaxY(maxY1);
322 domain.setMaxY(maxY1);
301 QCOMPARE(domain.maxY(), maxY1);
323 QCOMPARE(domain.maxY(), maxY1);
302 domain.setMaxY(maxY2);
324 domain.setMaxY(maxY2);
303 QCOMPARE(domain.maxY(), maxY2);
325 QCOMPARE(domain.maxY(), maxY2);
304
326
305 TRY_COMPARE(spy0.count(), count);
327 TRY_COMPARE(spy0.count(), count);
306 TRY_COMPARE(spy1.count(), 0);
328 TRY_COMPARE(spy1.count(), 0);
307 TRY_COMPARE(spy2.count(), count);
329 TRY_COMPARE(spy2.count(), count);
308 }
330 }
309
331
310 void tst_Domain::minX_data()
332 void tst_Domain::minX_data()
311 {
333 {
312 QTest::addColumn<qreal>("minX1");
334 QTest::addColumn<qreal>("minX1");
313 QTest::addColumn<qreal>("minX2");
335 QTest::addColumn<qreal>("minX2");
314 QTest::addColumn<int>("count");
336 QTest::addColumn<int>("count");
315 QTest::newRow("1") << 0.0 << 1.0 << 1;
337 QTest::newRow("1") << 0.0 << 1.0 << 1;
316 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
338 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
317 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
339 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
318 }
340 }
319
341
320 void tst_Domain::minX()
342 void tst_Domain::minX()
321 {
343 {
322 QFETCH(qreal, minX1);
344 QFETCH(qreal, minX1);
323 QFETCH(qreal, minX2);
345 QFETCH(qreal, minX2);
324 QFETCH(int, count);
346 QFETCH(int, count);
325
347
326 Domain domain;
348 Domain domain;
327
349
328 QSignalSpy spy0(&domain, SIGNAL(updated()));
350 QSignalSpy spy0(&domain, SIGNAL(updated()));
329 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
351 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
330 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
352 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
331
353
332 domain.setMinX(minX1);
354 domain.setMinX(minX1);
333 QCOMPARE(domain.minX(), minX1);
355 QCOMPARE(domain.minX(), minX1);
334 domain.setMinX(minX2);
356 domain.setMinX(minX2);
335 QCOMPARE(domain.minX(), minX2);
357 QCOMPARE(domain.minX(), minX2);
336
358
337 TRY_COMPARE(spy0.count(), count);
359 TRY_COMPARE(spy0.count(), count);
338 TRY_COMPARE(spy1.count(), count);
360 TRY_COMPARE(spy1.count(), count);
339 TRY_COMPARE(spy2.count(), 0);
361 TRY_COMPARE(spy2.count(), 0);
340 }
362 }
341
363
342 void tst_Domain::minY_data()
364 void tst_Domain::minY_data()
343 {
365 {
344 QTest::addColumn<qreal>("minY1");
366 QTest::addColumn<qreal>("minY1");
345 QTest::addColumn<qreal>("minY2");
367 QTest::addColumn<qreal>("minY2");
346 QTest::addColumn<int>("count");
368 QTest::addColumn<int>("count");
347 QTest::newRow("1") << 0.0 << 1.0 << 1;
369 QTest::newRow("1") << 0.0 << 1.0 << 1;
348 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
370 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
349 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
371 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
350 }
372 }
351
373
352 void tst_Domain::minY()
374 void tst_Domain::minY()
353 {
375 {
354 QFETCH(qreal, minY1);
376 QFETCH(qreal, minY1);
355 QFETCH(qreal, minY2);
377 QFETCH(qreal, minY2);
356 QFETCH(int, count);
378 QFETCH(int, count);
357
379
358 Domain domain;
380 Domain domain;
359
381
360 QSignalSpy spy0(&domain, SIGNAL(updated()));
382 QSignalSpy spy0(&domain, SIGNAL(updated()));
361 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
383 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
362 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
384 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
363
385
364 domain.setMinY(minY1);
386 domain.setMinY(minY1);
365 QCOMPARE(domain.minY(), minY1);
387 QCOMPARE(domain.minY(), minY1);
366 domain.setMinY(minY2);
388 domain.setMinY(minY2);
367 QCOMPARE(domain.minY(), minY2);
389 QCOMPARE(domain.minY(), minY2);
368
390
369 TRY_COMPARE(spy0.count(), count);
391 TRY_COMPARE(spy0.count(), count);
370 TRY_COMPARE(spy1.count(), 0);
392 TRY_COMPARE(spy1.count(), 0);
371 TRY_COMPARE(spy2.count(), count);
393 TRY_COMPARE(spy2.count(), count);
372 }
394 }
373
395
374 void tst_Domain::operatorEquals_data()
396 void tst_Domain::operatorEquals_data()
375 {
397 {
376
398
377 QTest::addColumn<Domain*>("domain1");
399 QTest::addColumn<Domain*>("domain1");
378 QTest::addColumn<Domain*>("domain2");
400 QTest::addColumn<Domain*>("domain2");
379 QTest::addColumn<bool>("equals");
401 QTest::addColumn<bool>("equals");
380 QTest::addColumn<bool>("notEquals");
402 QTest::addColumn<bool>("notEquals");
381 Domain* a;
403 Domain* a;
382 Domain* b;
404 Domain* b;
383 a = new Domain();
405 a = new Domain();
384 a->setRange(0, 100, 0, 100);
406 a->setRange(0, 100, 0, 100);
385 b = new Domain();
407 b = new Domain();
386 b->setRange(0, 100, 0, 100);
408 b->setRange(0, 100, 0, 100);
387 QTest::newRow("equals") << a << b << true << false;
409 QTest::newRow("equals") << a << b << true << false;
388 a = new Domain();
410 a = new Domain();
389 a->setRange(0, 100, 0, 100);
411 a->setRange(0, 100, 0, 100);
390 b = new Domain();
412 b = new Domain();
391 b->setRange(0, 100, 0, 1);
413 b->setRange(0, 100, 0, 1);
392 QTest::newRow("equals") << a << b << false << true;
414 QTest::newRow("equals") << a << b << false << true;
393 a = new Domain();
415 a = new Domain();
394 a->setRange(0, 100, 0, 100);
416 a->setRange(0, 100, 0, 100);
395 b = new Domain();
417 b = new Domain();
396 b->setRange(0, 1, 0, 100);
418 b->setRange(0, 1, 0, 100);
397 QTest::newRow("equals") << a << b << false << true;
419 QTest::newRow("equals") << a << b << false << true;
398
420
399 }
421 }
400
422
401 void tst_Domain::operatorEquals()
423 void tst_Domain::operatorEquals()
402 {
424 {
403 QFETCH(Domain*, domain1);
425 QFETCH(Domain*, domain1);
404 QFETCH(Domain*, domain2);
426 QFETCH(Domain*, domain2);
405 QFETCH(bool, equals);
427 QFETCH(bool, equals);
406 QFETCH(bool, notEquals);
428 QFETCH(bool, notEquals);
407
429
408 Domain domain;
430 Domain domain;
409
431
410 QSignalSpy spy0(&domain, SIGNAL(updated()));
432 QSignalSpy spy0(&domain, SIGNAL(updated()));
411 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
433 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
412 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
434 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
413
435
414 QCOMPARE(*domain1==*domain2, equals);
436 QCOMPARE(*domain1==*domain2, equals);
415 QCOMPARE(*domain1!=*domain2, notEquals);
437 QCOMPARE(*domain1!=*domain2, notEquals);
416
438
417 TRY_COMPARE(spy0.count(), 0);
439 TRY_COMPARE(spy0.count(), 0);
418 TRY_COMPARE(spy1.count(), 0);
440 TRY_COMPARE(spy1.count(), 0);
419 TRY_COMPARE(spy2.count(), 0);
441 TRY_COMPARE(spy2.count(), 0);
420 }
442 }
421
443
422 void tst_Domain::setRange_data()
444 void tst_Domain::setRange_data()
423 {
445 {
424 QTest::addColumn<qreal>("minX");
446 QTest::addColumn<qreal>("minX");
425 QTest::addColumn<qreal>("maxX");
447 QTest::addColumn<qreal>("maxX");
426 QTest::addColumn<qreal>("minY");
448 QTest::addColumn<qreal>("minY");
427 QTest::addColumn<qreal>("maxY");
449 QTest::addColumn<qreal>("maxY");
428 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
450 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
429 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
451 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
430 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
452 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
431 }
453 }
432
454
433 void tst_Domain::setRange()
455 void tst_Domain::setRange()
434 {
456 {
435 QFETCH(qreal, minX);
457 QFETCH(qreal, minX);
436 QFETCH(qreal, maxX);
458 QFETCH(qreal, maxX);
437 QFETCH(qreal, minY);
459 QFETCH(qreal, minY);
438 QFETCH(qreal, maxY);
460 QFETCH(qreal, maxY);
439
461
440 Domain domain;
462 Domain domain;
441
463
442 QSignalSpy spy0(&domain, SIGNAL(updated()));
464 QSignalSpy spy0(&domain, SIGNAL(updated()));
443 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
465 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
444 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
466 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
445
467
446 domain.setRange(minX, maxX, minY, maxY);
468 domain.setRange(minX, maxX, minY, maxY);
447
469
448 QCOMPARE(domain.minX(), minX);
470 QCOMPARE(domain.minX(), minX);
449 QCOMPARE(domain.maxX(), maxX);
471 QCOMPARE(domain.maxX(), maxX);
450 QCOMPARE(domain.minY(), minY);
472 QCOMPARE(domain.minY(), minY);
451 QCOMPARE(domain.maxY(), maxY);
473 QCOMPARE(domain.maxY(), maxY);
452
474
453 TRY_COMPARE(spy0.count(), 1);
475 TRY_COMPARE(spy0.count(), 1);
454 TRY_COMPARE(spy1.count(), 1);
476 TRY_COMPARE(spy1.count(), 1);
455 TRY_COMPARE(spy2.count(), 1);
477 TRY_COMPARE(spy2.count(), 1);
456
478
457 }
479 }
458
480
459 void tst_Domain::setRangeX_data()
481 void tst_Domain::setRangeX_data()
460 {
482 {
461 QTest::addColumn<qreal>("min");
483 QTest::addColumn<qreal>("min");
462 QTest::addColumn<qreal>("max");
484 QTest::addColumn<qreal>("max");
463 QTest::newRow("-1 1") << -1.0 << 1.0;
485 QTest::newRow("-1 1") << -1.0 << 1.0;
464 QTest::newRow("0 1") << 0.0 << 1.0;
486 QTest::newRow("0 1") << 0.0 << 1.0;
465 QTest::newRow("-1 0") << -1.0 << 0.0;
487 QTest::newRow("-1 0") << -1.0 << 0.0;
466 }
488 }
467
489
468 void tst_Domain::setRangeX()
490 void tst_Domain::setRangeX()
469 {
491 {
470 QFETCH(qreal, min);
492 QFETCH(qreal, min);
471 QFETCH(qreal, max);
493 QFETCH(qreal, max);
472
494
473 Domain domain;
495 Domain domain;
474
496
475 QSignalSpy spy0(&domain, SIGNAL(updated()));
497 QSignalSpy spy0(&domain, SIGNAL(updated()));
476 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
498 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
477 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
499 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
478
500
479 domain.setRangeX(min, max);
501 domain.setRangeX(min, max);
480
502
481 QVERIFY(qFuzzyIsNull(domain.minX() - min));
503 QVERIFY(qFuzzyIsNull(domain.minX() - min));
482 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
504 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
483
505
484 QList<QVariant> arg1 = spy1.first();
506 QList<QVariant> arg1 = spy1.first();
485 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
507 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
486 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
508 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
487
509
488 TRY_COMPARE(spy0.count(), 1);
510 TRY_COMPARE(spy0.count(), 1);
489 TRY_COMPARE(spy1.count(), 1);
511 TRY_COMPARE(spy1.count(), 1);
490 TRY_COMPARE(spy2.count(), 0);
512 TRY_COMPARE(spy2.count(), 0);
491 }
513 }
492
514
493 void tst_Domain::setRangeY_data()
515 void tst_Domain::setRangeY_data()
494 {
516 {
495 QTest::addColumn<qreal>("min");
517 QTest::addColumn<qreal>("min");
496 QTest::addColumn<qreal>("max");
518 QTest::addColumn<qreal>("max");
497 QTest::newRow("-1 1") << -1.0 << 1.0;
519 QTest::newRow("-1 1") << -1.0 << 1.0;
498 QTest::newRow("0 1") << 0.0 << 1.0;
520 QTest::newRow("0 1") << 0.0 << 1.0;
499 QTest::newRow("-1 0") << -1.0 << 0.0;
521 QTest::newRow("-1 0") << -1.0 << 0.0;
500 }
522 }
501
523
502 void tst_Domain::setRangeY()
524 void tst_Domain::setRangeY()
503 {
525 {
504 QFETCH(qreal, min);
526 QFETCH(qreal, min);
505 QFETCH(qreal, max);
527 QFETCH(qreal, max);
506
528
507 Domain domain;
529 Domain domain;
508
530
509 QSignalSpy spy0(&domain, SIGNAL(updated()));
531 QSignalSpy spy0(&domain, SIGNAL(updated()));
510 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
532 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
511 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
533 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
512
534
513 domain.setRangeY(min, max);
535 domain.setRangeY(min, max);
514
536
515 QVERIFY(qFuzzyIsNull(domain.minY() - min));
537 QVERIFY(qFuzzyIsNull(domain.minY() - min));
516 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
538 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
517
539
518 QList<QVariant> arg1 = spy2.first();
540 QList<QVariant> arg1 = spy2.first();
519 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
541 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
520 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
542 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
521
543
522 TRY_COMPARE(spy0.count(), 1);
544 TRY_COMPARE(spy0.count(), 1);
523 TRY_COMPARE(spy1.count(), 0);
545 TRY_COMPARE(spy1.count(), 0);
524 TRY_COMPARE(spy2.count(), 1);
546 TRY_COMPARE(spy2.count(), 1);
525 }
547 }
526
548
527 void tst_Domain::spanX_data()
549 void tst_Domain::spanX_data()
528 {
550 {
529 QTest::addColumn<qreal>("minX");
551 QTest::addColumn<qreal>("minX");
530 QTest::addColumn<qreal>("maxX");
552 QTest::addColumn<qreal>("maxX");
531 QTest::addColumn<qreal>("spanX");
553 QTest::addColumn<qreal>("spanX");
532 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
554 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
533 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
555 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
534 }
556 }
535
557
536 void tst_Domain::spanX()
558 void tst_Domain::spanX()
537 {
559 {
538 QFETCH(qreal, minX);
560 QFETCH(qreal, minX);
539 QFETCH(qreal, maxX);
561 QFETCH(qreal, maxX);
540 QFETCH(qreal, spanX);
562 QFETCH(qreal, spanX);
541
563
542 Domain domain;
564 Domain domain;
543
565
544 domain.setRangeX(minX, maxX);
566 domain.setRangeX(minX, maxX);
545
567
546 QSignalSpy spy0(&domain, SIGNAL(updated()));
568 QSignalSpy spy0(&domain, SIGNAL(updated()));
547 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
569 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
548 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
570 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
549
571
550 QCOMPARE(domain.spanX(), spanX);
572 QCOMPARE(domain.spanX(), spanX);
551
573
552 TRY_COMPARE(spy0.count(), 0);
574 TRY_COMPARE(spy0.count(), 0);
553 TRY_COMPARE(spy1.count(), 0);
575 TRY_COMPARE(spy1.count(), 0);
554 TRY_COMPARE(spy2.count(), 0);
576 TRY_COMPARE(spy2.count(), 0);
555 }
577 }
556
578
557 void tst_Domain::spanY_data()
579 void tst_Domain::spanY_data()
558 {
580 {
559 QTest::addColumn<qreal>("minY");
581 QTest::addColumn<qreal>("minY");
560 QTest::addColumn<qreal>("maxY");
582 QTest::addColumn<qreal>("maxY");
561 QTest::addColumn<qreal>("spanY");
583 QTest::addColumn<qreal>("spanY");
562 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
584 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
563 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
585 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
564 }
586 }
565
587
566 void tst_Domain::spanY()
588 void tst_Domain::spanY()
567 {
589 {
568 QFETCH(qreal, minY);
590 QFETCH(qreal, minY);
569 QFETCH(qreal, maxY);
591 QFETCH(qreal, maxY);
570 QFETCH(qreal, spanY);
592 QFETCH(qreal, spanY);
571
593
572 Domain domain;
594 Domain domain;
573
595
574 domain.setRangeY(minY, maxY);
596 domain.setRangeY(minY, maxY);
575
597
576 QSignalSpy spy0(&domain, SIGNAL(updated()));
598 QSignalSpy spy0(&domain, SIGNAL(updated()));
577 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
599 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
578 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
600 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
579
601
580 QCOMPARE(domain.spanY(), spanY);
602 QCOMPARE(domain.spanY(), spanY);
581
603
582 TRY_COMPARE(spy0.count(), 0);
604 TRY_COMPARE(spy0.count(), 0);
583 TRY_COMPARE(spy1.count(), 0);
605 TRY_COMPARE(spy1.count(), 0);
584 TRY_COMPARE(spy2.count(), 0);
606 TRY_COMPARE(spy2.count(), 0);
585 }
607 }
586
608
587 void tst_Domain::zoom_data()
609 void tst_Domain::zoom_data()
588 {
610 {
589 QTest::addColumn<QRectF>("rect0");
611 QTest::addColumn<QRectF>("rect0");
590 QTest::addColumn<QSizeF>("size0");
612 QTest::addColumn<QSizeF>("size0");
591 QTest::addColumn<QRectF>("rect1");
613 QTest::addColumn<QRectF>("rect1");
592 QTest::addColumn<QSizeF>("size1");
614 QTest::addColumn<QSizeF>("size1");
593 QTest::addColumn<QRectF>("rect2");
615 QTest::addColumn<QRectF>("rect2");
594 QTest::addColumn<QSizeF>("size2");
616 QTest::addColumn<QSizeF>("size2");
595 QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000)
617 QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000)
596 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
618 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
597 << QSizeF(1000, 1000);
619 << QSizeF(1000, 1000);
598 QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000)
620 QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000)
599 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
621 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
600 << QSizeF(1000, 1000);
622 << QSizeF(1000, 1000);
601 QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20)
623 QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20)
602 << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100);
624 << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100);
603 }
625 }
604
626
605 void tst_Domain::zoom()
627 void tst_Domain::zoom()
606 {
628 {
607 QFETCH(QRectF, rect0);
629 QFETCH(QRectF, rect0);
608 QFETCH(QSizeF, size0);
630 QFETCH(QSizeF, size0);
609 QFETCH(QRectF, rect1);
631 QFETCH(QRectF, rect1);
610 QFETCH(QSizeF, size1);
632 QFETCH(QSizeF, size1);
611 QFETCH(QRectF, rect2);
633 QFETCH(QRectF, rect2);
612 QFETCH(QSizeF, size2);
634 QFETCH(QSizeF, size2);
613
635
614 Domain domain;
636 Domain domain;
615
637
616 domain.setRange(0, 1000, 0, 1000);
638 domain.setRange(0, 1000, 0, 1000);
617
639
618 QSignalSpy spy0(&domain, SIGNAL(updated()));
640 QSignalSpy spy0(&domain, SIGNAL(updated()));
619 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
641 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
620 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
642 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
621
643
622 Domain domain0;
644 Domain domain0;
623 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
645 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
624 domain.zoomIn(rect0, size0);
646 domain.zoomIn(rect0, size0);
625 Domain domain1;
647 Domain domain1;
626 domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
648 domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
627 domain.zoomIn(rect1, size1);
649 domain.zoomIn(rect1, size1);
628 Domain domain2;
650 Domain domain2;
629 domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
651 domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
630 domain.zoomIn(rect2, size2);
652 domain.zoomIn(rect2, size2);
631 domain.zoomOut(rect2, size2);
653 domain.zoomOut(rect2, size2);
632 QCOMPARE(domain == domain2, true);
654 QCOMPARE(domain == domain2, true);
633 domain.zoomOut(rect1, size1);
655 domain.zoomOut(rect1, size1);
634 QCOMPARE(domain == domain1, true);
656 QCOMPARE(domain == domain1, true);
635 domain.zoomOut(rect0, size0);
657 domain.zoomOut(rect0, size0);
636 QCOMPARE(domain == domain0, true);
658 QCOMPARE(domain == domain0, true);
637 TRY_COMPARE(spy0.count(), 6);
659 TRY_COMPARE(spy0.count(), 6);
638 TRY_COMPARE(spy1.count(), 6);
660 TRY_COMPARE(spy1.count(), 6);
639 TRY_COMPARE(spy2.count(), 6);
661 TRY_COMPARE(spy2.count(), 6);
640 }
662 }
641
663
642 void tst_Domain::move_data()
664 void tst_Domain::move_data()
643 {
665 {
644 QTest::addColumn<int>("dx");
666 QTest::addColumn<int>("dx");
645 QTest::addColumn<int>("dy");
667 QTest::addColumn<int>("dy");
646 QTest::addColumn<QSizeF>("size");
668 QTest::addColumn<QSizeF>("size");
647 QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000);
669 QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000);
648 QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000);
670 QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000);
649 QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000);
671 QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000);
650 QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000);
672 QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000);
651 QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000);
673 QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000);
652 QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000);
674 QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000);
653 }
675 }
654
676
655 void tst_Domain::move()
677 void tst_Domain::move()
656 {
678 {
657 QFETCH(int, dx);
679 QFETCH(int, dx);
658 QFETCH(int, dy);
680 QFETCH(int, dy);
659 QFETCH(QSizeF, size);
681 QFETCH(QSizeF, size);
660 Domain domain;
682 Domain domain;
661
683
662 domain.setRange(0, size.width(), 0, size.height());
684 domain.setRange(0, size.width(), 0, size.height());
663
685
664 QSignalSpy spy0(&domain, SIGNAL(updated()));
686 QSignalSpy spy0(&domain, SIGNAL(updated()));
665 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
687 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
666 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
688 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
667
689
668 domain.move(dx, dy, size);
690 domain.move(dx, dy, size);
669
691
670 Domain result;
692 Domain result;
671 result.setRange(dx, size.width() + dx, dy, size.height() + dy);
693 result.setRange(dx, size.width() + dx, dy, size.height() + dy);
672
694
673 QCOMPARE(domain == result, true);
695 QCOMPARE(domain == result, true);
674 TRY_COMPARE(spy0.count(), 1);
696 TRY_COMPARE(spy0.count(), 1);
675 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
697 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
676 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
698 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
677 }
699 }
678
700
679 QTEST_MAIN(tst_Domain)
701 QTEST_MAIN(tst_Domain)
680 #include "tst_domain.moc"
702 #include "tst_domain.moc"
681
703 #endif
General Comments 0
You need to be logged in to leave comments. Login now