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