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