100 Test class for constructors |
101 Test class for constructors |
101 1. Test if content widget is correcty created |
102 1. Test if content widget is correcty created |
102 */ |
103 */ |
103 void TestCalenContentWidget::testConstructors() |
104 void TestCalenContentWidget::testConstructors() |
104 { |
105 { |
105 QVERIFY(!mContentWidget); |
106 CalenDayContentWidget *contentWidget = NULL; |
106 mContentWidget = new CalenDayContentWidget(*mModelMgr); |
107 |
107 QVERIFY(mContentWidget); |
108 QVERIFY(!contentWidget); |
|
109 contentWidget = new CalenDayContentWidget(); |
|
110 QVERIFY(contentWidget); |
|
111 |
|
112 delete contentWidget; |
|
113 } |
|
114 |
|
115 /*! |
|
116 Test add() function |
|
117 1. Test no error when trying to add NULL pointer |
|
118 2. Test if widget is added correctly and layout is created |
|
119 3. Test if widget is added correctly at end of list |
|
120 4. Test if widget is added correctly as first item |
|
121 5. Test if widget is added correctly when no position is specified |
|
122 */ |
|
123 void TestCalenContentWidget::testAdd() |
|
124 { |
|
125 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
126 QVERIFY(!mContentWidget->mLayout); |
|
127 |
|
128 //1) |
|
129 mContentWidget->add(NULL); |
|
130 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
131 QVERIFY(!mContentWidget->mLayout); |
|
132 |
|
133 //2) |
|
134 HbWidget *second = new HbWidget(); |
|
135 mContentWidget->add(second); |
|
136 QVERIFY(mContentWidget->mLayout); |
|
137 QCOMPARE(mContentWidget->mWidgets.count(), 1); |
|
138 |
|
139 //3) |
|
140 HbWidget *last = new HbWidget(); |
|
141 mContentWidget->add(last, CalenDayContentWidget::ECalenLastWidget); |
|
142 QCOMPARE(mContentWidget->mWidgets.count(), 2); |
|
143 QCOMPARE(mContentWidget->mWidgets.at(1), last); |
|
144 |
|
145 //4) |
|
146 HbWidget *first = new HbWidget(); |
|
147 mContentWidget->add(first, CalenDayContentWidget::ECalenFirstWidget); |
|
148 QCOMPARE(mContentWidget->mWidgets.count(), 3); |
|
149 QCOMPARE(mContentWidget->mWidgets.at(0), first); |
|
150 |
|
151 //5) |
|
152 HbWidget *other = new HbWidget(); |
|
153 mContentWidget->add(other, CalenDayContentWidget::CalenWidgetPosition(-1)); |
|
154 QCOMPARE(mContentWidget->mWidgets.count(), 4); |
|
155 QCOMPARE(mContentWidget->mWidgets.last(), other); |
|
156 } |
|
157 |
|
158 /*! |
|
159 Test take() function |
|
160 1. Test NULL pointer if there are no widgets to be taken |
|
161 2. Test if first widget is taken correctly |
|
162 3. Test if last widget is taken correctly |
|
163 4. Test default behavior if wrong position is specified |
|
164 */ |
|
165 void TestCalenContentWidget::testTake() |
|
166 { |
|
167 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
168 |
|
169 //1) |
|
170 QVERIFY(!mContentWidget->take(CalenDayContentWidget::ECalenFirstWidget)); |
|
171 |
|
172 // Prepare data |
|
173 HbWidget *first = new HbWidget(); |
|
174 HbWidget *second = new HbWidget(); |
|
175 HbWidget *last = new HbWidget(); |
|
176 mContentWidget->add(first); |
|
177 mContentWidget->add(second); |
|
178 mContentWidget->add(last); |
|
179 QCOMPARE(mContentWidget->mWidgets.count(), 3); |
|
180 |
|
181 //2) |
|
182 HbWidget *widget = mContentWidget->take(CalenDayContentWidget::ECalenFirstWidget); |
|
183 QCOMPARE(mContentWidget->mWidgets.count(), 2); |
|
184 QCOMPARE(widget, first); |
|
185 |
|
186 delete widget; |
|
187 widget = NULL; |
|
188 |
|
189 //3) |
|
190 widget = mContentWidget->take(CalenDayContentWidget::ECalenLastWidget); |
|
191 QCOMPARE(mContentWidget->mWidgets.count(), 1); |
|
192 QCOMPARE(widget, last); |
|
193 |
|
194 delete widget; |
|
195 widget = NULL; |
|
196 |
|
197 //4) |
|
198 widget = mContentWidget->take(CalenDayContentWidget::CalenWidgetPosition(-1)); |
|
199 QCOMPARE(mContentWidget->mWidgets.count(), 1); |
|
200 QVERIFY(!widget); |
|
201 } |
|
202 |
|
203 /*! |
|
204 Test remove() function |
|
205 1. Test if there is no error if remove is called on empty content |
|
206 2. Test if first widget is removed correctly |
|
207 3. Test if last widget is removed correctly |
|
208 */ |
|
209 void TestCalenContentWidget::testRemove() |
|
210 { |
|
211 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
212 |
|
213 //1) |
|
214 mContentWidget->remove(CalenDayContentWidget::ECalenFirstWidget); |
|
215 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
216 |
|
217 // Prepare data |
|
218 HbWidget *first = new HbWidget(); |
|
219 HbWidget *second = new HbWidget(); |
|
220 HbWidget *last = new HbWidget(); |
|
221 mContentWidget->add(first); |
|
222 mContentWidget->add(second); |
|
223 mContentWidget->add(last); |
|
224 QCOMPARE(mContentWidget->mWidgets.count(), 3); |
|
225 |
|
226 //2) |
|
227 mContentWidget->remove(CalenDayContentWidget::ECalenFirstWidget); |
|
228 QCOMPARE(mContentWidget->mWidgets.count(), 2); |
|
229 QCOMPARE(mContentWidget->mWidgets.first(), second); |
|
230 |
|
231 //3) |
|
232 mContentWidget->remove(CalenDayContentWidget::ECalenLastWidget); |
|
233 QCOMPARE(mContentWidget->mWidgets.count(), 1); |
|
234 QCOMPARE(mContentWidget->mWidgets.last(), second); |
|
235 } |
|
236 |
|
237 /*! |
|
238 Test relayoutWidgets() slot |
|
239 1. Test if relayout widgets on empty content |
|
240 2. Test ECalenScrollToNext case |
|
241 3. Test ECalenScrollToPrev case |
|
242 4. Test ECalenScrollNoDayChange case |
|
243 5. Test wrong case |
|
244 */ |
|
245 void TestCalenContentWidget::testRelayoutWidgets() |
|
246 { |
|
247 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
248 |
|
249 //1) |
|
250 mContentWidget->relayoutWidgets(ECalenScrollNoDayChange); |
|
251 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
252 |
|
253 // Prepare data |
|
254 HbWidget *first = new HbWidget(); |
|
255 HbWidget *second = new HbWidget(); |
|
256 HbWidget *last = new HbWidget(); |
|
257 mContentWidget->add(first); |
|
258 mContentWidget->add(second); |
|
259 mContentWidget->add(last); |
|
260 QCOMPARE(mContentWidget->mWidgets.count(), 3); |
|
261 |
|
262 //2) |
|
263 mContentWidget->relayoutWidgets(ECalenScrollToNext); |
|
264 QCOMPARE(mContentWidget->mWidgets.first(), second); |
|
265 |
|
266 //3) |
|
267 mContentWidget->relayoutWidgets(ECalenScrollToPrev); |
|
268 QCOMPARE(mContentWidget->mWidgets.first(), first); |
|
269 |
|
270 //4) |
|
271 mContentWidget->relayoutWidgets(ECalenScrollNoDayChange); |
|
272 QCOMPARE(mContentWidget->mWidgets.first(), first); |
|
273 |
|
274 //5) |
|
275 mContentWidget->relayoutWidgets(CalenScrollDirection(-1)); |
|
276 QCOMPARE(mContentWidget->mWidgets.first(), first); |
|
277 } |
|
278 |
|
279 /*! |
|
280 Test testWidgetScrolled() slot |
|
281 1. Test widgetScrolled with empty content |
|
282 2. Test widgetScrolled with 3 views |
|
283 */ |
|
284 void TestCalenContentWidget::testWidgetScrolled() |
|
285 { |
|
286 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
287 QPointF newPos(10, 20); |
|
288 |
|
289 //1) |
|
290 mContentWidget->widgetScrolled(newPos); |
|
291 QCOMPARE(mContentWidget->mWidgets.count(), 0); |
|
292 |
|
293 #ifndef __WINSCW__ |
|
294 // Prepare data |
|
295 MCalenServices services; |
|
296 HbModelIterator iterator(0); |
|
297 CalenDayItemView *first = new CalenDayItemView(services, &iterator); |
|
298 CalenDayItemView *second = new CalenDayItemView(services, &iterator); |
|
299 CalenDayItemView *last = new CalenDayItemView(services, &iterator); |
|
300 mContentWidget->add(first); |
|
301 mContentWidget->add(second); |
|
302 mContentWidget->add(last); |
|
303 QCOMPARE(mContentWidget->mWidgets.count(), 3); |
|
304 QCOMPARE(first->mCurrentPos, QPointF(0,0)); |
|
305 QCOMPARE(second->mCurrentPos, QPointF(0,0)); |
|
306 QCOMPARE(last->mCurrentPos, QPointF(0,0)); |
|
307 |
|
308 //2 |
|
309 mContentWidget->widgetScrolled(newPos); |
|
310 CalenDayItemView *view = static_cast<CalenDayItemView *> (mContentWidget->mWidgets.at(0)); |
|
311 QCOMPARE(view->mCurrentPos, newPos); |
|
312 view = static_cast<CalenDayItemView *> (mContentWidget->mWidgets.at(1)); |
|
313 QCOMPARE(view->mCurrentPos, newPos); |
|
314 view = static_cast<CalenDayItemView *> (mContentWidget->mWidgets.at(2)); |
|
315 QCOMPARE(view->mCurrentPos, newPos); |
|
316 #endif // __WINSCW__ |
108 } |
317 } |
109 |
318 |
110 QTEST_MAIN(TestCalenContentWidget); |
319 QTEST_MAIN(TestCalenContentWidget); |
111 #include "unittest_calendaycontentwidget.moc" |
320 #include "unittest_calendaycontentwidget.moc" |