gssettingsuis/Gs/tsrc/private/Src/T_CGSPluginInterface.cpp
changeset 68 13e71d907dc3
parent 0 8c5d936e5675
equal deleted inserted replaced
40:6465d5bb863a 68:13e71d907dc3
       
     1 /*
       
     2 * Copyright (c) 2006 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  CLASS HEADER
       
    20 #include "T_CGSPluginInterface.h"
       
    21 
       
    22 //  EXTERNAL INCLUDES
       
    23 #include <EUnitMacros.h>
       
    24 #include <EUnitDecorators.h>
       
    25 #include <GSFWViewUIDs.h>
       
    26 #include <ecom.h>
       
    27 
       
    28 #include "GSWatchDog.h"
       
    29 
       
    30 //  INTERNAL INCLUDES
       
    31 
       
    32 
       
    33 
       
    34 CGSPluginIndexer* CGSPluginIndexer::NewL( TUid aInterface )
       
    35     {
       
    36     CGSPluginIndexer* self = new( ELeave ) CGSPluginIndexer( aInterface );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 CGSPluginIndexer::CGSPluginIndexer( TUid aInterface )
       
    44     : iInterfaceUid( aInterface)
       
    45     {
       
    46     }
       
    47 
       
    48 
       
    49 CGSPluginIndexer::~CGSPluginIndexer()
       
    50     {
       
    51     iImplInfoArray.ResetAndDestroy();// This is needed
       
    52     iImplInfoArray.Close();
       
    53     }
       
    54 
       
    55 
       
    56 void CGSPluginIndexer::ConstructL()
       
    57     {
       
    58     REComSession::ListImplementationsL( iInterfaceUid,
       
    59                                         iImplInfoArray );
       
    60     iIndex = 0;
       
    61     }
       
    62 
       
    63 
       
    64 TBool CGSPluginIndexer::HasNext()
       
    65     {
       
    66     if( iImplInfoArray.Count() >= iIndex + 1 )
       
    67         {
       
    68         return ETrue;
       
    69         }
       
    70     else
       
    71         {
       
    72         EUNIT_PRINT( _L("CGSPluginIndexer(%d/%d)"), iIndex, iImplInfoArray.Count() );
       
    73         return EFalse;
       
    74         }
       
    75     }
       
    76 
       
    77 
       
    78 TUid CGSPluginIndexer::NextUid()
       
    79     {
       
    80     EUNIT_PRINT( _L("NextUid(%d/%d)"), iIndex, iImplInfoArray.Count() );
       
    81     return iImplInfoArray[ iIndex++ ]->ImplementationUid();
       
    82     }
       
    83 
       
    84 
       
    85 void CGSPluginIndexer::ResetIndex()
       
    86     {
       
    87     iIndex = 0;
       
    88     }
       
    89 
       
    90 
       
    91 TInt CGSPluginIndexer::Index()
       
    92     {
       
    93     return iIndex;
       
    94     }
       
    95 
       
    96 TInt CGSPluginIndexer::Count()
       
    97     {
       
    98     return iImplInfoArray.Count();
       
    99     }
       
   100 
       
   101 ///////////////////////////////////////////////////////////////
       
   102 
       
   103 
       
   104 // CONSTRUCTION
       
   105 T_CGSPluginInterface* T_CGSPluginInterface::NewL()
       
   106     {
       
   107     T_CGSPluginInterface* self = T_CGSPluginInterface::NewLC();
       
   108     CleanupStack::Pop();
       
   109     return self;
       
   110     }
       
   111 
       
   112 T_CGSPluginInterface* T_CGSPluginInterface::NewLC()
       
   113     {
       
   114     T_CGSPluginInterface* self = new( ELeave ) T_CGSPluginInterface();
       
   115     CleanupStack::PushL( self );
       
   116     self->ConstructL();
       
   117     return self;
       
   118     }
       
   119 
       
   120 // Destructor (virtual by CBase)
       
   121 T_CGSPluginInterface::~T_CGSPluginInterface()
       
   122     {
       
   123     delete iPluginIndexer;
       
   124     }
       
   125 
       
   126 // Default constructor
       
   127 T_CGSPluginInterface::T_CGSPluginInterface()
       
   128     {
       
   129     }
       
   130 
       
   131 // Second phase construct
       
   132 void T_CGSPluginInterface::ConstructL()
       
   133     {
       
   134     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
   135     // It generates the test case table.
       
   136     CEUnitTestSuiteClass::ConstructL();
       
   137 
       
   138     // Create iterator for plugins:
       
   139     iPluginIndexer = CGSPluginIndexer::NewL( KGSPluginInterfaceUid );
       
   140     }
       
   141 
       
   142 //  METHODS
       
   143 
       
   144 
       
   145 void T_CGSPluginInterface::SetupL(  )
       
   146     {
       
   147     if( !iPluginIndexer->HasNext() )
       
   148         {
       
   149         iPluginIndexer->ResetIndex();
       
   150         }
       
   151     }
       
   152 
       
   153 void T_CGSPluginInterface::Teardown(  )
       
   154     {
       
   155 //    REComSession::DestroyedImplementation( iCGSPluginInterface->DestructorID() );
       
   156 //    delete iCGSPluginInterface;
       
   157 //    iCGSPluginInterface = NULL;
       
   158 //    REComSession::FinalClose();
       
   159     }
       
   160 
       
   161 
       
   162 void T_CGSPluginInterface::T_CGSPluginInterface_SetToBlacklistL()
       
   163     {
       
   164     TUid toBeBlacklisted = {  0x10282E06 };
       
   165     EUNIT_PRINT( _L("Setting 0x%X to blacklist..."), toBeBlacklisted.iUid );
       
   166 
       
   167     CGSWatchDog* dog =  CGSWatchDog::NewL();
       
   168     CleanupStack::PushL( dog );
       
   169     dog->QuarantineL( toBeBlacklisted );
       
   170     // Destroying watchdog without removing from quarantine will blacklist the 
       
   171     // plugin.
       
   172     CleanupStack::PopAndDestroy( dog );
       
   173     
       
   174     dog =  CGSWatchDog::NewL();
       
   175     CleanupStack::PushL( dog );
       
   176     dog->QuarantineL( toBeBlacklisted );
       
   177     // Destroying watchdog without removing from quarantine will blacklist the 
       
   178     // plugin. Do this twice as dog does not blacklist for the first run.
       
   179     CleanupStack::PopAndDestroy( dog );
       
   180     
       
   181     dog =  CGSWatchDog::NewL();
       
   182     CleanupStack::PushL( dog );
       
   183     
       
   184     EUNIT_ASSERT_DESC( dog->IsInBlackList( toBeBlacklisted ), 
       
   185             "The plugin should be in the blacklist");
       
   186     
       
   187     CleanupStack::PopAndDestroy( dog );
       
   188     EUNIT_PRINT( _L("setting to blacklist done.") );
       
   189     }
       
   190 
       
   191 
       
   192 void T_CGSPluginInterface::T_CGSPluginInterface_ResetBlacklistL()
       
   193     {
       
   194     EUNIT_PRINT( _L("Resetting blacklist...") );
       
   195     TInt runs = KGSDefaultMaxPluginBlackListedRuns + 1;
       
   196     for( TInt i = 0; i < runs; i++ )
       
   197         {
       
   198         CGSWatchDog* dog =  CGSWatchDog::NewL();
       
   199         CleanupStack::PushL( dog );
       
   200         dog->ReportCleanExitL();
       
   201         CleanupStack::PopAndDestroy( dog );
       
   202         }
       
   203     EUNIT_PRINT( _L("Resetting blacklist done.") );
       
   204     }
       
   205 
       
   206 
       
   207 void T_CGSPluginInterface::T_CGSPluginInterface_CheckHeapL()
       
   208     {
       
   209     EUNIT_PRINT( _L("CheckHeapL...") );
       
   210     RHeap heap = User::Heap();
       
   211     TInt maxBlock;
       
   212     TInt free;
       
   213     TInt delta;
       
   214     TBuf<256> buf;
       
   215     TUid plgId;
       
   216     _LIT( KCaptionErr, "Caption unavailable");
       
   217 
       
   218     CGSWatchDog* dog =  CGSWatchDog::NewL();
       
   219     CleanupStack::PushL( dog );
       
   220 
       
   221     while( iPluginIndexer->HasNext() )
       
   222         {
       
   223         EUNIT_PRINT( _L("Heap test (%d/%d)..."), iPluginIndexer->Index()+1, iPluginIndexer->Count() );
       
   224         plgId = iPluginIndexer->NextUid();
       
   225         if( dog->IsInBlackList( plgId ) )
       
   226             {
       
   227             EUNIT_PRINT( _L("Blacklisted: 0x%X"), plgId.iUid );
       
   228             continue;
       
   229             }
       
   230         dog->QuarantineL( plgId );
       
   231 
       
   232         free = heap.Available( maxBlock );
       
   233 
       
   234         CGSPluginInterface* plugin = CGSPluginInterface::NewL( plgId, NULL );
       
   235         TRAPD(
       
   236             err,
       
   237             plugin->GetCaptionL( buf );
       
   238             );
       
   239         if( err )
       
   240             {
       
   241             buf = KCaptionErr;
       
   242             }
       
   243         EUNIT_PRINT( _L("Releasing (0x%X %S)..."), plgId.iUid, &buf );
       
   244         REComSession::DestroyedImplementation( plugin->DestructorID() );
       
   245         EUNIT_PRINT( _L("Deleting (0x%X %S)..."), plgId.iUid, &buf );
       
   246         delete plugin;
       
   247         plugin = NULL;
       
   248         EUNIT_PRINT( _L("REComSession::FinalClose()...") );
       
   249         REComSession::FinalClose();
       
   250 
       
   251         delta = heap.Available( maxBlock ) - free;
       
   252         
       
   253         EUNIT_PRINT( _L("Plugin heap alloc (%S, 0x%X) delta:%d"), &buf, plgId.iUid, delta );
       
   254         if( delta > 0 )
       
   255             {
       
   256             EUNIT_PRINT( _L("MEMORY LEAK: %S(0x%X) delta:%d"), &buf, plgId.iUid, delta );
       
   257             }
       
   258         dog->RemoveFromQuarantineL( plgId );
       
   259         }
       
   260     dog-> ReportCleanExitL();
       
   261     CleanupStack::PopAndDestroy( dog );
       
   262     EUNIT_ASSERT_DESC( ETrue, "Wow, the test ran here without a crash!");
       
   263     EUNIT_PRINT( _L("CheckHeapL finished.") );
       
   264     }
       
   265 
       
   266 
       
   267 void T_CGSPluginInterface::T_CGSPluginInterface__CGSPluginInterfaceL(  )
       
   268     {
       
   269 //    iCGSPluginInterface->~CGSPluginInterface( );
       
   270      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   271     }
       
   272 
       
   273 void T_CGSPluginInterface::T_CGSPluginInterface_GetCaptionLL(  )
       
   274     {
       
   275     // iCGSPluginInterface->GetCaptionL( <add parameters here > );
       
   276     EUNIT_PRINT( _L("Caption test...") );
       
   277     EUNIT_ASSERT_DESC( /*EFalse*/ETrue, "Generated assert, replace with real");
       
   278     }
       
   279 
       
   280 void T_CGSPluginInterface::T_CGSPluginInterface_GetValueL(  )
       
   281     {
       
   282     // iCGSPluginInterface->GetValue( <add parameters here > );
       
   283      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   284     }
       
   285 
       
   286 void T_CGSPluginInterface::T_CGSPluginInterface_HandleSelectionL(  )
       
   287     {
       
   288     // iCGSPluginInterface->HandleSelection( <add parameters here > );
       
   289      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   290     }
       
   291 
       
   292 void T_CGSPluginInterface::T_CGSPluginInterface_ItemTypeL(  )
       
   293     {
       
   294     iCGSPluginInterface->ItemType( );
       
   295      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   296     }
       
   297 
       
   298 void T_CGSPluginInterface::T_CGSPluginInterface_MenuActivationItemL(  )
       
   299     {
       
   300     iCGSPluginInterface->MenuActivationItem( );
       
   301      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   302     }
       
   303 
       
   304 void T_CGSPluginInterface::T_CGSPluginInterface_CreateIconLL(  )
       
   305     {
       
   306     // iCGSPluginInterface->CreateIconL( <add parameters here > );
       
   307      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   308     }
       
   309 
       
   310 void T_CGSPluginInterface::T_CGSPluginInterface_PluginProviderCategoryL(  )
       
   311     {
       
   312     iCGSPluginInterface->PluginProviderCategory( );
       
   313      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   314     }
       
   315 
       
   316 void T_CGSPluginInterface::T_CGSPluginInterface_CustomOperationLL(  )
       
   317     {
       
   318     // iCGSPluginInterface->CustomOperationL( <add parameters here > );
       
   319      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   320     }
       
   321 
       
   322 void T_CGSPluginInterface::T_CGSPluginInterface_VisibleL(  )
       
   323     {
       
   324     iCGSPluginInterface->Visible( );
       
   325      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   326     }
       
   327 
       
   328 void T_CGSPluginInterface::T_CGSPluginInterface_ResetSelectedItemIndexL(  )
       
   329     {
       
   330     iCGSPluginInterface->ResetSelectedItemIndex( );
       
   331      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   332     }
       
   333 
       
   334 void T_CGSPluginInterface::T_CGSPluginInterface_SetOrderL(  )
       
   335     {
       
   336     // iCGSPluginInterface->SetOrder( <add parameters here > );
       
   337      EUNIT_ASSERT_DESC( EFalse, "Generated assert, replace with real");
       
   338     }
       
   339 
       
   340 
       
   341 //  TEST TABLE
       
   342 EUNIT_BEGIN_TEST_TABLE(
       
   343     T_CGSPluginInterface,
       
   344     "Add test suite description here.",
       
   345     "UNIT" )
       
   346 
       
   347 EUNIT_TEST(
       
   348     "~CGSPluginInterface - test0",
       
   349     "CGSPluginInterface",
       
   350     "~CGSPluginInterface - test0",
       
   351     "FUNCTIONALITY",
       
   352     SetupL, T_CGSPluginInterface__CGSPluginInterfaceL, Teardown)
       
   353 
       
   354 EUNIT_TEST(
       
   355     "GetCaptionL - test1",
       
   356     "CGSPluginInterface",
       
   357     "GetCaptionL - test1",
       
   358     "FUNCTIONALITY",
       
   359     SetupL, T_CGSPluginInterface_GetCaptionLL, Teardown)
       
   360 
       
   361 EUNIT_TEST(
       
   362     "GetValue - test2",
       
   363     "CGSPluginInterface",
       
   364     "GetValue - test2",
       
   365     "FUNCTIONALITY",
       
   366     SetupL, T_CGSPluginInterface_GetValueL, Teardown)
       
   367 
       
   368 EUNIT_TEST(
       
   369     "HandleSelection - test3",
       
   370     "CGSPluginInterface",
       
   371     "HandleSelection - test3",
       
   372     "FUNCTIONALITY",
       
   373     SetupL, T_CGSPluginInterface_HandleSelectionL, Teardown)
       
   374 
       
   375 EUNIT_TEST(
       
   376     "ItemType - test4",
       
   377     "CGSPluginInterface",
       
   378     "ItemType - test4",
       
   379     "FUNCTIONALITY",
       
   380     SetupL, T_CGSPluginInterface_ItemTypeL, Teardown)
       
   381 
       
   382 EUNIT_TEST(
       
   383     "MenuActivationItem - test5",
       
   384     "CGSPluginInterface",
       
   385     "MenuActivationItem - test5",
       
   386     "FUNCTIONALITY",
       
   387     SetupL, T_CGSPluginInterface_MenuActivationItemL, Teardown)
       
   388 
       
   389 EUNIT_TEST(
       
   390     "CreateIconL - test6",
       
   391     "CGSPluginInterface",
       
   392     "CreateIconL - test6",
       
   393     "FUNCTIONALITY",
       
   394     SetupL, T_CGSPluginInterface_CreateIconLL, Teardown)
       
   395 
       
   396 EUNIT_TEST(
       
   397     "PluginProviderCategory - test7",
       
   398     "CGSPluginInterface",
       
   399     "PluginProviderCategory - test7",
       
   400     "FUNCTIONALITY",
       
   401     SetupL, T_CGSPluginInterface_PluginProviderCategoryL, Teardown)
       
   402 
       
   403 EUNIT_TEST(
       
   404     "CustomOperationL - test8",
       
   405     "CGSPluginInterface",
       
   406     "CustomOperationL - test8",
       
   407     "FUNCTIONALITY",
       
   408     SetupL, T_CGSPluginInterface_CustomOperationLL, Teardown)
       
   409 
       
   410 EUNIT_TEST(
       
   411     "Visible - test9",
       
   412     "CGSPluginInterface",
       
   413     "Visible - test9",
       
   414     "FUNCTIONALITY",
       
   415     SetupL, T_CGSPluginInterface_VisibleL, Teardown)
       
   416 
       
   417 EUNIT_TEST(
       
   418     "ResetSelectedItemIndex - test10",
       
   419     "CGSPluginInterface",
       
   420     "ResetSelectedItemIndex - test10",
       
   421     "FUNCTIONALITY",
       
   422     SetupL, T_CGSPluginInterface_ResetSelectedItemIndexL, Teardown)
       
   423 
       
   424 EUNIT_TEST(
       
   425     "SetOrder - test11",
       
   426     "CGSPluginInterface",
       
   427     "SetOrder - test11",
       
   428     "FUNCTIONALITY",
       
   429     SetupL, T_CGSPluginInterface_SetOrderL, Teardown)
       
   430 
       
   431 EUNIT_TEST(
       
   432         "Check heap - test12",
       
   433         "CGSPluginInterface",
       
   434         "Check heap - test12",
       
   435         "FUNCTIONALITY",
       
   436         SetupL, T_CGSPluginInterface_CheckHeapL, Teardown)
       
   437 
       
   438 EUNIT_TEST(
       
   439         "Reset blacklist - test13",
       
   440         "CGSPluginInterface",
       
   441         "Reset blacklist - test13",
       
   442         "FUNCTIONALITY",
       
   443         SetupL, T_CGSPluginInterface_ResetBlacklistL, Teardown)
       
   444 
       
   445         EUNIT_TEST(
       
   446         "Set to blacklist - test14",
       
   447         "CGSPluginInterface",
       
   448         "Set to blacklist - test14",
       
   449         "FUNCTIONALITY",
       
   450         SetupL, T_CGSPluginInterface_SetToBlacklistL, Teardown)
       
   451 
       
   452         
       
   453 
       
   454 EUNIT_END_TEST_TABLE
       
   455 
       
   456 
       
   457 
       
   458 
       
   459 
       
   460 
       
   461 
       
   462 
       
   463 //  END OF FILE