photosgallery/viewframework/medialists/tsrc/src/glxlisttestbase.inl
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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 #include "glxlistreconstruction.h"
       
    22 
       
    23 #include <digia/eunit/eunitmacros.h>
       
    24 #include <digia/eunit/eunitdecorators.h>
       
    25 #include <mpxcollectionpath.h>
       
    26 #include <glxlistdefs.h>
       
    27 #include <glxpanic.h>
       
    28 
       
    29 #include "glxmediastaticitemdefs.h"
       
    30 
       
    31 const TGlxIdSpaceId KListIdSpace( 1 );
       
    32       
       
    33 // -----------------------------------------------------------------------------
       
    34 // Destructor
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 template < class _List, class _Reconstruction >
       
    38 CGlxListTestBase< _List, _Reconstruction >::~CGlxListTestBase() 
       
    39     {
       
    40     DeleteMembers();
       
    41     }
       
    42     
       
    43 // -----------------------------------------------------------------------------
       
    44 // Destructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 template < class _List, class _Reconstruction >
       
    48 void CGlxListTestBase< _List, _Reconstruction >::DeleteMembers()
       
    49     {
       
    50     delete iReconstruction;
       
    51     iReconstruction = NULL;
       
    52     delete iList;
       
    53     iList = NULL;
       
    54     iMediaPool.ResetAndDestroy();
       
    55     }
       
    56     
       
    57 // -----------------------------------------------------------------------------
       
    58 // Ignore
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 template < class _List, class _Reconstruction >
       
    62     void CGlxListTestBase< _List, _Reconstruction >::GetRequiredAttributesL( 
       
    63         TInt /*aIndex*/, RArray< TMPXAttribute >& /*aAttributes*/ )
       
    64     {
       
    65     }
       
    66     
       
    67 // -----------------------------------------------------------------------------
       
    68 // Ignore
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 template < class _List, class _Reconstruction >
       
    72     void CGlxListTestBase< _List, _Reconstruction >
       
    73         ::HandleAttributesAvailableL(TInt /*aIndex*/, 
       
    74             const RArray< TMPXAttribute >& /*aAttributes*/ )
       
    75     {
       
    76     }    
       
    77     
       
    78 // -----------------------------------------------------------------------------
       
    79 // Ignore
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 template < class _List, class _Reconstruction >
       
    83     void CGlxListTestBase< _List, _Reconstruction >
       
    84         ::RemoveReference( TInt /*aIndex*/ )
       
    85     {
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // Ignore
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 template < class _List, class _Reconstruction >
       
    93     void CGlxListTestBase< _List, _Reconstruction >
       
    94         ::HandleError( TInt /*aError*/ )
       
    95     {
       
    96     }
       
    97     
       
    98 // -----------------------------------------------------------------------------
       
    99 // MGlxMediaPool::Media implementation
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 template < class _List, class _Reconstruction >
       
   103 CGlxMedia* CGlxListTestBase< _List, _Reconstruction >
       
   104         ::Media( const TGlxIdSpaceId& /*aIdSpaceId*/, const TGlxMediaId& /*aId*/) const  
       
   105     {
       
   106     return NULL;
       
   107     }
       
   108     
       
   109 // -----------------------------------------------------------------------------
       
   110 // Create a list from string
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 template < class _List, class _Reconstruction >
       
   114     void CGlxListTestBase< _List, _Reconstruction >
       
   115         ::CreateListL( const TDesC8& aString )
       
   116     {
       
   117     CMPXCollectionPath* path = CreatePathLC( aString );
       
   118 
       
   119     // Create reconstruction
       
   120     CreateReconstructionL();
       
   121     
       
   122     // Delete media items
       
   123     iMediaPool.ResetAndDestroy();
       
   124     
       
   125     // Create list
       
   126     delete iList;
       
   127     iList = NULL;
       
   128     iList = _List::NewL( KListIdSpace, *iReconstruction, *this );
       
   129     iReconstruction->SetList( *iList );
       
   130     // Set the contents of the old list
       
   131     iList->SetContentsL( *path, *this );
       
   132     // Reset for test
       
   133     iReconstruction->ClearNotifications();
       
   134 
       
   135     CleanupStack::PopAndDestroy(path );
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // Create a list from string
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 template < class _List, class _Reconstruction >
       
   143     void CGlxListTestBase< _List, _Reconstruction >
       
   144         ::CreateListL( const TDesC8& aString, const TDesC8& aLinkedToMedia )
       
   145     {
       
   146     // Create list
       
   147     CreateListL( aString );
       
   148 
       
   149     // Link to media
       
   150     for ( TInt i = 0; i < aLinkedToMedia.Length(); i++)
       
   151         {
       
   152         if ( aLinkedToMedia[ i ] == 't' )
       
   153             {
       
   154             CGlxMedia* media = new (ELeave) CGlxMedia( iList->Item( i ).Id() );
       
   155             CleanupStack::PushL( media );
       
   156             iMediaPool.AppendL( media );
       
   157             CleanupStack::Pop( media );
       
   158 
       
   159             media->ReserveUsersL( 1 );
       
   160             iList->Item(i).SetMedia( media, *this);
       
   161             }
       
   162         }
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // Create a list from string
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 template < class _List, class _Reconstruction >
       
   170     void CGlxListTestBase< _List, _Reconstruction >
       
   171         ::CreateListL( const TDesC8& aString, TBool aStaticItemsEnabled,
       
   172             NGlxListTestHelpers::TStaticItemInfo::TData* aStaticItemInfos )
       
   173     {
       
   174     // Create list
       
   175     CreateListL( aString );
       
   176     // Add static items, if any
       
   177     AddStaticItemsL( aStaticItemInfos );
       
   178     // Enable/disable static items
       
   179     iList->SetStaticItemsEnabled( aStaticItemsEnabled );
       
   180     // Reset for test
       
   181     iReconstruction->ClearNotifications();
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // Create reconstruction
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 template < class _List, class _Reconstruction >
       
   189     void CGlxListTestBase< _List, _Reconstruction >::CreateReconstructionL()
       
   190     {
       
   191     delete iReconstruction;
       
   192     iReconstruction = NULL;
       
   193     iReconstruction = _Reconstruction::NewL();
       
   194     }
       
   195     
       
   196 // -----------------------------------------------------------------------------
       
   197 // Test if list equals the list in the string
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 template < class _List, class _Reconstruction >
       
   201     TBool CGlxListTestBase< _List, _Reconstruction >::Equals( const TDesC8& aNewString )
       
   202     {
       
   203     ASSERT( iList && iReconstruction );
       
   204     // length of list and string must match
       
   205     TBool fail = ( iList->Count() != aNewString.Length() );
       
   206 
       
   207     for ( TInt i = 0; i < iList->Count(); i++ )
       
   208         {
       
   209         fail |= ( iList->Item( i ).Id() != TGlxMediaId( aNewString[ i ] ) );
       
   210         }
       
   211         
       
   212     // Test reconstruction 
       
   213     fail |= !iReconstruction->ReconstructionEquals();
       
   214     
       
   215     return !fail;
       
   216     }
       
   217     
       
   218 // -----------------------------------------------------------------------------
       
   219 // Test if list matches the string and reconstruction matches original
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 template < class _List, class _Reconstruction >
       
   223 TBool CGlxListTestBase< _List, _Reconstruction >::Equals( const TDesC8& aNewString, 
       
   224         const TNotification::TData* aNotificationList )
       
   225     {
       
   226     ASSERT( iList && iReconstruction );
       
   227     // Test if list contents match the new intended contents
       
   228     TBool fail = !Equals( aNewString );
       
   229 
       
   230     // Test notifications and reconstruction match
       
   231     fail |= !iReconstruction->NotificationListEquals( aNotificationList );
       
   232     
       
   233     return !fail;
       
   234     }
       
   235  
       
   236 // -----------------------------------------------------------------------------
       
   237 // Test match
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 template < class _List, class _Reconstruction >
       
   241 TBool CGlxListTestBase< _List, _Reconstruction >
       
   242     ::Equals( const TDesC8& aStringWithoutStaticItems, 
       
   243         const TDesC8& aStringWithStaticItems, 
       
   244             TBool aStaticItemsEnabled, 
       
   245                 const TNotification::TData* aNotificationList)
       
   246     {
       
   247     TBool fail = EFalse;
       
   248     if ( aStaticItemsEnabled )
       
   249         {
       
   250         fail |= !Equals( aStringWithStaticItems, aNotificationList );
       
   251         }
       
   252     else
       
   253         {
       
   254         fail |= !Equals( aStringWithoutStaticItems, aNotificationList );
       
   255         }
       
   256     
       
   257     return !fail;
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // Test if items are linked to media objects correctly
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 template < class _List, class _Reconstruction >
       
   265     TBool CGlxListTestBase< _List, _Reconstruction >
       
   266         ::IsLinkedToMedia( const TDesC8& aAnswers ) const
       
   267     {
       
   268     TBool fail = EFalse;
       
   269     for ( TInt i = 0; i < aAnswers.Length(); i++)
       
   270         {
       
   271         TBool shouldBeLinked = ( aAnswers[ i ] == 't' ); 
       
   272         TBool isLinked = ( iList->Item( i ).Properties() != NULL );
       
   273         // Test via not, just in case true is not always exactly 1
       
   274         fail |= ( !shouldBeLinked != !isLinked );       
       
   275         }
       
   276     return !fail;
       
   277     }   
       
   278     
       
   279 // -----------------------------------------------------------------------------
       
   280 // Try linking to media item
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 /*template < class _List, class _Reconstruction >
       
   284     TBool CGlxListTestBase< _List, _Reconstruction >
       
   285         ::TryOfferMedia( TChar aId, const TDesC8& aAnswers, TBool aShouldAccept )
       
   286     {
       
   287     ASSERT( iList );
       
   288 
       
   289     CGlxMedia* media = new (ELeave) CGlxMedia( TGlxMediaId( aId ) );
       
   290     CleanupStack::PushL( media );
       
   291     iMediaPool.AppendL( media );
       
   292     CleanupStack::Pop( media );
       
   293     media->ReserveUsersL( 1 );
       
   294     // Offer media and test acceptance. Compare via not, to since True might be not be 1
       
   295     TBool fail = ( !iList->OfferMedia(KListIdSpace,  *media ) != !aShouldAccept );    
       
   296     fail |= !IsLinkedToMedia( aAnswers );
       
   297     return !fail;
       
   298     }*/
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // Try removing link from media item
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 template < class _List, class _Reconstruction >
       
   305     TBool CGlxListTestBase< _List, _Reconstruction >
       
   306         ::TryRemoveReference( TInt aIndex, const TDesC8& aAnswers )
       
   307     {
       
   308     ASSERT( iList );
       
   309 
       
   310     // Remove reference
       
   311     iList->RemoveReference( aIndex );
       
   312     TBool fail = !IsLinkedToMedia( aAnswers );
       
   313     return !fail;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // Test OfferMedia(...)
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 /*template < class _List, class _Reconstruction >
       
   321     void CGlxListTestBase< _List, _Reconstruction >::TestOfferMediaL()
       
   322     {
       
   323     // Create the item list
       
   324     CreateListL( _L8("abcdefg") );
       
   325 
       
   326     EUNIT_ASSERT( IsLinkedToMedia( _L8("fffffff") ) );
       
   327     EUNIT_ASSERT( TryOfferMedia( '0', _L8("fffffff"), EFalse ) ); // reject
       
   328     EUNIT_ASSERT( TryOfferMedia( 'a', _L8("tffffff"), ETrue ) );  
       
   329     EUNIT_ASSERT( TryOfferMedia( 'c', _L8("tftffff"), ETrue ) );  
       
   330     EUNIT_ASSERT( TryOfferMedia( 'd', _L8("tfttfff"), ETrue ) );  
       
   331     EUNIT_ASSERT( TryOfferMedia( 'g', _L8("tfttfft"), ETrue ) );  
       
   332     EUNIT_ASSERT( TryOfferMedia( '1', _L8("tfttfft"), EFalse ) ); // reject
       
   333     }*/
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // Test RemoveReference(...)
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 template < class _List, class _Reconstruction >
       
   340     void CGlxListTestBase< _List, _Reconstruction >::TestRemoveReferenceL()
       
   341     {
       
   342     // Create the item list
       
   343     CreateListL( _L8("abcdefg"), _L8("tfttfft") );
       
   344     EUNIT_ASSERT( IsLinkedToMedia( _L8("tfttfft") ) );
       
   345 
       
   346     // Add static items
       
   347     // Static items are linked to media
       
   348     AddStaticItemL( '0', NGlxListDefs::EInsertFirst );
       
   349     AddStaticItemL( '1', NGlxListDefs::EInsertLast );
       
   350     EUNIT_ASSERT( IsLinkedToMedia( _L8("ttfttfftt") ) );
       
   351 
       
   352     EUNIT_ASSERT( TryRemoveReference( 1, _L8("tffttfftt") ) );
       
   353     EUNIT_ASSERT( TryRemoveReference( 3, _L8("tffftfftt") ) );
       
   354     EUNIT_ASSERT( TryRemoveReference( 4, _L8("tfffffftt") ) );
       
   355     EUNIT_ASSERT( TryRemoveReference( 7, _L8("tffffffft") ) );
       
   356     EUNIT_ASSERT_PANIC_DESC( TryRemoveReference( 8, _L8("tffffffft") ), 
       
   357                              "Images & videos", EGlxPanicIllegalArgument, 
       
   358                              "Incorrect panic" );
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // Test setting new contents
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 template < class _List, class _Reconstruction >
       
   366     TBool CGlxListTestBase< _List, _Reconstruction >
       
   367         ::SetContentsL( const TDesC8& aString )
       
   368     {
       
   369     ASSERT( iList );
       
   370 
       
   371     // Create source
       
   372     CMPXCollectionPath* path = CreatePathLC( aString );
       
   373     // Copy source for comparison
       
   374     TInt originalIndex = path->Index();
       
   375     // Set the source 
       
   376     iList->SetContentsL( *path, *this );
       
   377     
       
   378     // Test path was not modified
       
   379     TBool fail = !( !path->Levels() || originalIndex == path->Index() );
       
   380     
       
   381     CleanupStack::PopAndDestroy( path );
       
   382     return !fail;
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // Test reordering contents
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 template < class _List, class _Reconstruction >
       
   390     TBool CGlxListTestBase< _List, _Reconstruction >
       
   391         ::ReorderContentsL( const TDesC8& aString )
       
   392     {
       
   393     ASSERT( iList );
       
   394 
       
   395     // Create source
       
   396     CMPXCollectionPath* path = CreatePathLC( aString );
       
   397     // Copy source for comparison
       
   398     TInt originalIndex = path->Index();
       
   399     // Set the source 
       
   400     iList->ReorderContentsL( *path, *this );
       
   401     
       
   402     // Test path was not modified
       
   403     TBool fail = !( !path->Levels() || originalIndex == path->Index() );
       
   404     
       
   405     CleanupStack::PopAndDestroy( path );
       
   406     return !fail;
       
   407     }
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // Test setting new contents
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 template < class _List, class _Reconstruction >
       
   414     TBool CGlxListTestBase< _List, _Reconstruction >
       
   415         ::TrySetContentsL(  const TDesC8& aOldString, const TDesC8& aNewString )
       
   416     {
       
   417     // Create the item list
       
   418     CreateListL( aOldString );
       
   419     // Set the contents
       
   420     TBool fail = !SetContentsL( aNewString );
       
   421     // Test if list contents match the new intended contents
       
   422     fail |= !Equals( aNewString );
       
   423     
       
   424     return !fail;
       
   425     }
       
   426     
       
   427 // -----------------------------------------------------------------------------
       
   428 // Test setting contents and test notifications also
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 template < class _List, class _Reconstruction >
       
   432     TBool CGlxListTestBase< _List, _Reconstruction >
       
   433         ::TrySetContentsL(  const TDesC8& aOldString, const TDesC8& aNewString, 
       
   434             const TNotification::TData* aNotificationList )
       
   435     {
       
   436     // Test list creation
       
   437     TBool fail = !TrySetContentsL( aOldString, aNewString );
       
   438     // Test if notification list matches expected
       
   439     fail |= !Equals( aNewString, aNotificationList );
       
   440     
       
   441     return !fail;
       
   442     }
       
   443     
       
   444 // -----------------------------------------------------------------------------
       
   445 // Test setting contents and test notifications also
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 template < class _List, class _Reconstruction >
       
   449     TBool CGlxListTestBase< _List, _Reconstruction >
       
   450         ::TrySetContentsL(  const TDesC8& aOldString, const TDesC8& aNewString, 
       
   451             const TDesC8& aNewStringWithStaticItems, 
       
   452                 const TNotification::TData* aNotificationList, 
       
   453                     TBool aStaticItemsEnabled, 
       
   454                         NGlxListTestHelpers::TStaticItemInfo::TData* aStaticItemInfos )
       
   455     {
       
   456     // Create list
       
   457     CreateListL( aOldString, aStaticItemsEnabled, aStaticItemInfos );
       
   458 
       
   459     TBool fail = !SetContentsL( aNewString );
       
   460     fail |= !Equals( aNewString, aNewStringWithStaticItems, aStaticItemsEnabled,
       
   461         aNotificationList );
       
   462     
       
   463     return !fail;
       
   464     }
       
   465     
       
   466 // -----------------------------------------------------------------------------
       
   467 // Test setting contents and test notifications also with and without static items
       
   468 // -----------------------------------------------------------------------------
       
   469 //
       
   470 template < class _List, class _Reconstruction >
       
   471     TBool CGlxListTestBase< _List, _Reconstruction >
       
   472         ::TrySetContentsL( const TDesC8& aOldString, const TDesC8& aNewString, 
       
   473             const TDesC8& aNewStringWithStaticItems, 
       
   474                 const TNotification::TData* aNotificationListStaticItemsEnabled,
       
   475                     const TNotification::TData* aNotificationListStaticItemsDisabled, 
       
   476                         NGlxListTestHelpers::TStaticItemInfo::TData* aStaticItemInfos )
       
   477     {
       
   478     // without adding static items, while static items are enabled
       
   479     TBool fail = !TrySetContentsL( aOldString, aNewString, aNewString,
       
   480         aNotificationListStaticItemsDisabled, ETrue, NULL );
       
   481 
       
   482     // without adding static items, while static items are disabled
       
   483     fail |= !TrySetContentsL( aOldString, aNewString, aNewStringWithStaticItems, 
       
   484         aNotificationListStaticItemsDisabled, EFalse, NULL );
       
   485         
       
   486     // with adding static items, while static items are enabled
       
   487      fail |= !TrySetContentsL( aOldString, aNewString, aNewStringWithStaticItems,
       
   488         aNotificationListStaticItemsEnabled, ETrue, aStaticItemInfos );
       
   489 
       
   490     // with adding static items, while static items are disabled    
       
   491     fail |= !TrySetContentsL( aOldString, aNewString, aNewStringWithStaticItems, 
       
   492         aNotificationListStaticItemsDisabled, EFalse, aStaticItemInfos );
       
   493     
       
   494     return !fail;
       
   495     }
       
   496 
       
   497 // -----------------------------------------------------------------------------
       
   498 // Test Adding a static item
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 template < class _List, class _Reconstruction >
       
   502     TBool CGlxListTestBase< _List, _Reconstruction >
       
   503         ::TryAddStaticItemL( const TDesC8& aInitString, TChar aStaticItemId, 
       
   504             NGlxListDefs::TInsertionPosition aInsertPos,
       
   505                 const TDesC8& aStringAfter,
       
   506                     const TNotification::TData* aNotificationList,
       
   507                         TBool aStaticItemsEnabled,
       
   508                             NGlxListTestHelpers::TStaticItemInfo::TData* aStaticItemInfos )
       
   509     {
       
   510     CreateListL( aInitString, aStaticItemsEnabled, aStaticItemInfos );
       
   511     CGlxMedia* media = new (ELeave) CGlxMedia( TGlxMediaId ( aStaticItemId ) );
       
   512     CleanupStack::PushL( media );
       
   513     iList->AddStaticItemL( media, aInsertPos );
       
   514     CleanupStack::Pop( media );
       
   515 
       
   516     TBool fail = !Equals( aInitString, aStringAfter, aStaticItemsEnabled,
       
   517         aNotificationList );
       
   518     
       
   519     return !fail;
       
   520     }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // Test Adding a static item
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 template < class _List, class _Reconstruction >
       
   527     TBool CGlxListTestBase< _List, _Reconstruction >
       
   528         ::TryAddStaticItemL( const TDesC8& aInitString, 
       
   529             TChar aStaticItemId, NGlxListDefs::TInsertionPosition aInsertPos,
       
   530                 const TDesC8& aStringAfter, const TNotification::TData* aNotificationListForAdd,
       
   531                     const TNotification::TData* aNotificationListForAllStatic,
       
   532                         NGlxListTestHelpers::TStaticItemInfo::TData* aStaticItemInfos )
       
   533     {
       
   534     TNotification::TData noNotifications[] = 
       
   535                            { { END_MARKER } };
       
   536     
       
   537     // with adding static items, while static items are enabled
       
   538     TBool fail = !TryAddStaticItemL( aInitString, aStaticItemId, aInsertPos, 
       
   539         aStringAfter, aNotificationListForAdd, ETrue, aStaticItemInfos );
       
   540 
       
   541     // with adding static items, while static items are disabled    
       
   542     fail |= !TryAddStaticItemL( aInitString, aStaticItemId, aInsertPos,
       
   543         aInitString, noNotifications, EFalse, aStaticItemInfos );
       
   544         
       
   545     // turn on static items, to make sure items were added in disabled state
       
   546     iReconstruction->ClearNotifications();
       
   547     iList->SetStaticItemsEnabled( ETrue );
       
   548     fail |= !Equals( aStringAfter, aNotificationListForAllStatic );
       
   549     
       
   550     return !fail;
       
   551     }
       
   552             
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // Test removing an item
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 template < class _List, class _Reconstruction >
       
   559     TBool CGlxListTestBase< _List, _Reconstruction >
       
   560         ::TryRemoveL( const TDesC8& aOldString, const TChar aItemToRemove, 
       
   561             const TDesC8& aNewString, const TNotification::TData* aNotificationList )
       
   562     {
       
   563     CreateListL( aOldString );
       
   564     iList->Remove( KListIdSpace, TGlxMediaId( aItemToRemove ) );
       
   565     // Test if notification list matches expected
       
   566     return Equals( aNewString, aNotificationList );
       
   567     }
       
   568 
       
   569 // -----------------------------------------------------------------------------
       
   570 // Test removing an item
       
   571 // -----------------------------------------------------------------------------
       
   572 //
       
   573 template < class _List, class _Reconstruction >
       
   574     TBool CGlxListTestBase< _List, _Reconstruction >
       
   575         ::TryRemoveL( const TDesC8& aOldString, const TChar aItemToRemove, 
       
   576             TBool aIsStaticId, const TDesC8& aNewString, 
       
   577                     const TNotification::TData* aNotificationList,
       
   578                         TBool aStaticItemsEnabled,
       
   579                             NGlxListTestHelpers::TStaticItemInfo::TData* aStaticItemInfos )
       
   580     {
       
   581     CreateListL( aOldString, aStaticItemsEnabled, aStaticItemInfos );
       
   582 
       
   583     iList->Remove( aIsStaticId ? KGlxStaticItemIdSpaceId : KListIdSpace, 
       
   584         TGlxMediaId( aItemToRemove ) );
       
   585     TBool fail = !Equals( aNewString, aNotificationList );
       
   586     
       
   587     return !fail;
       
   588     }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // Test setting contents and test notifications also
       
   592 // -----------------------------------------------------------------------------
       
   593 //
       
   594 template < class _List, class _Reconstruction >
       
   595 TBool CGlxListTestBase< _List, _Reconstruction >
       
   596     ::TryRemoveL( const TDesC8& aOldString, const TChar aItemToRemove, TBool aIsStaticId, 
       
   597         const TDesC8& aNewStringWithoutStaticItems, 
       
   598             const TDesC8& aNewStringWithStaticItems, 
       
   599                 const TNotification::TData* aNotificationListStaticItemsDisabled,
       
   600                     const TNotification::TData* aNotificationListStaticItemsEnabled, 
       
   601                         NGlxListTestHelpers::TStaticItemInfo::TData* aStaticItemInfos)
       
   602     {
       
   603     // without adding static items, while static items are enabled
       
   604     TBool fail = !TryRemoveL( aOldString, aItemToRemove, aIsStaticId, 
       
   605         aNewStringWithoutStaticItems, aNotificationListStaticItemsDisabled, 
       
   606             ETrue, NULL );
       
   607 
       
   608     // without adding static items, while static items are disabled
       
   609     fail |= !TryRemoveL( aOldString, aItemToRemove, aIsStaticId, 
       
   610         aNewStringWithoutStaticItems, aNotificationListStaticItemsDisabled, 
       
   611             EFalse, NULL );
       
   612         
       
   613     // with adding static items, while static items are enabled
       
   614      fail |= !TryRemoveL( aOldString, aItemToRemove, aIsStaticId, 
       
   615          aNewStringWithStaticItems, aNotificationListStaticItemsEnabled, 
       
   616             ETrue, aStaticItemInfos );
       
   617 
       
   618     // with adding static items, while static items are disabled    
       
   619     fail |= !TryRemoveL( aOldString, aItemToRemove, aIsStaticId, 
       
   620         aNewStringWithoutStaticItems, aNotificationListStaticItemsDisabled, 
       
   621             EFalse, aStaticItemInfos );
       
   622     
       
   623     return !fail;
       
   624     }
       
   625 
       
   626 // -----------------------------------------------------------------------------
       
   627 // MGlxMediaPool::Media implementation
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 template < class _List, class _Reconstruction >
       
   631     CMPXCollectionPath* CGlxListTestBase< _List, _Reconstruction >
       
   632         ::CreatePathLC( const TDesC8& aString )
       
   633     {
       
   634     // Populate array from the string
       
   635     RArray<TMPXItemId> ids;
       
   636     CleanupClosePushL( ids );
       
   637     TInt count = aString.Length();
       
   638     for ( TInt i = 0; i < count; i++ )
       
   639         {
       
   640         ids.AppendL( aString[ i ] );
       
   641         }
       
   642     // Populate path from the array
       
   643     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
   644     CleanupStack::PushL( path );
       
   645     path->AppendL( ids.Array() );
       
   646     CleanupStack::Pop( path ); // ids
       
   647     CleanupStack::PopAndDestroy(); // ids
       
   648     CleanupStack::PushL( path );
       
   649     return path;
       
   650     }
       
   651     
       
   652 // -----------------------------------------------------------------------------
       
   653 // Add a static item
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 template < class _List, class _Reconstruction >
       
   657     void CGlxListTestBase< _List, _Reconstruction >::AddStaticItemL( 
       
   658         TChar aId, NGlxListDefs::TInsertionPosition aPosition )
       
   659     {
       
   660     ASSERT( iList );
       
   661     CGlxMedia* item = new (ELeave) CGlxMedia( TGlxMediaId( aId ) );
       
   662     CleanupStack::PushL( item );
       
   663     iList->AddStaticItemL( item, aPosition );
       
   664     CleanupStack::Pop( item );
       
   665     }
       
   666 
       
   667 // -----------------------------------------------------------------------------
       
   668 // Add a static items
       
   669 // -----------------------------------------------------------------------------
       
   670 //
       
   671 template < class _List, class _Reconstruction >
       
   672     void CGlxListTestBase< _List, _Reconstruction >
       
   673         ::AddStaticItemsL( NGlxListTestHelpers::TStaticItemInfo::TData* aInfos )
       
   674     {
       
   675     if ( aInfos )
       
   676         {
       
   677         TInt i = 0;
       
   678         while ( NGlxListTestHelpers::KEndMarker != aInfos[ i ] )
       
   679             {
       
   680             AddStaticItemL( aInfos[ i ].iId, aInfos[ i ].iPosition );
       
   681             i++; 
       
   682             }
       
   683         }
       
   684     }
       
   685     
       
   686 // -----------------------------------------------------------------------------
       
   687 // Check if counts equal
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 template < class _List, class _Reconstruction >
       
   691     TBool CGlxListTestBase< _List, _Reconstruction >::CountEqualsL( TInt aAll, 
       
   692         TInt aNonStatic, TInt aAllStatic, TInt aPreStatic, TInt aPostStatic )
       
   693     {
       
   694     TBool enabled = iList->IsStaticItemsEnabled();
       
   695 
       
   696     // static items disabled
       
   697     iList->SetStaticItemsEnabled( EFalse );
       
   698     TBool fail = ( iList->Count( NGlxListDefs::ECountAll ) != aNonStatic );
       
   699     fail |= ( iList->Count( NGlxListDefs::ECountNonStatic ) != aNonStatic );
       
   700     fail |= ( iList->Count( NGlxListDefs::ECountAllStatic ) != 0 );
       
   701     fail |= ( iList->Count( NGlxListDefs::ECountPreStatic ) != 0 );
       
   702     fail |= ( iList->Count( NGlxListDefs::ECountPostStatic ) != 0 );
       
   703     fail |= ( iList->Count() != iList->Count( NGlxListDefs::ECountAll ) );
       
   704     
       
   705     // static items enabled
       
   706     iList->SetStaticItemsEnabled( ETrue );
       
   707     fail |= ( iList->Count( NGlxListDefs::ECountAll ) != aAll );
       
   708     fail |= ( iList->Count( NGlxListDefs::ECountNonStatic ) != aNonStatic );
       
   709     fail |= ( iList->Count( NGlxListDefs::ECountAllStatic ) != aAllStatic );
       
   710     fail |= ( iList->Count( NGlxListDefs::ECountPreStatic ) != aPreStatic );
       
   711     fail |= ( iList->Count( NGlxListDefs::ECountPostStatic ) != aPostStatic );
       
   712     fail |= ( iList->Count() != iList->Count( NGlxListDefs::ECountAll ) );
       
   713 
       
   714     // Reset to original state
       
   715     iList->SetStaticItemsEnabled( enabled );
       
   716     return !fail;
       
   717     }
       
   718     
       
   719 // -----------------------------------------------------------------------------
       
   720 // Try enabling static items
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 template < class _List, class _Reconstruction >
       
   724     TBool CGlxListTestBase< _List, _Reconstruction >
       
   725         ::TrySetStaticItemsEnabledL( const TDesC8& aStringWithoutStaticItems, 
       
   726             const TDesC8& aStringWithStaticItems, 
       
   727                 NGlxListTestHelpers::TStaticItemInfo::TData* aInfos,
       
   728                     const TNotification::TData* aNotificationListForEnable,
       
   729                         const TNotification::TData* aNotificationListForDisable )
       
   730     {
       
   731     CreateListL( aStringWithoutStaticItems );
       
   732     AddStaticItemsL( aInfos );
       
   733     iList->SetStaticItemsEnabled( EFalse );
       
   734     TBool fail = iList->IsStaticItemsEnabled();
       
   735     // test enabling static items
       
   736     iReconstruction->ClearNotifications();
       
   737     iList->SetStaticItemsEnabled( ETrue );
       
   738     fail |= !iList->IsStaticItemsEnabled();
       
   739     fail |= !Equals( aStringWithStaticItems, aNotificationListForEnable );
       
   740     // test disabling static items 
       
   741     iReconstruction->ClearNotifications();
       
   742     iList->SetStaticItemsEnabled( EFalse );
       
   743     fail |= iList->IsStaticItemsEnabled();
       
   744     fail |= !Equals( aStringWithoutStaticItems, aNotificationListForDisable );
       
   745     
       
   746     return !fail;
       
   747     }
       
   748     
       
   749 // -----------------------------------------------------------------------------
       
   750 // Test Count(...)
       
   751 // -----------------------------------------------------------------------------
       
   752 //
       
   753 template < class _List, class _Reconstruction >
       
   754     void CGlxListTestBase< _List, _Reconstruction >::TestCountL()
       
   755     {
       
   756     // Test list with no normal items
       
   757     CreateListL( _L8("") );
       
   758     EUNIT_ASSERT( CountEqualsL( 0, 0, 0, 0, 0 ) ); // All, non-static, static, pre-static, post-static
       
   759 
       
   760     AddStaticItemL( '0', NGlxListDefs::EInsertFirst );
       
   761     EUNIT_ASSERT( CountEqualsL( 1, 0, 1, 1, 0 ) ); // All, non-static, static, pre-static, post-static
       
   762 
       
   763     AddStaticItemL( '1', NGlxListDefs::EInsertFirst );
       
   764     EUNIT_ASSERT( CountEqualsL( 2, 0, 2, 2, 0 ) ); // All, non-static, static, pre-static, post-static
       
   765 
       
   766     AddStaticItemL( '2', NGlxListDefs::EInsertLast );
       
   767     EUNIT_ASSERT( CountEqualsL( 3, 0, 3, 2, 1 ) ); // All, non-static, static, pre-static, post-static
       
   768 
       
   769     // Test list with normal items
       
   770     CreateListL( _L8("abcdefg") );
       
   771     // test items
       
   772     EUNIT_ASSERT( CountEqualsL( 7, 7, 0, 0, 0 ) ); // All, non-static, static, pre-static, post-static
       
   773     
       
   774     AddStaticItemL( '0', NGlxListDefs::EInsertFirst );
       
   775     EUNIT_ASSERT( CountEqualsL( 8, 7, 1, 1, 0 ) ); // All, non-static, static, pre-static, post-static
       
   776 
       
   777     AddStaticItemL( '1', NGlxListDefs::EInsertFirst );
       
   778     EUNIT_ASSERT( CountEqualsL( 9, 7, 2, 2, 0 ) ); // All, non-static, static, pre-static, post-static
       
   779 
       
   780     AddStaticItemL( '2', NGlxListDefs::EInsertLast );
       
   781     EUNIT_ASSERT( CountEqualsL( 10, 7, 3, 2, 1 ) ); // All, non-static, static, pre-static, post-static
       
   782     }
       
   783     
       
   784 // -----------------------------------------------------------------------------
       
   785 // Test Item(...)
       
   786 // -----------------------------------------------------------------------------
       
   787 //
       
   788 template < class _List, class _Reconstruction >
       
   789     void CGlxListTestBase< _List, _Reconstruction >::TestItemL(  )
       
   790     {
       
   791     // Test list with no normal items
       
   792     CreateListL( _L8("") );
       
   793     AddStaticItemL( '0', NGlxListDefs::EInsertFirst );
       
   794     EUNIT_ASSERT( iList->Item(0).Id() == TGlxMediaId( '0' ) );
       
   795 
       
   796     AddStaticItemL( '1', NGlxListDefs::EInsertFirst );
       
   797     EUNIT_ASSERT( iList->Item(0).Id() == TGlxMediaId( '1' ) );
       
   798     EUNIT_ASSERT( iList->Item(1).Id() == TGlxMediaId( '0' ) );
       
   799 
       
   800     AddStaticItemL( '2', NGlxListDefs::EInsertLast );
       
   801     EUNIT_ASSERT( iList->Item(0).Id() == TGlxMediaId( '1' ) );
       
   802     EUNIT_ASSERT( iList->Item(1).Id() == TGlxMediaId( '0' ) );
       
   803     EUNIT_ASSERT( iList->Item(2).Id() == TGlxMediaId( '2' ) );
       
   804 
       
   805     // Test list with normal items
       
   806     CreateListL( _L8("abcdefg") );
       
   807     // test items
       
   808     EUNIT_ASSERT( iList->Item(0).Id() == TGlxMediaId( 'a' ) );
       
   809     EUNIT_ASSERT( iList->Item(2).Id() == TGlxMediaId( 'c' ) );
       
   810     EUNIT_ASSERT( iList->Item(6).Id() == TGlxMediaId( 'g' ) );
       
   811     
       
   812     AddStaticItemL( '0', NGlxListDefs::EInsertFirst );
       
   813     EUNIT_ASSERT( iList->Item(0).Id() == TGlxMediaId( '0' ) );
       
   814     EUNIT_ASSERT( iList->Item(1).Id() == TGlxMediaId( 'a' ) );
       
   815     EUNIT_ASSERT( iList->Item(3).Id() == TGlxMediaId( 'c' ) );
       
   816     EUNIT_ASSERT( iList->Item(7).Id() == TGlxMediaId( 'g' ) );
       
   817 
       
   818     AddStaticItemL( '1', NGlxListDefs::EInsertFirst );
       
   819     EUNIT_ASSERT( iList->Item(0).Id() == TGlxMediaId( '1' ) );
       
   820     EUNIT_ASSERT( iList->Item(1).Id() == TGlxMediaId( '0' ) );
       
   821     EUNIT_ASSERT( iList->Item(2).Id() == TGlxMediaId( 'a' ) );
       
   822     EUNIT_ASSERT( iList->Item(4).Id() == TGlxMediaId( 'c' ) );
       
   823     EUNIT_ASSERT( iList->Item(8).Id() == TGlxMediaId( 'g' ) );
       
   824 
       
   825     AddStaticItemL( '2', NGlxListDefs::EInsertLast );
       
   826     EUNIT_ASSERT( iList->Item(0).Id() == TGlxMediaId( '1' ) );
       
   827     EUNIT_ASSERT( iList->Item(1).Id() == TGlxMediaId( '0' ) );
       
   828     EUNIT_ASSERT( iList->Item(2).Id() == TGlxMediaId( 'a' ) );
       
   829     EUNIT_ASSERT( iList->Item(4).Id() == TGlxMediaId( 'c' ) );
       
   830     EUNIT_ASSERT( iList->Item(8).Id() == TGlxMediaId( 'g' ) );
       
   831     EUNIT_ASSERT( iList->Item(9).Id() == TGlxMediaId( '2' ) );
       
   832     }
       
   833     
       
   834 // -----------------------------------------------------------------------------
       
   835 // Test Index(...)
       
   836 // -----------------------------------------------------------------------------
       
   837 //
       
   838 template < class _List, class _Reconstruction >
       
   839     void CGlxListTestBase< _List, _Reconstruction >::TestIndexL()
       
   840     {
       
   841     // Test list with no normal items
       
   842     CreateListL( _L8("") );
       
   843     AddStaticItemL( '0', NGlxListDefs::EInsertFirst );
       
   844     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '0' ) ) == 0 );
       
   845 
       
   846     AddStaticItemL( '1', NGlxListDefs::EInsertFirst );
       
   847     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '1' ) ) == 0 );
       
   848     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '0' ) ) == 1 );
       
   849 
       
   850     AddStaticItemL( '2', NGlxListDefs::EInsertLast );
       
   851     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '1' ) ) == 0 );
       
   852     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '0' ) ) == 1 );
       
   853     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '2' ) ) == 2 );
       
   854 
       
   855     // Test list with normal items
       
   856     CreateListL( _L8("abcdefg") );
       
   857     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'a' ) ) == 0 );
       
   858     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'c' ) ) == 2 );
       
   859     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'g' ) ) == 6 );
       
   860     
       
   861     AddStaticItemL( '0', NGlxListDefs::EInsertFirst );
       
   862     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '0' ) ) == 0 );
       
   863     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'a' ) ) == 1 );
       
   864     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'c' ) ) == 3 );
       
   865     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'g' ) ) == 7 );
       
   866 
       
   867     AddStaticItemL( '1', NGlxListDefs::EInsertFirst );
       
   868     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '1' ) ) == 0 );
       
   869     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '0' ) ) == 1 );
       
   870     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'a' ) ) == 2 );
       
   871     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'c' ) ) == 4 );
       
   872     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'g' ) ) == 8 );
       
   873 
       
   874     AddStaticItemL( '2', NGlxListDefs::EInsertLast );
       
   875     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '1' ) ) == 0 );
       
   876     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '0' ) ) == 1 );
       
   877     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'a' ) ) == 2 );
       
   878     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'c' ) ) == 4 );
       
   879     EUNIT_ASSERT( iList->Index(KListIdSpace, TGlxMediaId( 'g' ) ) == 8 );
       
   880     EUNIT_ASSERT( iList->Index(KGlxStaticItemIdSpaceId, TGlxMediaId( '2' ) ) == 9 );
       
   881     }
       
   882     
       
   883 // -----------------------------------------------------------------------------
       
   884 // Test IdSpaceId
       
   885 // -----------------------------------------------------------------------------
       
   886 //
       
   887 template < class _List, class _Reconstruction >
       
   888     void CGlxListTestBase< _List, _Reconstruction >::TestIdSpaceIdL()
       
   889     {
       
   890     CreateReconstructionL();
       
   891     iList = _List::NewL( KListIdSpace, *iReconstruction, *this );
       
   892     EUNIT_ASSERT( iList->IdSpaceId() == TGlxIdSpaceId( 1 ) );
       
   893     }