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