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 |
|
57
|
20 |
#include "hbstyle.h"
|
45
|
21 |
#include "calendayutils.h"
|
55
|
22 |
#include "hbdeviceprofile.h"
|
45
|
23 |
#include "calendaycommonheaders.h"
|
81
|
24 |
#include "agendaentry.h"
|
45
|
25 |
|
|
26 |
// Test variables
|
|
27 |
QRectF gTestWindowRect = QRectF(0, 0, 10, 20);
|
|
28 |
Qt::Orientation gTestOrientation = Qt::Horizontal;
|
55
|
29 |
qreal param_value = 10;
|
57
|
30 |
qreal unitInPix = 1;
|
45
|
31 |
|
|
32 |
class TestCalenDayUtils : public QObject
|
81
|
33 |
{
|
45
|
34 |
Q_OBJECT
|
|
35 |
|
|
36 |
public:
|
81
|
37 |
TestCalenDayUtils();
|
|
38 |
virtual ~TestCalenDayUtils();
|
45
|
39 |
|
|
40 |
private slots:
|
81
|
41 |
void initTestCase();
|
|
42 |
void cleanupTestCase();
|
|
43 |
void init();
|
|
44 |
void cleanup();
|
45
|
45 |
|
81
|
46 |
void testInstance();
|
|
47 |
void testScreenWidth();
|
83
|
48 |
void testScreenHeight();
|
81
|
49 |
void testHourElementWidth();
|
|
50 |
void testHourElementHeight();
|
|
51 |
void testContentWidth();
|
|
52 |
void testMinEventHeight();
|
|
53 |
void testMainWindow();
|
|
54 |
void testGetEventValidStartEndTime();
|
55
|
55 |
|
81
|
56 |
void testConstructors();
|
|
57 |
void testOrientation();
|
45
|
58 |
|
|
59 |
private:
|
81
|
60 |
CalenDayUtils *mUtils;
|
|
61 |
qreal mUnit;
|
|
62 |
};
|
45
|
63 |
|
|
64 |
/*!
|
|
65 |
Constructor
|
|
66 |
*/
|
|
67 |
TestCalenDayUtils::TestCalenDayUtils() :
|
81
|
68 |
mUtils(NULL)
|
|
69 |
{
|
|
70 |
HbDeviceProfile s;
|
|
71 |
mUnit = s.unitValue();
|
|
72 |
}
|
45
|
73 |
|
|
74 |
/*!
|
|
75 |
Destructor
|
|
76 |
*/
|
|
77 |
TestCalenDayUtils::~TestCalenDayUtils()
|
81
|
78 |
{
|
45
|
79 |
|
81
|
80 |
}
|
45
|
81 |
|
|
82 |
/*!
|
|
83 |
Called before testcase
|
|
84 |
*/
|
|
85 |
void TestCalenDayUtils::initTestCase()
|
81
|
86 |
{
|
|
87 |
}
|
45
|
88 |
|
|
89 |
/*!
|
|
90 |
Called after testcase
|
|
91 |
*/
|
|
92 |
void TestCalenDayUtils::cleanupTestCase()
|
81
|
93 |
{
|
|
94 |
}
|
45
|
95 |
|
|
96 |
/*!
|
|
97 |
Called before every function
|
|
98 |
*/
|
|
99 |
void TestCalenDayUtils::init()
|
81
|
100 |
{
|
|
101 |
mUtils = CalenDayUtils::instance();
|
|
102 |
}
|
45
|
103 |
|
|
104 |
/*!
|
|
105 |
Called after everyfunction
|
|
106 |
*/
|
|
107 |
void TestCalenDayUtils::cleanup()
|
81
|
108 |
{
|
|
109 |
//delete mUtils;
|
|
110 |
}
|
55
|
111 |
|
|
112 |
void TestCalenDayUtils::testInstance()
|
81
|
113 |
{
|
|
114 |
CalenDayUtils* utils = CalenDayUtils::instance();
|
|
115 |
QVERIFY(utils);
|
|
116 |
}
|
55
|
117 |
|
|
118 |
void TestCalenDayUtils::testScreenWidth()
|
81
|
119 |
{
|
|
120 |
qreal sw = mUtils->screenWidth();
|
|
121 |
QVERIFY(sw == gTestWindowRect.width());
|
|
122 |
}
|
55
|
123 |
|
83
|
124 |
void TestCalenDayUtils::testScreenHeight()
|
|
125 |
{
|
|
126 |
qreal sw = mUtils->screenHeight();
|
|
127 |
QVERIFY(sw == gTestWindowRect.height());
|
|
128 |
}
|
|
129 |
|
55
|
130 |
void TestCalenDayUtils::testHourElementWidth()
|
81
|
131 |
{
|
|
132 |
qreal hEW = mUtils->hourElementWidth();
|
|
133 |
qreal myWidth = mUnit * 8.04 + param_value * 2;
|
|
134 |
|
|
135 |
QCOMPARE(hEW, myWidth);
|
|
136 |
|
|
137 |
}
|
55
|
138 |
|
|
139 |
void TestCalenDayUtils::testHourElementHeight()
|
81
|
140 |
{
|
|
141 |
|
|
142 |
qreal hEH = mUtils->hourElementHeight();
|
83
|
143 |
qreal myHeight = mUnit * 5 + param_value * 2 + param_value * 2;
|
81
|
144 |
|
|
145 |
QCOMPARE(hEH, myHeight);
|
|
146 |
}
|
55
|
147 |
|
|
148 |
void TestCalenDayUtils::testContentWidth()
|
81
|
149 |
{
|
|
150 |
qreal cW = mUtils->contentWidth();
|
|
151 |
qreal myWidth = gTestWindowRect.width() - (mUnit * 8.04 + param_value * 2);
|
|
152 |
|
|
153 |
QCOMPARE(cW, myWidth);
|
|
154 |
}
|
|
155 |
|
|
156 |
/*!
|
|
157 |
Test function for minimum event's height
|
|
158 |
*/
|
|
159 |
void TestCalenDayUtils::testMinEventHeight()
|
|
160 |
{
|
|
161 |
qreal minH = mUtils->minEventHeight();
|
|
162 |
qreal myH = param_value + param_value + param_value;
|
|
163 |
|
|
164 |
QCOMPARE(minH, myH);
|
|
165 |
}
|
|
166 |
|
|
167 |
/*!
|
|
168 |
Test function for main window getter
|
|
169 |
*/
|
|
170 |
void TestCalenDayUtils::testMainWindow()
|
|
171 |
{
|
|
172 |
HbMainWindow *window = NULL;
|
|
173 |
QVERIFY(!window);
|
|
174 |
|
|
175 |
window = mUtils->mainWindow();
|
|
176 |
QVERIFY(window);
|
|
177 |
}
|
55
|
178 |
|
81
|
179 |
/*!
|
|
180 |
Test function for getEventValidStartEndTime function
|
|
181 |
1) start and end time are in current day: event start - end
|
|
182 |
2) start time is yesterday, end time is in current day: event 0.00 - end
|
|
183 |
3) start time is yesterday, end time is tomorrow: event 0.00 - 23.59
|
|
184 |
*/
|
|
185 |
void TestCalenDayUtils::testGetEventValidStartEndTime()
|
|
186 |
{
|
|
187 |
QDateTime currentDate(QDate(2010, 9, 5), QTime(8, 15));
|
|
188 |
|
|
189 |
//1)
|
|
190 |
QDateTime inStart = currentDate.addSecs(-3600); // currentTime - 1 hour
|
|
191 |
QDateTime inEnd = currentDate.addSecs(3600); // currentTime + 1 hour
|
|
192 |
|
|
193 |
AgendaEntry entry;
|
|
194 |
entry.setStartAndEndTime(inStart, inEnd);
|
|
195 |
|
|
196 |
QDateTime outStart;
|
|
197 |
QDateTime outEnd;
|
|
198 |
mUtils->getEventValidStartEndTime(outStart, outEnd, entry, currentDate);
|
|
199 |
QCOMPARE(outStart, inStart);
|
|
200 |
QCOMPARE(outEnd, inEnd);
|
|
201 |
|
|
202 |
//2)
|
|
203 |
inStart = currentDate.addDays(-1); // currentTime - 1 day
|
|
204 |
inEnd = currentDate.addSecs(3600); // currentTime + 1 hour
|
|
205 |
|
|
206 |
entry.setStartAndEndTime(inStart, inEnd);
|
|
207 |
|
|
208 |
mUtils->getEventValidStartEndTime(outStart, outEnd, entry, currentDate);
|
|
209 |
QCOMPARE(outStart, QDateTime(currentDate.date(), QTime(0, 0, 0, 0)));
|
|
210 |
QCOMPARE(outEnd, inEnd);
|
|
211 |
|
|
212 |
//3)
|
|
213 |
inStart = currentDate.addDays(-1); // currentTime - 1 day
|
|
214 |
inEnd = currentDate.addDays(1); // currentTime + 1 day
|
|
215 |
|
|
216 |
entry.setStartAndEndTime(inStart, inEnd);
|
|
217 |
|
|
218 |
mUtils->getEventValidStartEndTime(outStart, outEnd, entry, currentDate);
|
|
219 |
QCOMPARE(outStart, QDateTime(currentDate.date(), QTime(0, 0, 0, 0)));
|
|
220 |
QCOMPARE(outEnd, QDateTime(currentDate.date(), QTime(23, 59, 0, 0)));
|
|
221 |
}
|
45
|
222 |
|
|
223 |
/*!
|
|
224 |
Test function for constructors
|
|
225 |
1. Test if content widget is not initialized
|
|
226 |
2. Test if content widget is correcty created
|
|
227 |
*/
|
|
228 |
void TestCalenDayUtils::testConstructors()
|
81
|
229 |
{
|
|
230 |
//1)
|
|
231 |
CalenDayUtils *testUtils = 0;
|
|
232 |
QVERIFY(!testUtils);
|
55
|
233 |
|
81
|
234 |
//2)
|
|
235 |
testUtils = CalenDayUtils::instance();
|
|
236 |
QVERIFY(testUtils);
|
|
237 |
}
|
45
|
238 |
|
|
239 |
/*!
|
55
|
240 |
Test function for getting main window's orientation
|
|
241 |
1)test if horizontal orientation is returned
|
|
242 |
2)test if vertical orientation is returned
|
45
|
243 |
*/
|
|
244 |
void TestCalenDayUtils::testOrientation()
|
81
|
245 |
{
|
|
246 |
//1)
|
|
247 |
gTestOrientation = Qt::Horizontal;
|
|
248 |
QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Horizontal);
|
55
|
249 |
|
81
|
250 |
//2)
|
|
251 |
gTestOrientation = Qt::Vertical;
|
|
252 |
QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Vertical);
|
|
253 |
}
|
45
|
254 |
|
|
255 |
QTEST_MAIN(TestCalenDayUtils);
|
|
256 |
#include "unittest_calendayutils.moc"
|