web_pub/favourites_engine_api/tsrc/src/FavouritesEngineTest.cpp
changeset 1 7c90e6132015
child 15 60c5402cb945
equal deleted inserted replaced
0:dd21522fd290 1:7c90e6132015
       
     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 the License "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:  FavouritesBCTest class member functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <Stiftestinterface.h>
       
    22 #include "FavouritesEngineTest.h"
       
    23 
       
    24 // EXTERNAL DATA STRUCTURES
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES  
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // MACROS
       
    31 
       
    32 // LOCAL CONSTANTS AND MACROS
       
    33 
       
    34 // MODULE DATA STRUCTURES
       
    35 
       
    36 // LOCAL FUNCTION PROTOTYPES
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 
       
    40 // ============================= LOCAL FUNCTIONS ===============================
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // DeleteFileL
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 void DeleteFileL( const TDesC& aFile, RFs& aFs )
       
    47     {
       
    48     TParse file;
       
    49     User::LeaveIfError( aFs.Parse( aFile, file ) );
       
    50     TUint att;
       
    51     TInt res = aFs.Att( file.FullName(), att );
       
    52     if ( res == KErrNone )
       
    53         {
       
    54         User::LeaveIfError( aFs.Delete( file.FullName() ) );
       
    55         }
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CopyFileL
       
    60 // ---------------------------------------------------------
       
    61 //
       
    62 void CopyFileL( const TDesC& aSrc, const TDesC& aDst, RFs& aFs )
       
    63     {
       
    64     RFile src;
       
    65     RFile dst;
       
    66     TBuf8<256> buf;
       
    67 
       
    68     User::LeaveIfError( src.Open
       
    69         ( aFs, aSrc, EFileRead | EFileShareReadersOnly | EFileStream ) );
       
    70     CleanupClosePushL<RFile>( src );
       
    71     (void)aFs.MkDirAll( aDst );    
       
    72     (void)aFs.SetAtt( aDst, 0, KEntryAttReadOnly ); // Overwrite read-only.
       
    73     User::LeaveIfError( dst.Replace
       
    74         ( aFs, aDst, EFileWrite | EFileShareExclusive | EFileStream ) );
       
    75     CleanupClosePushL<RFile>( dst );
       
    76     FOREVER
       
    77         {
       
    78         User::LeaveIfError( src.Read( buf ) );
       
    79         if ( !buf.Length() )
       
    80             {
       
    81             break;
       
    82             }
       
    83         User::LeaveIfError( dst.Write( buf ) );
       
    84         }
       
    85     CleanupStack::PopAndDestroy( 2 );   // close dst, src
       
    86     }
       
    87 
       
    88 
       
    89 // ============================ MEMBER FUNCTIONS ===============================
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CFavouritesEngineTest::CFavouritesEngineTest
       
    93 // C++ default constructor can NOT contain any code, that
       
    94 // might leave.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CFavouritesEngineTest::CFavouritesEngineTest()
       
    98     {
       
    99 
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CFavouritesEngineTest::ConstructL
       
   104 // Symbian 2nd phase constructor can leave.
       
   105 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created
       
   106 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger 
       
   107 // allocates memory from heap and therefore causes error situations with OOM 
       
   108 // testing. For more information about STIF Logger construction, see STIF Users 
       
   109 // Guide.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CFavouritesEngineTest::ConstructL()
       
   113     {
       
   114     iLog = CStifLogger::NewL( KFavouritesEngineTestLogPath, 
       
   115                           KFavouritesEngineTestLogFile);
       
   116                           
       
   117     User::LeaveIfError( iFileSystem.Connect() );
       
   118 
       
   119     User::LeaveIfError( iFavouritesSession.Connect() );
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CFavouritesEngineTest::NewL
       
   124 // Two-phased constructor.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 CFavouritesEngineTest* CFavouritesEngineTest::NewL()
       
   128     {
       
   129     CFavouritesEngineTest* self = new (ELeave) CFavouritesEngineTest;
       
   130 
       
   131     CleanupStack::PushL( self );
       
   132     self->ConstructL();
       
   133     CleanupStack::Pop();
       
   134 
       
   135     return self;
       
   136 
       
   137     }
       
   138 
       
   139 // Destructor
       
   140 CFavouritesEngineTest::~CFavouritesEngineTest()
       
   141     {
       
   142     iFavouritesDb.Close();
       
   143     iFavouritesSession.Close();
       
   144     iFileSystem.Close();
       
   145     delete iLog;
       
   146     }
       
   147 
       
   148 // ----------------------------------------------------------
       
   149 // CFavouritesDbTester::MapAccessPoint()
       
   150 // ----------------------------------------------------------
       
   151 //
       
   152 TBool CFavouritesEngineTest::MapAccessPoint
       
   153 ( TUint aOldUid, TUint& aNewUid )
       
   154     {
       
   155     aNewUid = aOldUid;
       
   156     return ETrue;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CFavouritesEngineTest::InitL
       
   161 // InitL is used to initialize the Test Module.
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 TInt CFavouritesEngineTest::InitL( 
       
   165     TFileName& /*aIniFile*/, 
       
   166     TBool /*aFirstTime*/ )
       
   167     {
       
   168     return KErrNone;
       
   169 
       
   170     }
       
   171 
       
   172 /*
       
   173 -------------------------------------------------------------------------------
       
   174 
       
   175     Class: CDemoModule
       
   176 
       
   177     Method: Case
       
   178 
       
   179     Description: Returns a test case by number.
       
   180 
       
   181     This function contains an array of all available test cases 
       
   182     i.e pair of case name and test function. If case specified by parameter
       
   183     aCaseNumber is found from array, then that item is returned.
       
   184 
       
   185     The reason for this rather complicated function is to specify all the
       
   186     test cases only in one place. It is not necessary to understand how
       
   187     function pointers to class member functions works when adding new test
       
   188     cases. See function body for instructions how to add new test case.
       
   189     
       
   190     Parameters:    const TInt aCaseNumber :in:      Test case number
       
   191 
       
   192     Return Values: const TCaseInfo Struct containing case name & function
       
   193 
       
   194     Errors/Exceptions: None
       
   195 
       
   196     Status: Approved
       
   197 
       
   198 -------------------------------------------------------------------------------
       
   199 */ 
       
   200 const TCaseInfo CFavouritesEngineTest::Case ( 
       
   201     const TInt aCaseNumber ) const 
       
   202      {
       
   203 
       
   204     /*
       
   205     * To add new test cases, implement new test case function and add new 
       
   206     * line to KCases array specify the name of the case and the function 
       
   207     * doing the test case
       
   208     * In practice, do following
       
   209     *
       
   210     * 1) Make copy of existing test case function and change its name
       
   211     *    and functionality. Note that the function must be added to 
       
   212     *    OOMHard.cpp file and to OOMHard.h 
       
   213     *    header file.
       
   214     *
       
   215     * 2) Add entry to following KCases array either by using:
       
   216     *
       
   217     * 2.1: FUNCENTRY or ENTRY macro
       
   218     * ENTRY macro takes two parameters: test case name and test case 
       
   219     * function name.
       
   220     *
       
   221     * FUNCENTRY macro takes only test case function name as a parameter and
       
   222     * uses that as a test case name and test case function name.
       
   223     *
       
   224     * Or
       
   225     *
       
   226     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   227     * only with OOM (Out-Of-Memory) testing!
       
   228     *
       
   229     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   230     * function name, TBool which specifies is method supposed to be run using
       
   231     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   232     * TInt value for last heap memory allocation failure.
       
   233     * 
       
   234     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   235     * that as a test case name, TBool which specifies is method supposed to be
       
   236     * run using OOM conditions, TInt value for first heap memory allocation 
       
   237     * failure and TInt value for last heap memory allocation failure. 
       
   238     */ 
       
   239 
       
   240     static TCaseInfoInternal const KCases[] =
       
   241         {
       
   242         // To add new test cases, add new items to this array
       
   243         
       
   244         // NOTE: When compiled to GCCE, there must be Classname::
       
   245         // declaration in front of the method name, e.g. 
       
   246         // CDemoModule::PrintTest. Otherwise the compiler
       
   247         // gives errors.
       
   248                 
       
   249         ENTRY( "Item NewLC test", CFavouritesEngineTest::ItemNewLCTestL ),
       
   250         ENTRY( "Item NewL test", CFavouritesEngineTest::ItemNewLTestL ),
       
   251         ENTRY( "Item Destructor test", CFavouritesEngineTest::ItemDestructorTestL ),
       
   252         ENTRY( "Item Assign(=) operator test", CFavouritesEngineTest::ItemAssignTestL ),
       
   253         ENTRY( "Item Uid test", CFavouritesEngineTest::ItemUidTestL ),
       
   254         ENTRY( "Item ParentFolder test", CFavouritesEngineTest::ItemParentFolderTestL ),
       
   255         ENTRY( "Item Type test", CFavouritesEngineTest::ItemTypeTestL ),
       
   256         ENTRY( "Item Name test", CFavouritesEngineTest::ItemNameTestL ),
       
   257         ENTRY( "Item Url test", CFavouritesEngineTest::ItemUrlTestL ),
       
   258         ENTRY( "Item WapAp test", CFavouritesEngineTest::ItemWapApTestL ),
       
   259         ENTRY( "Item UserName test", CFavouritesEngineTest::ItemUserNameTestL ),
       
   260         ENTRY( "Item Password test", CFavouritesEngineTest::ItemPasswordTestL ),
       
   261         ENTRY( "Item ContextId test", CFavouritesEngineTest::ItemContextIdTestL ),
       
   262         ENTRY( "Item IsItem test", CFavouritesEngineTest::ItemIsItemTestL ),
       
   263         ENTRY( "Item IsFolder test", CFavouritesEngineTest::ItemIsFolderTestL ),
       
   264         ENTRY( "Item IsFactoryItem test", CFavouritesEngineTest::ItemIsFactoryItemTestL ),
       
   265         ENTRY( "Item IsReadOnly test", CFavouritesEngineTest::ItemIsReadOnlyTestL ),
       
   266         ENTRY( "Item Modified test", CFavouritesEngineTest::ItemModifiedTestL ),
       
   267         ENTRY( "Item ClearL test", CFavouritesEngineTest::ItemClearLTestL ),
       
   268         ENTRY( "Item SetParentFolder test", CFavouritesEngineTest::ItemSetParentFolderTestL ),
       
   269         ENTRY( "Item SetType test", CFavouritesEngineTest::ItemSetTypeTestL ),
       
   270         ENTRY( "Item SetNameL test", CFavouritesEngineTest::ItemSetNameLTestL ),
       
   271         ENTRY( "Item SetUrlL test", CFavouritesEngineTest::ItemSetUrlLTestL ),
       
   272         ENTRY( "Item SetWapAp test", CFavouritesEngineTest::ItemSetWapApTestL ),
       
   273         ENTRY( "Item SetUserNameL test", CFavouritesEngineTest::ItemSetUserNameLTestL ),
       
   274         ENTRY( "Item SetPasswordL test", CFavouritesEngineTest::ItemSetPasswordLTestL ),
       
   275         ENTRY( "Item SetContextId test", CFavouritesEngineTest::ItemSetContextIdTestL ),
       
   276         ENTRY( "List Constructor test", CFavouritesEngineTest::ListConstructorTestL ),
       
   277         ENTRY( "List Destructor test", CFavouritesEngineTest::ListDestructorTestL ),
       
   278         ENTRY( "List Delete test", CFavouritesEngineTest::ListDeleteTestL ),
       
   279         ENTRY( "List Delete Range test", CFavouritesEngineTest::ListDeleteRangeTestL ),
       
   280         ENTRY( "List Sort test", CFavouritesEngineTest::ListSortTestL ),
       
   281         ENTRY( "List UidToIndex test", CFavouritesEngineTest::ListUidToIndexTestL ),
       
   282         ENTRY( "List IndexToUid test", CFavouritesEngineTest::ListIndexToUidTestL ),
       
   283         ENTRY( "List ItemByUid test", CFavouritesEngineTest::ListItemByUidTestL ),
       
   284         ENTRY( "Db Open test", CFavouritesEngineTest::DbOpenTestL ),
       
   285         ENTRY( "Db Version test", CFavouritesEngineTest::DbVersionTestL ),
       
   286         ENTRY( "Db IsDamaged test", CFavouritesEngineTest::DbIsDamagedTestL ),
       
   287         ENTRY( "Db Recover test", CFavouritesEngineTest::DbRecoverTestL ),
       
   288         ENTRY( "Db Compact test", CFavouritesEngineTest::DbCompactTestL ),
       
   289         ENTRY( "Db Size test", CFavouritesEngineTest::DbSizeTestL ),
       
   290         ENTRY( "Db UpdateStats test", CFavouritesEngineTest::DbUpdateStatsTestL ),
       
   291         ENTRY( "Db Begin test", CFavouritesEngineTest::DbBeginTestL ),
       
   292         ENTRY( "Db Commit test", CFavouritesEngineTest::DbCommitTestL ),
       
   293         ENTRY( "Db Rollback test", CFavouritesEngineTest::DbRollbackTestL ),
       
   294         ENTRY( "Db CleanupRollbackPushL test", CFavouritesEngineTest::DbCleanupRollbackPushLTestL ),
       
   295         ENTRY( "Db Get test", CFavouritesEngineTest::DbGetTestL ),
       
   296         ENTRY( "Db GetAll test", CFavouritesEngineTest::DbGetAllTestL ),
       
   297         ENTRY( "Db GetUids test", CFavouritesEngineTest::DbGetUidsTestL ),
       
   298         ENTRY( "Db PreferredUid test", CFavouritesEngineTest::DbPreferredUidTestL ),
       
   299         ENTRY( "Db Delete test", CFavouritesEngineTest::DbDeleteTestL ),
       
   300         ENTRY( "Db Update test", CFavouritesEngineTest::DbUpdateTestL ),
       
   301         ENTRY( "Db Add test", CFavouritesEngineTest::DbAddTestL ),
       
   302         ENTRY( "Db SetHomepage test", CFavouritesEngineTest::DbSetHomepageTestL ),
       
   303         ENTRY( "Db SetLastVisited test", CFavouritesEngineTest::DbSetLastVisitedTestL ),
       
   304         ENTRY( "Db SetFactoryItem test", CFavouritesEngineTest::DbSetFactoryItemTestL ),
       
   305         ENTRY( "Db SetReadOnly test", CFavouritesEngineTest::DbSetReadOnlyTestL ),
       
   306         ENTRY( "Db SetModified test", CFavouritesEngineTest::DbSetModifiedTestL ),
       
   307         ENTRY( "Db SetPreferredUid test", CFavouritesEngineTest::DbSetPreferredUidTestL ),
       
   308         ENTRY( "Db ItemExists test", CFavouritesEngineTest::DbItemExistsTestL ),
       
   309         ENTRY( "Db FolderExists test", CFavouritesEngineTest::DbFolderExistsTestL ),
       
   310         ENTRY( "Db Count test", CFavouritesEngineTest::DbCountTestL ),
       
   311         ENTRY( "Db SetData test", CFavouritesEngineTest::DbSetDataTestL ),
       
   312         ENTRY( "Db GetData test", CFavouritesEngineTest::DbGetDataTestL ),
       
   313         ENTRY( "Db SetBrowserData test", CFavouritesEngineTest::DbSetBrowserDataTestL ),
       
   314         ENTRY( "Db GetBrowserData test", CFavouritesEngineTest::DbGetBrowserDataTestL ),
       
   315         ENTRY( "Db MakeUniqueName with folder test", CFavouritesEngineTest::DbMakeUniqueNameWithFolderTestL ),
       
   316         ENTRY( "Db MakeUniqueName test", CFavouritesEngineTest::DbMakeUniqueNameTestL ),
       
   317         ENTRY( "Db CreateStartPageItemL test", CFavouritesEngineTest::DbCreateStartPageItemLTestL ),
       
   318         ENTRY( "Db CreateAdaptiveItemsFolderL test", CFavouritesEngineTest::DbCreateAdaptiveItemsFolderLTestL ),
       
   319         ENTRY( "Db DeleteFile test", CFavouritesEngineTest::DbDeleteFileTestL ),
       
   320 //        ENTRY( "Db RestoreFactorySettingsL test", CFavouritesEngineTest::DbRestoreFactorySettingsLTestL ),
       
   321         ENTRY( "WapAp Constructor test", CFavouritesEngineTest::WapApConstructorTest ),
       
   322         ENTRY( "WapAp Assign with Ap test", CFavouritesEngineTest::WapApAssignWithApTest ),
       
   323         ENTRY( "WapAp Assign with ApId test", CFavouritesEngineTest::WapApAssignWithApIdTest ),
       
   324         ENTRY( "WapAp SetNull test", CFavouritesEngineTest::WapApSetNullTest ),
       
   325         ENTRY( "WapAp SetDefault test", CFavouritesEngineTest::WapApSetDefaultTest ),
       
   326         ENTRY( "WapAp SetApId test", CFavouritesEngineTest::WapApSetApIdTest ),
       
   327         ENTRY( "WapAp IsNull test", CFavouritesEngineTest::WapApIsNullTest ),
       
   328         ENTRY( "WapAp IsDefault test", CFavouritesEngineTest::WapApIsDefaultTest ),
       
   329         ENTRY( "WapAp ApId test", CFavouritesEngineTest::WapApApIdTest ),
       
   330         ENTRY( "DbInc Recover test", CFavouritesEngineTest::DbIncRecoverTestL ),
       
   331         ENTRY( "DbInc Compact test", CFavouritesEngineTest::DbIncCompactTestL ),
       
   332         ENTRY( "DbInc Next test", CFavouritesEngineTest::DbIncNextTestL ),
       
   333         ENTRY( "File Close test", CFavouritesEngineTest::FileCloseTestL ),
       
   334         ENTRY( "File Open test", CFavouritesEngineTest::FileOpenTestL ),
       
   335         ENTRY( "File Replace test", CFavouritesEngineTest::FileReplaceTestL ),
       
   336         ENTRY( "File Read test", CFavouritesEngineTest::FileReadTestL ),
       
   337         ENTRY( "File Write test", CFavouritesEngineTest::FileWriteTestL ),
       
   338         ENTRY( "File Size test", CFavouritesEngineTest::FileSizeTestL ),
       
   339         ENTRY( "Session Version test", CFavouritesEngineTest::SessionVersionTest ),
       
   340         ENTRY( "Session Connect test", CFavouritesEngineTest::SessionConnectTest ),
       
   341         ENTRY( "Session ResourceMark test", CFavouritesEngineTest::SessionResourceMarkTest ),
       
   342         ENTRY( "Session ResourceCheck test", CFavouritesEngineTest::SessionResourceCheckTest ),
       
   343         ENTRY( "Session ResourceCount test", CFavouritesEngineTest::SessionResourceCountTest ),
       
   344         ENTRY( "Session DeleteDatabase test", CFavouritesEngineTest::SessionDeleteDatabaseTestL ),
       
   345         ENTRY( "Session __DbgSetAllocFail test", CFavouritesEngineTest::SessionDbgSetAllocFailTest ),
       
   346         ENTRY( "Notifier constructor test", CFavouritesEngineTest::NotifierConstructorTestL ),
       
   347         ENTRY( "Notifier destructor test", CFavouritesEngineTest::NotifierDestructorTestL ),
       
   348         ENTRY( "Notifier Start test", CFavouritesEngineTest::NotifierStartTestL ),
       
   349         ENTRY( "Db DeleteFolder test", CFavouritesEngineTest::DbDeleteFolderTestL )
       
   350         };
       
   351 
       
   352     // Verify that case number is valid
       
   353     if( (TUint) aCaseNumber >= sizeof( KCases ) / 
       
   354                                sizeof( TCaseInfoInternal ) )
       
   355         {
       
   356 
       
   357         // Invalid case, construct empty object
       
   358         TCaseInfo null( (const TText*) L"" );
       
   359         null.iMethod = NULL;
       
   360         null.iIsOOMTest = EFalse;
       
   361         null.iFirstMemoryAllocation = 0;
       
   362         null.iLastMemoryAllocation = 0;
       
   363         return null;
       
   364 
       
   365         } 
       
   366 
       
   367     // Construct TCaseInfo object and return it
       
   368     TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   369     tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   370     tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   371     tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   372     tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   373     return tmp;
       
   374 
       
   375     }
       
   376 
       
   377 /*
       
   378 -------------------------------------------------------------------------------
       
   379 
       
   380     Class: CFavouritesEngineTest
       
   381 
       
   382     Method: CreatePopulatedDb
       
   383 
       
   384     Description: Populate a test db with items.
       
   385   
       
   386     Parameters:  None   
       
   387 
       
   388     Return Values: None
       
   389 
       
   390     Errors/Exceptions: None
       
   391 
       
   392     Status: Approved
       
   393 
       
   394 -------------------------------------------------------------------------------
       
   395 */
       
   396 void CFavouritesEngineTest::CreatePopulatedDbL()
       
   397     {
       
   398     DestroyDbItems();
       
   399 
       
   400     // Create reference items in inst vars.
       
   401     CreateFolderL( iItemFolder1 );
       
   402     CreateFolderL( iItemFolder2 );
       
   403     CreateItemL( iItem1 );
       
   404     CreateItemL( iItem2 );
       
   405     CreateItemL( iItem3 );
       
   406     CreateItemL( iItem4 );
       
   407     CreateItemL( iItem5 );
       
   408     CreateItemL( iItem6 );
       
   409 
       
   410     // Add items to database.
       
   411     iFavouritesDb.Add( *iItemFolder1, EFalse );
       
   412     iFavouritesDb.Add( *iItemFolder2, EFalse );
       
   413 
       
   414     iItem3->SetParentFolder( iItemFolder1->Uid() );
       
   415     iItem4->SetParentFolder( iItemFolder1->Uid() );
       
   416     iItem5->SetParentFolder( iItemFolder2->Uid() );
       
   417     iItem6->SetParentFolder( iItemFolder2->Uid() );
       
   418 
       
   419     // Insert out of order for sort test
       
   420     iFavouritesDb.Add( *iItem5, EFalse );
       
   421     iFavouritesDb.Add( *iItem1, EFalse );
       
   422     iFavouritesDb.Add( *iItem6, EFalse );
       
   423     iFavouritesDb.Add( *iItem3, EFalse );
       
   424     iFavouritesDb.Add( *iItem2, EFalse );
       
   425     iFavouritesDb.Add( *iItem4, EFalse );
       
   426 
       
   427     }
       
   428 
       
   429 /*
       
   430 -------------------------------------------------------------------------------
       
   431 
       
   432     Class: CFavouritesEngineTest
       
   433 
       
   434     Method: DestroyDb
       
   435 
       
   436     Description: Delete the test database and all items in it.
       
   437   
       
   438     Parameters:  None
       
   439 
       
   440     Return Values: None
       
   441 
       
   442     Errors/Exceptions: None
       
   443 
       
   444     Status: Approved
       
   445 
       
   446 -------------------------------------------------------------------------------
       
   447 */
       
   448 void CFavouritesEngineTest::DestroyDbItems()
       
   449     {
       
   450     delete iItemFolder1;
       
   451     delete iItemFolder2;
       
   452     delete iItem1;
       
   453     delete iItem2;
       
   454     delete iItem3;
       
   455     delete iItem4;
       
   456     delete iItem5;
       
   457     delete iItem6;
       
   458 
       
   459     iItemFolder1 = NULL;
       
   460     iItemFolder2 = NULL;
       
   461     iItem1 = NULL;
       
   462     iItem2 = NULL;
       
   463     iItem3 = NULL;
       
   464     iItem4 = NULL;
       
   465     iItem5 = NULL;
       
   466     iItem6 = NULL;
       
   467     }
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // CFavouritesEngineTest::GetTestCasesL
       
   471 // GetTestCases is used to inquire test cases from the Test Module. Test
       
   472 // cases are stored to array of test cases. The Test Framework will be 
       
   473 // the owner of the data in the RPointerArray after GetTestCases return
       
   474 // and it does the memory deallocation. 
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 TInt CFavouritesEngineTest::GetTestCasesL( 
       
   478     const TFileName& /*aConfig*/, 
       
   479     RPointerArray<TTestCaseInfo>& aTestCases )
       
   480     {
       
   481 
       
   482     // Loop through all test cases and create new
       
   483     // TTestCaseInfo items and append items to aTestCase array    
       
   484     for( TInt i = 0; Case(i).iMethod != NULL; i++ )
       
   485         {
       
   486         // Allocate new TTestCaseInfo from heap for a testcase definition.
       
   487         TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
       
   488     
       
   489         // PushL TTestCaseInfo to CleanupStack.    
       
   490         CleanupStack::PushL( newCase );
       
   491 
       
   492         // Set number for the testcase.
       
   493         // When the testcase is run, this comes as a parameter to RunTestCaseL.
       
   494         newCase->iCaseNumber = i;
       
   495 
       
   496         // Set title for the test case. This is shown in UI to user.
       
   497         newCase->iTitle.Copy( Case(i).iCaseName );
       
   498 
       
   499         // Append TTestCaseInfo to the testcase array. After appended 
       
   500         // successfully the TTestCaseInfo object is owned (and freed) 
       
   501         // by the TestServer. 
       
   502         User::LeaveIfError(aTestCases.Append ( newCase ) );
       
   503         
       
   504         // Pop TTestCaseInfo from the CleanupStack.
       
   505         CleanupStack::Pop( newCase );
       
   506         }
       
   507 
       
   508     return KErrNone;
       
   509 
       
   510     }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CFavouritesEngineTest::RunTestCaseL
       
   514 // RunTestCaseL is used to run an individual test case specified 
       
   515 // by aTestCase. Test cases that can be run may be requested from 
       
   516 // Test Module by GetTestCases method before calling RunTestCase.
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 TInt CFavouritesEngineTest::RunTestCaseL(
       
   520     const TInt aCaseNumber,
       
   521     const TFileName& /*aConfig*/,
       
   522     TTestResult& aResult )
       
   523     {
       
   524     // Return value
       
   525     TInt execStatus = KErrNone;
       
   526 
       
   527     // Get the pointer to test case function
       
   528     TCaseInfo tmp = Case ( aCaseNumber );
       
   529 
       
   530     _LIT( KLogInfo, "Starting testcase [%S]" );
       
   531     iLog->Log( KLogInfo, &tmp.iCaseName);
       
   532 
       
   533     // Check that case number was valid
       
   534     if ( tmp.iMethod != NULL )
       
   535         {
       
   536         // Valid case was found, call it via function pointer
       
   537         iMethod = tmp.iMethod;        
       
   538         execStatus  = ( this->*iMethod )( aResult );
       
   539         }
       
   540     else
       
   541         {
       
   542         // Valid case was not found, return error.
       
   543         execStatus = KErrNotFound;
       
   544         }
       
   545 
       
   546     // Return case execution status (not the result of the case execution)
       
   547     return execStatus;
       
   548 
       
   549     }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // CFavouritesEngineTest::OOMTestQueryL
       
   553 // Used to check if a particular test case should be run in OOM conditions and 
       
   554 // which memory allocations should fail.    
       
   555 //
       
   556 // NOTE: This method is virtual and must be implemented only if test case
       
   557 // should be executed using OOM conditions.  
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 TBool CFavouritesEngineTest::OOMTestQueryL( 
       
   561                                 const TFileName& /* aTestCaseFile */, 
       
   562                                 const TInt /* aCaseNumber */, 
       
   563                                 TOOMFailureType& /* aFailureType */, 
       
   564                                 TInt& /* aFirstMemFailure */, 
       
   565                                 TInt& /* aLastMemFailure */ ) 
       
   566     {
       
   567     _LIT( KOOMTestQueryL, "CFavouritesEngineTest::OOMTestQueryL" );
       
   568     iLog->Log( KOOMTestQueryL ); 
       
   569 
       
   570     return EFalse;
       
   571 
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // CFavouritesEngineTest::OOMTestInitializeL
       
   576 // Used to perform the test environment setup for a particular OOM test case. 
       
   577 // Test Modules may use the initialization file to read parameters for Test 
       
   578 // Module initialization but they can also have their own configure file or 
       
   579 // some other routine to initialize themselves.  
       
   580 //
       
   581 // NOTE: This method is virtual and must be implemented only if test case
       
   582 // should be executed using OOM conditions.  
       
   583 // -----------------------------------------------------------------------------
       
   584 //
       
   585 void CFavouritesEngineTest::OOMTestInitializeL( 
       
   586                                 const TFileName& /* aTestCaseFile */, 
       
   587                                 const TInt /* aCaseNumber */ )
       
   588     {
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // CFavouritesEngineTest::OOMHandleWarningL
       
   593 // In some cases the heap memory allocation should be skipped, either due to
       
   594 // problems in the OS code or components used by the code being tested, or even 
       
   595 // inside the tested components which are implemented this way on purpose (by 
       
   596 // design), so it is important to give the tester a way to bypass allocation 
       
   597 // failures.
       
   598 //
       
   599 // NOTE: This method is virtual and must be implemented only if test case
       
   600 // should be executed using OOM conditions.  
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 void CFavouritesEngineTest::OOMHandleWarningL( 
       
   604                                 const TFileName& /* aTestCaseFile */,
       
   605                                 const TInt /* aCaseNumber */, 
       
   606                                 TInt& /* aFailNextValue */ )
       
   607     {
       
   608     }
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // CFavouritesEngineTest::OOMTestFinalizeL
       
   612 // Used to perform the test environment cleanup for a particular OOM test case.
       
   613 //
       
   614 // NOTE: This method is virtual and must be implemented only if test case
       
   615 // should be executed using OOM conditions.  
       
   616 // -----------------------------------------------------------------------------
       
   617 //                  
       
   618 void CFavouritesEngineTest::OOMTestFinalizeL( 
       
   619                                 const TFileName& /* aTestCaseFile */, 
       
   620                                 const TInt /* aCaseNumber */ )
       
   621     {
       
   622     }
       
   623 
       
   624 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   625 
       
   626 // -----------------------------------------------------------------------------
       
   627 // LibEntryL is a polymorphic Dll entry point
       
   628 // Returns: CTestModuleBase*: Pointer to Test Module object
       
   629 // -----------------------------------------------------------------------------
       
   630 //
       
   631 EXPORT_C CTestModuleBase* LibEntryL()
       
   632     {
       
   633     return CFavouritesEngineTest::NewL();
       
   634 
       
   635     }
       
   636 
       
   637 // -----------------------------------------------------------------------------
       
   638 // SetRequirements handles test module parameters(implements evolution
       
   639 // version 1 for test module's heap and stack sizes configuring).
       
   640 // Returns: TInt: Symbian error code.
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/, 
       
   644                                 TUint32& /*aParameterValid*/ )
       
   645     {
       
   646 
       
   647     /* --------------------------------- NOTE ---------------------------------
       
   648     USER PANICS occurs in test thread creation when:
       
   649     1) "The panic occurs when the value of the stack size is negative."
       
   650     2) "The panic occurs if the minimum heap size specified is less
       
   651        than KMinHeapSize".
       
   652        KMinHeapSize: "Functions that require a new heap to be allocated will
       
   653        either panic, or will reset the required heap size to this value if
       
   654        a smaller heap size is specified".
       
   655     3) "The panic occurs if the minimum heap size specified is greater than
       
   656        the maximum size to which the heap can grow".
       
   657     Other:
       
   658     1) Make sure that your hardware or Symbian OS is supporting given sizes.
       
   659        e.g. Hardware might support only sizes that are divisible by four.
       
   660     ------------------------------- NOTE end ------------------------------- */
       
   661 
       
   662     // Normally STIF uses default heap and stack sizes for test thread, see:
       
   663     // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
       
   664     // If needed heap and stack sizes can be configured here by user. Remove
       
   665     // comments and define sizes.
       
   666 
       
   667 /*
       
   668     aParameterValid = KStifTestModuleParameterChanged;
       
   669 
       
   670     CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
       
   671     // Stack size
       
   672     param->iTestThreadStackSize= 16384; // 16K stack
       
   673     // Heap sizes
       
   674     param->iTestThreadMinHeap = 4096;   // 4K heap min
       
   675     param->iTestThreadMaxHeap = 1048576;// 1M heap max
       
   676 
       
   677     aTestModuleParam = param;
       
   678 */
       
   679     return KErrNone;
       
   680 
       
   681     }
       
   682 
       
   683 // -----------------------------------------------------------------------------
       
   684 // E32Dll is a DLL entry point function
       
   685 // Returns: KErrNone: No error
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 #ifndef EKA2 // Hide Dll entry point to EKA2
       
   689 GLDEF_C TInt E32Dll(
       
   690     TDllReason /*aReason*/) // Reason
       
   691     {
       
   692     return(KErrNone);
       
   693 
       
   694     }
       
   695 #endif // EKA2
       
   696 
       
   697 //  End of File