|
1 /* |
|
2 * Copyright (c) 2007 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: Unit tests |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "ut_CGlxNavigableList.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 #include <digia/eunit/eunitdecorators.h> |
|
27 |
|
28 // INTERNAL INCLUDES |
|
29 #include "glxnavigablelist.h" |
|
30 |
|
31 using namespace NGlxListDefs; |
|
32 |
|
33 const TNotification::TData KNotificationsList_Empty[] = { { END_MARKER } }; |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // Constructors |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CGlxNavigableListReconstruction* CGlxNavigableListReconstruction::NewL( TInt aReservationCount ) |
|
40 { |
|
41 CGlxNavigableListReconstruction* self = new (ELeave) CGlxNavigableListReconstruction(); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL( aReservationCount ); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // Test if reconstruction equals original |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 TBool CGlxNavigableListReconstruction::ReconstructionEquals() const |
|
53 { |
|
54 // test items |
|
55 TBool fail = !ItemsEqual(); |
|
56 // test focus |
|
57 fail |= ( iList->FocusIndex() != iFocusIndex ); |
|
58 // test selection |
|
59 fail |= !SelectionEquals(); |
|
60 |
|
61 return !fail; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // Test if reconstruction of selection equals original |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 TBool CGlxNavigableListReconstruction::SelectionEquals() const |
|
69 { |
|
70 TBool fail = ( iList->SelectedItemIndices().Count() != iSelectedItemIndices.Count() ); |
|
71 |
|
72 // Don't assume order in arrays is the same: make sure all items in replica |
|
73 // exist in original, and all items in original are in replica |
|
74 for ( TInt i = 0; i < iSelectedItemIndices.Count(); i++ ) |
|
75 { |
|
76 // Try to find replica index from original |
|
77 fail |= ( KErrNotFound == FindInOriginalSelection( iSelectedItemIndices[ i ] ) ); |
|
78 } |
|
79 |
|
80 for ( TInt i = 0; i < iList->SelectedItemIndices().Count(); i++ ) |
|
81 { |
|
82 fail |= ( KErrNotFound == iSelectedItemIndices.Find( iList->SelectedItemIndices()[ i ] ) ); |
|
83 } |
|
84 |
|
85 return !fail; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // Return index of selected item index in original list |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt CGlxNavigableListReconstruction::FindInOriginalSelection( TInt aSelectionIndex ) const |
|
93 { |
|
94 TInt i = 0; |
|
95 while ( i < iList->SelectedItemIndices().Count() ) |
|
96 { |
|
97 TInt originalIndex = iList->SelectedItemIndices()[ i ]; |
|
98 if ( originalIndex == aSelectionIndex ) |
|
99 { |
|
100 return i; // Found it |
|
101 } |
|
102 i++; |
|
103 } |
|
104 return KErrNotFound; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // Constructors & destructors |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 ut_CGlxNavigableList* ut_CGlxNavigableList::NewL() |
|
112 { |
|
113 ut_CGlxNavigableList* self = ut_CGlxNavigableList::NewLC(); |
|
114 CleanupStack::Pop(); |
|
115 |
|
116 return self; |
|
117 } |
|
118 |
|
119 ut_CGlxNavigableList* ut_CGlxNavigableList::NewLC() |
|
120 { |
|
121 ut_CGlxNavigableList* self = new( ELeave ) ut_CGlxNavigableList(); |
|
122 CleanupStack::PushL( self ); |
|
123 |
|
124 self->ConstructL(); |
|
125 |
|
126 return self; |
|
127 } |
|
128 |
|
129 // Destructor (virtual by CBase) |
|
130 ut_CGlxNavigableList::~ut_CGlxNavigableList() |
|
131 { |
|
132 } |
|
133 |
|
134 // Default constructor |
|
135 ut_CGlxNavigableList::ut_CGlxNavigableList() |
|
136 { |
|
137 } |
|
138 |
|
139 // Second phase construct |
|
140 void ut_CGlxNavigableList::ConstructL() |
|
141 { |
|
142 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
143 // It generates the test case table. |
|
144 CEUnitTestSuiteClass::ConstructL(); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // Setup & Teardown |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void ut_CGlxNavigableList::SetupL( ) |
|
152 { |
|
153 } |
|
154 |
|
155 void ut_CGlxNavigableList::Teardown( ) |
|
156 { |
|
157 DeleteMembers(); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // Test FocusIndex(...) |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void ut_CGlxNavigableList::T_FocusIndexL( ) |
|
165 { |
|
166 CreateListL( _L8("") ); |
|
167 EUNIT_ASSERT ( KErrNotFound == iList->FocusIndex() ); |
|
168 CreateListL( _L8("ab") ); |
|
169 EUNIT_ASSERT ( 0 == iList->FocusIndex() ); |
|
170 iList->SetFocus( EAbsolute, 1 ); |
|
171 EUNIT_ASSERT ( 1 == iList->FocusIndex() ); |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // TrySetFocusL |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TBool ut_CGlxNavigableList::TrySetFocusL( const TDesC8& aContents, |
|
179 TInt aInitialFocus, TFocusSetType aFocusSetType, |
|
180 TInt aFocusValue, TInt aExpectedFocus, |
|
181 const TNotification::TData* aNotificationList ) |
|
182 { |
|
183 CreateListL( aContents ); |
|
184 // We need to set the focus to aInitialFocus only if it's valid |
|
185 if ( KErrNotFound != aInitialFocus ) |
|
186 { |
|
187 iList->SetFocus( EAbsolute, aInitialFocus ); |
|
188 } |
|
189 iReconstruction->ClearNotifications(); |
|
190 // Set focus |
|
191 iList->SetFocus( aFocusSetType, aFocusValue ); |
|
192 TBool fail = ( iList->FocusIndex() != aExpectedFocus ); |
|
193 fail |= !iReconstruction->ReconstructionEquals(); |
|
194 fail |= !iReconstruction->NotificationListEquals( aNotificationList ); |
|
195 return !fail; |
|
196 |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // Test SetFocus(...) |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void ut_CGlxNavigableList::T_SetFocusL( ) |
|
204 { |
|
205 { // Test setting focus to same index |
|
206 // absolute |
|
207 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 1, EAbsolute, 1, |
|
208 1, KNotificationsList_Empty ) ); |
|
209 // relative |
|
210 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 1, ERelative, 0, |
|
211 1, KNotificationsList_Empty ) ); |
|
212 } |
|
213 |
|
214 { // Test setting focus to another index |
|
215 TNotification::TData notifications[] = |
|
216 { { END_MARKER } }; |
|
217 // absolute |
|
218 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 1, EAbsolute, 1, |
|
219 1, notifications ) ); |
|
220 // relative |
|
221 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 1, ERelative, 0, |
|
222 1, notifications ) ); |
|
223 } |
|
224 |
|
225 { // Test setting focus to directly another index |
|
226 TNotification::TData notifications[] = |
|
227 { { TNotification::EFocus, 0, EUnknown }, // type, old focus, focus change type |
|
228 { END_MARKER } }; |
|
229 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 0, EAbsolute, 1, |
|
230 1, notifications ) ); |
|
231 } |
|
232 |
|
233 // Test moving focus |
|
234 { // Non-looping, 0 > 2 |
|
235 TNotification::TData notifications[] = |
|
236 { { TNotification::EFocus, 0, EForward }, // type, old focus, focus change type |
|
237 { END_MARKER } }; |
|
238 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 0, ERelative, 2, |
|
239 2, notifications ) ); |
|
240 } |
|
241 |
|
242 { // Non-looping, 1 > 4 |
|
243 TNotification::TData notifications[] = |
|
244 { { TNotification::EFocus, 1, EForward }, // type, old focus, focus change type |
|
245 { END_MARKER } }; |
|
246 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 1, ERelative, 3, |
|
247 4, notifications ) ); |
|
248 } |
|
249 |
|
250 { // Non-looping, 4 > 0 |
|
251 TNotification::TData notifications[] = |
|
252 { { TNotification::EFocus, 4, EBackward }, // type, old focus, focus change type |
|
253 { END_MARKER } }; |
|
254 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 4, ERelative, -4, |
|
255 0, notifications ) ); |
|
256 } |
|
257 |
|
258 { // Looping, 4 > 0 |
|
259 TNotification::TData notifications[] = |
|
260 { { TNotification::EFocus, 4, EForward }, // type, old focus, focus change type |
|
261 { END_MARKER } }; |
|
262 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 4, ERelative, 1, |
|
263 0, notifications ) ); |
|
264 } |
|
265 |
|
266 { // Looping, 2 > 3 |
|
267 TNotification::TData notifications[] = |
|
268 { { TNotification::EFocus, 2, EForward }, // type, old focus, focus change type |
|
269 { END_MARKER } }; |
|
270 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 2, ERelative, 6, |
|
271 3, notifications ) ); |
|
272 } |
|
273 |
|
274 { // Looping, 3 > 2 |
|
275 TNotification::TData notifications[] = |
|
276 { { TNotification::EFocus, 3, EBackward }, // type, old focus, focus change type |
|
277 { END_MARKER } }; |
|
278 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 3, ERelative, -1, |
|
279 2, notifications ) ); |
|
280 } |
|
281 |
|
282 { // Looping, 2 > 2 |
|
283 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 2, ERelative, 5, |
|
284 2, KNotificationsList_Empty ) ); |
|
285 } |
|
286 |
|
287 { // Looping, 2 > 2 |
|
288 EUNIT_ASSERT ( TrySetFocusL( _L8("abcde"), 2, ERelative, -5, |
|
289 2, KNotificationsList_Empty ) ); |
|
290 } |
|
291 |
|
292 { // empty list |
|
293 EUNIT_ASSERT ( TrySetFocusL( _L8(""), -1, ERelative, -5, |
|
294 -1, KNotificationsList_Empty ) ); |
|
295 } |
|
296 |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // Test IsSelected(...) |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 void ut_CGlxNavigableList::T_IsSelectedL( ) |
|
304 { |
|
305 CreateListL( _L8("abcde") ); |
|
306 EUNIT_ASSERT( !iList->IsSelected( 0 ) ); |
|
307 EUNIT_ASSERT( !iList->IsSelected( 1 ) ); |
|
308 EUNIT_ASSERT( !iList->IsSelected( 2 ) ); |
|
309 EUNIT_ASSERT( !iList->IsSelected( 3 ) ); |
|
310 EUNIT_ASSERT( !iList->IsSelected( 4 ) ); |
|
311 iList->SetSelectedL( 3, ETrue ); |
|
312 iList->SetSelectedL( 0, ETrue ); |
|
313 iList->SetSelectedL( 4, ETrue ); |
|
314 EUNIT_ASSERT( iList->IsSelected( 0 ) ); |
|
315 EUNIT_ASSERT( !iList->IsSelected( 1 ) ); |
|
316 EUNIT_ASSERT( !iList->IsSelected( 2 ) ); |
|
317 EUNIT_ASSERT( iList->IsSelected( 3 ) ); |
|
318 EUNIT_ASSERT( iList->IsSelected( 4 ) ); |
|
319 } |
|
320 |
|
321 // ----------------------------------------------------------------------------- |
|
322 // SetSelectedL(...) |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 void ut_CGlxNavigableList::SetSelectedL( const TDesC8& aSelection ) |
|
326 { |
|
327 for ( TInt i = 0; i < aSelection.Length(); i++ ) |
|
328 { |
|
329 iList->SetSelectedL( i, 't' == aSelection[ i ] ); |
|
330 } |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // SelectionEquals(...) |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 TBool ut_CGlxNavigableList::SelectionEquals( const TDesC8& aSelection ) const |
|
338 { |
|
339 // aSelection should have a flag for each item in the list |
|
340 TBool fail = ( iList->Count() != aSelection.Length() ); |
|
341 TInt selectedItemCount = 0; |
|
342 for ( TInt i = 0; i < aSelection.Length(); i++ ) |
|
343 { |
|
344 TBool shouldBeSelected = 't' == aSelection[ i ]; |
|
345 if ( shouldBeSelected ) |
|
346 { |
|
347 selectedItemCount++; |
|
348 } |
|
349 // Compare via not, to make sure true is always the same value |
|
350 fail |= ( !iList->IsSelected( i ) != !shouldBeSelected ); |
|
351 } |
|
352 // Make sure there are no additional items selected |
|
353 fail |= ( iList->SelectedItemIndices().Count() != selectedItemCount ); |
|
354 return !fail; |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // Test SetSelectedL(...) |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 TBool ut_CGlxNavigableList::TrySetSelectedL( const TDesC8& aContents, |
|
362 const TDesC8& aInitialSelection, const TDesC8& aFinalSelection, |
|
363 TBool aSelect, TInt aIndex, |
|
364 const TNotification::TData* aNotificationList ) |
|
365 { |
|
366 CreateListL( aContents ); |
|
367 // set initial selection |
|
368 SetSelectedL( aInitialSelection ); |
|
369 iReconstruction->ClearNotifications(); |
|
370 // run test |
|
371 iList->SetSelectedL( aIndex, aSelect ); |
|
372 |
|
373 // Check item is selected/unselected as expected |
|
374 TBool fail = EFalse; |
|
375 if ( aSelect ) |
|
376 { |
|
377 fail |= !iList->IsSelected( aIndex ); |
|
378 } |
|
379 else |
|
380 { |
|
381 fail |= iList->IsSelected( aIndex ); |
|
382 } |
|
383 // Test selection matches |
|
384 fail |= SelectionEquals( aFinalSelection ); |
|
385 // Test reconstruction matched |
|
386 fail |= !iReconstruction->ReconstructionEquals(); |
|
387 // Test notification equal |
|
388 fail |= !iReconstruction->NotificationListEquals( aNotificationList ); |
|
389 |
|
390 return !fail; |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // Test SetSelectedL(...) |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void ut_CGlxNavigableList::T_SetSelectedLL( ) |
|
398 { |
|
399 { // Select first item |
|
400 TNotification::TData notifications[] = |
|
401 { { TNotification::ESelection, 0, ETrue }, |
|
402 { END_MARKER } }; |
|
403 TrySetSelectedL( _L8("abcde"), _L8("fffff"), _L8("tffff"), ETrue, 0, |
|
404 notifications ); |
|
405 } |
|
406 |
|
407 { // Select another item |
|
408 TNotification::TData notifications[] = |
|
409 { { TNotification::ESelection, 3, ETrue }, |
|
410 { END_MARKER } }; |
|
411 TrySetSelectedL( _L8("abcde"), _L8("tfftf"), _L8("tfttf"), ETrue, 3, |
|
412 notifications ); |
|
413 } |
|
414 |
|
415 { // Select a selected item |
|
416 TrySetSelectedL( _L8("abcde"), _L8("tfftf"), _L8("tfftf"), ETrue, 0, |
|
417 KNotificationsList_Empty ); |
|
418 } |
|
419 |
|
420 { // Unselect item |
|
421 TNotification::TData notifications[] = |
|
422 { { TNotification::ESelection, 4, EFalse }, |
|
423 { END_MARKER } }; |
|
424 TrySetSelectedL( _L8("abcde"), _L8("tfftf"), _L8("tffff"), EFalse, 4, |
|
425 notifications ); |
|
426 } |
|
427 |
|
428 { // Unselect last item |
|
429 TNotification::TData notifications[] = |
|
430 { { TNotification::ESelection, 0, EFalse }, |
|
431 { END_MARKER } }; |
|
432 TrySetSelectedL( _L8("abcde"), _L8("tffff"), _L8("fffff"), EFalse, 0, |
|
433 notifications ); |
|
434 } |
|
435 |
|
436 { // Unselect an unselected item |
|
437 TrySetSelectedL( _L8("abcde"), _L8("tftff"), _L8("tftff"), EFalse, 4, |
|
438 KNotificationsList_Empty ); |
|
439 } |
|
440 |
|
441 { // Try to select static items |
|
442 // Add a static item at front, and two at rear |
|
443 NGlxListTestHelpers::TStaticItemInfo::TData staticItemInfos[] = |
|
444 { { '0', EInsertFirst }, |
|
445 { '1', EInsertLast }, |
|
446 { '2', EInsertLast }, |
|
447 { K_STATIC_ITEMS_END } }; |
|
448 |
|
449 CreateListL( _L8("abcde"), ETrue, staticItemInfos ); |
|
450 iList->SetSelectedL( 0, ETrue ); // static item |
|
451 iList->SetSelectedL( 1, ETrue ); // normal item |
|
452 iList->SetSelectedL( 6, ETrue ); // static item |
|
453 iList->SetSelectedL( 7, ETrue ); // static item |
|
454 TNotification::TData notifications[] = |
|
455 { { TNotification::ESelection, 1, ETrue }, |
|
456 { END_MARKER } }; |
|
457 // Test selection matches |
|
458 TBool fail = !SelectionEquals( _L8("ftffffff") ); |
|
459 // Test reconstruction matched |
|
460 fail |= !iReconstruction->ReconstructionEquals(); |
|
461 // Test notification equal |
|
462 fail |= !iReconstruction->NotificationListEquals( notifications); |
|
463 EUNIT_ASSERT( !fail ); |
|
464 } |
|
465 } |
|
466 |
|
467 // ----------------------------------------------------------------------------- |
|
468 // Test SelectedItemIndices(...) |
|
469 // ----------------------------------------------------------------------------- |
|
470 // |
|
471 void ut_CGlxNavigableList::T_SelectedItemIndicesL( ) |
|
472 { |
|
473 CreateListL( _L8("abcde") ); |
|
474 EUNIT_ASSERT( iList->SelectedItemIndices().Count() == 0 ); |
|
475 iList->SetSelectedL( 3, ETrue ); |
|
476 iList->SetSelectedL( 0, ETrue ); |
|
477 iList->SetSelectedL( 4, ETrue ); |
|
478 EUNIT_ASSERT( iList->SelectedItemIndices().Count() == 3 ); |
|
479 // This test code assumes indexes are ordered, but this is not a requirement |
|
480 // for navigable list. So if ordering navigable list is modified, this may |
|
481 // need changing also |
|
482 EUNIT_ASSERT( iList->SelectedItemIndices()[ 0 ] == 0 ); |
|
483 EUNIT_ASSERT( iList->SelectedItemIndices()[ 1 ] == 3 ); |
|
484 EUNIT_ASSERT( iList->SelectedItemIndices()[ 2 ] == 4 ); |
|
485 } |
|
486 |
|
487 // ----------------------------------------------------------------------------- |
|
488 // TrySetContentsL(...) |
|
489 // ----------------------------------------------------------------------------- |
|
490 // |
|
491 TBool ut_CGlxNavigableList::TrySetContentsL( const TDesC8& aStringBefore, |
|
492 const TDesC8& aStringAfter, TBool aFocusBefore, TBool aFocusAfter, |
|
493 const TDesC8& aSelectionBefore, const TDesC8& aSelectionAfter, |
|
494 const TNotification::TData* aNotificationList ) |
|
495 { |
|
496 CreateListL( aStringBefore ); |
|
497 SetSelectedL( aSelectionBefore ); |
|
498 if ( KErrNotFound != aFocusBefore ) |
|
499 { |
|
500 iList->SetFocus( EAbsolute, aFocusBefore ); |
|
501 } |
|
502 iReconstruction->ClearNotifications(); |
|
503 |
|
504 // Run function under test |
|
505 SetContentsL( aStringAfter ); |
|
506 |
|
507 // Test reconstruction matched |
|
508 TBool fail = !Equals( aStringAfter ); |
|
509 // Test focus matches |
|
510 fail |= ( iList->FocusIndex() != aFocusAfter ); |
|
511 // Test selection matches |
|
512 fail |= !SelectionEquals( aSelectionAfter ); |
|
513 // Test notification equal |
|
514 fail |= !iReconstruction->NotificationListEquals( aNotificationList ); |
|
515 |
|
516 return !fail; |
|
517 } |
|
518 |
|
519 // ----------------------------------------------------------------------------- |
|
520 // Test SetContentsL(...) |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 void ut_CGlxNavigableList::T_SetContentsLL( ) |
|
524 { |
|
525 // Set no contents to empty list |
|
526 { |
|
527 EUNIT_ASSERT( TrySetContentsL( _L8(""), _L8(""), KErrNotFound, KErrNotFound, |
|
528 _L8(""), _L8(""), KNotificationsList_Empty ) ); |
|
529 } |
|
530 |
|
531 // Set contents to empty list |
|
532 { |
|
533 TNotification::TData notifications[] = |
|
534 { { TNotification::EAdd, 0, 5 }, |
|
535 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
536 { END_MARKER } }; |
|
537 EUNIT_ASSERT( TrySetContentsL( _L8(""), _L8("abcde"), KErrNotFound, 0, |
|
538 _L8(""), _L8("fffff"), notifications ) ); |
|
539 } |
|
540 |
|
541 // Set contents so that focus is before insertion point |
|
542 { |
|
543 TNotification::TData notifications[] = |
|
544 { { TNotification::EAdd, 3, 4 }, |
|
545 { END_MARKER } }; |
|
546 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("abc0123de"), 2, 2, |
|
547 _L8("tfttf"), _L8("tftfffftf"), notifications ) ); |
|
548 } |
|
549 // Set contents so that focus is after insertion point |
|
550 { |
|
551 TNotification::TData notifications[] = |
|
552 { { TNotification::EAdd, 2, 4 }, |
|
553 { TNotification::EFocus, 2, EUnknown }, |
|
554 { END_MARKER } }; |
|
555 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("ab0123cde"), 2, 6, |
|
556 _L8("ftftf"), _L8("ftffffftf"), notifications ) ); |
|
557 } |
|
558 // Set contents so that focus is before removed items |
|
559 { |
|
560 TNotification::TData notifications[] = |
|
561 { { TNotification::ERemove, 2, 2 }, |
|
562 { END_MARKER } }; |
|
563 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("abe"), 1, 1, |
|
564 _L8("ftttf"), _L8("ftf"), notifications ) ); |
|
565 |
|
566 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("abe"), 0, 0, |
|
567 _L8("ttttt"), _L8("ttt"), notifications ) ); |
|
568 } |
|
569 // Set contents so that focus is after removed items |
|
570 { |
|
571 TNotification::TData notifications[] = |
|
572 { { TNotification::ERemove, 2, 2 }, |
|
573 { TNotification::EFocus, 4, EUnknown }, |
|
574 { END_MARKER } }; |
|
575 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("abe"), 4, 2, // focus on e |
|
576 _L8("ffttf"), _L8("fff"), notifications ) ); |
|
577 } |
|
578 // Set contents so that focus is on removed items, item before exists |
|
579 { |
|
580 TNotification::TData notifications[] = |
|
581 { { TNotification::ERemove, 2, 2 }, |
|
582 { TNotification::EFocus, 3, EUnknown }, |
|
583 { END_MARKER } }; |
|
584 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("abe"), 3, 1, // Focus from d to b |
|
585 _L8("fffff"), _L8("fff"), notifications ) ); |
|
586 } |
|
587 { |
|
588 TNotification::TData notifications[] = |
|
589 { { TNotification::ERemove, 2, 2 }, |
|
590 { TNotification::EFocus, 2, EUnknown }, |
|
591 { END_MARKER } }; |
|
592 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("abe"), 2, 1, // Focus from c to b |
|
593 _L8("fffff"), _L8("fff"), notifications ) ); |
|
594 } |
|
595 // Set contents so that focus is on removed items, item before does not exist |
|
596 { |
|
597 TNotification::TData notifications[] = |
|
598 { { TNotification::ERemove, 0, 2 }, |
|
599 { TNotification::EFocus, 0, EUnknown }, |
|
600 { END_MARKER } }; |
|
601 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("cde"), 0, 0, // Focus from a to c |
|
602 _L8("fffff"), _L8("fff"), notifications ) ); |
|
603 } |
|
604 { |
|
605 TNotification::TData notifications[] = |
|
606 { { TNotification::ERemove, 0, 2 }, |
|
607 { TNotification::EFocus, 1, EUnknown }, |
|
608 { END_MARKER } }; |
|
609 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("cde"), 1, 0, // Focus from b to c |
|
610 _L8("fffff"), _L8("fff"), notifications ) ); |
|
611 } |
|
612 { |
|
613 TNotification::TData notifications[] = |
|
614 { { TNotification::ERemove, 0, 2 }, |
|
615 { TNotification::EFocus, 2, EUnknown }, |
|
616 { END_MARKER } }; |
|
617 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("cde"), 2, 0, // Focus on c |
|
618 _L8("fffff"), _L8("fff"), notifications ) ); |
|
619 } |
|
620 { |
|
621 TNotification::TData notifications[] = |
|
622 { { TNotification::ERemove, 0, 2 }, |
|
623 { TNotification::EFocus, 3, EUnknown }, |
|
624 { END_MARKER } }; |
|
625 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("cde"), 3, 1, // Focus on d |
|
626 _L8("fffff"), _L8("fff"), notifications ) ); |
|
627 } |
|
628 // Set contents to empty |
|
629 { |
|
630 TNotification::TData notifications[] = |
|
631 { { TNotification::ERemove, 0, 5 }, |
|
632 { TNotification::EFocus, 1, EUnknown }, |
|
633 { END_MARKER } }; |
|
634 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8(""), 1, KErrNotFound, // focus initially on b |
|
635 _L8("fffff"), _L8(""), notifications ) ); |
|
636 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8(""), 1, KErrNotFound, // focus initially on b |
|
637 _L8("ttttt"), _L8(""), notifications ) ); |
|
638 } |
|
639 // Set contents so items get replaced |
|
640 { |
|
641 TNotification::TData notifications[] = |
|
642 { { TNotification::ERemove, 2, 2 }, |
|
643 { TNotification::EFocus, 3, EUnknown }, |
|
644 { TNotification::EAdd, 2, 4 }, |
|
645 { END_MARKER } }; |
|
646 EUNIT_ASSERT( TrySetContentsL( _L8("abcde"), _L8("ab0123e"), 3, 1, // focus d to b |
|
647 _L8("fttft"), _L8("ftfffft"), notifications ) ); |
|
648 } |
|
649 // Set contents so that some selected items stay, some move and some are removed |
|
650 } |
|
651 |
|
652 // ----------------------------------------------------------------------------- |
|
653 // TryReorderContentsL(...) |
|
654 // ----------------------------------------------------------------------------- |
|
655 // |
|
656 TBool ut_CGlxNavigableList::TryReorderContentsL( const TDesC8& aStringBefore, |
|
657 const TDesC8& aStringAfter, TBool aFocusBefore, TBool aFocusAfter, |
|
658 const TDesC8& aSelectionBefore, const TDesC8& aSelectionAfter, |
|
659 const TNotification::TData* aNotificationList ) |
|
660 { |
|
661 CreateListL( aStringBefore ); |
|
662 SetSelectedL( aSelectionBefore ); |
|
663 if ( KErrNotFound != aFocusBefore ) |
|
664 { |
|
665 iList->SetFocus( EAbsolute, aFocusBefore ); |
|
666 } |
|
667 iReconstruction->ClearNotifications(); |
|
668 |
|
669 // Run function under test |
|
670 ReorderContentsL( aStringAfter ); |
|
671 |
|
672 // Test reconstruction matched |
|
673 TBool fail = !Equals( aStringAfter ); |
|
674 // Test focus matches |
|
675 fail |= ( iList->FocusIndex() != aFocusAfter ); |
|
676 // Test selection matches |
|
677 fail |= !SelectionEquals( aSelectionAfter ); |
|
678 // Test notification equal |
|
679 fail |= !iReconstruction->NotificationListEquals( aNotificationList ); |
|
680 |
|
681 return !fail; |
|
682 } |
|
683 |
|
684 // ----------------------------------------------------------------------------- |
|
685 // Test ReorderContentsL(...) |
|
686 // ----------------------------------------------------------------------------- |
|
687 // |
|
688 void ut_CGlxNavigableList::T_ReorderContentsLL( ) |
|
689 { |
|
690 // Reorder no contents from empty list |
|
691 { |
|
692 EUNIT_ASSERT( TryReorderContentsL( _L8(""), _L8(""), KErrNotFound, KErrNotFound, |
|
693 _L8(""), _L8(""), KNotificationsList_Empty ) ); |
|
694 } |
|
695 |
|
696 // Reorder contents from empty list |
|
697 { |
|
698 TNotification::TData notifications[] = |
|
699 { { TNotification::EAdd, 0, 5 }, |
|
700 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
701 { END_MARKER } }; |
|
702 EUNIT_ASSERT( TryReorderContentsL( _L8(""), _L8("abcde"), KErrNotFound, 0, |
|
703 _L8(""), _L8("fffff"), notifications ) ); |
|
704 } |
|
705 |
|
706 // Reorder contents so that focus is unchanged |
|
707 { |
|
708 TNotification::TData notifications[] = |
|
709 { { TNotification::ERemove, 0, 5 }, |
|
710 { TNotification::EFocus, 0, EUnknown }, |
|
711 { TNotification::EAdd, 0, 5 }, |
|
712 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
713 { END_MARKER } }; |
|
714 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8("abcde"), 0, 0, |
|
715 _L8("fffff"), _L8("fffff"), notifications ) ); |
|
716 } |
|
717 |
|
718 // Reorder contents so that focus is changed |
|
719 { |
|
720 TNotification::TData notifications[] = |
|
721 { { TNotification::ERemove, 0, 5 }, |
|
722 { TNotification::EFocus, 0, EUnknown }, |
|
723 { TNotification::EAdd, 0, 5 }, |
|
724 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
725 { TNotification::EFocus, 0, EUnknown }, |
|
726 { END_MARKER } }; |
|
727 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8("bcdea"), 0, 4, |
|
728 _L8("fffff"), _L8("fffff"), notifications ) ); |
|
729 } |
|
730 |
|
731 // Reorder contents so that focus is lost |
|
732 { |
|
733 TNotification::TData notifications[] = |
|
734 { { TNotification::ERemove, 0, 5 }, |
|
735 { TNotification::EFocus, 0, EUnknown }, |
|
736 { TNotification::EAdd, 0, 4 }, |
|
737 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
738 { END_MARKER } }; |
|
739 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8("bcde"), 0, 0, |
|
740 _L8("fffff"), _L8("ffff"), notifications ) ); |
|
741 } |
|
742 |
|
743 // Reorder contents so that selection is unchanged |
|
744 { |
|
745 TNotification::TData notifications[] = |
|
746 { { TNotification::ERemove, 0, 5 }, |
|
747 { TNotification::EFocus, 0, EUnknown }, |
|
748 { TNotification::EAdd, 0, 5 }, |
|
749 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
750 { TNotification::ESelection, 0, ETrue }, |
|
751 { END_MARKER } }; |
|
752 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8("abcde"), 0, 0, |
|
753 _L8("tffff"), _L8("tffff"), notifications ) ); |
|
754 } |
|
755 |
|
756 // Reorder contents so that selection is changed |
|
757 { |
|
758 TNotification::TData notifications[] = |
|
759 { { TNotification::ERemove, 0, 5 }, |
|
760 { TNotification::EFocus, 0, EUnknown }, |
|
761 { TNotification::EAdd, 0, 5 }, |
|
762 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
763 { TNotification::EFocus, 0, EUnknown }, |
|
764 { TNotification::ESelection, 4, ETrue }, |
|
765 { TNotification::ESelection, 1, ETrue }, |
|
766 { TNotification::ESelection, 3, ETrue }, |
|
767 { END_MARKER } }; |
|
768 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8("bcdea"), 0, 4, |
|
769 _L8("tftft"), _L8("ftftt"), notifications ) ); |
|
770 } |
|
771 |
|
772 // Reorder contents so that selection is lost |
|
773 { |
|
774 TNotification::TData notifications[] = |
|
775 { { TNotification::ERemove, 0, 5 }, |
|
776 { TNotification::EFocus, 0, EUnknown }, |
|
777 { TNotification::EAdd, 0, 5 }, |
|
778 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
779 { TNotification::ESelection, 0, ETrue }, |
|
780 { TNotification::ESelection, 2, ETrue }, |
|
781 { END_MARKER } }; |
|
782 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8("abcd0"), 0, 0, |
|
783 _L8("tftft"), _L8("tftff"), notifications ) ); |
|
784 } |
|
785 { |
|
786 TNotification::TData notifications[] = |
|
787 { { TNotification::ERemove, 0, 5 }, |
|
788 { TNotification::EFocus, 0, EUnknown }, |
|
789 { TNotification::EAdd, 0, 5 }, |
|
790 { TNotification::EFocus, KErrNotFound, EUnknown }, |
|
791 { END_MARKER } }; |
|
792 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8("a0123"), 0, 0, |
|
793 _L8("ftttt"), _L8("fffff"), notifications ) ); |
|
794 } |
|
795 |
|
796 // Reorder contents to empty |
|
797 { |
|
798 TNotification::TData notifications[] = |
|
799 { { TNotification::ERemove, 0, 5 }, |
|
800 { TNotification::EFocus, 0, EUnknown }, |
|
801 { END_MARKER } }; |
|
802 EUNIT_ASSERT( TryReorderContentsL( _L8("abcde"), _L8(""), 0, KErrNotFound, |
|
803 _L8("ttttt"), _L8(""), notifications ) ); |
|
804 } |
|
805 } |
|
806 |
|
807 // ----------------------------------------------------------------------------- |
|
808 // Test RemoveReference(...) |
|
809 // ----------------------------------------------------------------------------- |
|
810 // |
|
811 void ut_CGlxNavigableList::T_RemoveReferenceL( ) |
|
812 { |
|
813 TestRemoveReferenceL(); |
|
814 } |
|
815 |
|
816 // ----------------------------------------------------------------------------- |
|
817 // Test Remove(...) |
|
818 // ----------------------------------------------------------------------------- |
|
819 // |
|
820 void ut_CGlxNavigableList::T_RemoveL( ) |
|
821 { |
|
822 } |
|
823 |
|
824 // ----------------------------------------------------------------------------- |
|
825 // Test AddStaticItemL(...) |
|
826 // ----------------------------------------------------------------------------- |
|
827 // |
|
828 void ut_CGlxNavigableList::T_AddStaticItemLL( ) |
|
829 { |
|
830 } |
|
831 |
|
832 // ----------------------------------------------------------------------------- |
|
833 // Test SetStaticItemsEnabled(...) |
|
834 // ----------------------------------------------------------------------------- |
|
835 // |
|
836 void ut_CGlxNavigableList::T_SetStaticItemsEnabledL( ) |
|
837 { |
|
838 } |
|
839 |
|
840 // ----------------------------------------------------------------------------- |
|
841 // Test Count(...) |
|
842 // ----------------------------------------------------------------------------- |
|
843 // |
|
844 void ut_CGlxNavigableList::T_CountL( ) |
|
845 { |
|
846 TestCountL(); |
|
847 } |
|
848 |
|
849 // ----------------------------------------------------------------------------- |
|
850 // Test Item(...) |
|
851 // ----------------------------------------------------------------------------- |
|
852 // |
|
853 void ut_CGlxNavigableList::T_ItemL( ) |
|
854 { |
|
855 TestItemL(); |
|
856 } |
|
857 |
|
858 // ----------------------------------------------------------------------------- |
|
859 // Test Index(...) |
|
860 // ----------------------------------------------------------------------------- |
|
861 // |
|
862 void ut_CGlxNavigableList::T_IndexL( ) |
|
863 { |
|
864 TestIndexL(); |
|
865 } |
|
866 |
|
867 // ----------------------------------------------------------------------------- |
|
868 // Test IdSpaceId |
|
869 // ----------------------------------------------------------------------------- |
|
870 // |
|
871 void ut_CGlxNavigableList::T_IdSpaceIdL() |
|
872 { |
|
873 TestIdSpaceIdL(); |
|
874 } |
|
875 |
|
876 // ----------------------------------------------------------------------------- |
|
877 // Test table |
|
878 // ----------------------------------------------------------------------------- |
|
879 // |
|
880 EUNIT_BEGIN_TEST_TABLE( |
|
881 ut_CGlxNavigableList, |
|
882 "Add test suite description here.", |
|
883 "UNIT" ) |
|
884 |
|
885 /*EUNIT_TEST( |
|
886 "SetContentsL", |
|
887 "CGlxNavigableList", |
|
888 "SetContentsL", |
|
889 "FUNCTIONALITY", |
|
890 SetupL, T_SetContentsLL, Teardown)*/ |
|
891 |
|
892 /*EUNIT_TEST( |
|
893 "ReorderContentsL", |
|
894 "CGlxNavigableList", |
|
895 "ReorderContentsL", |
|
896 "FUNCTIONALITY", |
|
897 SetupL, T_ReorderContentsLL, Teardown)*/ |
|
898 |
|
899 EUNIT_TEST( |
|
900 "Remove", |
|
901 "CGlxNavigableList", |
|
902 "Remove", |
|
903 "FUNCTIONALITY", |
|
904 SetupL, T_RemoveL, Teardown) |
|
905 |
|
906 EUNIT_TEST( |
|
907 "RemoveReference", |
|
908 "CGlxNavigableList", |
|
909 "RemoveReference", |
|
910 "FUNCTIONALITY", |
|
911 SetupL, T_RemoveReferenceL, Teardown) |
|
912 |
|
913 EUNIT_TEST( |
|
914 "AddStaticItemL", |
|
915 "CGlxNavigableList", |
|
916 "AddStaticItemL", |
|
917 "FUNCTIONALITY", |
|
918 SetupL, T_AddStaticItemLL, Teardown) |
|
919 |
|
920 EUNIT_TEST( |
|
921 "SetStaticItemsEnabled", |
|
922 "CGlxNavigableList", |
|
923 "SetStaticItemsEnabled", |
|
924 "FUNCTIONALITY", |
|
925 SetupL, T_SetStaticItemsEnabledL, Teardown) |
|
926 |
|
927 EUNIT_TEST( |
|
928 "Count", |
|
929 "CGlxNavigableList", |
|
930 "Count", |
|
931 "FUNCTIONALITY", |
|
932 SetupL, T_CountL, Teardown) |
|
933 |
|
934 EUNIT_TEST( |
|
935 "FocusIndex", |
|
936 "CGlxNavigableList", |
|
937 "FocusIndex", |
|
938 "FUNCTIONALITY", |
|
939 SetupL, T_FocusIndexL, Teardown) |
|
940 |
|
941 /*EUNIT_TEST( |
|
942 "SetFocus", |
|
943 "CGlxNavigableList", |
|
944 "SetFocus", |
|
945 "FUNCTIONALITY", |
|
946 SetupL, T_SetFocusL, Teardown)*/ |
|
947 |
|
948 EUNIT_TEST( |
|
949 "Item", |
|
950 "CGlxNavigableList", |
|
951 "Item", |
|
952 "FUNCTIONALITY", |
|
953 SetupL, T_ItemL, Teardown) |
|
954 |
|
955 EUNIT_TEST( |
|
956 "Index", |
|
957 "CGlxNavigableList", |
|
958 "Index", |
|
959 "FUNCTIONALITY", |
|
960 SetupL, T_IndexL, Teardown) |
|
961 |
|
962 EUNIT_TEST( |
|
963 "IsSelected", |
|
964 "CGlxNavigableList", |
|
965 "IsSelected", |
|
966 "FUNCTIONALITY", |
|
967 SetupL, T_IsSelectedL, Teardown) |
|
968 |
|
969 EUNIT_TEST( |
|
970 "SetSelectedL", |
|
971 "CGlxNavigableList", |
|
972 "SetSelectedL", |
|
973 "FUNCTIONALITY", |
|
974 SetupL, T_SetSelectedLL, Teardown) |
|
975 |
|
976 EUNIT_TEST( |
|
977 "SelectedItemIndices", |
|
978 "CGlxNavigableList", |
|
979 "SelectedItemIndices", |
|
980 "FUNCTIONALITY", |
|
981 SetupL, T_SelectedItemIndicesL, Teardown) |
|
982 |
|
983 EUNIT_TEST( |
|
984 "IdSpaceId", |
|
985 "CGlxNavigableList", |
|
986 "IdSpaceId", |
|
987 "FUNCTIONALITY", |
|
988 SetupL, T_IdSpaceIdL, Teardown) |
|
989 |
|
990 EUNIT_END_TEST_TABLE |
|
991 |
|
992 // END OF FILE |