photosgallery/viewframework/medialists/tsrc/t_cglxcache/t_cglxcache.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
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:    CGlxCache unit tests
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "t_cglxcache.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <digia/eunit/eunitmacros.h>
       
    26 #include <digia/eunit/eunitdecorators.h>
       
    27 
       
    28 #include <mpxmedia.h>
       
    29 #include <mpxmediaarray.h>
       
    30 #include <mpxmediageneraldefs.h>
       
    31 #include <mpxmediacontainerdefs.h>
       
    32 #include <mpxmediadrmdefs.h>
       
    33 
       
    34 //  INTERNAL INCLUDES
       
    35 #include "glxcachemanager.h"
       
    36 #include "glxmedia.h"
       
    37 
       
    38 #include "glxmediageneraldefs.h"
       
    39 
       
    40 #include "glxpanic.h"
       
    41 
       
    42 #include "t_cachetesthelpers.h"
       
    43 
       
    44 const TInt KIdSpaceId = 1;
       
    45 
       
    46 const TInt KMediaId1 = 1;
       
    47 const TInt KMediaId2 = 2;
       
    48 const TInt KMediaId3 = 3;
       
    49 const TInt KMediaId4 = 4;
       
    50 const TInt KMediaId5 = 5;
       
    51 
       
    52 // CONSTRUCTION
       
    53 T_CGlxCache* T_CGlxCache::NewL()
       
    54     {
       
    55     T_CGlxCache* self = T_CGlxCache::NewLC();
       
    56     CleanupStack::Pop();
       
    57 
       
    58     return self;
       
    59     }
       
    60 
       
    61 T_CGlxCache* T_CGlxCache::NewLC()
       
    62     {
       
    63     T_CGlxCache* self = new( ELeave ) T_CGlxCache();
       
    64     CleanupStack::PushL( self );
       
    65 
       
    66     self->ConstructL();
       
    67 
       
    68     return self;
       
    69     }
       
    70 
       
    71 // Destructor (virtual by CBase)
       
    72 T_CGlxCache::~T_CGlxCache()
       
    73     {
       
    74     }
       
    75 
       
    76 // Default constructor
       
    77 T_CGlxCache::T_CGlxCache()
       
    78     {
       
    79     }
       
    80 
       
    81 // Second phase construct
       
    82 void T_CGlxCache::ConstructL()
       
    83     {
       
    84     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    85     // It generates the test case table.
       
    86     CEUnitTestSuiteClass::ConstructL();
       
    87     }
       
    88 
       
    89 //  METHODS
       
    90 
       
    91 
       
    92 void T_CGlxCache::SetupL(  )
       
    93     {
       
    94     iCacheManager = CGlxCacheManager::InstanceL();
       
    95     iCGlxCache = new (ELeave) CGlxCache(TGlxIdSpaceId(KIdSpaceId),iCacheManager);
       
    96 
       
    97     SetupCacheL();
       
    98     }
       
    99     
       
   100 
       
   101 void T_CGlxCache::Teardown(  )
       
   102     {
       
   103 	iCacheManager->Close();
       
   104     delete iCGlxCache; 
       
   105     iCGlxCache = NULL; 
       
   106     }
       
   107     
       
   108 
       
   109 void T_CGlxCache::T_CGlxCache_IdSpaceIdL(  )
       
   110     {
       
   111     TGlxIdSpaceId idSpaceId = iCGlxCache->IdSpaceId( );
       
   112     EUNIT_PRINT(_L("Check IdSpaceId"));
       
   113     EUNIT_ASSERT_DESC( idSpaceId == TGlxIdSpaceId(KIdSpaceId), "Incorrect IdSpaceId");
       
   114     }
       
   115     
       
   116 void T_CGlxCache::T_CGlxCache_MediaUpdatedLL(  )
       
   117     {
       
   118     // Create helper class
       
   119     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   120 
       
   121     // New media
       
   122     CMPXMedia* newMedia3 = CMPXMedia::NewL();
       
   123     CleanupStack::PushL(newMedia3);
       
   124 
       
   125     newMedia3->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId3));
       
   126 
       
   127     EUNIT_PRINT(_L("Add new media"));
       
   128     iCGlxCache->MediaUpdatedL(*newMedia3);
       
   129 
       
   130     EUNIT_PRINT(_L("Check new media added"));
       
   131     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 3, "Cache doesn't contain three items");
       
   132 
       
   133     TInt cachedNewMedia3Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId3), T_CacheTestHelpers::MediaItemOrderByKey);
       
   134     EUNIT_ASSERT_DESC(cachedNewMedia3Index != KErrNotFound, "New media not added to cache");
       
   135 
       
   136     CleanupStack::PopAndDestroy(newMedia3);
       
   137 
       
   138     // Multiple new media
       
   139     CMPXMedia* newMultipleMedia = CMPXMedia::NewL();
       
   140     CleanupStack::PushL(newMultipleMedia);
       
   141 
       
   142     CMPXMediaArray* newMediaArray = CMPXMediaArray::NewL();
       
   143     CleanupStack::PushL(newMediaArray);
       
   144 
       
   145     CMPXMedia* newMedia4 = CMPXMedia::NewL();
       
   146     CleanupStack::PushL(newMedia4);
       
   147 
       
   148     newMedia4->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId4));
       
   149 
       
   150     newMediaArray->AppendL(newMedia4);
       
   151     CleanupStack::Pop(newMedia4);
       
   152 
       
   153     CMPXMedia* newMedia5 = CMPXMedia::NewL();
       
   154     CleanupStack::PushL(newMedia5);
       
   155 
       
   156     newMedia5->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId5));
       
   157 
       
   158     newMediaArray->AppendL(newMedia5);
       
   159     CleanupStack::Pop(newMedia5);
       
   160 
       
   161     newMultipleMedia->SetCObjectValueL(KMPXMediaArrayContents, newMediaArray);
       
   162     newMultipleMedia->SetTObjectValueL(KMPXMediaArrayCount, newMediaArray->Count());
       
   163 
       
   164     EUNIT_PRINT(_L("Add multiple new media"));
       
   165     iCGlxCache->MediaUpdatedL(*newMultipleMedia);
       
   166 
       
   167     CleanupStack::PopAndDestroy(newMediaArray);
       
   168     CleanupStack::PopAndDestroy(newMultipleMedia);
       
   169 
       
   170     EUNIT_PRINT(_L("Check multiple new media added"));
       
   171     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 5, "Cache doesn't contain five items");
       
   172 
       
   173     TInt cachedNewMedia4Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId4), T_CacheTestHelpers::MediaItemOrderByKey);
       
   174     TInt cachedNewMedia5Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId5), T_CacheTestHelpers::MediaItemOrderByKey);
       
   175     EUNIT_ASSERT_DESC((cachedNewMedia4Index != KErrNotFound) && (cachedNewMedia5Index != KErrNotFound), "Multiple new media not added to cache");
       
   176     }
       
   177     
       
   178 void T_CGlxCache::T_CGlxCache_UpdateMediaLL(  )
       
   179     {
       
   180     // Create helper class
       
   181     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   182 
       
   183     // Create cache observer class
       
   184     CGlxCacheObserverTest* cacheObserver = CGlxCacheObserverTest::NewL();
       
   185     CleanupStack::PushL(cacheObserver);
       
   186 
       
   187     CGlxCacheManager* cacheManager = CGlxCacheManager::InstanceL();
       
   188     CleanupClosePushL(*cacheManager);
       
   189 
       
   190     cacheManager->AddObserverL(cacheObserver);
       
   191 
       
   192     // New media without id
       
   193     CMPXMedia* newMedia3 = CMPXMedia::NewL();
       
   194     CleanupStack::PushL(newMedia3);
       
   195 
       
   196     EUNIT_PRINT(_L("Add new media without id"));
       
   197     iCGlxCache->UpdateMediaL(*newMedia3);
       
   198 
       
   199     EUNIT_PRINT(_L("Check new media not added"));
       
   200     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 2, "Cache doesn't contain two items");
       
   201 
       
   202     // New media without attributes
       
   203     newMedia3->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId3));
       
   204 
       
   205     EUNIT_PRINT(_L("Add new media without attributes"));
       
   206     iCGlxCache->UpdateMediaL(*newMedia3);
       
   207 
       
   208     EUNIT_PRINT(_L("Check new media added without attributes"));
       
   209     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 3, "Cache doesn't contain three items");
       
   210     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool()[2]->Count() == 0, "Item contains attributes");
       
   211 
       
   212     TInt cachedNewMedia3Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId3), T_CacheTestHelpers::MediaItemOrderByKey);
       
   213     EUNIT_ASSERT_DESC(cachedNewMedia3Index != KErrNotFound, "New media not added to cache");
       
   214 
       
   215     EUNIT_PRINT(_L("Check observer not notified of new media attributes"));
       
   216     EUNIT_ASSERT_DESC(!cacheObserver->AttributesAvailableNotified(), "Observer notified of new media attributes");
       
   217 
       
   218     CleanupStack::PopAndDestroy(newMedia3);
       
   219 
       
   220     // New media with attributes
       
   221     CMPXMedia* newMedia4 = CMPXMedia::NewL();
       
   222     CleanupStack::PushL(newMedia4);
       
   223 
       
   224     newMedia4->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId4));
       
   225     newMedia4->SetTObjectValueL<TSize>(KGlxMediaGeneralDimensions, TSize(640, 480));
       
   226 
       
   227     EUNIT_PRINT(_L("Add new media with attributes"));
       
   228     cacheObserver->ResetCalls();
       
   229     iCGlxCache->UpdateMediaL(*newMedia4);
       
   230 
       
   231     EUNIT_PRINT(_L("Check new media added with attributes"));
       
   232     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 4, "Cache doesn't contain four items");
       
   233     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool()[3]->Count() == 1, "Item doesn't contain attributes");
       
   234 
       
   235     EUNIT_PRINT(_L("Check observer notified of new media attributes"));
       
   236     EUNIT_ASSERT_DESC(cacheObserver->AttributesAvailableNotified(), "Observer not notified of new media attributes");
       
   237     EUNIT_ASSERT_DESC(cacheObserver->IdSpaceId().Value() == KIdSpaceId, "Observer not notified of correct new media IdSpaceId");
       
   238     EUNIT_ASSERT_DESC(cacheObserver->MediaId().Value() == KMediaId4, "Observer not notified of correct new media Id");
       
   239 
       
   240     EUNIT_ASSERT_DESC(TMPXAttribute::Match(cacheObserver->Attributes()[0], KGlxMediaGeneralDimensions), "Observer not notified of correct new media attribute");
       
   241     EUNIT_ASSERT_DESC(cacheObserver->Attributes().Count() == 1, "Observer not notified of correct new media attribute count");
       
   242 
       
   243     EUNIT_ASSERT_DESC(cacheObserver->Media() == cacheTestHelper.ItemPool()[3], "Observer not notified of correct new media pointer");
       
   244 
       
   245     CleanupStack::PopAndDestroy(newMedia4);
       
   246 
       
   247     // Create media user class
       
   248     CGlxMediaUserTest* mediaUser = CGlxMediaUserTest::NewL();
       
   249     CleanupStack::PushL(mediaUser);
       
   250 
       
   251     cacheTestHelper.ItemPool()[0]->ReserveUsersL(1);
       
   252     cacheTestHelper.ItemPool()[0]->AddUser(*mediaUser, KErrNotFound);
       
   253 
       
   254     // Update media with existing attributes
       
   255     CMPXMedia* Media1 = CMPXMedia::NewL();
       
   256     CleanupStack::PushL(Media1);
       
   257     Media1->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId1));
       
   258     Media1->SetTObjectValueL<TBool>(KMPXMediaDrmProtected, ETrue);
       
   259 
       
   260     EUNIT_PRINT(_L("Update media with existing attributes"));
       
   261     cacheObserver->ResetCalls();
       
   262     iCGlxCache->UpdateMediaL(*Media1);
       
   263 
       
   264     EUNIT_PRINT(_L("Check media updated with existing attributes"));
       
   265     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 4, "Cache doesn't contain four items");
       
   266     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool()[0]->Count() == 1, "Item doesn't contain 1 attribute");
       
   267 
       
   268     EUNIT_PRINT(_L("Check user not notified of media new attributes"));
       
   269     EUNIT_ASSERT_DESC(!mediaUser->AttributesAvailableNotified(), "User notified of updated media new attributes");
       
   270     EUNIT_ASSERT_DESC(!cacheObserver->AttributesAvailableNotified(), "Observer notified of updated media new attributes");
       
   271 
       
   272     // Update media with new attributes
       
   273     Media1->SetTObjectValueL<TSize>(KGlxMediaGeneralDimensions, TSize(1024, 768));
       
   274 
       
   275     EUNIT_PRINT(_L("Update media with new attributes"));
       
   276     cacheObserver->ResetCalls();
       
   277     mediaUser->ResetCalls();
       
   278     iCGlxCache->UpdateMediaL(*Media1);
       
   279 
       
   280     EUNIT_PRINT(_L("Check media updated with new attributes"));
       
   281     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 4, "Cache doesn't contain four items");
       
   282     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool()[0]->Count() == 2, "Item doesn't contain 2 attributes");
       
   283 
       
   284     EUNIT_PRINT(_L("Check user notified of updated media new attributes"));
       
   285     EUNIT_ASSERT_DESC(mediaUser->AttributesAvailableNotified(), "User not notified of updated media new attributes");
       
   286     EUNIT_ASSERT_DESC(mediaUser->IdSpaceId().Value() == KIdSpaceId, "User not notified of correct updated media IdSpaceId");
       
   287     EUNIT_ASSERT_DESC(mediaUser->MediaId().Value() == KMediaId1, "User not notified of correct updated media Id");
       
   288 
       
   289     EUNIT_ASSERT_DESC(TMPXAttribute::Match(mediaUser->Attributes()[0], KGlxMediaGeneralDimensions), "Observer not notified of correct updated media attribute");
       
   290     EUNIT_ASSERT_DESC(mediaUser->Attributes().Count() == 1, "Observer not notified of correct updated media attribute count");
       
   291 
       
   292     EUNIT_PRINT(_L("Check observer notified of updated media new attributes"));
       
   293     EUNIT_ASSERT_DESC(cacheObserver->AttributesAvailableNotified(), "Observer not notified of updated media new attributes");
       
   294     EUNIT_ASSERT_DESC(cacheObserver->IdSpaceId().Value() == KIdSpaceId, "Observer not notified of correct updated media IdSpaceId");
       
   295     EUNIT_ASSERT_DESC(cacheObserver->MediaId().Value() == KMediaId1, "Observer not notified of correct updated media Id");
       
   296 
       
   297     EUNIT_ASSERT_DESC(TMPXAttribute::Match(cacheObserver->Attributes()[0], KGlxMediaGeneralDimensions), "Observer not notified of correct updated media attribute");
       
   298     EUNIT_ASSERT_DESC(cacheObserver->Attributes().Count() == 1, "Observer not notified of correct updated media attribute count");
       
   299 
       
   300     EUNIT_ASSERT_DESC(cacheObserver->Media() == cacheTestHelper.ItemPool()[0], "Observer not notified of correct updated media pointer");
       
   301 
       
   302     cacheTestHelper.ItemPool()[0]->RemoveUser(*mediaUser);
       
   303     cacheManager->RemoveObserver(cacheObserver);
       
   304 
       
   305     CleanupStack::PopAndDestroy(Media1);
       
   306     CleanupStack::PopAndDestroy(mediaUser);
       
   307     CleanupStack::PopAndDestroy(cacheManager);
       
   308     CleanupStack::PopAndDestroy(cacheObserver);
       
   309     }
       
   310     
       
   311 void T_CGlxCache::T_CGlxCache_HandleItemModifiedL(  )
       
   312     {
       
   313     // Create helper class
       
   314     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   315 
       
   316     RArray<TMPXAttribute> attributes;
       
   317     CleanupClosePushL(attributes);
       
   318 
       
   319     attributes.AppendL(KMPXMediaDrmProtected);
       
   320 
       
   321     EUNIT_PRINT(_L("Modify item attributes"));
       
   322     iCGlxCache->HandleItemModified(TGlxMediaId(KMediaId1), attributes);
       
   323 
       
   324     CleanupStack::PopAndDestroy(&attributes);
       
   325 
       
   326     EUNIT_PRINT(_L("Check attribute deleted as result of item modification"));
       
   327     TInt Media1AttributeCount = cacheTestHelper.ItemPool()[0]->Count();
       
   328     TInt Media2AttributeCount = cacheTestHelper.ItemPool()[1]->Count();
       
   329     
       
   330     EUNIT_ASSERT_DESC(Media1AttributeCount == 0, "Attribute not deleted for item modified");
       
   331     EUNIT_ASSERT_DESC(Media2AttributeCount == 1, "Attribute deleted for item not modified");
       
   332     }
       
   333     
       
   334 void T_CGlxCache::T_CGlxCache_MediaL(  )
       
   335     {
       
   336     // Create helper class
       
   337     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   338 
       
   339     EUNIT_PRINT(_L("Obtain non-existing media by id"));
       
   340     CGlxMedia* media = iCGlxCache->Media(TGlxMediaId(KMediaId3));
       
   341 
       
   342     EUNIT_PRINT(_L("Check returned media"));
       
   343     EUNIT_ASSERT_DESC(media == NULL, "Media returned");
       
   344 
       
   345     EUNIT_PRINT(_L("Obtain media by id"));
       
   346     media = iCGlxCache->Media(TGlxMediaId(KMediaId1));
       
   347 
       
   348     EUNIT_PRINT(_L("Check returned media"));
       
   349     EUNIT_ASSERT_DESC(media == cacheTestHelper.ItemPool()[0], "Incorrect media returned");
       
   350     }
       
   351     
       
   352 void T_CGlxCache::T_CGlxCache_FindItemForceCreateLL(  )
       
   353     {
       
   354     // Create helper class
       
   355     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   356 
       
   357     // Find existing instance
       
   358     EUNIT_PRINT(_L("Find existing media"));
       
   359     CGlxMedia* media = iCGlxCache->FindItemForceCreateL(TGlxMediaId(KMediaId1));
       
   360 
       
   361     EUNIT_PRINT(_L("Check returned media"));
       
   362     EUNIT_ASSERT_DESC(media == cacheTestHelper.ItemPool()[0], "Incorrect media returned");
       
   363 
       
   364     // Find non-existing media
       
   365     EUNIT_PRINT(_L("Find non-existing media"));
       
   366     media = iCGlxCache->FindItemForceCreateL(TGlxMediaId(KMediaId3));
       
   367 
       
   368     EUNIT_PRINT(_L("Check returned media"));
       
   369     EUNIT_ASSERT_DESC(media == cacheTestHelper.ItemPool()[2], "Incorrect media returned");
       
   370     }
       
   371     
       
   372 void T_CGlxCache::T_CGlxCache_CountL(  )
       
   373     {
       
   374     EUNIT_PRINT(_L("Obtain media count"));
       
   375     TInt count = iCGlxCache->Count();
       
   376 
       
   377     EUNIT_PRINT(_L("Check media count"));
       
   378     EUNIT_ASSERT_DESC(count == 2, "Incorrect media count");
       
   379     }
       
   380     
       
   381 void T_CGlxCache::T_CGlxCache_Media2L(  )
       
   382     {
       
   383     EUNIT_PRINT(_L("Obtain media by index"));
       
   384     CGlxMedia& media = iCGlxCache->Media(1);
       
   385 
       
   386     EUNIT_PRINT(_L("Check returned media"));
       
   387     EUNIT_ASSERT_DESC(media.Id().Value() == KMediaId2, "Incorrect media returned");
       
   388     }
       
   389     
       
   390 void T_CGlxCache::T_CGlxCache_Delete_SubTest1L(  )
       
   391     {
       
   392 #ifdef _DEBUG
       
   393     // Delete index less than 0
       
   394     EUNIT_PRINT(_L("Delete index less than 0"));
       
   395     EUNIT_ASSERT_PANIC_DESC(iCGlxCache->Delete(-1), "Images & videos", EGlxPanicIllegalArgument, "Incorrect panic");
       
   396 #endif // _DEBUG
       
   397     }
       
   398 
       
   399 void T_CGlxCache::T_CGlxCache_Delete_SubTest2L(  )
       
   400     {
       
   401 #ifdef _DEBUG
       
   402     // Delete index greater than number of items
       
   403     EUNIT_PRINT(_L("Delete index greater than number of items"));
       
   404     EUNIT_ASSERT_PANIC_DESC(iCGlxCache->Delete(2), "Images & videos", EGlxPanicIllegalArgument, "Incorrect panic");
       
   405 #endif // _DEBUG
       
   406     }
       
   407 
       
   408 void T_CGlxCache::T_CGlxCache_Delete_SubTest3L(  )
       
   409     {
       
   410     // Create helper class
       
   411     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   412 
       
   413     // Create item without users
       
   414     CGlxMedia* media3 = new (ELeave) CGlxMedia(TGlxMediaId(KMediaId3));
       
   415     CleanupStack::PushL(media3);
       
   416 
       
   417     media3->SetTObjectValueL<TBool>(KGlxMediaGeneralSystemItem, EFalse);
       
   418     cacheTestHelper.ItemPool().AppendL(media3);
       
   419 
       
   420     CleanupStack::Pop(media3);
       
   421 
       
   422     // Delete item without users
       
   423     EUNIT_PRINT(_L("Delete item without users"));
       
   424     iCGlxCache->Delete(2);
       
   425 
       
   426     EUNIT_PRINT(_L("Check item deleted"));
       
   427     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 2, "Cache doesn't contain two items");
       
   428 
       
   429     TInt media1Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId1), T_CacheTestHelpers::MediaItemOrderByKey);
       
   430     TInt media2Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId2), T_CacheTestHelpers::MediaItemOrderByKey);
       
   431     EUNIT_ASSERT_DESC((media1Index != KErrNotFound) && (media2Index != KErrNotFound), "Incorrect item deleted from cache");
       
   432     }
       
   433     
       
   434 void T_CGlxCache::T_CGlxCache_Delete_SubTest4L(  )
       
   435     {
       
   436 #ifdef _DEBUG
       
   437     // Create helper class
       
   438     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   439 
       
   440     // Create media user class
       
   441     CGlxMediaUserTest* mediaUser = CGlxMediaUserTest::NewL();
       
   442     CleanupStack::PushL(mediaUser);
       
   443 
       
   444     cacheTestHelper.ItemPool()[0]->ReserveUsersL(1);
       
   445     cacheTestHelper.ItemPool()[0]->AddUser(*mediaUser, KErrNotFound);
       
   446 
       
   447     // Delete item where user doesn't have reference to media
       
   448     EUNIT_PRINT(_L("Delete item where user doesn't have reference to media"));
       
   449     EUNIT_ASSERT_PANIC_DESC(iCGlxCache->Delete(0), "Images & videos", EGlxPanicLogicError, "Item deleted where user had reference to media");
       
   450 #endif // _DEBUG
       
   451     }
       
   452 
       
   453 void T_CGlxCache::T_CGlxCache_Delete_SubTest5L(  )
       
   454     {
       
   455     // Create helper class
       
   456     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   457 
       
   458     // Create media user class
       
   459     CGlxMediaUserTest* mediaUser = CGlxMediaUserTest::NewL();
       
   460     CleanupStack::PushL(mediaUser);
       
   461 
       
   462     cacheTestHelper.ItemPool()[1]->ReserveUsersL(1);
       
   463     cacheTestHelper.ItemPool()[1]->AddUser(*mediaUser, KErrNotFound);
       
   464 
       
   465     // Delete item where user has reference to media
       
   466     EUNIT_PRINT(_L("Delete item where user has reference to media"));
       
   467     iCGlxCache->Delete(1);
       
   468 
       
   469     EUNIT_PRINT(_L("Check item deleted"));
       
   470     EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 1, "Cache doesn't contain one item");
       
   471 
       
   472     TInt media1Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId1), T_CacheTestHelpers::MediaItemOrderByKey);
       
   473     EUNIT_ASSERT_DESC(media1Index != KErrNotFound, "Incorrect item deleted from cache");
       
   474 
       
   475     EUNIT_PRINT(_L("Check user called to remove reference"));
       
   476     EUNIT_ASSERT_DESC(mediaUser->RemoveReferenceCalled(), "User not called to remove reference");
       
   477 
       
   478     CleanupStack::PopAndDestroy(mediaUser);
       
   479     }
       
   480 
       
   481 void T_CGlxCache::T_CGlxCache_ReserveUsersLL(  )
       
   482     {
       
   483     // iCGlxCache->ReserveUsersL( <add parameters here > );
       
   484     EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   485     }
       
   486     
       
   487 void T_CGlxCache::SetupCacheL()
       
   488     {
       
   489     // Create helper class
       
   490     T_CacheTestHelpers cacheTestHelper(iCGlxCache);
       
   491 
       
   492     CGlxMedia* media1 = new (ELeave) CGlxMedia(TGlxMediaId(KMediaId1));
       
   493     CleanupStack::PushL(media1);
       
   494 
       
   495     media1->SetTObjectValueL<TBool>(KMPXMediaDrmProtected, EFalse);
       
   496     cacheTestHelper.ItemPool().AppendL(media1);
       
   497 
       
   498     CleanupStack::Pop(media1);
       
   499 
       
   500     CGlxMedia* media2 = new (ELeave) CGlxMedia(TGlxMediaId(KMediaId2));
       
   501     CleanupStack::PushL(media2);
       
   502 
       
   503     media2->SetTObjectValueL<TSize>(KGlxMediaGeneralDimensions, TSize(320, 240));
       
   504     cacheTestHelper.ItemPool().AppendL(media2);
       
   505 
       
   506     CleanupStack::Pop(media2);
       
   507     }
       
   508 
       
   509 // Test cache observer
       
   510 T_CGlxCache::CGlxCacheObserverTest* T_CGlxCache::CGlxCacheObserverTest::NewL()
       
   511     {
       
   512     CGlxCacheObserverTest* self = new (ELeave) CGlxCacheObserverTest();
       
   513     CleanupStack::PushL(self);
       
   514     self->ConstructL();
       
   515     CleanupStack::Pop();
       
   516     return self;
       
   517     }
       
   518 
       
   519 T_CGlxCache::CGlxCacheObserverTest::CGlxCacheObserverTest() :
       
   520         iAttributesAvailableNotified(EFalse),
       
   521         iIdSpaceId(KGlxIdNone),
       
   522         iMediaId(KGlxIdNone),
       
   523         iAttributes(),
       
   524         iMedia(NULL)
       
   525     {
       
   526     }
       
   527 
       
   528 T_CGlxCache::CGlxCacheObserverTest::~CGlxCacheObserverTest()
       
   529     {
       
   530     iAttributes.Close();
       
   531     }
       
   532 
       
   533 void T_CGlxCache::CGlxCacheObserverTest::ConstructL()
       
   534     {
       
   535     }
       
   536 
       
   537 TBool T_CGlxCache::CGlxCacheObserverTest::AttributesAvailableNotified() const
       
   538     {
       
   539     return iAttributesAvailableNotified;
       
   540     }
       
   541 
       
   542 void T_CGlxCache::CGlxCacheObserverTest::ResetCalls()
       
   543     {
       
   544     iAttributesAvailableNotified = EFalse;
       
   545     }
       
   546 
       
   547 const TGlxIdSpaceId& T_CGlxCache::CGlxCacheObserverTest::IdSpaceId() const
       
   548     {
       
   549     return iIdSpaceId;
       
   550     }
       
   551 
       
   552 const TGlxMediaId& T_CGlxCache::CGlxCacheObserverTest::MediaId() const
       
   553     {
       
   554     return iMediaId;
       
   555     }
       
   556 
       
   557 const RArray<TMPXAttribute>& T_CGlxCache::CGlxCacheObserverTest::Attributes() const
       
   558     {
       
   559     return iAttributes;
       
   560     }
       
   561 
       
   562 const CGlxMedia* T_CGlxCache::CGlxCacheObserverTest::Media() const
       
   563     {
       
   564     return iMedia;
       
   565     }
       
   566 
       
   567 void T_CGlxCache::CGlxCacheObserverTest::HandleAttributesAvailableL(
       
   568         const TGlxIdSpaceId& aIdSpaceId, 
       
   569         const TGlxMediaId& aMediaId, 
       
   570         const RArray<TMPXAttribute>& aAttributes, 
       
   571         const CGlxMedia* aMedia)
       
   572     {
       
   573     iIdSpaceId = aIdSpaceId;
       
   574     iMediaId = aMediaId;
       
   575 
       
   576     iAttributes.Reset();
       
   577     TInt attributeCount = aAttributes.Count();
       
   578     for (TInt i = 0; i < attributeCount; ++i)
       
   579         {
       
   580         TMPXAttribute attribute = aAttributes[i];
       
   581         iAttributes.AppendL(attribute);
       
   582         }
       
   583 
       
   584     iMedia = const_cast<CGlxMedia*>(aMedia);
       
   585 
       
   586     iAttributesAvailableNotified = ETrue;
       
   587     }
       
   588 
       
   589 
       
   590 void T_CGlxCache::CGlxCacheObserverTest::CleanupMedia(const TGlxMediaId& /*aMediaId*/)
       
   591     {
       
   592     //No Implementation
       
   593     }
       
   594 
       
   595 
       
   596 // Test media user
       
   597 T_CGlxCache::CGlxMediaUserTest* T_CGlxCache::CGlxMediaUserTest::NewL()
       
   598     {
       
   599     CGlxMediaUserTest* self = new (ELeave) CGlxMediaUserTest();
       
   600     CleanupStack::PushL(self);
       
   601     self->ConstructL();
       
   602     CleanupStack::Pop();
       
   603     return self;
       
   604     }
       
   605 
       
   606 T_CGlxCache::CGlxMediaUserTest::CGlxMediaUserTest() :
       
   607         iAttributesAvailableNotified(EFalse),
       
   608         iRemoveReferenceCalled(EFalse),
       
   609         iIdSpaceId(KGlxIdNone),
       
   610         iMediaId(KGlxIdNone),
       
   611         iAttributes()
       
   612     {
       
   613     }
       
   614 
       
   615 T_CGlxCache::CGlxMediaUserTest::~CGlxMediaUserTest()
       
   616     {
       
   617     iAttributes.Close();
       
   618     }
       
   619 
       
   620 void T_CGlxCache::CGlxMediaUserTest::ConstructL()
       
   621     {
       
   622     }
       
   623 
       
   624 TBool T_CGlxCache::CGlxMediaUserTest::AttributesAvailableNotified() const
       
   625     {
       
   626     return iAttributesAvailableNotified;
       
   627     }
       
   628 
       
   629 TBool T_CGlxCache::CGlxMediaUserTest::RemoveReferenceCalled() const
       
   630     {
       
   631     return iRemoveReferenceCalled;
       
   632     }
       
   633 
       
   634 void T_CGlxCache::CGlxMediaUserTest::ResetCalls()
       
   635     {
       
   636     iAttributesAvailableNotified = EFalse;
       
   637     iRemoveReferenceCalled = EFalse;
       
   638     }
       
   639 
       
   640 const TGlxIdSpaceId& T_CGlxCache::CGlxMediaUserTest::IdSpaceId() const
       
   641     {
       
   642     return iIdSpaceId;
       
   643     }
       
   644 
       
   645 const TGlxMediaId& T_CGlxCache::CGlxMediaUserTest::MediaId() const
       
   646     {
       
   647     return iMediaId;
       
   648     }
       
   649 
       
   650 const RArray<TMPXAttribute>& T_CGlxCache::CGlxMediaUserTest::Attributes() const
       
   651     {
       
   652     return iAttributes;
       
   653     }
       
   654 
       
   655 void T_CGlxCache::CGlxMediaUserTest::HandleAttributesAvailableL(
       
   656         const TGlxIdSpaceId& aIdSpaceId, 
       
   657         const TGlxMediaId& aItemId, 
       
   658         const RArray<TMPXAttribute>& aAttributes)
       
   659     {
       
   660     iIdSpaceId = aIdSpaceId;
       
   661     iMediaId = aItemId;
       
   662 
       
   663     iAttributes.Reset();
       
   664     TInt attributeCount = aAttributes.Count();
       
   665     for (TInt i = 0; i < attributeCount; ++i)
       
   666         {
       
   667         TMPXAttribute attribute = aAttributes[i];
       
   668         iAttributes.AppendL(attribute);
       
   669         }
       
   670 
       
   671     iAttributesAvailableNotified = ETrue;
       
   672     }
       
   673 
       
   674 void T_CGlxCache::CGlxMediaUserTest::RemoveReference(CGlxMedia& aMedia)
       
   675     {
       
   676     // This is related to T_CGlxCache_Delete_SubTest4L and T_CGlxCache_Delete_SubTest5L
       
   677     // T_CGlxCache_Delete_SubTest4L: Delete item where user doesn't have reference to media -> Don't remove reference
       
   678     // T_CGlxCache_Delete_SubTest5L: Delete item where user has reference to media -> Remove reference
       
   679     if (aMedia.Id().Value() == KMediaId2)
       
   680         {
       
   681         aMedia.RemoveUser(*this);
       
   682         }
       
   683 
       
   684     iRemoveReferenceCalled = ETrue;
       
   685     }
       
   686     
       
   687     
       
   688 void T_CGlxCache::CGlxMediaUserTest::RemoveReference(TInt aIndex)
       
   689 	{
       
   690 	
       
   691 	}
       
   692 
       
   693 
       
   694 void T_CGlxCache::CGlxMediaUserTest:: HandleAttributesAvailableL(TInt aIndex,
       
   695  			 const RArray<TMPXAttribute>& aAttributes)
       
   696  	{
       
   697  	
       
   698  	}
       
   699 
       
   700 //  TEST TABLE
       
   701 EUNIT_BEGIN_TEST_TABLE(
       
   702     T_CGlxCache,
       
   703     "Add test suite description here.",
       
   704     "UNIT" )
       
   705 
       
   706 EUNIT_TEST(
       
   707     "IdSpaceId - test1",
       
   708     "CGlxCache",
       
   709     "IdSpaceId - test1",
       
   710     "FUNCTIONALITY",
       
   711     SetupL, T_CGlxCache_IdSpaceIdL, Teardown)
       
   712     
       
   713 /*EUNIT_TEST(
       
   714     "MediaUpdatedL - test2",
       
   715     "CGlxCache",
       
   716     "MediaUpdatedL - test2",
       
   717     "FUNCTIONALITY",
       
   718     SetupL, T_CGlxCache_MediaUpdatedLL, Teardown)*/
       
   719     
       
   720 /*EUNIT_TEST(
       
   721     "UpdateMediaL - test3",
       
   722     "CGlxCache",
       
   723     "UpdateMediaL - test3",
       
   724     "FUNCTIONALITY",
       
   725     SetupL, T_CGlxCache_UpdateMediaLL, Teardown)*/
       
   726     
       
   727 EUNIT_TEST(
       
   728     "HandleItemModified - test4",
       
   729     "CGlxCache",
       
   730     "HandleItemModified - test4",
       
   731     "FUNCTIONALITY",
       
   732     SetupL, T_CGlxCache_HandleItemModifiedL, Teardown)
       
   733     
       
   734 EUNIT_TEST(
       
   735     "Media - test5",
       
   736     "CGlxCache",
       
   737     "Media - test5",
       
   738     "FUNCTIONALITY",
       
   739     SetupL, T_CGlxCache_MediaL, Teardown)
       
   740     
       
   741 /*EUNIT_TEST(
       
   742     "FindItemForceCreateL - test6",
       
   743     "CGlxCache",
       
   744     "FindItemForceCreateL - test6",
       
   745     "FUNCTIONALITY",
       
   746     SetupL, T_CGlxCache_FindItemForceCreateLL, Teardown)*/
       
   747     
       
   748 EUNIT_TEST(
       
   749     "Count - test7",
       
   750     "CGlxCache",
       
   751     "Count - test7",
       
   752     "FUNCTIONALITY",
       
   753     SetupL, T_CGlxCache_CountL, Teardown)
       
   754     
       
   755 EUNIT_TEST(
       
   756     "Media - test8",
       
   757     "CGlxCache",
       
   758     "Media - test8",
       
   759     "FUNCTIONALITY",
       
   760     SetupL, T_CGlxCache_Media2L, Teardown)
       
   761     
       
   762 EUNIT_TEST(
       
   763     "Delete - test9, subtest1",
       
   764     "CGlxCache",
       
   765     "Delete - test9, subtest1",
       
   766     "FUNCTIONALITY",
       
   767     SetupL, T_CGlxCache_Delete_SubTest1L, Teardown)
       
   768 
       
   769 EUNIT_TEST(
       
   770     "Delete - test9, subtest2",
       
   771     "CGlxCache",
       
   772     "Delete - test9, subtest2",
       
   773     "FUNCTIONALITY",
       
   774     SetupL, T_CGlxCache_Delete_SubTest2L, Teardown)
       
   775 
       
   776 EUNIT_TEST(
       
   777     "Delete - test9, subtest3",
       
   778     "CGlxCache",
       
   779     "Delete - test9, subtest3",
       
   780     "FUNCTIONALITY",
       
   781     SetupL, T_CGlxCache_Delete_SubTest3L, Teardown)
       
   782 
       
   783 EUNIT_TEST(
       
   784     "Delete - test9, subtest4",
       
   785     "CGlxCache",
       
   786     "Delete - test9, subtest4",
       
   787     "FUNCTIONALITY",
       
   788     SetupL, T_CGlxCache_Delete_SubTest4L, Teardown)
       
   789 
       
   790 EUNIT_TEST(
       
   791     "Delete - test9, subtest5",
       
   792     "CGlxCache",
       
   793     "Delete - test9, subtest5",
       
   794     "FUNCTIONALITY",
       
   795     SetupL, T_CGlxCache_Delete_SubTest5L, Teardown)
       
   796     
       
   797 /*EUNIT_TEST(
       
   798     "ReserveUsersL - test10",
       
   799     "CGlxCache",
       
   800     "ReserveUsersL - test10",
       
   801     "FUNCTIONALITY",
       
   802     SetupL, T_CGlxCache_ReserveUsersLL, Teardown)*/
       
   803     
       
   804 
       
   805 EUNIT_END_TEST_TABLE
       
   806 
       
   807 //  END OF FILE