##// END OF EJS Templates
use standardized test export macros...
Oswald Buddenhagen -
r2892:5c50b9f6fefd
parent child
Show More
@@ -1,94 +1,89
1 ############################# BUILD CONFIG ######################################
1 ############################# BUILD CONFIG ######################################
2
2
3 TARGET = QtCharts
3 TARGET = QtCharts
4
4
5 QT = core gui widgets
5 QT = core gui widgets
6
6
7 QMAKE_DOCS = $$PWD/doc/qtcharts.qdocconf
7 QMAKE_DOCS = $$PWD/doc/qtcharts.qdocconf
8
8
9 QMAKE_TARGET_PRODUCT = "Qt Charts (Qt $$QT_VERSION)"
9 QMAKE_TARGET_PRODUCT = "Qt Charts (Qt $$QT_VERSION)"
10 QMAKE_TARGET_DESCRIPTION = "Charts component for Qt."
10 QMAKE_TARGET_DESCRIPTION = "Charts component for Qt."
11
11
12 ############################# SOURCES ##########################################
12 ############################# SOURCES ##########################################
13
13
14 SOURCES += \
14 SOURCES += \
15 $$PWD/chartdataset.cpp \
15 $$PWD/chartdataset.cpp \
16 $$PWD/chartpresenter.cpp \
16 $$PWD/chartpresenter.cpp \
17 $$PWD/chartthememanager.cpp \
17 $$PWD/chartthememanager.cpp \
18 $$PWD/qchart.cpp \
18 $$PWD/qchart.cpp \
19 $$PWD/qchartview.cpp \
19 $$PWD/qchartview.cpp \
20 $$PWD/qabstractseries.cpp \
20 $$PWD/qabstractseries.cpp \
21 $$PWD/chartbackground.cpp \
21 $$PWD/chartbackground.cpp \
22 $$PWD/chartelement.cpp \
22 $$PWD/chartelement.cpp \
23 $$PWD/chartitem.cpp \
23 $$PWD/chartitem.cpp \
24 $$PWD/scroller.cpp \
24 $$PWD/scroller.cpp \
25 $$PWD/charttitle.cpp \
25 $$PWD/charttitle.cpp \
26 $$PWD/qpolarchart.cpp
26 $$PWD/qpolarchart.cpp
27
27
28 contains(QT_CONFIG, opengl): SOURCES += $$PWD/glwidget.cpp
28 contains(QT_CONFIG, opengl): SOURCES += $$PWD/glwidget.cpp
29
29
30 PRIVATE_HEADERS += \
30 PRIVATE_HEADERS += \
31 $$PWD/chartdataset_p.h \
31 $$PWD/chartdataset_p.h \
32 $$PWD/chartitem_p.h \
32 $$PWD/chartitem_p.h \
33 $$PWD/chartpresenter_p.h \
33 $$PWD/chartpresenter_p.h \
34 $$PWD/chartthememanager_p.h \
34 $$PWD/chartthememanager_p.h \
35 $$PWD/chartbackground_p.h \
35 $$PWD/chartbackground_p.h \
36 $$PWD/chartelement_p.h \
36 $$PWD/chartelement_p.h \
37 $$PWD/chartconfig_p.h \
37 $$PWD/chartconfig_p.h \
38 $$PWD/qchart_p.h \
38 $$PWD/qchart_p.h \
39 $$PWD/qchartview_p.h \
39 $$PWD/qchartview_p.h \
40 $$PWD/scroller_p.h \
40 $$PWD/scroller_p.h \
41 $$PWD/qabstractseries_p.h \
41 $$PWD/qabstractseries_p.h \
42 $$PWD/charttitle_p.h \
42 $$PWD/charttitle_p.h \
43 $$PWD/charthelpers_p.h
43 $$PWD/charthelpers_p.h
44
44
45 contains(QT_CONFIG, opengl): PRIVATE_HEADERS += $$PWD/glwidget_p.h
45 contains(QT_CONFIG, opengl): PRIVATE_HEADERS += $$PWD/glwidget_p.h
46
46
47 PUBLIC_HEADERS += \
47 PUBLIC_HEADERS += \
48 $$PWD/qchart.h \
48 $$PWD/qchart.h \
49 $$PWD/qchartglobal.h \
49 $$PWD/qchartglobal.h \
50 $$PWD/qabstractseries.h \
50 $$PWD/qabstractseries.h \
51 $$PWD/qchartview.h \
51 $$PWD/qchartview.h \
52 $$PWD/chartsnamespace.h \
52 $$PWD/chartsnamespace.h \
53 $$PWD/qpolarchart.h
53 $$PWD/qpolarchart.h
54
54
55 include($$PWD/animations/animations.pri)
55 include($$PWD/animations/animations.pri)
56 include($$PWD/areachart/areachart.pri)
56 include($$PWD/areachart/areachart.pri)
57 include($$PWD/axis/axis.pri)
57 include($$PWD/axis/axis.pri)
58 include($$PWD/domain/domain.pri)
58 include($$PWD/domain/domain.pri)
59 include($$PWD/barchart/barchart.pri)
59 include($$PWD/barchart/barchart.pri)
60 include($$PWD/legend/legend.pri)
60 include($$PWD/legend/legend.pri)
61 include($$PWD/linechart/linechart.pri)
61 include($$PWD/linechart/linechart.pri)
62 include($$PWD/piechart/piechart.pri)
62 include($$PWD/piechart/piechart.pri)
63 include($$PWD/scatterchart/scatter.pri)
63 include($$PWD/scatterchart/scatter.pri)
64 include($$PWD/splinechart/splinechart.pri)
64 include($$PWD/splinechart/splinechart.pri)
65 include($$PWD/themes/themes.pri)
65 include($$PWD/themes/themes.pri)
66 include($$PWD/xychart/xychart.pri)
66 include($$PWD/xychart/xychart.pri)
67 include($$PWD/layout/layout.pri)
67 include($$PWD/layout/layout.pri)
68 include($$PWD/boxplotchart/boxplotchart.pri)
68 include($$PWD/boxplotchart/boxplotchart.pri)
69
69
70 HEADERS += $$PUBLIC_HEADERS
70 HEADERS += $$PUBLIC_HEADERS
71 HEADERS += $$PRIVATE_HEADERS
71 HEADERS += $$PRIVATE_HEADERS
72 HEADERS += $$THEMES
72 HEADERS += $$THEMES
73
73
74 OTHER_FILES += doc/qtcharts.qdocconf \
74 OTHER_FILES += doc/qtcharts.qdocconf \
75 doc/src/* \
75 doc/src/* \
76 doc/images/*
76 doc/images/*
77
77
78 #Define for unit tests
79 CONFIG(debug, debug|release) {
80 DEFINES += BUILD_PRIVATE_UNIT_TESTS
81 }
82
83 msvc {
78 msvc {
84 # Suppress "conversion from 'size_t' to 'int', possible loss of data" warnings in 64bit
79 # Suppress "conversion from 'size_t' to 'int', possible loss of data" warnings in 64bit
85 # builds resulting from usage of str::sort
80 # builds resulting from usage of str::sort
86 QMAKE_CXXFLAGS_WARN_ON += -wd4267
81 QMAKE_CXXFLAGS_WARN_ON += -wd4267
87 }
82 }
88
83
89 win32:!winrt:!wince {
84 win32:!winrt:!wince {
90 # ChartThemeSystem uses Windows native API
85 # ChartThemeSystem uses Windows native API
91 LIBS += -luser32
86 LIBS += -luser32
92 }
87 }
93
88
94 load(qt_module)
89 load(qt_module)
@@ -1,77 +1,70
1 /******************************************************************************
1 /******************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
4 ** Contact: http://www.qt.io/licensing/
5 **
5 **
6 ** This file is part of the Qt Charts module.
6 ** This file is part of the Qt Charts module.
7 **
7 **
8 ** $QT_BEGIN_LICENSE:COMM$
8 ** $QT_BEGIN_LICENSE:COMM$
9 **
9 **
10 ** Commercial License Usage
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
16 ** information use the contact form at http://www.qt.io/contact-us.
17 **
17 **
18 ** $QT_END_LICENSE$
18 ** $QT_END_LICENSE$
19 **
19 **
20 ******************************************************************************/
20 ******************************************************************************/
21
21
22 #ifndef QCHARTGLOBAL_H
22 #ifndef QCHARTGLOBAL_H
23 #define QCHARTGLOBAL_H
23 #define QCHARTGLOBAL_H
24
24
25 #include <QtCore/QtGlobal>
25 #include <QtCore/QtGlobal>
26
26
27 #define QT_CHARTS_VERSION_STR "2.1.1"
27 #define QT_CHARTS_VERSION_STR "2.1.1"
28 /*
28 /*
29 QT_CHARTS_VERSION is (major << 16) + (minor << 8) + patch.
29 QT_CHARTS_VERSION is (major << 16) + (minor << 8) + patch.
30 */
30 */
31 #define QT_CHARTS_VERSION 0x020101
31 #define QT_CHARTS_VERSION 0x020101
32 /*
32 /*
33 can be used like #if (QT_CHARTS_VERSION >= QT_CHARTS_VERSION_CHECK(1, 1, 0))
33 can be used like #if (QT_CHARTS_VERSION >= QT_CHARTS_VERSION_CHECK(1, 1, 0))
34 */
34 */
35 #define QT_CHARTS_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
35 #define QT_CHARTS_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
36
36
37 #ifndef QT_STATIC
37 #ifndef QT_STATIC
38 # if defined(QT_BUILD_CHARTS_LIB)
38 # if defined(QT_BUILD_CHARTS_LIB)
39 # define QT_CHARTS_EXPORT Q_DECL_EXPORT
39 # define QT_CHARTS_EXPORT Q_DECL_EXPORT
40 # else
40 # else
41 # define QT_CHARTS_EXPORT Q_DECL_IMPORT
41 # define QT_CHARTS_EXPORT Q_DECL_IMPORT
42 # endif
42 # endif
43 #else
43 #else
44 # define QT_CHARTS_EXPORT
44 # define QT_CHARTS_EXPORT
45 #endif
45 #endif
46
46
47 #if defined(BUILD_PRIVATE_UNIT_TESTS) && defined(QT_BUILD_CHARTS_LIB)
47 #define QT_CHARTS_AUTOTEST_EXPORT Q_AUTOTEST_EXPORT
48 # define QT_CHARTS_AUTOTEST_EXPORT Q_DECL_EXPORT
49 #elif defined(BUILD_PRIVATE_UNIT_TESTS) && !defined(QT_BUILD_CHARTS_LIB)
50 # define QT_CHARTS_AUTOTEST_EXPORT Q_DECL_IMPORT
51 #else
52 # define QT_CHARTS_AUTOTEST_EXPORT
53 #endif
54
55
48
56 #define QT_CHARTS_NAMESPACE QtCharts
49 #define QT_CHARTS_NAMESPACE QtCharts
57
50
58 #ifdef QT_CHARTS_NAMESPACE
51 #ifdef QT_CHARTS_NAMESPACE
59 # define QT_CHARTS_BEGIN_NAMESPACE namespace QT_CHARTS_NAMESPACE {
52 # define QT_CHARTS_BEGIN_NAMESPACE namespace QT_CHARTS_NAMESPACE {
60 # define QT_CHARTS_END_NAMESPACE }
53 # define QT_CHARTS_END_NAMESPACE }
61 # define QT_CHARTS_USE_NAMESPACE using namespace QT_CHARTS_NAMESPACE;
54 # define QT_CHARTS_USE_NAMESPACE using namespace QT_CHARTS_NAMESPACE;
62 #else
55 #else
63 # define QT_CHARTS_BEGIN_NAMESPACE
56 # define QT_CHARTS_BEGIN_NAMESPACE
64 # define QT_CHARTS_END_NAMESPACE
57 # define QT_CHARTS_END_NAMESPACE
65 # define QT_CHARTS_USE_NAMESPACE
58 # define QT_CHARTS_USE_NAMESPACE
66 #endif
59 #endif
67
60
68 /*
61 /*
69 On Windows min and max conflict with standard macros
62 On Windows min and max conflict with standard macros
70 */
63 */
71 #ifdef Q_OS_WIN
64 #ifdef Q_OS_WIN
72 #ifndef NOMINMAX
65 #ifndef NOMINMAX
73 #define NOMINMAX
66 #define NOMINMAX
74 #endif
67 #endif
75 #endif
68 #endif
76
69
77 #endif // QCHARTGLOBAL_H
70 #endif // QCHARTGLOBAL_H
@@ -1,15 +1,10
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 QT += testlib widgets
5 QT += testlib widgets
6
6
7 !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_")
7 !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_")
8
8
9 INCLUDEPATH += ../inc
9 INCLUDEPATH += ../inc
10 HEADERS += ../inc/tst_definitions.h
10 HEADERS += ../inc/tst_definitions.h
11
12 #Define for unit tests
13 CONFIG(debug, debug|release) {
14 DEFINES += BUILD_PRIVATE_UNIT_TESTS
15 }
@@ -1,399 +1,399
1 /******************************************************************************
1 /******************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
4 ** Contact: http://www.qt.io/licensing/
5 **
5 **
6 ** This file is part of the Qt Charts module.
6 ** This file is part of the Qt Charts module.
7 **
7 **
8 ** $QT_BEGIN_LICENSE:COMM$
8 ** $QT_BEGIN_LICENSE:COMM$
9 **
9 **
10 ** Commercial License Usage
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
16 ** information use the contact form at http://www.qt.io/contact-us.
17 **
17 **
18 ** $QT_END_LICENSE$
18 ** $QT_END_LICENSE$
19 **
19 **
20 ******************************************************************************/
20 ******************************************************************************/
21 #ifndef BUILD_PRIVATE_UNIT_TESTS
21 #ifndef QT_BUILD_INTERNAL
22 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
23
23
24 class tst_ChartDataSet: public QObject {
24 class tst_ChartDataSet: public QObject {
25
25
26 Q_OBJECT
26 Q_OBJECT
27
27
28 private Q_SLOTS:
28 private Q_SLOTS:
29 void skip();
29 void skip();
30
30
31 };
31 };
32
32
33 void tst_ChartDataSet::skip()
33 void tst_ChartDataSet::skip()
34 {
34 {
35 QSKIP("This test requires the debug version of library");
35 QSKIP("This test requires a developer build of the library");
36 }
36 }
37
37
38 QTEST_MAIN(tst_ChartDataSet)
38 QTEST_MAIN(tst_ChartDataSet)
39 #include "tst_chartdataset.moc"
39 #include "tst_chartdataset.moc"
40
40
41 #else
41 #else
42
42
43 #include <QtTest/QtTest>
43 #include <QtTest/QtTest>
44 #include <QtCharts/QAbstractAxis>
44 #include <QtCharts/QAbstractAxis>
45 #include <QtCharts/QValueAxis>
45 #include <QtCharts/QValueAxis>
46 #include <QtCharts/QBarCategoryAxis>
46 #include <QtCharts/QBarCategoryAxis>
47 #include <QtCharts/QCategoryAxis>
47 #include <QtCharts/QCategoryAxis>
48 #ifndef QT_ON_ARM
48 #ifndef QT_ON_ARM
49 #include <QtCharts/QDateTimeAxis>
49 #include <QtCharts/QDateTimeAxis>
50 #endif
50 #endif
51 #include <QtCharts/QLineSeries>
51 #include <QtCharts/QLineSeries>
52 #include <QtCharts/QAreaSeries>
52 #include <QtCharts/QAreaSeries>
53 #include <QtCharts/QScatterSeries>
53 #include <QtCharts/QScatterSeries>
54 #include <QtCharts/QSplineSeries>
54 #include <QtCharts/QSplineSeries>
55 #include <QtCharts/QPieSeries>
55 #include <QtCharts/QPieSeries>
56 #include <QtCharts/QBarSeries>
56 #include <QtCharts/QBarSeries>
57 #include <QtCharts/QPercentBarSeries>
57 #include <QtCharts/QPercentBarSeries>
58 #include <QtCharts/QStackedBarSeries>
58 #include <QtCharts/QStackedBarSeries>
59 #include <private/chartdataset_p.h>
59 #include <private/chartdataset_p.h>
60 #include <private/abstractdomain_p.h>
60 #include <private/abstractdomain_p.h>
61 #include <tst_definitions.h>
61 #include <tst_definitions.h>
62
62
63 QT_CHARTS_USE_NAMESPACE
63 QT_CHARTS_USE_NAMESPACE
64
64
65 Q_DECLARE_METATYPE(AbstractDomain *)
65 Q_DECLARE_METATYPE(AbstractDomain *)
66 Q_DECLARE_METATYPE(QAbstractAxis *)
66 Q_DECLARE_METATYPE(QAbstractAxis *)
67 Q_DECLARE_METATYPE(QAbstractSeries *)
67 Q_DECLARE_METATYPE(QAbstractSeries *)
68 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
68 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
69 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
69 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
70 Q_DECLARE_METATYPE(Qt::Alignment)
70 Q_DECLARE_METATYPE(Qt::Alignment)
71 Q_DECLARE_METATYPE(QList<Qt::Alignment>)
71 Q_DECLARE_METATYPE(QList<Qt::Alignment>)
72 Q_DECLARE_METATYPE(QLineSeries *)
72 Q_DECLARE_METATYPE(QLineSeries *)
73
73
74 class tst_ChartDataSet: public QObject {
74 class tst_ChartDataSet: public QObject {
75
75
76 Q_OBJECT
76 Q_OBJECT
77 public:
77 public:
78 tst_ChartDataSet():m_dataset(0){};
78 tst_ChartDataSet():m_dataset(0){};
79
79
80 public Q_SLOTS:
80 public Q_SLOTS:
81 void initTestCase();
81 void initTestCase();
82 void cleanupTestCase();
82 void cleanupTestCase();
83 void init();
83 void init();
84 void cleanup();
84 void cleanup();
85
85
86 private Q_SLOTS:
86 private Q_SLOTS:
87 void chartdataset_data();
87 void chartdataset_data();
88 void chartdataset();
88 void chartdataset();
89 void addSeries_data();
89 void addSeries_data();
90 void addSeries();
90 void addSeries();
91 void removeSeries_data();
91 void removeSeries_data();
92 void removeSeries();
92 void removeSeries();
93 void addAxis_data();
93 void addAxis_data();
94 void addAxis();
94 void addAxis();
95 void removeAxis_data();
95 void removeAxis_data();
96 void removeAxis();
96 void removeAxis();
97 void attachAxis_data();
97 void attachAxis_data();
98 void attachAxis();
98 void attachAxis();
99 void detachAxis_data();
99 void detachAxis_data();
100 void detachAxis();
100 void detachAxis();
101
101
102 private:
102 private:
103 ChartDataSet* m_dataset;
103 ChartDataSet* m_dataset;
104 };
104 };
105
105
106 void tst_ChartDataSet::initTestCase()
106 void tst_ChartDataSet::initTestCase()
107 {
107 {
108 qRegisterMetaType<AbstractDomain*>();
108 qRegisterMetaType<AbstractDomain*>();
109 qRegisterMetaType<QAbstractAxis*>();
109 qRegisterMetaType<QAbstractAxis*>();
110 qRegisterMetaType<QAbstractSeries*>();
110 qRegisterMetaType<QAbstractSeries*>();
111 }
111 }
112
112
113 void tst_ChartDataSet::cleanupTestCase()
113 void tst_ChartDataSet::cleanupTestCase()
114 {
114 {
115 QTest::qWait(1); // Allow final deleteLaters to run
115 QTest::qWait(1); // Allow final deleteLaters to run
116 }
116 }
117
117
118 void tst_ChartDataSet::init()
118 void tst_ChartDataSet::init()
119 {
119 {
120 Q_ASSERT(!m_dataset);
120 Q_ASSERT(!m_dataset);
121 m_dataset = new ChartDataSet(0);
121 m_dataset = new ChartDataSet(0);
122 }
122 }
123
123
124
124
125 void tst_ChartDataSet::cleanup()
125 void tst_ChartDataSet::cleanup()
126 {
126 {
127 delete m_dataset;
127 delete m_dataset;
128 m_dataset = 0;
128 m_dataset = 0;
129 }
129 }
130
130
131 void tst_ChartDataSet::chartdataset_data()
131 void tst_ChartDataSet::chartdataset_data()
132 {
132 {
133 }
133 }
134
134
135 void tst_ChartDataSet::chartdataset()
135 void tst_ChartDataSet::chartdataset()
136 {
136 {
137 QVERIFY(m_dataset->axes().isEmpty());
137 QVERIFY(m_dataset->axes().isEmpty());
138 QVERIFY(m_dataset->series().isEmpty());
138 QVERIFY(m_dataset->series().isEmpty());
139 m_dataset->createDefaultAxes();
139 m_dataset->createDefaultAxes();
140 }
140 }
141
141
142
142
143 void tst_ChartDataSet::addSeries_data()
143 void tst_ChartDataSet::addSeries_data()
144 {
144 {
145 QTest::addColumn<QAbstractSeries*>("series");
145 QTest::addColumn<QAbstractSeries*>("series");
146
146
147 QAbstractSeries* line = new QLineSeries(this);
147 QAbstractSeries* line = new QLineSeries(this);
148 QTest::newRow("line") << line;
148 QTest::newRow("line") << line;
149
149
150 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this)));
150 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this)));
151 QTest::newRow("area") << area;
151 QTest::newRow("area") << area;
152
152
153 QAbstractSeries* scatter = new QScatterSeries(this);
153 QAbstractSeries* scatter = new QScatterSeries(this);
154 QTest::newRow("scatter") << scatter;
154 QTest::newRow("scatter") << scatter;
155
155
156 QAbstractSeries* spline = new QSplineSeries(this);
156 QAbstractSeries* spline = new QSplineSeries(this);
157 QTest::newRow("spline") << spline;
157 QTest::newRow("spline") << spline;
158
158
159 QAbstractSeries* pie = new QPieSeries(this);
159 QAbstractSeries* pie = new QPieSeries(this);
160 QTest::newRow("pie") << pie;
160 QTest::newRow("pie") << pie;
161
161
162 QAbstractSeries* bar = new QBarSeries(this);
162 QAbstractSeries* bar = new QBarSeries(this);
163 QTest::newRow("bar") << bar;
163 QTest::newRow("bar") << bar;
164
164
165 QAbstractSeries* percent = new QPercentBarSeries(this);
165 QAbstractSeries* percent = new QPercentBarSeries(this);
166 QTest::newRow("percent") << percent;
166 QTest::newRow("percent") << percent;
167
167
168 QAbstractSeries* stacked = new QStackedBarSeries(this);
168 QAbstractSeries* stacked = new QStackedBarSeries(this);
169 QTest::newRow("stacked") << stacked;
169 QTest::newRow("stacked") << stacked;
170 }
170 }
171
171
172 void tst_ChartDataSet::addSeries()
172 void tst_ChartDataSet::addSeries()
173 {
173 {
174 QFETCH(QAbstractSeries*, series);
174 QFETCH(QAbstractSeries*, series);
175 QVERIFY(m_dataset->series().isEmpty());
175 QVERIFY(m_dataset->series().isEmpty());
176
176
177 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
177 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
178 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
178 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
179 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
179 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
180 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
180 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
181
181
182 m_dataset->addSeries(series);
182 m_dataset->addSeries(series);
183
183
184 QCOMPARE(m_dataset->series().count(),1);
184 QCOMPARE(m_dataset->series().count(),1);
185 TRY_COMPARE(spy0.count(), 0);
185 TRY_COMPARE(spy0.count(), 0);
186 TRY_COMPARE(spy1.count(), 0);
186 TRY_COMPARE(spy1.count(), 0);
187 TRY_COMPARE(spy2.count(), 1);
187 TRY_COMPARE(spy2.count(), 1);
188 TRY_COMPARE(spy3.count(), 0);
188 TRY_COMPARE(spy3.count(), 0);
189 }
189 }
190
190
191 void tst_ChartDataSet::removeSeries_data()
191 void tst_ChartDataSet::removeSeries_data()
192 {
192 {
193 addSeries_data();
193 addSeries_data();
194 }
194 }
195
195
196 void tst_ChartDataSet::removeSeries()
196 void tst_ChartDataSet::removeSeries()
197 {
197 {
198 QFETCH(QAbstractSeries*, series);
198 QFETCH(QAbstractSeries*, series);
199 QVERIFY(m_dataset->series().isEmpty());
199 QVERIFY(m_dataset->series().isEmpty());
200 m_dataset->addSeries(series);
200 m_dataset->addSeries(series);
201
201
202 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
202 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
203 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
203 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
204 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
204 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
205 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
205 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
206
206
207 m_dataset->removeSeries(series);
207 m_dataset->removeSeries(series);
208
208
209 QCOMPARE(m_dataset->series().count(),0);
209 QCOMPARE(m_dataset->series().count(),0);
210 TRY_COMPARE(spy0.count(), 0);
210 TRY_COMPARE(spy0.count(), 0);
211 TRY_COMPARE(spy1.count(), 0);
211 TRY_COMPARE(spy1.count(), 0);
212 TRY_COMPARE(spy2.count(), 0);
212 TRY_COMPARE(spy2.count(), 0);
213 TRY_COMPARE(spy3.count(), 1);
213 TRY_COMPARE(spy3.count(), 1);
214
214
215 delete series;
215 delete series;
216 }
216 }
217
217
218 void tst_ChartDataSet::addAxis_data()
218 void tst_ChartDataSet::addAxis_data()
219 {
219 {
220 QTest::addColumn<QAbstractAxis*>("axis");
220 QTest::addColumn<QAbstractAxis*>("axis");
221 QAbstractAxis* value = new QValueAxis(this);
221 QAbstractAxis* value = new QValueAxis(this);
222 QAbstractAxis* category = new QCategoryAxis(this);
222 QAbstractAxis* category = new QCategoryAxis(this);
223 QAbstractAxis* barcategory = new QBarCategoryAxis(this);
223 QAbstractAxis* barcategory = new QBarCategoryAxis(this);
224 #ifndef Q_WS_QWS
224 #ifndef Q_WS_QWS
225 QAbstractAxis* datetime = new QDateTimeAxis(this);
225 QAbstractAxis* datetime = new QDateTimeAxis(this);
226 #endif
226 #endif
227
227
228 QTest::newRow("value") << value;
228 QTest::newRow("value") << value;
229 QTest::newRow("category") << category;
229 QTest::newRow("category") << category;
230 QTest::newRow("barcategory") << barcategory;
230 QTest::newRow("barcategory") << barcategory;
231 #ifndef Q_WS_QWS
231 #ifndef Q_WS_QWS
232 QTest::newRow("datetime") << datetime;
232 QTest::newRow("datetime") << datetime;
233 #endif
233 #endif
234 }
234 }
235
235
236 void tst_ChartDataSet::addAxis()
236 void tst_ChartDataSet::addAxis()
237 {
237 {
238 QFETCH(QAbstractAxis*, axis);
238 QFETCH(QAbstractAxis*, axis);
239 QVERIFY(m_dataset->axes().isEmpty());
239 QVERIFY(m_dataset->axes().isEmpty());
240
240
241 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
241 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
242 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
242 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
243 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
243 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
244 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
244 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
245
245
246 m_dataset->addAxis(axis,Qt::AlignBottom);
246 m_dataset->addAxis(axis,Qt::AlignBottom);
247
247
248 QCOMPARE(m_dataset->axes().count(),1);
248 QCOMPARE(m_dataset->axes().count(),1);
249 TRY_COMPARE(spy0.count(), 1);
249 TRY_COMPARE(spy0.count(), 1);
250 TRY_COMPARE(spy1.count(), 0);
250 TRY_COMPARE(spy1.count(), 0);
251 TRY_COMPARE(spy2.count(), 0);
251 TRY_COMPARE(spy2.count(), 0);
252 TRY_COMPARE(spy3.count(), 0);
252 TRY_COMPARE(spy3.count(), 0);
253 }
253 }
254
254
255 void tst_ChartDataSet::removeAxis_data()
255 void tst_ChartDataSet::removeAxis_data()
256 {
256 {
257 addAxis_data();
257 addAxis_data();
258 }
258 }
259
259
260 void tst_ChartDataSet::removeAxis()
260 void tst_ChartDataSet::removeAxis()
261 {
261 {
262 QFETCH(QAbstractAxis*, axis);
262 QFETCH(QAbstractAxis*, axis);
263 QVERIFY(m_dataset->series().isEmpty());
263 QVERIFY(m_dataset->series().isEmpty());
264 m_dataset->addAxis(axis,Qt::AlignBottom);
264 m_dataset->addAxis(axis,Qt::AlignBottom);
265
265
266 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
266 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
267 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
267 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
268 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
268 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
269 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
269 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
270
270
271 m_dataset->removeAxis(axis);
271 m_dataset->removeAxis(axis);
272
272
273 QCOMPARE(m_dataset->axes().count(),0);
273 QCOMPARE(m_dataset->axes().count(),0);
274 QCOMPARE(m_dataset->series().count(),0);
274 QCOMPARE(m_dataset->series().count(),0);
275 TRY_COMPARE(spy0.count(), 0);
275 TRY_COMPARE(spy0.count(), 0);
276 TRY_COMPARE(spy1.count(), 1);
276 TRY_COMPARE(spy1.count(), 1);
277 TRY_COMPARE(spy2.count(), 0);
277 TRY_COMPARE(spy2.count(), 0);
278 TRY_COMPARE(spy3.count(), 0);
278 TRY_COMPARE(spy3.count(), 0);
279
279
280 delete axis;
280 delete axis;
281 }
281 }
282
282
283 void tst_ChartDataSet::attachAxis_data()
283 void tst_ChartDataSet::attachAxis_data()
284 {
284 {
285
285
286 QTest::addColumn<QList<QAbstractSeries*> >("series");
286 QTest::addColumn<QList<QAbstractSeries*> >("series");
287 QTest::addColumn<QList<QAbstractAxis*> >("axis");
287 QTest::addColumn<QList<QAbstractAxis*> >("axis");
288 QTest::addColumn<QList<Qt::Alignment> >("alignment");
288 QTest::addColumn<QList<Qt::Alignment> >("alignment");
289 QTest::addColumn<QAbstractSeries*>("attachSeries");
289 QTest::addColumn<QAbstractSeries*>("attachSeries");
290 QTest::addColumn<QAbstractAxis*>("attachAxis");
290 QTest::addColumn<QAbstractAxis*>("attachAxis");
291 QTest::addColumn<bool>("success");
291 QTest::addColumn<bool>("success");
292
292
293 {
293 {
294 QList<QAbstractSeries*> series;
294 QList<QAbstractSeries*> series;
295 QList<QAbstractAxis*> axes;
295 QList<QAbstractAxis*> axes;
296 QList<Qt::Alignment> alignment;
296 QList<Qt::Alignment> alignment;
297 QAbstractSeries* line = new QLineSeries(this);
297 QAbstractSeries* line = new QLineSeries(this);
298 QAbstractAxis* value1 = new QValueAxis(this);
298 QAbstractAxis* value1 = new QValueAxis(this);
299 QAbstractAxis* value2 = new QValueAxis(this);
299 QAbstractAxis* value2 = new QValueAxis(this);
300 series << line << 0;
300 series << line << 0;
301 axes << value1 << value2;
301 axes << value1 << value2;
302 alignment << Qt::AlignBottom << Qt::AlignLeft;
302 alignment << Qt::AlignBottom << Qt::AlignLeft;
303 QTest::newRow("first") << series << axes << alignment << line << value2 << true ;
303 QTest::newRow("first") << series << axes << alignment << line << value2 << true ;
304 }
304 }
305
305
306 {
306 {
307 QList<QAbstractSeries*> series;
307 QList<QAbstractSeries*> series;
308 QList<QAbstractAxis*> axes;
308 QList<QAbstractAxis*> axes;
309 QList<Qt::Alignment> alignment;
309 QList<Qt::Alignment> alignment;
310 QAbstractSeries* line = new QLineSeries(this);
310 QAbstractSeries* line = new QLineSeries(this);
311 QAbstractAxis* value1 = new QValueAxis(this);
311 QAbstractAxis* value1 = new QValueAxis(this);
312 QAbstractAxis* value2 = new QValueAxis(this);
312 QAbstractAxis* value2 = new QValueAxis(this);
313 series << 0 << line;
313 series << 0 << line;
314 axes << value1 << value2;
314 axes << value1 << value2;
315 alignment << Qt::AlignBottom << Qt::AlignLeft;
315 alignment << Qt::AlignBottom << Qt::AlignLeft;
316 QTest::newRow("second") << series << axes << alignment << line << value1 << true;
316 QTest::newRow("second") << series << axes << alignment << line << value1 << true;
317 }
317 }
318
318
319 }
319 }
320
320
321 void tst_ChartDataSet::attachAxis()
321 void tst_ChartDataSet::attachAxis()
322 {
322 {
323 QFETCH(QList<QAbstractSeries*>, series);
323 QFETCH(QList<QAbstractSeries*>, series);
324 QFETCH(QList<QAbstractAxis*>, axis);
324 QFETCH(QList<QAbstractAxis*>, axis);
325 QFETCH(QList<Qt::Alignment>, alignment);
325 QFETCH(QList<Qt::Alignment>, alignment);
326 QFETCH(QAbstractSeries*, attachSeries);
326 QFETCH(QAbstractSeries*, attachSeries);
327 QFETCH(QAbstractAxis*, attachAxis);
327 QFETCH(QAbstractAxis*, attachAxis);
328 QFETCH(bool, success);
328 QFETCH(bool, success);
329
329
330 Q_ASSERT(series.count() == axis.count());
330 Q_ASSERT(series.count() == axis.count());
331 Q_ASSERT(series.count() == alignment.count());
331 Q_ASSERT(series.count() == alignment.count());
332
332
333 QVERIFY(m_dataset->series().isEmpty());
333 QVERIFY(m_dataset->series().isEmpty());
334 QVERIFY(m_dataset->axes().isEmpty());
334 QVERIFY(m_dataset->axes().isEmpty());
335
335
336 for(int i = 0 ; i < series.count() ; i++){
336 for(int i = 0 ; i < series.count() ; i++){
337 if(series[i]) m_dataset->addSeries(series[i]);
337 if(series[i]) m_dataset->addSeries(series[i]);
338 if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]);
338 if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]);
339 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
339 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
340 }
340 }
341
341
342 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
342 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
343 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
343 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
344 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
344 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
345 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
345 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
346
346
347 QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success);
347 QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success);
348
348
349 }
349 }
350
350
351 void tst_ChartDataSet::detachAxis_data()
351 void tst_ChartDataSet::detachAxis_data()
352 {
352 {
353 QTest::addColumn<QList<QAbstractSeries*> >("series");
353 QTest::addColumn<QList<QAbstractSeries*> >("series");
354 QTest::addColumn<QList<QAbstractAxis*> >("axis");
354 QTest::addColumn<QList<QAbstractAxis*> >("axis");
355 QTest::addColumn<QAbstractSeries*>("detachSeries");
355 QTest::addColumn<QAbstractSeries*>("detachSeries");
356 QTest::addColumn<QAbstractAxis*>("detachAxis");
356 QTest::addColumn<QAbstractAxis*>("detachAxis");
357 QTest::addColumn<bool>("success");
357 QTest::addColumn<bool>("success");
358
358
359 {
359 {
360 QList<QAbstractSeries*> series;
360 QList<QAbstractSeries*> series;
361 QList<QAbstractAxis*> axes;
361 QList<QAbstractAxis*> axes;
362 QAbstractSeries* line = new QLineSeries(this);
362 QAbstractSeries* line = new QLineSeries(this);
363 QAbstractAxis* value = new QValueAxis(this);
363 QAbstractAxis* value = new QValueAxis(this);
364 series << line;
364 series << line;
365 axes << value;
365 axes << value;
366 QTest::newRow("first") << series << axes << line << value << true;
366 QTest::newRow("first") << series << axes << line << value << true;
367 }
367 }
368 }
368 }
369
369
370 void tst_ChartDataSet::detachAxis()
370 void tst_ChartDataSet::detachAxis()
371 {
371 {
372 QFETCH(QList<QAbstractSeries*>, series);
372 QFETCH(QList<QAbstractSeries*>, series);
373 QFETCH(QList<QAbstractAxis*>, axis);
373 QFETCH(QList<QAbstractAxis*>, axis);
374 QFETCH(QAbstractSeries*, detachSeries);
374 QFETCH(QAbstractSeries*, detachSeries);
375 QFETCH(QAbstractAxis*, detachAxis);
375 QFETCH(QAbstractAxis*, detachAxis);
376 QFETCH(bool, success);
376 QFETCH(bool, success);
377
377
378 Q_ASSERT(series.count() == axis.count());
378 Q_ASSERT(series.count() == axis.count());
379
379
380 QVERIFY(m_dataset->series().isEmpty());
380 QVERIFY(m_dataset->series().isEmpty());
381 QVERIFY(m_dataset->axes().isEmpty());
381 QVERIFY(m_dataset->axes().isEmpty());
382
382
383 for(int i = 0; i < series.count(); i++) {
383 for(int i = 0; i < series.count(); i++) {
384 if(series[i]) m_dataset->addSeries(series[i]);
384 if(series[i]) m_dataset->addSeries(series[i]);
385 if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom);
385 if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom);
386 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
386 if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]);
387 }
387 }
388
388
389 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
389 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)));
390 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
390 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
391 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
391 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)));
392 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
392 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
393
393
394 QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success);
394 QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success);
395 }
395 }
396
396
397 QTEST_MAIN(tst_ChartDataSet)
397 QTEST_MAIN(tst_ChartDataSet)
398 #include "tst_chartdataset.moc"
398 #include "tst_chartdataset.moc"
399 #endif
399 #endif
@@ -1,748 +1,748
1 /******************************************************************************
1 /******************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
4 ** Contact: http://www.qt.io/licensing/
5 **
5 **
6 ** This file is part of the Qt Charts module.
6 ** This file is part of the Qt Charts module.
7 **
7 **
8 ** $QT_BEGIN_LICENSE:COMM$
8 ** $QT_BEGIN_LICENSE:COMM$
9 **
9 **
10 ** Commercial License Usage
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
16 ** information use the contact form at http://www.qt.io/contact-us.
17 **
17 **
18 ** $QT_END_LICENSE$
18 ** $QT_END_LICENSE$
19 **
19 **
20 ******************************************************************************/
20 ******************************************************************************/
21 #ifndef BUILD_PRIVATE_UNIT_TESTS
21 #ifndef QT_BUILD_INTERNAL
22
22
23 #include <QtTest/QtTest>
23 #include <QtTest/QtTest>
24
24
25 class tst_Domain: public QObject {
25 class tst_Domain: public QObject {
26
26
27 Q_OBJECT
27 Q_OBJECT
28
28
29 private Q_SLOTS:
29 private Q_SLOTS:
30 void skip();
30 void skip();
31
31
32 };
32 };
33
33
34 void tst_Domain::skip()
34 void tst_Domain::skip()
35 {
35 {
36 QSKIP("This test requires the debug version of library");
36 QSKIP("This test requires a developer build of the library");
37 }
37 }
38
38
39 QTEST_MAIN(tst_Domain)
39 QTEST_MAIN(tst_Domain)
40 #include "tst_domain.moc"
40 #include "tst_domain.moc"
41
41
42 #else
42 #else
43
43
44 #include <QtTest/QtTest>
44 #include <QtTest/QtTest>
45 #include <private/xydomain_p.h>
45 #include <private/xydomain_p.h>
46 #include <private/qabstractaxis_p.h>
46 #include <private/qabstractaxis_p.h>
47 #include <tst_definitions.h>
47 #include <tst_definitions.h>
48
48
49 QT_CHARTS_USE_NAMESPACE
49 QT_CHARTS_USE_NAMESPACE
50
50
51 Q_DECLARE_METATYPE(XYDomain*)
51 Q_DECLARE_METATYPE(XYDomain*)
52 Q_DECLARE_METATYPE(QSizeF)
52 Q_DECLARE_METATYPE(QSizeF)
53 Q_DECLARE_METATYPE(QMargins)
53 Q_DECLARE_METATYPE(QMargins)
54
54
55
55
56 class AxisMock: public QAbstractAxisPrivate
56 class AxisMock: public QAbstractAxisPrivate
57 {
57 {
58 Q_OBJECT
58 Q_OBJECT
59 public:
59 public:
60 AxisMock(Qt::Alignment alignment):QAbstractAxisPrivate(0){ setAlignment(alignment);};
60 AxisMock(Qt::Alignment alignment):QAbstractAxisPrivate(0){ setAlignment(alignment);};
61 void initializeGraphics(QGraphicsItem* item)
61 void initializeGraphics(QGraphicsItem* item)
62 {
62 {
63 Q_UNUSED(item);
63 Q_UNUSED(item);
64 };
64 };
65
65
66 void initializeDomain(AbstractDomain* domain)
66 void initializeDomain(AbstractDomain* domain)
67 {
67 {
68 Q_UNUSED(domain);
68 Q_UNUSED(domain);
69 };
69 };
70 void setMin(const QVariant &min)
70 void setMin(const QVariant &min)
71 {
71 {
72 Q_UNUSED(min);
72 Q_UNUSED(min);
73 }
73 }
74 qreal min() { return m_min;}
74 qreal min() { return m_min;}
75 void setMax(const QVariant &max)
75 void setMax(const QVariant &max)
76 {
76 {
77 Q_UNUSED(max);
77 Q_UNUSED(max);
78 }
78 }
79 qreal max() { return m_max; }
79 qreal max() { return m_max; }
80 void setRange(const QVariant &min, const QVariant &max)
80 void setRange(const QVariant &min, const QVariant &max)
81 {
81 {
82 Q_UNUSED(min);
82 Q_UNUSED(min);
83 Q_UNUSED(max);
83 Q_UNUSED(max);
84 };
84 };
85
85
86 void setRange(qreal min, qreal max)
86 void setRange(qreal min, qreal max)
87 {
87 {
88 m_min=min;
88 m_min=min;
89 m_max=max;
89 m_max=max;
90 emit rangeChanged(min,max);
90 emit rangeChanged(min,max);
91 };
91 };
92
92
93 int count () const { return m_count; }
93 int count () const { return m_count; }
94
94
95 void handleDomainUpdated(){};
95 void handleDomainUpdated(){};
96 public:
96 public:
97 int m_count;
97 int m_count;
98 qreal m_min;
98 qreal m_min;
99 qreal m_max;
99 qreal m_max;
100 };
100 };
101
101
102 class tst_Domain: public QObject
102 class tst_Domain: public QObject
103 {
103 {
104 Q_OBJECT
104 Q_OBJECT
105
105
106 public Q_SLOTS:
106 public Q_SLOTS:
107 void initTestCase();
107 void initTestCase();
108 void cleanupTestCase();
108 void cleanupTestCase();
109 void init();
109 void init();
110 void cleanup();
110 void cleanup();
111
111
112 private Q_SLOTS:
112 private Q_SLOTS:
113 void domain();
113 void domain();
114 void handleHorizontalAxisRangeChanged_data();
114 void handleHorizontalAxisRangeChanged_data();
115 void handleHorizontalAxisRangeChanged();
115 void handleHorizontalAxisRangeChanged();
116 void handleVerticalAxisRangeChanged_data();
116 void handleVerticalAxisRangeChanged_data();
117 void handleVerticalAxisRangeChanged();
117 void handleVerticalAxisRangeChanged();
118 void isEmpty_data();
118 void isEmpty_data();
119 void isEmpty();
119 void isEmpty();
120 void maxX_data();
120 void maxX_data();
121 void maxX();
121 void maxX();
122 void maxY_data();
122 void maxY_data();
123 void maxY();
123 void maxY();
124 void minX_data();
124 void minX_data();
125 void minX();
125 void minX();
126 void minY_data();
126 void minY_data();
127 void minY();
127 void minY();
128 void operatorEquals_data();
128 void operatorEquals_data();
129 void operatorEquals();
129 void operatorEquals();
130 void setRange_data();
130 void setRange_data();
131 void setRange();
131 void setRange();
132 void setRangeX_data();
132 void setRangeX_data();
133 void setRangeX();
133 void setRangeX();
134 void setRangeY_data();
134 void setRangeY_data();
135 void setRangeY();
135 void setRangeY();
136 void spanX_data();
136 void spanX_data();
137 void spanX();
137 void spanX();
138 void spanY_data();
138 void spanY_data();
139 void spanY();
139 void spanY();
140 void zoomIn_data();
140 void zoomIn_data();
141 void zoomIn();
141 void zoomIn();
142 void zoomOut_data();
142 void zoomOut_data();
143 void zoomOut();
143 void zoomOut();
144 void move_data();
144 void move_data();
145 void move();
145 void move();
146 };
146 };
147
147
148 void tst_Domain::initTestCase()
148 void tst_Domain::initTestCase()
149 {
149 {
150 }
150 }
151
151
152 void tst_Domain::cleanupTestCase()
152 void tst_Domain::cleanupTestCase()
153 {
153 {
154 QTest::qWait(1); // Allow final deleteLaters to run
154 QTest::qWait(1); // Allow final deleteLaters to run
155 }
155 }
156
156
157 void tst_Domain::init()
157 void tst_Domain::init()
158 {
158 {
159 }
159 }
160
160
161 void tst_Domain::cleanup()
161 void tst_Domain::cleanup()
162 {
162 {
163 }
163 }
164
164
165 void tst_Domain::domain()
165 void tst_Domain::domain()
166 {
166 {
167 XYDomain domain;
167 XYDomain domain;
168
168
169 QCOMPARE(domain.isEmpty(), true);
169 QCOMPARE(domain.isEmpty(), true);
170 QCOMPARE(domain.maxX(), 0.0);
170 QCOMPARE(domain.maxX(), 0.0);
171 QCOMPARE(domain.maxY(), 0.0);
171 QCOMPARE(domain.maxY(), 0.0);
172 QCOMPARE(domain.minX(), 0.0);
172 QCOMPARE(domain.minX(), 0.0);
173 QCOMPARE(domain.minY(), 0.0);
173 QCOMPARE(domain.minY(), 0.0);
174 }
174 }
175
175
176 void tst_Domain::handleHorizontalAxisRangeChanged_data()
176 void tst_Domain::handleHorizontalAxisRangeChanged_data()
177 {
177 {
178 QTest::addColumn<qreal>("min");
178 QTest::addColumn<qreal>("min");
179 QTest::addColumn<qreal>("max");
179 QTest::addColumn<qreal>("max");
180 QTest::newRow("-1 1") << -1.0 << 1.0;
180 QTest::newRow("-1 1") << -1.0 << 1.0;
181 QTest::newRow("0 1") << 0.0 << 1.0;
181 QTest::newRow("0 1") << 0.0 << 1.0;
182 QTest::newRow("-1 0") << -1.0 << 0.0;
182 QTest::newRow("-1 0") << -1.0 << 0.0;
183 }
183 }
184
184
185 void tst_Domain::handleHorizontalAxisRangeChanged()
185 void tst_Domain::handleHorizontalAxisRangeChanged()
186 {
186 {
187 QFETCH(qreal, min);
187 QFETCH(qreal, min);
188 QFETCH(qreal, max);
188 QFETCH(qreal, max);
189
189
190 XYDomain domain;
190 XYDomain domain;
191
191
192 QSignalSpy spy0(&domain, SIGNAL(updated()));
192 QSignalSpy spy0(&domain, SIGNAL(updated()));
193 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
193 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
194 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
194 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
195
195
196 AxisMock axis(Qt::AlignBottom);
196 AxisMock axis(Qt::AlignBottom);
197 QObject::connect(&axis,SIGNAL(rangeChanged(qreal,qreal)),&domain,SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
197 QObject::connect(&axis,SIGNAL(rangeChanged(qreal,qreal)),&domain,SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
198 axis.setRange(min,max);
198 axis.setRange(min,max);
199
199
200 QVERIFY(qFuzzyCompare(domain.minX(), min));
200 QVERIFY(qFuzzyCompare(domain.minX(), min));
201 QVERIFY(qFuzzyCompare(domain.maxX(), max));
201 QVERIFY(qFuzzyCompare(domain.maxX(), max));
202
202
203 QList<QVariant> arg1 = spy1.first();
203 QList<QVariant> arg1 = spy1.first();
204 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
204 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
205 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
205 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
206
206
207 TRY_COMPARE(spy0.count(), 1);
207 TRY_COMPARE(spy0.count(), 1);
208 TRY_COMPARE(spy1.count(), 1);
208 TRY_COMPARE(spy1.count(), 1);
209 TRY_COMPARE(spy2.count(), 0);
209 TRY_COMPARE(spy2.count(), 0);
210
210
211 }
211 }
212
212
213 void tst_Domain::handleVerticalAxisRangeChanged_data()
213 void tst_Domain::handleVerticalAxisRangeChanged_data()
214 {
214 {
215 QTest::addColumn<qreal>("min");
215 QTest::addColumn<qreal>("min");
216 QTest::addColumn<qreal>("max");
216 QTest::addColumn<qreal>("max");
217 QTest::newRow("-1 1") << -1.0 << 1.0;
217 QTest::newRow("-1 1") << -1.0 << 1.0;
218 QTest::newRow("0 1") << 0.0 << 1.0;
218 QTest::newRow("0 1") << 0.0 << 1.0;
219 QTest::newRow("-1 0") << -1.0 << 0.0;
219 QTest::newRow("-1 0") << -1.0 << 0.0;
220 }
220 }
221
221
222 void tst_Domain::handleVerticalAxisRangeChanged()
222 void tst_Domain::handleVerticalAxisRangeChanged()
223 {
223 {
224 QFETCH(qreal, min);
224 QFETCH(qreal, min);
225 QFETCH(qreal, max);
225 QFETCH(qreal, max);
226
226
227 XYDomain domain;
227 XYDomain domain;
228
228
229 QSignalSpy spy0(&domain, SIGNAL(updated()));
229 QSignalSpy spy0(&domain, SIGNAL(updated()));
230 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
230 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
231 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
231 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
232
232
233 AxisMock axis(Qt::AlignLeft);
233 AxisMock axis(Qt::AlignLeft);
234 QObject::connect(&axis, SIGNAL(rangeChanged(qreal,qreal)), &domain, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
234 QObject::connect(&axis, SIGNAL(rangeChanged(qreal,qreal)), &domain, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
235 axis.setRange(min,max);
235 axis.setRange(min,max);
236
236
237 QVERIFY(qFuzzyCompare(domain.minY(), min));
237 QVERIFY(qFuzzyCompare(domain.minY(), min));
238 QVERIFY(qFuzzyCompare(domain.maxY(), max));
238 QVERIFY(qFuzzyCompare(domain.maxY(), max));
239
239
240 QList<QVariant> arg1 = spy2.first();
240 QList<QVariant> arg1 = spy2.first();
241 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
241 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
242 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
242 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
243
243
244 TRY_COMPARE(spy0.count(), 1);
244 TRY_COMPARE(spy0.count(), 1);
245 TRY_COMPARE(spy1.count(), 0);
245 TRY_COMPARE(spy1.count(), 0);
246 TRY_COMPARE(spy2.count(), 1);
246 TRY_COMPARE(spy2.count(), 1);
247 }
247 }
248
248
249 void tst_Domain::isEmpty_data()
249 void tst_Domain::isEmpty_data()
250 {
250 {
251 QTest::addColumn<qreal>("minX");
251 QTest::addColumn<qreal>("minX");
252 QTest::addColumn<qreal>("maxX");
252 QTest::addColumn<qreal>("maxX");
253 QTest::addColumn<qreal>("minY");
253 QTest::addColumn<qreal>("minY");
254 QTest::addColumn<qreal>("maxY");
254 QTest::addColumn<qreal>("maxY");
255 QTest::addColumn<QSizeF>("size");
255 QTest::addColumn<QSizeF>("size");
256 QTest::addColumn<bool>("isEmpty");
256 QTest::addColumn<bool>("isEmpty");
257 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << QSizeF(1,1) << true;
257 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << QSizeF(1,1) << true;
258 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true;
258 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true;
259 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true;
259 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true;
260 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(1,1) << false;
260 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(1,1) << false;
261 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(-11,1) << true;
261 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(-11,1) << true;
262 }
262 }
263
263
264 void tst_Domain::isEmpty()
264 void tst_Domain::isEmpty()
265 {
265 {
266 QFETCH(qreal, minX);
266 QFETCH(qreal, minX);
267 QFETCH(qreal, maxX);
267 QFETCH(qreal, maxX);
268 QFETCH(qreal, minY);
268 QFETCH(qreal, minY);
269 QFETCH(qreal, maxY);
269 QFETCH(qreal, maxY);
270 QFETCH(QSizeF, size);
270 QFETCH(QSizeF, size);
271 QFETCH(bool, isEmpty);
271 QFETCH(bool, isEmpty);
272
272
273 XYDomain domain;
273 XYDomain domain;
274 domain.setRange(minX, maxX, minY, maxY);
274 domain.setRange(minX, maxX, minY, maxY);
275 domain.setSize(size);
275 domain.setSize(size);
276 QCOMPARE(domain.isEmpty(), isEmpty);
276 QCOMPARE(domain.isEmpty(), isEmpty);
277 }
277 }
278
278
279 void tst_Domain::maxX_data()
279 void tst_Domain::maxX_data()
280 {
280 {
281 QTest::addColumn<qreal>("maxX1");
281 QTest::addColumn<qreal>("maxX1");
282 QTest::addColumn<qreal>("maxX2");
282 QTest::addColumn<qreal>("maxX2");
283 QTest::addColumn<int>("count");
283 QTest::addColumn<int>("count");
284 QTest::newRow("1") << 0.0 << 1.0 << 1;
284 QTest::newRow("1") << 0.0 << 1.0 << 1;
285 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
285 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
286 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
286 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
287 }
287 }
288
288
289 void tst_Domain::maxX()
289 void tst_Domain::maxX()
290 {
290 {
291 QFETCH(qreal, maxX1);
291 QFETCH(qreal, maxX1);
292 QFETCH(qreal, maxX2);
292 QFETCH(qreal, maxX2);
293 QFETCH(int, count);
293 QFETCH(int, count);
294
294
295 XYDomain domain;
295 XYDomain domain;
296
296
297 QSignalSpy spy0(&domain, SIGNAL(updated()));
297 QSignalSpy spy0(&domain, SIGNAL(updated()));
298 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
298 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
299 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
299 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
300
300
301 domain.setMaxX(maxX1);
301 domain.setMaxX(maxX1);
302 QCOMPARE(domain.maxX(), maxX1);
302 QCOMPARE(domain.maxX(), maxX1);
303 domain.setMaxX(maxX2);
303 domain.setMaxX(maxX2);
304 QCOMPARE(domain.maxX(), maxX2);
304 QCOMPARE(domain.maxX(), maxX2);
305
305
306 TRY_COMPARE(spy0.count(), count);
306 TRY_COMPARE(spy0.count(), count);
307 TRY_COMPARE(spy1.count(), count);
307 TRY_COMPARE(spy1.count(), count);
308 TRY_COMPARE(spy2.count(), 0);
308 TRY_COMPARE(spy2.count(), 0);
309
309
310 }
310 }
311
311
312 void tst_Domain::maxY_data()
312 void tst_Domain::maxY_data()
313 {
313 {
314 QTest::addColumn<qreal>("maxY1");
314 QTest::addColumn<qreal>("maxY1");
315 QTest::addColumn<qreal>("maxY2");
315 QTest::addColumn<qreal>("maxY2");
316 QTest::addColumn<int>("count");
316 QTest::addColumn<int>("count");
317 QTest::newRow("1") << 0.0 << 1.0 << 1;
317 QTest::newRow("1") << 0.0 << 1.0 << 1;
318 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
318 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
319 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
319 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
320 }
320 }
321
321
322 void tst_Domain::maxY()
322 void tst_Domain::maxY()
323 {
323 {
324 QFETCH(qreal, maxY1);
324 QFETCH(qreal, maxY1);
325 QFETCH(qreal, maxY2);
325 QFETCH(qreal, maxY2);
326 QFETCH(int, count);
326 QFETCH(int, count);
327
327
328 XYDomain domain;
328 XYDomain domain;
329
329
330 QSignalSpy spy0(&domain, SIGNAL(updated()));
330 QSignalSpy spy0(&domain, SIGNAL(updated()));
331 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
331 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
332 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
332 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
333
333
334 domain.setMaxY(maxY1);
334 domain.setMaxY(maxY1);
335 QCOMPARE(domain.maxY(), maxY1);
335 QCOMPARE(domain.maxY(), maxY1);
336 domain.setMaxY(maxY2);
336 domain.setMaxY(maxY2);
337 QCOMPARE(domain.maxY(), maxY2);
337 QCOMPARE(domain.maxY(), maxY2);
338
338
339 TRY_COMPARE(spy0.count(), count);
339 TRY_COMPARE(spy0.count(), count);
340 TRY_COMPARE(spy1.count(), 0);
340 TRY_COMPARE(spy1.count(), 0);
341 TRY_COMPARE(spy2.count(), count);
341 TRY_COMPARE(spy2.count(), count);
342 }
342 }
343
343
344 void tst_Domain::minX_data()
344 void tst_Domain::minX_data()
345 {
345 {
346 QTest::addColumn<qreal>("minX1");
346 QTest::addColumn<qreal>("minX1");
347 QTest::addColumn<qreal>("minX2");
347 QTest::addColumn<qreal>("minX2");
348 QTest::addColumn<int>("count");
348 QTest::addColumn<int>("count");
349 QTest::newRow("1") << 0.0 << 1.0 << 1;
349 QTest::newRow("1") << 0.0 << 1.0 << 1;
350 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
350 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
351 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
351 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
352 }
352 }
353
353
354 void tst_Domain::minX()
354 void tst_Domain::minX()
355 {
355 {
356 QFETCH(qreal, minX1);
356 QFETCH(qreal, minX1);
357 QFETCH(qreal, minX2);
357 QFETCH(qreal, minX2);
358 QFETCH(int, count);
358 QFETCH(int, count);
359
359
360 XYDomain domain;
360 XYDomain domain;
361
361
362 QSignalSpy spy0(&domain, SIGNAL(updated()));
362 QSignalSpy spy0(&domain, SIGNAL(updated()));
363 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
363 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
364 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
364 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
365
365
366 domain.setMinX(minX1);
366 domain.setMinX(minX1);
367 QCOMPARE(domain.minX(), minX1);
367 QCOMPARE(domain.minX(), minX1);
368 domain.setMinX(minX2);
368 domain.setMinX(minX2);
369 QCOMPARE(domain.minX(), minX2);
369 QCOMPARE(domain.minX(), minX2);
370
370
371 TRY_COMPARE(spy0.count(), count);
371 TRY_COMPARE(spy0.count(), count);
372 TRY_COMPARE(spy1.count(), count);
372 TRY_COMPARE(spy1.count(), count);
373 TRY_COMPARE(spy2.count(), 0);
373 TRY_COMPARE(spy2.count(), 0);
374 }
374 }
375
375
376 void tst_Domain::minY_data()
376 void tst_Domain::minY_data()
377 {
377 {
378 QTest::addColumn<qreal>("minY1");
378 QTest::addColumn<qreal>("minY1");
379 QTest::addColumn<qreal>("minY2");
379 QTest::addColumn<qreal>("minY2");
380 QTest::addColumn<int>("count");
380 QTest::addColumn<int>("count");
381 QTest::newRow("1") << 0.0 << 1.0 << 1;
381 QTest::newRow("1") << 0.0 << 1.0 << 1;
382 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
382 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
383 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
383 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
384 }
384 }
385
385
386 void tst_Domain::minY()
386 void tst_Domain::minY()
387 {
387 {
388 QFETCH(qreal, minY1);
388 QFETCH(qreal, minY1);
389 QFETCH(qreal, minY2);
389 QFETCH(qreal, minY2);
390 QFETCH(int, count);
390 QFETCH(int, count);
391
391
392 XYDomain domain;
392 XYDomain domain;
393
393
394 QSignalSpy spy0(&domain, SIGNAL(updated()));
394 QSignalSpy spy0(&domain, SIGNAL(updated()));
395 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
395 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
396 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
396 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
397
397
398 domain.setMinY(minY1);
398 domain.setMinY(minY1);
399 QCOMPARE(domain.minY(), minY1);
399 QCOMPARE(domain.minY(), minY1);
400 domain.setMinY(minY2);
400 domain.setMinY(minY2);
401 QCOMPARE(domain.minY(), minY2);
401 QCOMPARE(domain.minY(), minY2);
402
402
403 TRY_COMPARE(spy0.count(), count);
403 TRY_COMPARE(spy0.count(), count);
404 TRY_COMPARE(spy1.count(), 0);
404 TRY_COMPARE(spy1.count(), 0);
405 TRY_COMPARE(spy2.count(), count);
405 TRY_COMPARE(spy2.count(), count);
406 }
406 }
407
407
408 void tst_Domain::operatorEquals_data()
408 void tst_Domain::operatorEquals_data()
409 {
409 {
410
410
411 QTest::addColumn<XYDomain*>("domain1");
411 QTest::addColumn<XYDomain*>("domain1");
412 QTest::addColumn<XYDomain*>("domain2");
412 QTest::addColumn<XYDomain*>("domain2");
413 QTest::addColumn<bool>("equals");
413 QTest::addColumn<bool>("equals");
414 QTest::addColumn<bool>("notEquals");
414 QTest::addColumn<bool>("notEquals");
415 XYDomain* a;
415 XYDomain* a;
416 XYDomain* b;
416 XYDomain* b;
417 a = new XYDomain();
417 a = new XYDomain();
418 a->setRange(0, 100, 0, 100);
418 a->setRange(0, 100, 0, 100);
419 b = new XYDomain();
419 b = new XYDomain();
420 b->setRange(0, 100, 0, 100);
420 b->setRange(0, 100, 0, 100);
421 QTest::newRow("equals") << a << b << true << false;
421 QTest::newRow("equals") << a << b << true << false;
422 a = new XYDomain();
422 a = new XYDomain();
423 a->setRange(0, 100, 0, 100);
423 a->setRange(0, 100, 0, 100);
424 b = new XYDomain();
424 b = new XYDomain();
425 b->setRange(0, 100, 0, 1);
425 b->setRange(0, 100, 0, 1);
426 QTest::newRow("equals") << a << b << false << true;
426 QTest::newRow("equals") << a << b << false << true;
427 a = new XYDomain();
427 a = new XYDomain();
428 a->setRange(0, 100, 0, 100);
428 a->setRange(0, 100, 0, 100);
429 b = new XYDomain();
429 b = new XYDomain();
430 b->setRange(0, 1, 0, 100);
430 b->setRange(0, 1, 0, 100);
431 QTest::newRow("equals") << a << b << false << true;
431 QTest::newRow("equals") << a << b << false << true;
432
432
433 }
433 }
434
434
435 void tst_Domain::operatorEquals()
435 void tst_Domain::operatorEquals()
436 {
436 {
437 QFETCH(XYDomain*, domain1);
437 QFETCH(XYDomain*, domain1);
438 QFETCH(XYDomain*, domain2);
438 QFETCH(XYDomain*, domain2);
439 QFETCH(bool, equals);
439 QFETCH(bool, equals);
440 QFETCH(bool, notEquals);
440 QFETCH(bool, notEquals);
441
441
442 XYDomain domain;
442 XYDomain domain;
443
443
444 QSignalSpy spy0(&domain, SIGNAL(updated()));
444 QSignalSpy spy0(&domain, SIGNAL(updated()));
445 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
445 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
446 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
446 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
447
447
448 QCOMPARE(*domain1==*domain2, equals);
448 QCOMPARE(*domain1==*domain2, equals);
449 QCOMPARE(*domain1!=*domain2, notEquals);
449 QCOMPARE(*domain1!=*domain2, notEquals);
450
450
451 TRY_COMPARE(spy0.count(), 0);
451 TRY_COMPARE(spy0.count(), 0);
452 TRY_COMPARE(spy1.count(), 0);
452 TRY_COMPARE(spy1.count(), 0);
453 TRY_COMPARE(spy2.count(), 0);
453 TRY_COMPARE(spy2.count(), 0);
454
454
455 delete domain1;
455 delete domain1;
456 delete domain2;
456 delete domain2;
457 }
457 }
458
458
459 void tst_Domain::setRange_data()
459 void tst_Domain::setRange_data()
460 {
460 {
461 QTest::addColumn<qreal>("minX");
461 QTest::addColumn<qreal>("minX");
462 QTest::addColumn<qreal>("maxX");
462 QTest::addColumn<qreal>("maxX");
463 QTest::addColumn<qreal>("minY");
463 QTest::addColumn<qreal>("minY");
464 QTest::addColumn<qreal>("maxY");
464 QTest::addColumn<qreal>("maxY");
465 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
465 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
466 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
466 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
467 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
467 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
468 }
468 }
469
469
470 void tst_Domain::setRange()
470 void tst_Domain::setRange()
471 {
471 {
472 QFETCH(qreal, minX);
472 QFETCH(qreal, minX);
473 QFETCH(qreal, maxX);
473 QFETCH(qreal, maxX);
474 QFETCH(qreal, minY);
474 QFETCH(qreal, minY);
475 QFETCH(qreal, maxY);
475 QFETCH(qreal, maxY);
476
476
477 XYDomain domain;
477 XYDomain domain;
478
478
479 QSignalSpy spy0(&domain, SIGNAL(updated()));
479 QSignalSpy spy0(&domain, SIGNAL(updated()));
480 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
480 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
481 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
481 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
482
482
483 domain.setRange(minX, maxX, minY, maxY);
483 domain.setRange(minX, maxX, minY, maxY);
484
484
485 QCOMPARE(domain.minX(), minX);
485 QCOMPARE(domain.minX(), minX);
486 QCOMPARE(domain.maxX(), maxX);
486 QCOMPARE(domain.maxX(), maxX);
487 QCOMPARE(domain.minY(), minY);
487 QCOMPARE(domain.minY(), minY);
488 QCOMPARE(domain.maxY(), maxY);
488 QCOMPARE(domain.maxY(), maxY);
489
489
490 TRY_COMPARE(spy0.count(), 1);
490 TRY_COMPARE(spy0.count(), 1);
491 TRY_COMPARE(spy1.count(), 1);
491 TRY_COMPARE(spy1.count(), 1);
492 TRY_COMPARE(spy2.count(), 1);
492 TRY_COMPARE(spy2.count(), 1);
493
493
494 }
494 }
495
495
496 void tst_Domain::setRangeX_data()
496 void tst_Domain::setRangeX_data()
497 {
497 {
498 QTest::addColumn<qreal>("min");
498 QTest::addColumn<qreal>("min");
499 QTest::addColumn<qreal>("max");
499 QTest::addColumn<qreal>("max");
500 QTest::newRow("-1 1") << -1.0 << 1.0;
500 QTest::newRow("-1 1") << -1.0 << 1.0;
501 QTest::newRow("0 1") << 0.0 << 1.0;
501 QTest::newRow("0 1") << 0.0 << 1.0;
502 QTest::newRow("-1 0") << -1.0 << 0.0;
502 QTest::newRow("-1 0") << -1.0 << 0.0;
503 }
503 }
504
504
505 void tst_Domain::setRangeX()
505 void tst_Domain::setRangeX()
506 {
506 {
507 QFETCH(qreal, min);
507 QFETCH(qreal, min);
508 QFETCH(qreal, max);
508 QFETCH(qreal, max);
509
509
510 XYDomain domain;
510 XYDomain domain;
511
511
512 QSignalSpy spy0(&domain, SIGNAL(updated()));
512 QSignalSpy spy0(&domain, SIGNAL(updated()));
513 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
513 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
514 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
514 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
515
515
516 domain.setRangeX(min, max);
516 domain.setRangeX(min, max);
517
517
518 QVERIFY(qFuzzyCompare(domain.minX(), min));
518 QVERIFY(qFuzzyCompare(domain.minX(), min));
519 QVERIFY(qFuzzyCompare(domain.maxX(), max));
519 QVERIFY(qFuzzyCompare(domain.maxX(), max));
520
520
521 QList<QVariant> arg1 = spy1.first();
521 QList<QVariant> arg1 = spy1.first();
522 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
522 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
523 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
523 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
524
524
525 TRY_COMPARE(spy0.count(), 1);
525 TRY_COMPARE(spy0.count(), 1);
526 TRY_COMPARE(spy1.count(), 1);
526 TRY_COMPARE(spy1.count(), 1);
527 TRY_COMPARE(spy2.count(), 0);
527 TRY_COMPARE(spy2.count(), 0);
528 }
528 }
529
529
530 void tst_Domain::setRangeY_data()
530 void tst_Domain::setRangeY_data()
531 {
531 {
532 QTest::addColumn<qreal>("min");
532 QTest::addColumn<qreal>("min");
533 QTest::addColumn<qreal>("max");
533 QTest::addColumn<qreal>("max");
534 QTest::newRow("-1 1") << -1.0 << 1.0;
534 QTest::newRow("-1 1") << -1.0 << 1.0;
535 QTest::newRow("0 1") << 0.0 << 1.0;
535 QTest::newRow("0 1") << 0.0 << 1.0;
536 QTest::newRow("-1 0") << -1.0 << 0.0;
536 QTest::newRow("-1 0") << -1.0 << 0.0;
537 }
537 }
538
538
539 void tst_Domain::setRangeY()
539 void tst_Domain::setRangeY()
540 {
540 {
541 QFETCH(qreal, min);
541 QFETCH(qreal, min);
542 QFETCH(qreal, max);
542 QFETCH(qreal, max);
543
543
544 XYDomain domain;
544 XYDomain domain;
545
545
546 QSignalSpy spy0(&domain, SIGNAL(updated()));
546 QSignalSpy spy0(&domain, SIGNAL(updated()));
547 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
547 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
548 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
548 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
549
549
550 domain.setRangeY(min, max);
550 domain.setRangeY(min, max);
551
551
552 QVERIFY(qFuzzyCompare(domain.minY(), min));
552 QVERIFY(qFuzzyCompare(domain.minY(), min));
553 QVERIFY(qFuzzyCompare(domain.maxY(), max));
553 QVERIFY(qFuzzyCompare(domain.maxY(), max));
554
554
555 QList<QVariant> arg1 = spy2.first();
555 QList<QVariant> arg1 = spy2.first();
556 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
556 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
557 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
557 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
558
558
559 TRY_COMPARE(spy0.count(), 1);
559 TRY_COMPARE(spy0.count(), 1);
560 TRY_COMPARE(spy1.count(), 0);
560 TRY_COMPARE(spy1.count(), 0);
561 TRY_COMPARE(spy2.count(), 1);
561 TRY_COMPARE(spy2.count(), 1);
562 }
562 }
563
563
564 void tst_Domain::spanX_data()
564 void tst_Domain::spanX_data()
565 {
565 {
566 QTest::addColumn<qreal>("minX");
566 QTest::addColumn<qreal>("minX");
567 QTest::addColumn<qreal>("maxX");
567 QTest::addColumn<qreal>("maxX");
568 QTest::addColumn<qreal>("spanX");
568 QTest::addColumn<qreal>("spanX");
569 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
569 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
570 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
570 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
571 }
571 }
572
572
573 void tst_Domain::spanX()
573 void tst_Domain::spanX()
574 {
574 {
575 QFETCH(qreal, minX);
575 QFETCH(qreal, minX);
576 QFETCH(qreal, maxX);
576 QFETCH(qreal, maxX);
577 QFETCH(qreal, spanX);
577 QFETCH(qreal, spanX);
578
578
579 XYDomain domain;
579 XYDomain domain;
580
580
581 domain.setRangeX(minX, maxX);
581 domain.setRangeX(minX, maxX);
582
582
583 QSignalSpy spy0(&domain, SIGNAL(updated()));
583 QSignalSpy spy0(&domain, SIGNAL(updated()));
584 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
584 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
585 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
585 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
586
586
587 QCOMPARE(domain.spanX(), spanX);
587 QCOMPARE(domain.spanX(), spanX);
588
588
589 TRY_COMPARE(spy0.count(), 0);
589 TRY_COMPARE(spy0.count(), 0);
590 TRY_COMPARE(spy1.count(), 0);
590 TRY_COMPARE(spy1.count(), 0);
591 TRY_COMPARE(spy2.count(), 0);
591 TRY_COMPARE(spy2.count(), 0);
592 }
592 }
593
593
594 void tst_Domain::spanY_data()
594 void tst_Domain::spanY_data()
595 {
595 {
596 QTest::addColumn<qreal>("minY");
596 QTest::addColumn<qreal>("minY");
597 QTest::addColumn<qreal>("maxY");
597 QTest::addColumn<qreal>("maxY");
598 QTest::addColumn<qreal>("spanY");
598 QTest::addColumn<qreal>("spanY");
599 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
599 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
600 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
600 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
601 }
601 }
602
602
603 void tst_Domain::spanY()
603 void tst_Domain::spanY()
604 {
604 {
605 QFETCH(qreal, minY);
605 QFETCH(qreal, minY);
606 QFETCH(qreal, maxY);
606 QFETCH(qreal, maxY);
607 QFETCH(qreal, spanY);
607 QFETCH(qreal, spanY);
608
608
609 XYDomain domain;
609 XYDomain domain;
610
610
611 domain.setRangeY(minY, maxY);
611 domain.setRangeY(minY, maxY);
612
612
613 QSignalSpy spy0(&domain, SIGNAL(updated()));
613 QSignalSpy spy0(&domain, SIGNAL(updated()));
614 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
614 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
615 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
615 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
616
616
617 QCOMPARE(domain.spanY(), spanY);
617 QCOMPARE(domain.spanY(), spanY);
618
618
619 TRY_COMPARE(spy0.count(), 0);
619 TRY_COMPARE(spy0.count(), 0);
620 TRY_COMPARE(spy1.count(), 0);
620 TRY_COMPARE(spy1.count(), 0);
621 TRY_COMPARE(spy2.count(), 0);
621 TRY_COMPARE(spy2.count(), 0);
622 }
622 }
623
623
624 void tst_Domain::zoomIn_data()
624 void tst_Domain::zoomIn_data()
625 {
625 {
626 QTest::addColumn<QMargins>("range");
626 QTest::addColumn<QMargins>("range");
627 QTest::addColumn<QSizeF>("size");
627 QTest::addColumn<QSizeF>("size");
628 QTest::addColumn<QMargins>("zoom");
628 QTest::addColumn<QMargins>("zoom");
629 QTest::addColumn<QMargins>("result");
629 QTest::addColumn<QMargins>("result");
630
630
631 QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) <<
631 QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) <<
632 QMargins(100, 100, 900, 900) << QMargins(100,100,900,900);
632 QMargins(100, 100, 900, 900) << QMargins(100,100,900,900);
633 QTest::newRow("second") << QMargins(0,0,2000,2000) << QSizeF(1000, 1000) <<
633 QTest::newRow("second") << QMargins(0,0,2000,2000) << QSizeF(1000, 1000) <<
634 QMargins(100, 100, 900, 900) << QMargins(200,200,1800,1800);
634 QMargins(100, 100, 900, 900) << QMargins(200,200,1800,1800);
635 }
635 }
636
636
637 void tst_Domain::zoomIn()
637 void tst_Domain::zoomIn()
638 {
638 {
639 QFETCH(QMargins, range);
639 QFETCH(QMargins, range);
640 QFETCH(QSizeF, size);
640 QFETCH(QSizeF, size);
641 QFETCH(QMargins, zoom);
641 QFETCH(QMargins, zoom);
642 QFETCH(QMargins, result);
642 QFETCH(QMargins, result);
643
643
644 XYDomain domain;
644 XYDomain domain;
645 domain.setRange(range.left(), range.right(), range.top(),range.bottom());
645 domain.setRange(range.left(), range.right(), range.top(),range.bottom());
646 domain.setSize(size);
646 domain.setSize(size);
647
647
648 QSignalSpy spy0(&domain, SIGNAL(updated()));
648 QSignalSpy spy0(&domain, SIGNAL(updated()));
649 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
649 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
650 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
650 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
651
651
652 domain.zoomIn(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top()));
652 domain.zoomIn(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top()));
653
653
654 QCOMPARE(domain.minX(),qreal(result.left()));
654 QCOMPARE(domain.minX(),qreal(result.left()));
655 QCOMPARE(domain.maxX(),qreal(result.right()));
655 QCOMPARE(domain.maxX(),qreal(result.right()));
656 QCOMPARE(domain.minY(),qreal(result.top()));
656 QCOMPARE(domain.minY(),qreal(result.top()));
657 QCOMPARE(domain.maxY(),qreal(result.bottom()));
657 QCOMPARE(domain.maxY(),qreal(result.bottom()));
658
658
659 TRY_COMPARE(spy0.count(), 1);
659 TRY_COMPARE(spy0.count(), 1);
660 TRY_COMPARE(spy1.count(), 1);
660 TRY_COMPARE(spy1.count(), 1);
661 TRY_COMPARE(spy2.count(), 1);
661 TRY_COMPARE(spy2.count(), 1);
662 }
662 }
663
663
664 void tst_Domain::zoomOut_data()
664 void tst_Domain::zoomOut_data()
665 {
665 {
666 QTest::addColumn<QMargins>("range");
666 QTest::addColumn<QMargins>("range");
667 QTest::addColumn<QSizeF>("size");
667 QTest::addColumn<QSizeF>("size");
668 QTest::addColumn<QMargins>("zoom");
668 QTest::addColumn<QMargins>("zoom");
669 QTest::addColumn<QMargins>("result");
669 QTest::addColumn<QMargins>("result");
670
670
671 QTest::newRow("first") << QMargins(100,100,900,900) << QSizeF(1000, 1000) <<
671 QTest::newRow("first") << QMargins(100,100,900,900) << QSizeF(1000, 1000) <<
672 QMargins(100, 100, 900, 900) << QMargins(0,0,1000,1000);
672 QMargins(100, 100, 900, 900) << QMargins(0,0,1000,1000);
673 QTest::newRow("second") << QMargins(200,200,1800,1800) << QSizeF(1000, 1000) <<
673 QTest::newRow("second") << QMargins(200,200,1800,1800) << QSizeF(1000, 1000) <<
674 QMargins(100, 100, 900, 900) << QMargins(0,0,2000,2000);
674 QMargins(100, 100, 900, 900) << QMargins(0,0,2000,2000);
675 }
675 }
676
676
677 void tst_Domain::zoomOut()
677 void tst_Domain::zoomOut()
678 {
678 {
679 QFETCH(QMargins, range);
679 QFETCH(QMargins, range);
680 QFETCH(QSizeF, size);
680 QFETCH(QSizeF, size);
681 QFETCH(QMargins, zoom);
681 QFETCH(QMargins, zoom);
682 QFETCH(QMargins, result);
682 QFETCH(QMargins, result);
683
683
684 XYDomain domain;
684 XYDomain domain;
685 domain.setRange(range.left(), range.right(), range.top(),range.bottom());
685 domain.setRange(range.left(), range.right(), range.top(),range.bottom());
686 domain.setSize(size);
686 domain.setSize(size);
687
687
688 QSignalSpy spy0(&domain, SIGNAL(updated()));
688 QSignalSpy spy0(&domain, SIGNAL(updated()));
689 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
689 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
690 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
690 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
691
691
692 domain.zoomOut(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top()));
692 domain.zoomOut(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top()));
693
693
694 QCOMPARE(domain.minX(),qreal(result.left()));
694 QCOMPARE(domain.minX(),qreal(result.left()));
695 QCOMPARE(domain.maxX(),qreal(result.right()));
695 QCOMPARE(domain.maxX(),qreal(result.right()));
696 QCOMPARE(domain.minY(),qreal(result.top()));
696 QCOMPARE(domain.minY(),qreal(result.top()));
697 QCOMPARE(domain.maxY(),qreal(result.bottom()));
697 QCOMPARE(domain.maxY(),qreal(result.bottom()));
698
698
699 TRY_COMPARE(spy0.count(), 1);
699 TRY_COMPARE(spy0.count(), 1);
700 TRY_COMPARE(spy1.count(), 1);
700 TRY_COMPARE(spy1.count(), 1);
701 TRY_COMPARE(spy2.count(), 1);
701 TRY_COMPARE(spy2.count(), 1);
702 }
702 }
703
703
704 void tst_Domain::move_data()
704 void tst_Domain::move_data()
705 {
705 {
706 QTest::addColumn<QMargins>("range");
706 QTest::addColumn<QMargins>("range");
707 QTest::addColumn<QSizeF>("size");
707 QTest::addColumn<QSizeF>("size");
708 QTest::addColumn<int>("dx");
708 QTest::addColumn<int>("dx");
709 QTest::addColumn<int>("dy");
709 QTest::addColumn<int>("dy");
710 QTest::addColumn<QMargins>("result");
710 QTest::addColumn<QMargins>("result");
711
711
712 QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) <<
712 QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) <<
713 10 << 10 << QMargins(10,10,1010,1010);
713 10 << 10 << QMargins(10,10,1010,1010);
714 QTest::newRow("second") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) <<
714 QTest::newRow("second") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) <<
715 -10 << -10 << QMargins(-10,-10,990,990);
715 -10 << -10 << QMargins(-10,-10,990,990);
716 }
716 }
717
717
718 void tst_Domain::move()
718 void tst_Domain::move()
719 {
719 {
720 QFETCH(QMargins, range);
720 QFETCH(QMargins, range);
721 QFETCH(QSizeF, size);
721 QFETCH(QSizeF, size);
722 QFETCH(int, dx);
722 QFETCH(int, dx);
723 QFETCH(int, dy);
723 QFETCH(int, dy);
724 QFETCH(QMargins, result);
724 QFETCH(QMargins, result);
725
725
726 XYDomain domain;
726 XYDomain domain;
727 domain.setRange(range.left(), range.right(), range.top(),range.bottom());
727 domain.setRange(range.left(), range.right(), range.top(),range.bottom());
728 domain.setSize(size);
728 domain.setSize(size);
729
729
730 QSignalSpy spy0(&domain, SIGNAL(updated()));
730 QSignalSpy spy0(&domain, SIGNAL(updated()));
731 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
731 QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal)));
732 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
732 QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal)));
733
733
734 domain.move(dx, dy);
734 domain.move(dx, dy);
735
735
736 QCOMPARE(domain.minX(),qreal(result.left()));
736 QCOMPARE(domain.minX(),qreal(result.left()));
737 QCOMPARE(domain.maxX(),qreal(result.right()));
737 QCOMPARE(domain.maxX(),qreal(result.right()));
738 QCOMPARE(domain.minY(),qreal(result.top()));
738 QCOMPARE(domain.minY(),qreal(result.top()));
739 QCOMPARE(domain.maxY(),qreal(result.bottom()));
739 QCOMPARE(domain.maxY(),qreal(result.bottom()));
740
740
741 TRY_COMPARE(spy0.count(), 1);
741 TRY_COMPARE(spy0.count(), 1);
742 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
742 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
743 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
743 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
744 }
744 }
745
745
746 QTEST_MAIN(tst_Domain)
746 QTEST_MAIN(tst_Domain)
747 #include "tst_domain.moc"
747 #include "tst_domain.moc"
748 #endif
748 #endif
General Comments 0
You need to be logged in to leave comments. Login now