@@ -1,220 +1,171 | |||
|
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 | void keys_data(); | |
|
52 | void keys(); | |
|
53 | 51 | |
|
54 | 52 | private: |
|
55 | 53 | QChartView* m_view; |
|
56 | 54 | }; |
|
57 | 55 | |
|
58 | 56 | void tst_QChartView::initTestCase() |
|
59 | 57 | { |
|
60 | 58 | //test tracks mouse, give a while to user to relese it |
|
61 | 59 | QTest::qWait(1000); |
|
62 | 60 | } |
|
63 | 61 | |
|
64 | 62 | void tst_QChartView::cleanupTestCase() |
|
65 | 63 | { |
|
66 | 64 | } |
|
67 | 65 | |
|
68 | 66 | void tst_QChartView::init() |
|
69 | 67 | { |
|
70 | 68 | m_view = new QChartView(new QChart()); |
|
71 | 69 | m_view->chart()->legend()->setVisible(false); |
|
72 | 70 | } |
|
73 | 71 | |
|
74 | 72 | void tst_QChartView::cleanup() |
|
75 | 73 | { |
|
76 | 74 | delete m_view; |
|
77 | 75 | m_view =0; |
|
78 | 76 | } |
|
79 | 77 | |
|
80 | 78 | void tst_QChartView::qchartview_data() |
|
81 | 79 | { |
|
82 | 80 | |
|
83 | 81 | } |
|
84 | 82 | |
|
85 | 83 | void tst_QChartView::qchartview() |
|
86 | 84 | { |
|
87 | 85 | QVERIFY(m_view->chart()); |
|
88 | 86 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
89 | 87 | m_view->show(); |
|
90 | 88 | QTest::qWaitForWindowShown(m_view); |
|
91 | 89 | } |
|
92 | 90 | |
|
93 | 91 | void tst_QChartView::chart_data() |
|
94 | 92 | { |
|
95 | 93 | |
|
96 | 94 | QTest::addColumn<QChart*>("chart"); |
|
97 | 95 | QTest::newRow("qchart") << new QChart(); |
|
98 | 96 | } |
|
99 | 97 | |
|
100 | 98 | void tst_QChartView::chart() |
|
101 | 99 | { |
|
102 | 100 | QFETCH(QChart*, chart); |
|
103 | 101 | QChartView* view = new QChartView(chart); |
|
104 | 102 | QCOMPARE(view->chart(), chart); |
|
105 | 103 | delete view; |
|
106 | 104 | } |
|
107 | 105 | |
|
108 | 106 | void tst_QChartView::rubberBand_data() |
|
109 | 107 | { |
|
110 | 108 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
111 | 109 | QTest::addColumn<int>("Xcount"); |
|
112 | 110 | QTest::addColumn<int>("Ycount"); |
|
113 | 111 | |
|
114 | 112 | QTest::addColumn<int>("minX"); |
|
115 | 113 | QTest::addColumn<int>("maxX"); |
|
116 | 114 | QTest::addColumn<int>("minY"); |
|
117 | 115 | QTest::addColumn<int>("maxY"); |
|
118 | 116 | |
|
119 | 117 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; |
|
120 | 118 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; |
|
121 | 119 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; |
|
122 | 120 | } |
|
123 | 121 | |
|
124 | 122 | void tst_QChartView::rubberBand() |
|
125 | 123 | { |
|
126 | 124 | QFETCH(QChartView::RubberBands, rubberBand); |
|
127 | 125 | QFETCH(int, Xcount); |
|
128 | 126 | QFETCH(int, Ycount); |
|
129 | 127 | QFETCH(int, minX); |
|
130 | 128 | QFETCH(int, maxX); |
|
131 | 129 | QFETCH(int, minY); |
|
132 | 130 | QFETCH(int, maxY); |
|
133 | 131 | |
|
134 | 132 | m_view->setRubberBand(rubberBand); |
|
135 | 133 | QRectF padding = m_view->chart()->margins(); |
|
136 | 134 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
137 | 135 | |
|
138 | 136 | QLineSeries* line = new QLineSeries(); |
|
139 | 137 | *line << QPointF(0, 0) << QPointF(200, 200); |
|
140 | 138 | |
|
141 | 139 | m_view->chart()->addSeries(line); |
|
142 | 140 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); |
|
143 | 141 | m_view->show(); |
|
144 | 142 | |
|
145 | 143 | //this is hack since view does not get events otherwise |
|
146 | 144 | m_view->setMouseTracking(true); |
|
147 | 145 | |
|
148 | 146 | QAxis* axisY = m_view->chart()->axisY(); |
|
149 | 147 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); |
|
150 | 148 | QAxis* axisX = m_view->chart()->axisX(); |
|
151 | 149 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); |
|
152 | 150 | |
|
153 | 151 | QTest::qWaitForWindowShown(m_view); |
|
154 | QTest::qWait(500); | |
|
155 | 152 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
156 | 153 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
157 | 154 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); |
|
158 | 155 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); |
|
159 | 156 | |
|
160 | 157 | QCOMPARE(spy0.count(), Xcount); |
|
161 | 158 | QCOMPARE(spy1.count(), Ycount); |
|
162 | 159 | |
|
163 | 160 | //this is hack since view does not get events otherwise |
|
164 | 161 | m_view->setMouseTracking(false); |
|
165 | 162 | |
|
166 | 163 | QVERIFY(axisX->min() - minX < 1); |
|
167 | 164 | QVERIFY(axisX->max() - maxX < 1); |
|
168 | 165 | QVERIFY(axisY->min() - minY < 1); |
|
169 | 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 | 169 | QTEST_MAIN(tst_QChartView) |
|
219 | 170 | #include "tst_qchartview.moc" |
|
220 | 171 |
General Comments 0
You need to be logged in to leave comments.
Login now