|
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 CalenDayContainer |
|
15 * |
|
16 */ |
|
17 #include <QtTest/QtTest> |
|
18 |
|
19 #include <HbEffect> |
|
20 #include <HbWidget> |
|
21 #include <HbAbstractViewItem> |
|
22 |
|
23 #include "calendayinfo.h" |
|
24 #include "calendaymodel.h" |
|
25 |
|
26 #define private public |
|
27 |
|
28 |
|
29 #include "calendaycontainertest.h" |
|
30 |
|
31 QVariantList MOCK_EVENTS_LIST; |
|
32 QDateTime MOCK_EVENTS_DATE; |
|
33 |
|
34 // Test variables |
|
35 QRectF gTestWindowRect = QRectF(0, 0, 10, 20); |
|
36 Qt::Orientation gTestOrientation = Qt::Vertical; |
|
37 |
|
38 class TestCalenDayContainer : public QObject |
|
39 { |
|
40 Q_OBJECT |
|
41 |
|
42 public: |
|
43 TestCalenDayContainer(); |
|
44 virtual ~TestCalenDayContainer(); |
|
45 |
|
46 private slots: |
|
47 void initTestCase(); |
|
48 void cleanupTestCase(); |
|
49 void init(); |
|
50 void cleanup(); |
|
51 |
|
52 void testConstructors(); |
|
53 void testSetGetDayInfo(); |
|
54 void testItemAdded(); |
|
55 void testItemRemoved(); |
|
56 void testReset(); |
|
57 void testViewResized(); |
|
58 void testOrientationChanged(); |
|
59 void testCreateDefaultPrototype(); |
|
60 void testGetTimedEventLayoutValues(); |
|
61 void testCreateTouchEventAbsorbers(); |
|
62 void testCrateAbsorberBetweenSlots(); |
|
63 |
|
64 |
|
65 private: |
|
66 CalenDayContainerTest *mContainer; |
|
67 CalenDayInfo *mInfo; |
|
68 }; |
|
69 |
|
70 /*! |
|
71 Constructor |
|
72 */ |
|
73 TestCalenDayContainer::TestCalenDayContainer() : |
|
74 mContainer(NULL), mInfo(NULL) |
|
75 { |
|
76 |
|
77 } |
|
78 |
|
79 /*! |
|
80 Destructor |
|
81 */ |
|
82 TestCalenDayContainer::~TestCalenDayContainer() |
|
83 { |
|
84 |
|
85 } |
|
86 |
|
87 /*! |
|
88 Called before testcase |
|
89 */ |
|
90 void TestCalenDayContainer::initTestCase() |
|
91 { |
|
92 } |
|
93 |
|
94 /*! |
|
95 Called after testcase |
|
96 */ |
|
97 void TestCalenDayContainer::cleanupTestCase() |
|
98 { |
|
99 |
|
100 } |
|
101 |
|
102 /*! |
|
103 Called before every function |
|
104 */ |
|
105 void TestCalenDayContainer::init() |
|
106 { |
|
107 mContainer = new CalenDayContainerTest(); |
|
108 mInfo = new CalenDayInfo(CalenDayInfo::EOne); |
|
109 |
|
110 |
|
111 MOCK_EVENTS_DATE = QDateTime(QDate(12,07,2010),QTime(6,0)); |
|
112 |
|
113 QDateTime dateTimeStart1(QDate(12,07,2010),QTime(7,0)); |
|
114 QDateTime dateTimeEnd1(QDate(12,07,2010),QTime(10,0)); |
|
115 QDateTime dateTimeStart2(QDate(12,07,2010),QTime(11,0)); |
|
116 QDateTime dateTimeEnd2(QDate(12,07,2010),QTime(12,0)); |
|
117 QDateTime dateTimeStart3(QDate(12,07,2010),QTime(12,45)); |
|
118 QDateTime dateTimeEnd3(QDate(12,07,2010),QTime(18,45)); |
|
119 |
|
120 AgendaEntry entry1; |
|
121 AgendaEntry entry2; |
|
122 AgendaEntry entry3; |
|
123 |
|
124 entry1.setStartAndEndTime(dateTimeStart1,dateTimeEnd1); |
|
125 entry2.setStartAndEndTime(dateTimeStart2,dateTimeEnd2); |
|
126 entry3.setStartAndEndTime(dateTimeStart3,dateTimeEnd3); |
|
127 |
|
128 SCalenApptInfo calenInfo; |
|
129 calenInfo.iStatus = AgendaEntry::Confirmed; |
|
130 calenInfo.iId = TCalenInstanceId::create(entry1); |
|
131 mInfo->InsertAlldayEvent(calenInfo); |
|
132 mInfo->InsertAlldayEvent(calenInfo); |
|
133 |
|
134 MOCK_EVENTS_LIST << QVariant::fromValue(entry1); |
|
135 MOCK_EVENTS_LIST << QVariant::fromValue(entry2); |
|
136 MOCK_EVENTS_LIST << QVariant::fromValue(entry3); |
|
137 } |
|
138 |
|
139 /*! |
|
140 Called after everyfunction |
|
141 */ |
|
142 void TestCalenDayContainer::cleanup() |
|
143 { |
|
144 if (mContainer) { |
|
145 delete mContainer; |
|
146 mContainer = NULL; |
|
147 } |
|
148 if (mInfo) { |
|
149 delete mInfo; |
|
150 mInfo = NULL; |
|
151 } |
|
152 } |
|
153 |
|
154 /*! |
|
155 Test function for constructors |
|
156 1. Test if container is not initialized |
|
157 2. Test if container is correcty created |
|
158 */ |
|
159 void TestCalenDayContainer::testConstructors() |
|
160 { |
|
161 //1) |
|
162 CalenDayContainerTest *testContainer = 0; |
|
163 QVERIFY(!testContainer); |
|
164 |
|
165 //2) |
|
166 testContainer = new CalenDayContainerTest(); |
|
167 QVERIFY(testContainer); |
|
168 |
|
169 delete testContainer; |
|
170 } |
|
171 |
|
172 /*! |
|
173 Test function to check set and get day info |
|
174 Test after set if info day is good |
|
175 */ |
|
176 void TestCalenDayContainer::testSetGetDayInfo() |
|
177 { |
|
178 QVERIFY(mContainer->dayInfo() ==0); |
|
179 mContainer->setDayInfo(mInfo); |
|
180 |
|
181 QVERIFY(mContainer->dayInfo()!=0); |
|
182 } |
|
183 |
|
184 /*! |
|
185 Function not implemented |
|
186 */ |
|
187 void TestCalenDayContainer::testItemAdded() |
|
188 { |
|
189 //function dosen't do nothing. It will be updated after code changes |
|
190 } |
|
191 |
|
192 /*! |
|
193 Function not implemented |
|
194 */ |
|
195 void TestCalenDayContainer::testItemRemoved() |
|
196 { |
|
197 //function dosen't do nothing. It will be updated after code changes |
|
198 } |
|
199 |
|
200 /*! |
|
201 Test reset of caontainer based on absorders |
|
202 */ |
|
203 void TestCalenDayContainer::testReset() |
|
204 { |
|
205 QVERIFY(mContainer->mAbsorbers.count() == 0); |
|
206 mContainer->mAbsorbers << mContainer->crateAbsorberBetweenSlots(0,1,false); |
|
207 QVERIFY(mContainer->mAbsorbers.count() == 1); |
|
208 mContainer->reset(); |
|
209 QVERIFY(mContainer->mAbsorbers.count() == 0); |
|
210 } |
|
211 |
|
212 /*! |
|
213 Test is view of container is good resized. |
|
214 1)test if size is changed |
|
215 2)test if new size is good set |
|
216 */ |
|
217 void TestCalenDayContainer::testViewResized() |
|
218 { |
|
219 QSizeF size = mContainer->size(); |
|
220 //set new size |
|
221 QSizeF newSize(size.width()+100,size.height()+100); |
|
222 mContainer->viewResized(newSize); |
|
223 //1) |
|
224 QVERIFY(size != mContainer->size()); |
|
225 //2) |
|
226 QCOMPARE(mContainer->size(),newSize); |
|
227 } |
|
228 |
|
229 /*! |
|
230 It test change of orientation based on count of absorbers |
|
231 */ |
|
232 void TestCalenDayContainer::testOrientationChanged() |
|
233 { |
|
234 mContainer->setDayInfo(mInfo); |
|
235 QVERIFY(mContainer->mAbsorbers.count() == 0); |
|
236 |
|
237 mContainer->orientationChanged(Qt::Vertical); |
|
238 |
|
239 QVERIFY(mContainer->mAbsorbers.count() != 0); |
|
240 } |
|
241 |
|
242 /*! |
|
243 Test creating item prototype |
|
244 */ |
|
245 void TestCalenDayContainer::testCreateDefaultPrototype() |
|
246 { |
|
247 HbAbstractViewItem *testItem = 0; |
|
248 QVERIFY(!testItem); |
|
249 |
|
250 testItem = mContainer->createDefaultPrototype(); |
|
251 |
|
252 QVERIFY(testItem); |
|
253 |
|
254 delete testItem; |
|
255 } |
|
256 |
|
257 /*! |
|
258 Test geting timed layouts. |
|
259 */ |
|
260 void TestCalenDayContainer::testGetTimedEventLayoutValues() |
|
261 { |
|
262 CalenDayContainer::LayoutValues layoutValues; |
|
263 |
|
264 QVERIFY(layoutValues.eventAreaWidth == 0); |
|
265 QVERIFY(layoutValues.eventAreaX == 0); |
|
266 QVERIFY(layoutValues.eventMargin == 0); |
|
267 QVERIFY(layoutValues.maxColumns == 0); |
|
268 QVERIFY(layoutValues.slotHeight == 0); |
|
269 QVERIFY(layoutValues.unitInPixels == 0); |
|
270 |
|
271 mContainer->getTimedEventLayoutValues(layoutValues); |
|
272 |
|
273 QVERIFY(layoutValues.eventAreaWidth != 0); |
|
274 QVERIFY(layoutValues.eventAreaX == 0); |
|
275 QVERIFY(layoutValues.eventMargin != 0); |
|
276 QVERIFY(layoutValues.maxColumns != 0); |
|
277 QVERIFY(layoutValues.slotHeight != 0); |
|
278 QVERIFY(layoutValues.unitInPixels != 0); |
|
279 } |
|
280 |
|
281 /*! |
|
282 Test creating touch event absorbers. |
|
283 */ |
|
284 void TestCalenDayContainer::testCreateTouchEventAbsorbers() |
|
285 { |
|
286 mContainer->setDayInfo(mInfo); |
|
287 QVERIFY(mContainer->mAbsorbers.count() == 0); |
|
288 mContainer->createTouchEventAbsorbers(); |
|
289 QVERIFY(mContainer->mAbsorbers.count() != 0); |
|
290 } |
|
291 |
|
292 /*! |
|
293 test creating touch absorber beatween slots. |
|
294 */ |
|
295 void TestCalenDayContainer::testCrateAbsorberBetweenSlots() |
|
296 { |
|
297 TouchEventAbsorber* testValue = 0; |
|
298 QVERIFY(!testValue); |
|
299 testValue = mContainer->crateAbsorberBetweenSlots(0,1,false); |
|
300 QVERIFY(testValue); |
|
301 delete testValue; |
|
302 } |
|
303 |
|
304 |
|
305 QTEST_MAIN(TestCalenDayContainer); |
|
306 #include "unittest_calendaycontainer.moc" |