45
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 |
#include <QGraphicsItem>
|
|
18 |
#include <QtTest/QtTest>
|
|
19 |
|
55
|
20 |
#include <QPainter>
|
|
21 |
#include <QImage>
|
|
22 |
#include <QGraphicsScene>
|
|
23 |
#include <hbstyleloader.h>
|
|
24 |
|
45
|
25 |
#include "calendayhourscrollarea.h"
|
|
26 |
|
55
|
27 |
const qreal WIDGET_WIDTH = 300;
|
|
28 |
const qreal WIDGET_HEIGHT = 1000;
|
|
29 |
|
45
|
30 |
class TestCalenDayHourScrollArea : public QObject
|
|
31 |
{
|
|
32 |
Q_OBJECT
|
|
33 |
|
|
34 |
public:
|
|
35 |
TestCalenDayHourScrollArea();
|
|
36 |
virtual ~TestCalenDayHourScrollArea();
|
|
37 |
|
|
38 |
private slots:
|
|
39 |
void initTestCase();
|
|
40 |
void cleanupTestCase();
|
|
41 |
void init();
|
|
42 |
void cleanup();
|
|
43 |
|
|
44 |
void testConstructors();
|
55
|
45 |
void testSetGetDateTime();
|
|
46 |
void testScrollToHour();
|
|
47 |
void testscrollVertically();
|
45
|
48 |
|
|
49 |
private:
|
|
50 |
CalenDayHourScrollArea *mHourScrollArea;
|
|
51 |
};
|
|
52 |
|
|
53 |
/*!
|
|
54 |
Constructor
|
|
55 |
*/
|
|
56 |
TestCalenDayHourScrollArea::TestCalenDayHourScrollArea() :
|
|
57 |
mHourScrollArea(NULL)
|
|
58 |
{
|
|
59 |
|
|
60 |
}
|
|
61 |
|
|
62 |
/*!
|
|
63 |
Destructor
|
|
64 |
*/
|
|
65 |
TestCalenDayHourScrollArea::~TestCalenDayHourScrollArea()
|
|
66 |
{
|
|
67 |
|
|
68 |
}
|
|
69 |
|
|
70 |
/*!
|
|
71 |
Called before testcase
|
|
72 |
*/
|
|
73 |
void TestCalenDayHourScrollArea::initTestCase()
|
|
74 |
{
|
55
|
75 |
HbStyleLoader::registerFilePath(":/calendayhourelement.css");
|
|
76 |
HbStyleLoader::registerFilePath(":/calendayhourelement.widgetml");
|
|
77 |
HbStyleLoader::registerFilePath(":/calendayitem.css");
|
|
78 |
HbStyleLoader::registerFilePath(":/calendayitem.widgetml");
|
|
79 |
HbStyleLoader::registerFilePath(":/calendayeventspane.css");
|
45
|
80 |
}
|
|
81 |
|
|
82 |
/*!
|
|
83 |
Called after testcase
|
|
84 |
*/
|
|
85 |
void TestCalenDayHourScrollArea::cleanupTestCase()
|
|
86 |
{
|
|
87 |
|
|
88 |
}
|
|
89 |
|
|
90 |
/*!
|
|
91 |
Called before every function
|
|
92 |
*/
|
|
93 |
void TestCalenDayHourScrollArea::init()
|
|
94 |
{
|
|
95 |
mHourScrollArea = new CalenDayHourScrollArea();
|
|
96 |
}
|
|
97 |
|
|
98 |
/*!
|
|
99 |
Called after everyfunction
|
|
100 |
*/
|
|
101 |
void TestCalenDayHourScrollArea::cleanup()
|
|
102 |
{
|
|
103 |
if (mHourScrollArea) {
|
|
104 |
delete mHourScrollArea;
|
|
105 |
mHourScrollArea = NULL;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
|
110 |
Test function for constructors
|
|
111 |
1. Test if hour scroll area is not initialized
|
|
112 |
2. Test if hour scroll area is correcty created
|
|
113 |
*/
|
|
114 |
void TestCalenDayHourScrollArea::testConstructors()
|
|
115 |
{
|
|
116 |
//1)
|
|
117 |
CalenDayHourScrollArea *testHourScrollArea = 0;
|
|
118 |
QVERIFY(!testHourScrollArea);
|
|
119 |
|
|
120 |
testHourScrollArea = new CalenDayHourScrollArea();
|
|
121 |
|
|
122 |
QVERIFY(testHourScrollArea);
|
|
123 |
|
|
124 |
delete testHourScrollArea;
|
|
125 |
}
|
|
126 |
|
55
|
127 |
/*!
|
|
128 |
\brief It test seting and geting datetime.
|
|
129 |
1. Test first setting datetime
|
|
130 |
2. Test datetime after change
|
|
131 |
*/
|
|
132 |
void TestCalenDayHourScrollArea::testSetGetDateTime()
|
|
133 |
{
|
|
134 |
QDateTime testValue(QDate(2010,06,29),QTime(8,42,10));
|
|
135 |
//1)
|
|
136 |
mHourScrollArea->setDateTime(testValue);
|
|
137 |
QCOMPARE(mHourScrollArea->dateTime(),testValue);
|
|
138 |
|
|
139 |
//2)
|
|
140 |
testValue = QDateTime(QDate(2011,7,30),QTime(9,43,11));
|
|
141 |
mHourScrollArea->setDateTime(testValue);
|
|
142 |
QCOMPARE(mHourScrollArea->dateTime(),testValue);
|
|
143 |
}
|
|
144 |
|
|
145 |
/*!
|
|
146 |
\brief It test scrolling to given hour.
|
|
147 |
To draw result on image uncomment SAVE_IMAGES in pro file
|
|
148 |
1. Test scroll to 0h
|
|
149 |
2. Test scroll to 12h
|
|
150 |
3. Test scroll to 20h
|
|
151 |
*/
|
|
152 |
void TestCalenDayHourScrollArea::testScrollToHour()
|
|
153 |
{
|
|
154 |
mHourScrollArea->resize(WIDGET_WIDTH,WIDGET_HEIGHT);
|
|
155 |
QGraphicsScene scene;
|
|
156 |
scene.addItem(mHourScrollArea);
|
|
157 |
QDateTime testValue(QDate(2010,06,29),QTime(8,42,10));
|
|
158 |
mHourScrollArea->setDateTime(testValue);
|
|
159 |
//resize widget to be bigger than (0,0)
|
|
160 |
QSize size = mHourScrollArea->size().toSize();
|
|
161 |
|
|
162 |
//create image that will simulate widget where painting should be done
|
|
163 |
QPixmap img(size);
|
|
164 |
//create painter which will be used to paint
|
|
165 |
QPainter painter;
|
|
166 |
|
|
167 |
//0
|
|
168 |
mHourScrollArea->scrollToHour(0);
|
|
169 |
painter.begin(&img);
|
|
170 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
171 |
//fill image with white color to have better filings with look of "paper"
|
|
172 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
173 |
scene.render(&painter);
|
|
174 |
painter.end();
|
|
175 |
#ifdef SAVE_IMAGES
|
|
176 |
//save drawed image
|
|
177 |
img.save("c:/unittest/TestCalenDayHourScrollArea_testScrollToHour_0.png");
|
|
178 |
#endif
|
|
179 |
//1
|
|
180 |
|
|
181 |
mHourScrollArea->scrollToHour(12);
|
|
182 |
painter.begin(&img);
|
|
183 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
184 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
185 |
scene.render(&painter);
|
|
186 |
painter.end();
|
|
187 |
#ifdef SAVE_IMAGES
|
|
188 |
//save drawed image
|
|
189 |
img.save("c:/unittest/TestCalenDayHourScrollArea_testScrollToHour_12.png");
|
|
190 |
#endif
|
|
191 |
//2
|
|
192 |
|
|
193 |
mHourScrollArea->scrollToHour(20);
|
|
194 |
painter.begin(&img);
|
|
195 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
196 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
197 |
scene.render(&painter);
|
|
198 |
painter.end();
|
|
199 |
#ifdef SAVE_IMAGES
|
|
200 |
//save drawed image
|
|
201 |
img.save("c:/unittest/TestCalenDayHourScrollArea_testScrollToHour_20.png");
|
|
202 |
#endif
|
|
203 |
scene.removeItem(mHourScrollArea);
|
|
204 |
}
|
|
205 |
|
|
206 |
/*!
|
|
207 |
\brief It test scrolling to vertical position.
|
|
208 |
To draw result on image uncomment SAVE_IMAGES in pro file
|
|
209 |
1. Test scroll to QPoint(0,250)
|
|
210 |
2. Test scroll to QPoint(0,500)
|
|
211 |
3. Test scroll to QPoint(0,2000)
|
|
212 |
*/
|
|
213 |
void TestCalenDayHourScrollArea::testscrollVertically()
|
|
214 |
{
|
|
215 |
mHourScrollArea->resize(WIDGET_WIDTH,WIDGET_HEIGHT);
|
|
216 |
QGraphicsScene scene;
|
|
217 |
scene.addItem(mHourScrollArea);
|
|
218 |
QDateTime testValue(QDate(2010,06,29),QTime(8,42,10));
|
|
219 |
mHourScrollArea->setDateTime(testValue);
|
|
220 |
//resize widget to be bigger than (0,0)
|
|
221 |
QSize size = mHourScrollArea->size().toSize();
|
|
222 |
|
|
223 |
//create image that will simulate widget where painting should be done
|
|
224 |
QPixmap img(size);
|
|
225 |
//create painter which will be used to paint
|
|
226 |
QPainter painter;
|
|
227 |
|
|
228 |
//0
|
|
229 |
mHourScrollArea->scrollVertically(QPoint(10,250));
|
|
230 |
painter.begin(&img);
|
|
231 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
232 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
233 |
scene.render(&painter);
|
|
234 |
painter.end();
|
|
235 |
#ifdef SAVE_IMAGES
|
|
236 |
//save drawed image
|
|
237 |
img.save("c:/unittest/TestCalenDayHourScrollArea_testscrollVertically_250.png");
|
|
238 |
#endif
|
|
239 |
//1
|
|
240 |
mHourScrollArea->scrollVertically(QPoint(10,500));
|
|
241 |
painter.begin(&img);
|
|
242 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
243 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
244 |
scene.render(&painter);
|
|
245 |
painter.end();
|
|
246 |
#ifdef SAVE_IMAGES
|
|
247 |
//save drawed image
|
|
248 |
img.save("c:/unittest/TestCalenDayHourScrollArea_testscrollVertically_500.png");
|
|
249 |
#endif
|
|
250 |
//2
|
|
251 |
mHourScrollArea->scrollVertically(QPoint(10,2000));
|
|
252 |
painter.begin(&img);
|
|
253 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
254 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
255 |
scene.render(&painter);
|
|
256 |
painter.end();
|
|
257 |
#ifdef SAVE_IMAGES
|
|
258 |
//save drawed image
|
|
259 |
img.save("c:/unittest/TestCalenDayHourScrollArea_testscrollVertically_2000.png");
|
|
260 |
#endif
|
|
261 |
scene.removeItem(mHourScrollArea);
|
|
262 |
}
|
|
263 |
|
45
|
264 |
QTEST_MAIN(TestCalenDayHourScrollArea);
|
|
265 |
#include "unittest_calendayhourscrollarea.moc"
|