##// END OF EJS Templates
Add dealy to tst_qchartview
Michal Klocek -
r911:131b52731487
parent child
Show More
@@ -1,215 +1,215
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
20
21
21
22 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
23 #include <qchartview.h>
23 #include <qchartview.h>
24 #include <qlineseries.h>
24 #include <qlineseries.h>
25 #include <cmath>
25 #include <cmath>
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29
29
30 Q_DECLARE_METATYPE(QChart*)
30 Q_DECLARE_METATYPE(QChart*)
31 Q_DECLARE_METATYPE(QChartView::RubberBands)
31 Q_DECLARE_METATYPE(QChartView::RubberBands)
32 Q_DECLARE_METATYPE(Qt::Key)
32 Q_DECLARE_METATYPE(Qt::Key)
33
33
34 class tst_QChartView : public QObject
34 class tst_QChartView : public QObject
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37
37
38 public Q_SLOTS:
38 public Q_SLOTS:
39 void initTestCase();
39 void initTestCase();
40 void cleanupTestCase();
40 void cleanupTestCase();
41 void init();
41 void init();
42 void cleanup();
42 void cleanup();
43
43
44 private Q_SLOTS:
44 private Q_SLOTS:
45 void qchartview_data();
45 void qchartview_data();
46 void qchartview();
46 void qchartview();
47 void chart_data();
47 void chart_data();
48 void chart();
48 void chart();
49 void rubberBand_data();
49 void rubberBand_data();
50 void rubberBand();
50 void rubberBand();
51 void keys_data();
51 void keys_data();
52 void keys();
52 void keys();
53
53
54 private:
54 private:
55 QChartView* m_view;
55 QChartView* m_view;
56 };
56 };
57
57
58 void tst_QChartView::initTestCase()
58 void tst_QChartView::initTestCase()
59 {
59 {
60 //test tracks mouse, give a while to user to relese it
60 //test tracks mouse, give a while to user to relese it
61 QTest::qWait(1000);
61 QTest::qWait(1000);
62 }
62 }
63
63
64 void tst_QChartView::cleanupTestCase()
64 void tst_QChartView::cleanupTestCase()
65 {
65 {
66 }
66 }
67
67
68 void tst_QChartView::init()
68 void tst_QChartView::init()
69 {
69 {
70 m_view = new QChartView(new QChart());
70 m_view = new QChartView(new QChart());
71 m_view->chart()->legend()->setVisible(false);
71 m_view->chart()->legend()->setVisible(false);
72 }
72 }
73
73
74 void tst_QChartView::cleanup()
74 void tst_QChartView::cleanup()
75 {
75 {
76 delete m_view;
76 delete m_view;
77 m_view =0;
77 m_view =0;
78 }
78 }
79
79
80 void tst_QChartView::qchartview_data()
80 void tst_QChartView::qchartview_data()
81 {
81 {
82
82
83 }
83 }
84
84
85 void tst_QChartView::qchartview()
85 void tst_QChartView::qchartview()
86 {
86 {
87 QVERIFY(m_view->chart());
87 QVERIFY(m_view->chart());
88 QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand);
88 QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand);
89 m_view->show();
89 m_view->show();
90 QTest::qWaitForWindowShown(m_view);
90 QTest::qWaitForWindowShown(m_view);
91 }
91 }
92
92
93 void tst_QChartView::chart_data()
93 void tst_QChartView::chart_data()
94 {
94 {
95
95
96 QTest::addColumn<QChart*>("chart");
96 QTest::addColumn<QChart*>("chart");
97 QTest::newRow("qchart") << new QChart();
97 QTest::newRow("qchart") << new QChart();
98 }
98 }
99
99
100 void tst_QChartView::chart()
100 void tst_QChartView::chart()
101 {
101 {
102 QFETCH(QChart*, chart);
102 QFETCH(QChart*, chart);
103 QChartView* view = new QChartView(chart);
103 QChartView* view = new QChartView(chart);
104 QCOMPARE(view->chart(), chart);
104 QCOMPARE(view->chart(), chart);
105 delete view;
105 delete view;
106 }
106 }
107
107
108 void tst_QChartView::rubberBand_data()
108 void tst_QChartView::rubberBand_data()
109 {
109 {
110 QTest::addColumn<QChartView::RubberBands>("rubberBand");
110 QTest::addColumn<QChartView::RubberBands>("rubberBand");
111 QTest::addColumn<int>("Xcount");
111 QTest::addColumn<int>("Xcount");
112 QTest::addColumn<int>("Ycount");
112 QTest::addColumn<int>("Ycount");
113
113
114 QTest::addColumn<int>("minX");
114 QTest::addColumn<int>("minX");
115 QTest::addColumn<int>("maxX");
115 QTest::addColumn<int>("maxX");
116 QTest::addColumn<int>("minY");
116 QTest::addColumn<int>("minY");
117 QTest::addColumn<int>("maxY");
117 QTest::addColumn<int>("maxY");
118
118
119 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100;
119 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100;
120 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90;
120 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90;
121 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90;
121 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90;
122 }
122 }
123
123
124 void tst_QChartView::rubberBand()
124 void tst_QChartView::rubberBand()
125 {
125 {
126 QFETCH(QChartView::RubberBands, rubberBand);
126 QFETCH(QChartView::RubberBands, rubberBand);
127 QFETCH(int, Xcount);
127 QFETCH(int, Xcount);
128 QFETCH(int, Ycount);
128 QFETCH(int, Ycount);
129 QFETCH(int, minX);
129 QFETCH(int, minX);
130 QFETCH(int, maxX);
130 QFETCH(int, maxX);
131 QFETCH(int, minY);
131 QFETCH(int, minY);
132 QFETCH(int, maxY);
132 QFETCH(int, maxY);
133
133
134 m_view->setRubberBand(rubberBand);
134 m_view->setRubberBand(rubberBand);
135 QRectF padding = m_view->chart()->margins();
135 QRectF padding = m_view->chart()->margins();
136 QCOMPARE(m_view->rubberBand(), rubberBand);
136 QCOMPARE(m_view->rubberBand(), rubberBand);
137
137
138 QLineSeries* line = new QLineSeries();
138 QLineSeries* line = new QLineSeries();
139 *line << QPointF(0, 0) << QPointF(100, 100);
139 *line << QPointF(0, 0) << QPointF(100, 100);
140
140
141 m_view->chart()->addSeries(line);
141 m_view->chart()->addSeries(line);
142 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
142 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
143 m_view->show();
143 m_view->show();
144
144
145 //this is hack since view does not get events otherwise
145 //this is hack since view does not get events otherwise
146 m_view->setMouseTracking(true);
146 m_view->setMouseTracking(true);
147
147
148 QChartAxis* axisY = m_view->chart()->axisY();
148 QChartAxis* axisY = m_view->chart()->axisY();
149 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
149 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
150 QChartAxis* axisX = m_view->chart()->axisX();
150 QChartAxis* axisX = m_view->chart()->axisX();
151 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
151 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
152
152
153 QTest::qWaitForWindowShown(m_view);
153 QTest::qWaitForWindowShown(m_view);
154 QTest::qWait(500);
154 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint());
155 QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint());
155 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint());
156 QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint());
156 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint());
157 QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint());
157 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint());
158 QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint());
158
159
159
160 QCOMPARE(spy0.count(), Xcount);
160 QCOMPARE(spy0.count(), Xcount);
161 QCOMPARE(spy1.count(), Ycount);
161 QCOMPARE(spy1.count(), Ycount);
162
162
163 //this is hack since view does not get events otherwise
163 //this is hack since view does not get events otherwise
164 m_view->setMouseTracking(false);
164 m_view->setMouseTracking(false);
165
165
166 QVERIFY(axisX->min() - minX < 1);
166 QVERIFY(axisX->min() - minX < 1);
167 QVERIFY(axisX->max() - maxX < 1);
167 QVERIFY(axisX->max() - maxX < 1);
168 QVERIFY(axisY->min() - minY < 1);
168 QVERIFY(axisY->min() - minY < 1);
169 QVERIFY(axisY->max() - maxY < 1);
169 QVERIFY(axisY->max() - maxY < 1);
170 }
170 }
171
171
172 void tst_QChartView::keys_data()
172 void tst_QChartView::keys_data()
173 {
173 {
174 QTest::addColumn<Qt::Key>("key");
174 QTest::addColumn<Qt::Key>("key");
175 QTest::addColumn<int>("Xcount");
175 QTest::addColumn<int>("Xcount");
176 QTest::addColumn<int>("Ycount");
176 QTest::addColumn<int>("Ycount");
177 QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1;
177 QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1;
178 QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1;
178 QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1;
179 QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1;
179 QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1;
180 QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1;
180 QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1;
181 QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0;
181 QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0;
182 QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0;
182 QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0;
183 }
183 }
184
184
185 void tst_QChartView::keys()
185 void tst_QChartView::keys()
186 {
186 {
187 QFETCH(Qt::Key,key);
187 QFETCH(Qt::Key,key);
188 QFETCH(int, Xcount);
188 QFETCH(int, Xcount);
189 QFETCH(int, Ycount);
189 QFETCH(int, Ycount);
190
190
191 QRectF padding = m_view->chart()->margins();
191 QRectF padding = m_view->chart()->margins();
192
192
193 QLineSeries* line = new QLineSeries();
193 QLineSeries* line = new QLineSeries();
194 *line << QPointF(0, 0) << QPointF(100, 100);
194 *line << QPointF(0, 0) << QPointF(100, 100);
195
195
196 m_view->chart()->addSeries(line);
196 m_view->chart()->addSeries(line);
197 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
197 m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom());
198 m_view->show();
198 m_view->show();
199
199
200 QChartAxis* axisY = m_view->chart()->axisY();
200 QChartAxis* axisY = m_view->chart()->axisY();
201 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
201 QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal)));
202 QChartAxis* axisX = m_view->chart()->axisX();
202 QChartAxis* axisX = m_view->chart()->axisX();
203 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
203 QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal)));
204
204
205 QTest::keyPress(m_view, key);
205 QTest::keyPress(m_view, key);
206 QTest::keyRelease(m_view, key);
206 QTest::keyRelease(m_view, key);
207
207
208 QCOMPARE(spy0.count(), Ycount);
208 QCOMPARE(spy0.count(), Ycount);
209 QCOMPARE(spy1.count(), Xcount);
209 QCOMPARE(spy1.count(), Xcount);
210
210
211 }
211 }
212
212
213 QTEST_MAIN(tst_QChartView)
213 QTEST_MAIN(tst_QChartView)
214 #include "tst_qchartview.moc"
214 #include "tst_qchartview.moc"
215
215
General Comments 0
You need to be logged in to leave comments. Login now