|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Test class for CalenDayContentWidget |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QGraphicsItem> |
|
20 |
|
21 #include "calendaystatusstriptest.h" |
|
22 |
|
23 #include <QPainter> |
|
24 #include <QImage> |
|
25 #include <QPair> |
|
26 |
|
27 const qreal WIDGET_WIDTH = 50; |
|
28 const qreal WIDGET_HEIGHT = 150; |
|
29 |
|
30 class TestCalenStatusStrip : public QObject |
|
31 { |
|
32 Q_OBJECT |
|
33 |
|
34 public: |
|
35 TestCalenStatusStrip(); |
|
36 virtual ~TestCalenStatusStrip(); |
|
37 |
|
38 private slots: |
|
39 void initTestCase(); |
|
40 void cleanupTestCase(); |
|
41 void init(); |
|
42 void cleanup(); |
|
43 |
|
44 void testConstructors(); |
|
45 void testSetGetColor(); |
|
46 void testSetGetRange(); |
|
47 void testSetGetDrawingStyle_data(); |
|
48 void testSetGetDrawingStyle(); |
|
49 void testStartEndTime(); |
|
50 void testCreatingDiagonalLine(); |
|
51 void testCalculateStartEndTimePosition_data(); |
|
52 void testCalculateStartEndTimePosition(); |
|
53 void testCalculateMinuteHegiht(); |
|
54 void testPaint(); |
|
55 |
|
56 private: |
|
57 CalenDayStatusStripTest *mStatusStrip; |
|
58 }; |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 /*! |
|
64 Constructor |
|
65 */ |
|
66 TestCalenStatusStrip::TestCalenStatusStrip() : |
|
67 mStatusStrip(NULL) |
|
68 { |
|
69 |
|
70 } |
|
71 |
|
72 /*! |
|
73 Destructor |
|
74 */ |
|
75 TestCalenStatusStrip::~TestCalenStatusStrip() |
|
76 { |
|
77 |
|
78 } |
|
79 |
|
80 /*! |
|
81 Called before testcase |
|
82 */ |
|
83 void TestCalenStatusStrip::initTestCase() |
|
84 { |
|
85 } |
|
86 |
|
87 /*! |
|
88 Called after testcase |
|
89 */ |
|
90 void TestCalenStatusStrip::cleanupTestCase() |
|
91 { |
|
92 |
|
93 } |
|
94 |
|
95 /*! |
|
96 Called before every function |
|
97 */ |
|
98 void TestCalenStatusStrip::init() |
|
99 { |
|
100 mStatusStrip = new CalenDayStatusStripTest(); |
|
101 } |
|
102 |
|
103 /*! |
|
104 Called after everyfunction |
|
105 */ |
|
106 void TestCalenStatusStrip::cleanup() |
|
107 { |
|
108 if (mStatusStrip) { |
|
109 delete mStatusStrip; |
|
110 mStatusStrip = NULL; |
|
111 } |
|
112 } |
|
113 |
|
114 /*! |
|
115 Test function for constructors |
|
116 1. Test if content widget is not initialized |
|
117 2. Test if content widget is correcty created |
|
118 */ |
|
119 void TestCalenStatusStrip::testConstructors() |
|
120 { |
|
121 //1) |
|
122 CalenDayStatusStrip *testStatusStrip = 0; |
|
123 QVERIFY(!testStatusStrip); |
|
124 |
|
125 //2) |
|
126 testStatusStrip = new CalenDayStatusStrip(); |
|
127 QVERIFY(testStatusStrip); |
|
128 delete testStatusStrip; |
|
129 } |
|
130 |
|
131 /*! |
|
132 Test function for geting and setting color |
|
133 1. Test setting red color |
|
134 2. Test change color to blue |
|
135 */ |
|
136 void TestCalenStatusStrip::testSetGetColor() |
|
137 { |
|
138 //1) |
|
139 mStatusStrip->setColor(QColor(Qt::red)); |
|
140 QColor testColor = mStatusStrip->color(); |
|
141 QCOMPARE(QColor(Qt::red),testColor); |
|
142 |
|
143 //2) |
|
144 mStatusStrip->setColor(QColor(Qt::blue)); |
|
145 testColor = mStatusStrip->color(); |
|
146 QCOMPARE(QColor(Qt::blue),testColor); |
|
147 } |
|
148 |
|
149 /*! |
|
150 Test function for geting and setting range |
|
151 1. Test setting 5px range |
|
152 2. Test change range to 1px |
|
153 */ |
|
154 void TestCalenStatusStrip::testSetGetRange() |
|
155 { |
|
156 //1) |
|
157 mStatusStrip->setRange(5); |
|
158 QCOMPARE((qreal)5,mStatusStrip->range()); |
|
159 |
|
160 //2) |
|
161 mStatusStrip->setRange(1); |
|
162 QCOMPARE((qreal)1,mStatusStrip->range()); |
|
163 } |
|
164 |
|
165 /*! |
|
166 Preapre data for \sa testSetGetDrawingStyle |
|
167 Add new enum \sa CalenDayStatusStrip::DrawingStyle |
|
168 1)OnlyFrame |
|
169 2)StripWithLines |
|
170 3)Filled |
|
171 */ |
|
172 void TestCalenStatusStrip::testSetGetDrawingStyle_data() |
|
173 { |
|
174 QTest::addColumn<CalenDayStatusStrip::DrawingStyle>("testedValue"); |
|
175 QTest::addColumn<CalenDayStatusStrip::DrawingStyle>("testValue"); |
|
176 |
|
177 QTest::newRow("OnlyFrame") << CalenDayStatusStrip::OnlyFrame |
|
178 << CalenDayStatusStrip::OnlyFrame; |
|
179 QTest::newRow("StripWithLines") << CalenDayStatusStrip::StripWithLines |
|
180 << CalenDayStatusStrip::StripWithLines; |
|
181 QTest::newRow("Filled") << CalenDayStatusStrip::Filled |
|
182 << CalenDayStatusStrip::Filled; |
|
183 } |
|
184 |
|
185 /*! |
|
186 Test settting and getting drawing style on preapred data |
|
187 |
|
188 \sa testSetGetDrawingStyle_data |
|
189 */ |
|
190 void TestCalenStatusStrip::testSetGetDrawingStyle() |
|
191 { |
|
192 //get data to test |
|
193 QFETCH(CalenDayStatusStrip::DrawingStyle, testedValue); |
|
194 QFETCH(CalenDayStatusStrip::DrawingStyle, testValue); |
|
195 |
|
196 //set data |
|
197 mStatusStrip->setDrawingStyle(testedValue); |
|
198 |
|
199 //check data |
|
200 QCOMPARE(mStatusStrip->drawingStyle(),testValue); |
|
201 } |
|
202 |
|
203 /*! |
|
204 Test setting and getting start and end time of event |
|
205 1)Set end and start of event |
|
206 2)Change values |
|
207 */ |
|
208 void TestCalenStatusStrip::testStartEndTime() |
|
209 { |
|
210 QPair<QTime, QTime> startEndTime; |
|
211 startEndTime.first = QTime(12,12,12); |
|
212 startEndTime.second = QTime(15,15,15); |
|
213 |
|
214 mStatusStrip->setStartEndTime(startEndTime.first,startEndTime.second); |
|
215 |
|
216 QCOMPARE(mStatusStrip->startEndTime().first,startEndTime.first); |
|
217 QCOMPARE(mStatusStrip->startEndTime().second,startEndTime.second); |
|
218 |
|
219 startEndTime.first = QTime(1,1,1); |
|
220 startEndTime.second = QTime(5,5,5); |
|
221 |
|
222 mStatusStrip->setStartEndTime(startEndTime.first,startEndTime.second); |
|
223 |
|
224 QCOMPARE(mStatusStrip->startEndTime().first,startEndTime.first); |
|
225 QCOMPARE(mStatusStrip->startEndTime().second,startEndTime.second); |
|
226 } |
|
227 |
|
228 /*! |
|
229 Test creating polygon to draw diagonal line on widget |
|
230 */ |
|
231 void TestCalenStatusStrip::testCreatingDiagonalLine() |
|
232 { |
|
233 qreal dx = 10; |
|
234 qreal dy = 1; |
|
235 QPointF point(0,60); |
|
236 QVector<QPointF> points; |
|
237 |
|
238 points << QPointF(0,60); |
|
239 points << QPointF(0,59); |
|
240 points << QPointF(10,58); |
|
241 points << QPointF(10,59); |
|
242 |
|
243 QPolygonF testValue(points); |
|
244 QPolygonF testedValue = mStatusStrip->diagonalLine(point,dx,dy); |
|
245 |
|
246 QCOMPARE(testedValue,testValue); |
|
247 } |
|
248 |
|
249 /*! |
|
250 Prepare data for \sa testCalculateStartEndTimePosition |
|
251 Add new start and end time of event. |
|
252 1)Full time start and end |
|
253 2)Exactly 30min time start and end |
|
254 3)More than 30min time start and end |
|
255 4)time start > 30m and end > 23h30m |
|
256 */ |
|
257 void TestCalenStatusStrip::testCalculateStartEndTimePosition_data() |
|
258 { |
|
259 QTest::addColumn<QTime>("testedStartValue"); |
|
260 QTest::addColumn<QTime>("testedEndValue"); |
|
261 QTest::addColumn<QTime>("testStartValue"); |
|
262 QTest::addColumn<QTime>("testEndValue"); |
|
263 |
|
264 QTest::newRow("Full time start and end") << QTime(10,00,00) |
|
265 << QTime(11,00,00) |
|
266 << QTime(10,00,00) |
|
267 << QTime(11,00,00); |
|
268 QTest::newRow("Exactly 30min time start and end") << QTime(10,30,00) |
|
269 << QTime(11,30,00) |
|
270 << QTime(10,30,00) |
|
271 << QTime(11,30,00); |
|
272 QTest::newRow("More than 30min time start and end") << QTime(10,40,00) |
|
273 << QTime(12,35,00) |
|
274 << QTime(10,30,00) |
|
275 << QTime(13,00,00); |
|
276 QTest::newRow("time start > 30m and end > 23h30m") << QTime(20,35,00) |
|
277 << QTime(23,35,00) |
|
278 << QTime(20,30,00) |
|
279 << QTime(23,59,00); |
|
280 } |
|
281 |
|
282 /*! |
|
283 Test calculating start and end time drawing of event bubble on prepared data |
|
284 \sa testCalculateStartEndTimePosition_data |
|
285 */ |
|
286 void TestCalenStatusStrip::testCalculateStartEndTimePosition() |
|
287 { |
|
288 //get prepared data |
|
289 QFETCH(QTime, testedStartValue); |
|
290 QFETCH(QTime, testedEndValue); |
|
291 QFETCH(QTime, testStartValue); |
|
292 QFETCH(QTime, testEndValue); |
|
293 |
|
294 //run function |
|
295 QPair<QTime,QTime> testStartEndValue |
|
296 = mStatusStrip->calculateStartEndPostion(testedStartValue, |
|
297 testedEndValue); |
|
298 //check data |
|
299 QCOMPARE(testStartEndValue.first,testStartValue); |
|
300 QCOMPARE(testStartEndValue.second,testEndValue); |
|
301 } |
|
302 |
|
303 /*! |
|
304 Test calculating minute height based on widget height and given time. |
|
305 1)Calculate on given time |
|
306 2)Change time of event |
|
307 */ |
|
308 void TestCalenStatusStrip::testCalculateMinuteHegiht() |
|
309 { |
|
310 qreal testedValue; |
|
311 qreal testValue; |
|
312 mStatusStrip->resize(WIDGET_WIDTH,WIDGET_HEIGHT); |
|
313 |
|
314 //1) |
|
315 testedValue = mStatusStrip->calculateMinuteHeight(QTime(10,00,0), |
|
316 QTime(11,00,0)); |
|
317 testValue = WIDGET_HEIGHT / (qreal)60; |
|
318 QCOMPARE(testedValue,testValue); |
|
319 |
|
320 //2) |
|
321 testedValue = mStatusStrip->calculateMinuteHeight(QTime(10,00,0), |
|
322 QTime(11,30,0)); |
|
323 testValue = WIDGET_HEIGHT / (qreal)90; |
|
324 QCOMPARE(testedValue,testValue); |
|
325 } |
|
326 |
|
327 |
|
328 /*! |
|
329 Test drawing widget. |
|
330 |
|
331 If there is no SAVE_IMAGES macro defined it will only run this function. |
|
332 If there is macro defined and c:\unittest folder created then image will be |
|
333 created so user can see if it draw in good way. |
|
334 */ |
|
335 void TestCalenStatusStrip::testPaint() |
|
336 { |
|
337 //preapre data needed to draw on widget |
|
338 mStatusStrip->setColor(QColor(Qt::red)); |
|
339 QPair<QTime, QTime> startEndTime; |
|
340 startEndTime.first = QTime(10,20,0); |
|
341 startEndTime.second = QTime(15,10,00); |
|
342 |
|
343 //set event time |
|
344 mStatusStrip->setStartEndTime(startEndTime.first,startEndTime.second); |
|
345 |
|
346 //resize widget to be bigger than (0,0) |
|
347 mStatusStrip->resize(WIDGET_WIDTH,WIDGET_HEIGHT); |
|
348 QSize size = mStatusStrip->size().toSize(); |
|
349 |
|
350 //create image that will simulate widget where painting should be done |
|
351 QImage img(size,QImage::Format_RGB32); |
|
352 //create painter which will be used to paint |
|
353 QPainter painter(&img); |
|
354 //fill image with white color to have better filings with look of "paper" |
|
355 painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::white)); |
|
356 //run paint |
|
357 mStatusStrip->paint(&painter,0); |
|
358 |
|
359 #ifdef SAVE_IMAGES |
|
360 //save drawed image |
|
361 img.save("c:/unittest/TestCalenStatusStrip_testPaint.jpg"); |
|
362 |
|
363 #endif |
|
364 |
|
365 } |
|
366 |
|
367 QTEST_MAIN(TestCalenStatusStrip); |
|
368 #include "unittest_calendaystatusstrip.moc" |