email/pop3andsmtpmtm/clientmtms/test/src/T_IMPC.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name of test harness: T_IMPC
       
    15 // Component: IMCM
       
    16 // Owner: KP
       
    17 // Brief description of test harness:
       
    18 // Tests IMAP4 Query Capabilities; Creates/stores/restores IMAP4 service; 
       
    19 // checks for connection; creates folders; gives folders queued operations 
       
    20 // (populates folders with queued operations); tests queued operations access;
       
    21 // tests rewrite of queued operations; tests removal queued of operations; 
       
    22 // tests deleting folders.
       
    23 // Detailed description of test harness:
       
    24 // As above.
       
    25 // Input files required to run test harness:
       
    26 // None
       
    27 // Intermediate files produced while running test harness:
       
    28 // <DRIVE>:\msglogs\T_IMPC\T_IMCM.LOG
       
    29 // Output files produced by running test harness:
       
    30 // <DRIVE>:\msglogs\T_IMPC.<PLATFORM>.<VARIANT>.LOG.txt
       
    31 // Description of how to build test harness:
       
    32 // cd \msg\imcm\
       
    33 // bldmake bldfiles
       
    34 // abld test build
       
    35 // Description of how to run test harness:
       
    36 // The following instructions are the same for all platforms:
       
    37 // 1. Build T_DB test harness from COMMDB component:
       
    38 // cd \commdb\group
       
    39 // bldmake bldfiles
       
    40 // abld test build t_db
       
    41 // 2. Build the test utilities:
       
    42 // cd \msg\testutils\group\
       
    43 // bldmake bldfiles
       
    44 // abld build
       
    45 // WINS running instructions:
       
    46 // 1. \epoc32\release\wins\<VARIANT>\T_IMPC.exe can be used at the command prompt
       
    47 // or executable can be run from Windows Explorer.
       
    48 // All other platform running instructions:
       
    49 // 1. Copy \epoc32\release\<PLATFORM>\<VARIANT>\T_IMPC.exe onto the other platform
       
    50 // 2. Copy \epoc32\release\<PLATFORM>\<VARIANT>\MSVTESTUTILS.DLL into 
       
    51 // <DRIVE>:\system\libs on the other platform
       
    52 // 3. Copy \epoc32\release\<PLATFORM>\<VARIANT>\EMAILTESTUTILS.DLL into 
       
    53 // <DRIVE>:\system\libs on the other platform
       
    54 // 4. Run T_IMPC.exe on the other platform
       
    55 // define to mark stuff still to do. Should be switched on for the last compile.
       
    56 // 
       
    57 //
       
    58 
       
    59 #include "emailtestutils.h"
       
    60 #include <mtmuids.h>
       
    61 #include <miutlog.h>
       
    62 #include <impcmtm.h>
       
    63 #include <offop.h>
       
    64 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS  
       
    65 #include "msvconsts.h"
       
    66 #endif
       
    67 
       
    68 //
       
    69 // TestScheduler implements an error handler that doesn't panic.
       
    70 class TestScheduler : public CActiveScheduler
       
    71 	{
       
    72 	public:
       
    73 		void Error (TInt aError) const;
       
    74 	};
       
    75 
       
    76 //
       
    77 // Session observer, reports stuff it is notified about
       
    78 class CDummySessionObserver : public CBase , public MMsvSessionObserver
       
    79 	{
       
    80 public:
       
    81 	void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
       
    82 	};
       
    83 
       
    84 //
       
    85 //
       
    86 // Globals needed for the test code
       
    87 LOCAL_D RTest test(_L("T_IMPC test harness"));
       
    88 LOCAL_D CTrapCleanup* theCleanup;
       
    89 LOCAL_D CImLog* log;
       
    90 LOCAL_D CEmailTestUtils* testUtils;
       
    91 
       
    92 // a define to allow disabling user interaction in general, for this test exe.
       
    93 #define RECEIVE_KEYPRESS test.Getch();
       
    94 
       
    95 //
       
    96 // Client side classes
       
    97 CClientMtmRegistry*     theClientRegistry  = NULL;
       
    98 CDummySessionObserver*  theSessionObserver = NULL;
       
    99 CMsvSession*			theSession         = NULL;
       
   100 CBaseMtm*		        theClientMtm       = NULL;
       
   101 TMsvId					theServiceId       = KMsvNullIndexEntryId;
       
   102 
       
   103 // Folders created, to test the lists of queued operations stored within folders.
       
   104 CMsvEntrySelection*		theFolders		   = NULL; 
       
   105 CMsvEntrySelection*		theSubfolders	   = NULL; 
       
   106 
       
   107 _LIT(KServerMtmFileName, "z:\\system\\libs\\imps.dll");
       
   108 _LIT(KClientMtmFileName, "z:\\system\\libs\\imcm.dll");
       
   109 // The UI MTMs are not used here
       
   110 _LIT(KUiMtmFileName, "z:\\system\\libs\\dummyuimtm.dll");
       
   111 _LIT(KUiDataMtmFileName, "z:\\system\\libs\\dummyuidatamtm.dll");
       
   112 
       
   113 const TUid KUidEmailTechnologyGroup=	{0x10001671};
       
   114 LOCAL_D const TUid theTechnologyTypeUid   = KUidEmailTechnologyGroup; 
       
   115 
       
   116 // Nr folders to be created.
       
   117 const TInt KNrFolders = 2;
       
   118 const TInt KNrSubFolders = 2;
       
   119 const TInt KNrQueuedPerFolder = 5;
       
   120 
       
   121 //
       
   122 // Data component file name for client
       
   123 // The data component file is a file belonging to the
       
   124 // MTM. a class CMtmGroupData is stored in it, specifying the
       
   125 // UID's of the components belonging to the MTM.
       
   126 // The CMsvSession class needs it to install the MTM..
       
   127 // the function CreateDataComponentFileStoreL creates the file for this MTM.
       
   128 
       
   129 #define DataComponentFileName _L("c:\\system\\mtm\\impc.dat")  
       
   130 
       
   131 // Service we're connected to.
       
   132 TFileName theRootDir = _L("C:\\Data\\impc\\");
       
   133 
       
   134 _LIT(KTestSettingsServerAddress,"2.2.2.2");
       
   135 
       
   136 const TInt KTestSettingsPort = 111;
       
   137 _LIT8(KTestSettingsFolderPath,"\\a\\folder\\path\\");
       
   138 
       
   139 //
       
   140 void TestScheduler::Error(TInt anError) const
       
   141 	{
       
   142 	test.Printf(_L("Active object left with error code %d\n"), anError);
       
   143 	CActiveScheduler::Stop();
       
   144 	}
       
   145 
       
   146 //
       
   147 void CDummySessionObserver::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
       
   148 	{
       
   149 	switch (aEvent)
       
   150 		{
       
   151 		case EMsvEntriesCreated:
       
   152 			{
       
   153 			TMsvId newid    = *(TMsvId*)aArg1;
       
   154 			TMsvId parentid = *(TMsvId*)aArg2;
       
   155 			test.Printf(_L("SESSION EVENT : EMsvEntriesCreated id=%d, parentid=%d\n"),newid,parentid);
       
   156 			}
       
   157 			break;
       
   158 		case EMsvEntriesChanged:
       
   159 			{
       
   160 			TMsvId id    = *(TMsvId*)aArg1;
       
   161 			test.Printf(_L("SESSION EVENT : EMsvEntriesChanged id=%d\n"),id);
       
   162 			}
       
   163 			break;
       
   164 		case EMsvEntriesDeleted:
       
   165 			{
       
   166 			CMsvEntrySelection *selection=(CMsvEntrySelection *)aArg1;
       
   167 			test.Printf(_L("SESSION EVENT : EMsvEntriesDeleted (%d items)\n"),selection->Count());
       
   168 			}
       
   169 			break;
       
   170 		case EMsvEntriesMoved:
       
   171 			{
       
   172 			CMsvEntrySelection *selection=(CMsvEntrySelection *)aArg1;
       
   173 			test.Printf(_L("SESSION EVENT : EMsvEntriesMoved (%d items)\n"),selection->Count());
       
   174 			}
       
   175 			break;
       
   176 		case EMsvMtmGroupInstalled:
       
   177 			{
       
   178 			TUid id=*(TUid *)aArg2;
       
   179 			test.Printf(_L("SESSION EVENT : EMsvMtmGroupInstalled (uid=%d)\n"),id);
       
   180 			}
       
   181 			break;
       
   182 		case EMsvMtmGroupDeInstalled:
       
   183 			{
       
   184 			TUid id=*(TUid *)aArg2;
       
   185 			test.Printf(_L("SESSION EVENT : EMsvMtmGroupDeInstalled (uid=%d)\n"),id);
       
   186 			}
       
   187 			break;
       
   188 		default:
       
   189 			break;
       
   190 		}
       
   191 	};
       
   192 
       
   193 //
       
   194 
       
   195 LOCAL_C TMsvId FindTxtServiceEntry(CMsvEntry& aRootEntry)	
       
   196 //
       
   197 // Try to find a service entry for our TXT message types
       
   198 // return the id if it already exists. Otherwise returns KMsvNullIndexEntryId.
       
   199 //
       
   200 	{
       
   201 	TMsvId result = KMsvNullIndexEntryId;
       
   202 	// Get the direct children
       
   203 	aRootEntry.SetEntryL(KMsvRootIndexEntryId);
       
   204 	CMsvEntrySelection *selection = aRootEntry.ChildrenWithMtmL(KUidMsgTypeIMAP4); 
       
   205 	test (selection != NULL);
       
   206 	CleanupStack::PushL(selection);
       
   207 	// Now return the first found entry
       
   208 	TInt nrChildren = selection->Count();
       
   209 	test.Printf (_L("%d txt service entries\n"), nrChildren);
       
   210 	if (nrChildren >0)
       
   211 		result = (*selection)[0];
       
   212 	CleanupStack::PopAndDestroy(1);	//selection
       
   213 	return result;
       
   214 	}
       
   215 
       
   216 
       
   217 LOCAL_C TMsvId CreateServiceEntryL(CMsvEntry& aClientEntry, TInt aError)
       
   218 //
       
   219 // Create a service entry below aClientEntry, and see if there was an error.
       
   220 //
       
   221 	{
       
   222 	TMsvEntry serviceEntry;
       
   223 	serviceEntry.iDescription.Set(_L("IMAP4 Service Entry"));
       
   224 	serviceEntry.iDetails.Set(_L("IMAP4"));
       
   225 	serviceEntry.iType = KUidMsvServiceEntry;
       
   226 	serviceEntry.iSize = 0;
       
   227 	serviceEntry.iMtm = KUidMsgTypeIMAP4;
       
   228 	aClientEntry.SetEntryL(KMsvRootIndexEntryId);
       
   229 	
       
   230 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   231 	wait->Start();
       
   232 	CMsvOperation*  opert = aClientEntry.CreateL(serviceEntry, wait->iStatus);
       
   233 	CActiveScheduler::Start(); // operation complete
       
   234 	test(opert->iStatus.Int()==KErrNone);
       
   235 	test(opert->Mtm()==KUidMsvLocalServiceMtm);
       
   236 	TMsvLocalOperationProgress details;
       
   237 	TPckgC<TMsvLocalOperationProgress> package(details);	
       
   238 	package.Set(opert->ProgressL());
       
   239 	test(package().iType==TMsvLocalOperationProgress::ELocalNew);
       
   240 	test(package().iTotalNumberOfEntries==1);
       
   241 	test(package().iError==aError);
       
   242 	if (aError)
       
   243 		{
       
   244 		test(package().iNumberCompleted==0);
       
   245 		test(package().iNumberFailed==1);
       
   246 		}
       
   247 	else
       
   248 		{
       
   249 		test(package().iNumberCompleted==1);
       
   250 		test(package().iNumberFailed==0);
       
   251 		*(TMsvId*)&serviceEntry = package().iId;
       
   252 		}
       
   253 	test(package().iNumberRemaining==0);
       
   254 	delete opert; opert=NULL;
       
   255 	CleanupStack::PopAndDestroy(); // wait
       
   256 
       
   257 
       
   258 	// Store the service entry body (service settings)
       
   259 	// Get the store
       
   260 	aClientEntry.SetEntryL(serviceEntry.Id());
       
   261 	CMsvStore* store=NULL;
       
   262 	TRAPD(err,store=aClientEntry.EditStoreL());
       
   263 	CleanupStack::PushL(store);
       
   264 	// Store settings
       
   265 	
       
   266 	CleanupStack::PopAndDestroy();          //store
       
   267 
       
   268 	// The Id of the service entry
       
   269 	return serviceEntry.Id(); 
       
   270 	}
       
   271 
       
   272 LOCAL_C TMsvId CreateFolderEntryL(CMsvEntry& aClientEntry)
       
   273 //
       
   274 // Create a folder entry below aClientEntry, and see if there was an error.
       
   275 //
       
   276 	{
       
   277 	TMsvEntry folderEntry;
       
   278 
       
   279 	folderEntry.iDescription.Set(_L("IMAP4 Folder"));
       
   280 	folderEntry.iDetails.Set(_L("IMAP4"));
       
   281 	folderEntry.iType = KUidMsvFolderEntry;
       
   282 	folderEntry.iServiceId = theServiceId;
       
   283 	folderEntry.iSize = 0;
       
   284 	folderEntry.iMtm = KUidMsgTypeIMAP4;
       
   285 
       
   286 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   287 	wait->Start();
       
   288 	CMsvOperation*  opert = aClientEntry.CreateL(folderEntry, wait->iStatus);
       
   289 	CActiveScheduler::Start(); // operation complete
       
   290 	test(opert->iStatus.Int()==KErrNone);
       
   291 	test(opert->Mtm()==KUidMsvLocalServiceMtm);
       
   292 	TMsvLocalOperationProgress details;
       
   293 	TPckgC<TMsvLocalOperationProgress> package(details);	
       
   294 	package.Set(opert->ProgressL());
       
   295 	test(package().iType==TMsvLocalOperationProgress::ELocalNew);
       
   296 	test(package().iTotalNumberOfEntries==1);
       
   297 	test(package().iError==KErrNone);
       
   298 	test(package().iNumberCompleted==1);
       
   299 	test(package().iNumberFailed==0);
       
   300 	test(package().iNumberRemaining==0);
       
   301 	delete opert; opert=NULL;
       
   302 	CleanupStack::PopAndDestroy();//wait
       
   303 
       
   304 	// The Id of the service entry
       
   305 	return package().iId; 
       
   306 	}
       
   307 
       
   308 LOCAL_C void DeleteFolderEntryL(CMsvEntry& aClientEntry, TMsvId aIdToDelete)
       
   309 //
       
   310 // Delete a folder entry below aClientEntry, and see if there was an error.
       
   311 //
       
   312 	{
       
   313 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   314 	wait->Start();
       
   315 	CMsvOperation*  opert = aClientEntry.DeleteL(aIdToDelete, wait->iStatus);
       
   316 
       
   317 	CActiveScheduler::Start(); // operation complete
       
   318 	test(opert->iStatus.Int()==KErrNone);
       
   319 	test(opert->Mtm()==KUidMsvLocalServiceMtm);
       
   320 	TMsvLocalOperationProgress details;
       
   321 	TPckgC<TMsvLocalOperationProgress> package(details);	
       
   322 	package.Set(opert->ProgressL());
       
   323 	test(package().iType==TMsvLocalOperationProgress::ELocalDelete);
       
   324 	test(package().iTotalNumberOfEntries==package().iNumberCompleted);
       
   325 	test(package().iError==KErrNone);
       
   326 	test(package().iNumberFailed==0);
       
   327 	test(package().iNumberRemaining==0);
       
   328 	delete opert; opert=NULL;
       
   329 	CleanupStack::PopAndDestroy();//wait
       
   330 	}
       
   331 			   
       
   332 LOCAL_C CMsvEntrySelection* CreateFoldersL(TMsvId aRootId, TInt aNrFolders)
       
   333 	{
       
   334 	CMsvEntry* msventry=CMsvEntry::NewL(*theSession, aRootId, TMsvSelectionOrdering());
       
   335 	CleanupStack::PushL(msventry);
       
   336 
       
   337 	TInt i;
       
   338 	for ( i = 0 ; i < aNrFolders ; i ++ )
       
   339 		{
       
   340 		CreateFolderEntryL(*msventry);
       
   341 		}
       
   342 
       
   343 	CMsvEntrySelection* folders = msventry->ChildrenWithServiceL(theServiceId) ;
       
   344 	CleanupStack::PopAndDestroy();//msventry
       
   345 	return folders;
       
   346 	}
       
   347 
       
   348 LOCAL_C void testCreateFoldersL()
       
   349 	{
       
   350 	theFolders = CreateFoldersL(KMsvGlobalInBoxIndexEntryId, KNrFolders);
       
   351 	test (theFolders->Count() == KNrFolders);
       
   352 	theSubfolders = CreateFoldersL((*theFolders)[0], KNrSubFolders);
       
   353 	test (theSubfolders->Count() == KNrSubFolders);
       
   354 	}
       
   355 
       
   356 LOCAL_C void StoreQueuedOperationsL(CMsvEntry& aEntry, MImOffLineOperationArray& aArray)
       
   357 	{
       
   358 	CMsvStore* store=aEntry.EditStoreL();
       
   359 	CleanupStack::PushL(store);
       
   360     
       
   361     CImOffLineArrayStore externaliser(aArray);
       
   362     externaliser.StoreL(*store);
       
   363     store->CommitL();
       
   364     
       
   365     CleanupStack::PopAndDestroy();//store
       
   366 	}
       
   367 
       
   368 LOCAL_C void testPopulateFoldersWithQueuedOperationsL()
       
   369 	{
       
   370     TInt i;
       
   371 	CMsvEntry* msventry=CMsvEntry::NewL(*theSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
       
   372 	CleanupStack::PushL(msventry);
       
   373 
       
   374     CImOffLineOperationArray* array = CImOffLineOperationArray::NewL();
       
   375     CleanupStack::PushL(array);
       
   376 //    array->Reset();
       
   377     CImOffLineOperation operation;
       
   378     for (i=0;i<KNrQueuedPerFolder;i++)
       
   379         {
       
   380         array->AppendOperationL(operation);
       
   381         }
       
   382     
       
   383 	for (i=0;i<theFolders->Count();i++)
       
   384 		{
       
   385 		msventry->SetEntryL((*theFolders)[i]);
       
   386 		StoreQueuedOperationsL(*msventry, *array);
       
   387 		}
       
   388 
       
   389 	for (i=0;i<theSubfolders->Count();i++)
       
   390 		{
       
   391 		msventry->SetEntryL((*theSubfolders)[i]);
       
   392 		StoreQueuedOperationsL(*msventry, *array);
       
   393 		}
       
   394 
       
   395     CleanupStack::PopAndDestroy(2);// array, msventry
       
   396 	}
       
   397 
       
   398 LOCAL_C void testDeleteFoldersL()
       
   399 	{
       
   400 	CMsvEntry* msventry=CMsvEntry::NewL(*theSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
       
   401 	CleanupStack::PushL(msventry);
       
   402 	TInt i;
       
   403 
       
   404 	for ( i = 0 ; i < theFolders->Count() ; i ++ )
       
   405 		{
       
   406 		DeleteFolderEntryL(*msventry, (*theFolders)[i]);
       
   407 		}
       
   408 
       
   409 	CleanupStack::PopAndDestroy();//msventry
       
   410 
       
   411 	delete theFolders;
       
   412 	theFolders = NULL;
       
   413 	delete theSubfolders;
       
   414 	theSubfolders = NULL;
       
   415 	}
       
   416 
       
   417 LOCAL_C void testClearInboxL()
       
   418 	{
       
   419 	CMsvEntry* msventry=CMsvEntry::NewL(*theSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
       
   420 	CleanupStack::PushL(msventry);
       
   421 	theFolders = msventry->ChildrenWithServiceL(theServiceId) ;
       
   422 	CleanupStack::PopAndDestroy();//msventry
       
   423 	testDeleteFoldersL();
       
   424 	}
       
   425 
       
   426 //
       
   427 // Generic test setup (cleanup stack, file system, scheduler)
       
   428 // testSetup ensures the services that would normally be present
       
   429 // under the Operating system are created, so the test code can use it.
       
   430 
       
   431 LOCAL_C void GetMtmDetails(TUid aMtmId)
       
   432 	{
       
   433 	TBool isPresent=theClientRegistry->IsPresent(aMtmId);
       
   434 	__ASSERT_DEBUG(isPresent!=EFalse, User::Panic(_L("reg test 2"),0));
       
   435 	if (isPresent)
       
   436 		{
       
   437 		TPtrC name( theClientRegistry->RegisteredMtmDllInfo(aMtmId).HumanReadableName());
       
   438 		TInt ordinal = theClientRegistry->RegisteredMtmDllInfo(aMtmId).iEntryPointOrdinalNumber;
       
   439 		test.Printf(_L("%S  (ordinal %d)\n"), &name, ordinal);
       
   440 		}
       
   441 	}
       
   442 
       
   443 LOCAL_C void UseClientRegistry()
       
   444 	{
       
   445 	TInt numMtms;
       
   446 
       
   447 	numMtms = theClientRegistry->NumRegisteredMtmDlls();
       
   448 	for (TInt ii=0; ii<numMtms; ii++)
       
   449 		{
       
   450 		TUid mtmId = theClientRegistry->MtmTypeUid(ii);
       
   451 		GetMtmDetails(mtmId);
       
   452 		}
       
   453 	}
       
   454 
       
   455 LOCAL_C void CreateDataComponentFileStoreL()
       
   456 //
       
   457 // Test read file handling.
       
   458 //
       
   459 	{
       
   460 // Open file
       
   461 
       
   462 	CMtmDllInfoArray* mtmdllinfoarray=new(ELeave) CMtmDllInfoArray();
       
   463 	CleanupStack::PushL(mtmdllinfoarray);
       
   464 
       
   465 	CMtmDllInfo* mtmdllinfo1=CMtmDllInfo::NewL(_L("Email"),TUidType(KDynamicLibraryUid,KUidMtmServerComponent,TUid::Uid(KUidMtmDefaultSpecificVal)),KServerMtmFileName,1,TVersion(2,0,0));
       
   466 	mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo1);
       
   467 
       
   468 	CMtmDllInfo* mtmdllinfo2=CMtmDllInfo::NewL(_L("Email"),TUidType(KDynamicLibraryUid,KUidMtmClientComponent,TUid::Uid(KUidMtmDefaultSpecificVal)),KClientMtmFileName,3,TVersion(2,0,0));
       
   469 	mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo2);
       
   470 
       
   471 	CMtmDllInfo* mtmdllinfo3=CMtmDllInfo::NewL(_L("Email"),TUidType(KDynamicLibraryUid,KUidMtmUiComponent,TUid::Uid(KUidMtmDefaultSpecificVal)),KUiMtmFileName,1,TVersion(2,0,0));
       
   472 	mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo3);
       
   473 
       
   474 	CMtmDllInfo* mtmdllinfo4=CMtmDllInfo::NewL(_L("Email"),TUidType(KDynamicLibraryUid,KUidMtmUiDataComponent,TUid::Uid(KUidMtmDefaultSpecificVal)),KUiDataMtmFileName,1,TVersion(2,0,0));
       
   475 	mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo4);
       
   476 
       
   477 	TCapabilitySet capSet;
       
   478 	capSet.SetEmpty();
       
   479 	CleanupStack::Pop(mtmdllinfoarray); // next line takes ownership
       
   480 	CMtmGroupData* mtmgroupdata=CMtmGroupData::NewL(KUidMsgTypeIMAP4, theTechnologyTypeUid, mtmdllinfoarray, capSet);
       
   481 	CleanupStack::PushL(mtmgroupdata);
       
   482 
       
   483 	test.Printf(_L("Number of dlls %d\n"),mtmgroupdata->MtmDllInfoArray().Count());
       
   484 
       
   485 	CFileStore* filestore = CPermanentFileStore::ReplaceLC(testUtils->FileSession(),DataComponentFileName,EFileShareExclusive|EFileStream|EFileWrite);
       
   486 	TUidType uidtype(KPermanentFileStoreLayoutUid,KUidMsvDataComponent,KUidMsgTypeIMAP4);
       
   487 	filestore->SetTypeL(uidtype);
       
   488 	RStoreWriteStream out;
       
   489 	TStreamId streamid=out.CreateLC(*filestore);							// Push to stack
       
   490 	mtmgroupdata->ExternalizeL(out);
       
   491 	out.CommitL();
       
   492 	CleanupStack::PopAndDestroy(); // out
       
   493 	filestore->SetRootL(streamid);
       
   494 	filestore->CommitL();
       
   495 	CleanupStack::PopAndDestroy(2, mtmgroupdata); // filestore, mtmgroupdata
       
   496 	}
       
   497 
       
   498 LOCAL_C void CreateClientRegistryL()
       
   499 //
       
   500 // Get access to the Client MTM object (CBaseMtm-derived).
       
   501 //
       
   502 	{
       
   503 // Session observer. Needed to create a session
       
   504 	theSessionObserver = new (ELeave) CDummySessionObserver;
       
   505 	test(theSessionObserver != NULL);
       
   506 	CleanupStack::PushL(theSessionObserver);
       
   507 // Session. Needed to create a client registry.
       
   508 	theSession=CMsvSession::OpenSyncL(*theSessionObserver);
       
   509 	test(theSession != NULL);
       
   510 	CleanupStack::PushL(theSession);
       
   511 
       
   512     TInt err=theSession->InstallMtmGroup(DataComponentFileName);
       
   513     test(err==KErrNone || err==KErrAlreadyExists);
       
   514 
       
   515 // Client registry. Needed to get the MTM component
       
   516 	theClientRegistry=CClientMtmRegistry::NewL(*theSession,KMsvDefaultTimeoutMicroSeconds32);
       
   517 	test(theClientRegistry != NULL);
       
   518 	test(theClientRegistry->IsPresent(KUidMsgTypeIMAP4));
       
   519 	CleanupStack::PushL(theClientRegistry);
       
   520 
       
   521 // CMsvEntry, needed to create the root entry, and then the TXT service entry
       
   522 	CMsvEntry* msventry=CMsvEntry::NewL(*theSession, KMsvRootIndexEntryId, TMsvSelectionOrdering());
       
   523 	CleanupStack::PushL(msventry);
       
   524 // First try to find an already existing service node
       
   525 	theServiceId = FindTxtServiceEntry(*msventry);
       
   526 // Otherwise add it
       
   527 	if (theServiceId == KMsvNullIndexEntryId)
       
   528 		{
       
   529 		test.Printf(_L("Creating service entry\n"));
       
   530         theServiceId  = CreateServiceEntryL(*msventry,KErrNone);
       
   531 		}
       
   532 	else
       
   533 		{
       
   534 		test.Printf(_L("Service entry found\n"));
       
   535 		}
       
   536 	// 
       
   537 	test (theServiceId != KMsvNullIndexEntryId);
       
   538 	//
       
   539     test.Printf(_L("Create mtm\n"));
       
   540 	theClientMtm=(CImap4ClientMtm*)theClientRegistry->NewMtmL(KUidMsgTypeIMAP4);
       
   541 
       
   542 // Step to the level of the service entry.
       
   543 	msventry->SetEntryL(theServiceId);
       
   544 	CleanupStack::Pop(); //msventry is owned by theClientMtm
       
   545 	theClientMtm->SetCurrentEntryL(msventry);  // the object msventry points to is now owned by the mtm
       
   546 // Store the settings for the service entry
       
   547     theClientMtm->SaveMessageL();
       
   548 	test.Printf(_L("Text mtm type uid %d\n"),theClientMtm->Type());
       
   549 	CleanupStack::Pop(3);// Client registry, session Observer & session
       
   550     }
       
   551 
       
   552 LOCAL_C void DeleteClientRegistry()
       
   553 	{
       
   554 // Clean up
       
   555 	delete theClientMtm;		theClientMtm	   = NULL;
       
   556 	delete theClientRegistry;	theClientRegistry  = NULL;
       
   557 	delete theSession;			theSession         = NULL;
       
   558 	delete theSessionObserver;	theSessionObserver = NULL;
       
   559 	}
       
   560 
       
   561 LOCAL_C void testStoreServiceEntryL()
       
   562 	{
       
   563 	theClientMtm->SaveMessageL();
       
   564 	}
       
   565 
       
   566 /*LOCAL_C void testRestoreServiceEntryL()
       
   567 	{
       
   568 	theClientMtm->LoadMessageL();
       
   569 	}
       
   570 */
       
   571 LOCAL_C void testClearServiceEntry()
       
   572 	{
       
   573     CImImap4Settings *imap4Settings = new(ELeave)CImImap4Settings;
       
   574     imap4Settings->CopyL(((CImap4ClientMtm*)theClientMtm)->Imap4Settings());
       
   575     imap4Settings->Reset();
       
   576     ((CImap4ClientMtm*)theClientMtm)->SetImap4SettingsL(*imap4Settings);
       
   577     delete imap4Settings;
       
   578 	}
       
   579 
       
   580 // Server MTM Communication Test Functions //
       
   581 
       
   582 LOCAL_C void testCheckForConnectionL(TBool aShouldBeConnected)
       
   583 	{
       
   584     test(theClientMtm != NULL);
       
   585 	CMsvEntrySelection* aSelection = new (ELeave) CMsvEntrySelection;
       
   586 	CleanupStack::PushL(aSelection);
       
   587 	aSelection->AppendL(theServiceId);
       
   588     TBool result = aShouldBeConnected;
       
   589 
       
   590 	TBuf8<256> parameter;
       
   591     ((CImap4ClientMtm*)theClientMtm)->InvokeSyncFunctionL(KIMAP4MTMIsConnected, *aSelection, parameter);
       
   592 	TImap4GenericProgress temp;	
       
   593 	TPckgC<TImap4GenericProgress> paramPack(temp);
       
   594 
       
   595 	const TDesC8& progBuf = parameter;	
       
   596 	paramPack.Set(progBuf);
       
   597 	TImap4GenericProgress progress=paramPack();	
       
   598 
       
   599 	result = progress.iErrorCode;
       
   600 	if (result==KErrNone)
       
   601 		test.Printf(_L("Connected to internet               "));
       
   602 	else
       
   603 		test.Printf(_L("Not connected to internet           "));
       
   604 
       
   605     CleanupStack::PopAndDestroy();//aSelection
       
   606     
       
   607     User::LeaveIfError((result!=0) != (aShouldBeConnected!=0));
       
   608     }
       
   609 
       
   610 CImOperationQueueList *theQueue=NULL;
       
   611 
       
   612 LOCAL_C void testGetQueListL()
       
   613 	{
       
   614 	CMsvEntry* msventry=CMsvEntry::NewL(*theSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
       
   615 	// Queue takes over	ownership of msventry
       
   616 	theQueue = ((CImap4ClientMtm*)theClientMtm)->QueueListL(*msventry);
       
   617 	CleanupStack::PushL(theQueue);
       
   618 
       
   619 //	test.Printf(_L("%d operations queued\n"),theQueue->Count());
       
   620 	
       
   621 	CleanupStack::Pop();//theQueue
       
   622 	}
       
   623 
       
   624 LOCAL_C void testDeleteQueuedL(TInt aOffset, TInt aStep, TInt aNr)
       
   625 	{
       
   626 	test (theQueue != NULL);
       
   627 	test (aNr <= theQueue->Count()); 
       
   628 	TInt i;
       
   629 	for (i=0;i<aNr;i++)
       
   630 		{
       
   631 		theQueue->DeleteL(aOffset);
       
   632 		aOffset += aStep;
       
   633 		aOffset %= theQueue->Count();
       
   634 		}
       
   635 	}
       
   636 
       
   637 LOCAL_C void testExpungeQueListL()
       
   638 	{
       
   639 	test (theQueue != NULL);
       
   640 	theQueue->ExpungeDeletedOperationsL();
       
   641 	}
       
   642 
       
   643 LOCAL_C void testFreeQueListL()
       
   644 	{
       
   645 	test (theQueue != NULL);
       
   646 	delete theQueue;
       
   647 	theQueue = NULL;
       
   648 	}
       
   649 
       
   650 LOCAL_C void testSetServiceSettings(TInt aService)
       
   651 	{
       
   652     CImImap4Settings *imap4Settings = new(ELeave)CImImap4Settings;
       
   653     imap4Settings->CopyL(((CImap4ClientMtm*)theClientMtm)->Imap4Settings());
       
   654 	switch (aService)
       
   655 		{
       
   656 		case 0:
       
   657             imap4Settings->SetServerAddressL(_L("128.2.10.131"));
       
   658 			imap4Settings->SetPort(143);
       
   659 			imap4Settings->SetLoginNameL(testUtils->MachineName());
       
   660 			imap4Settings->SetPasswordL(testUtils->MachineName());
       
   661 			imap4Settings->SetFolderPathL(_L8(""));
       
   662             break;
       
   663         default:
       
   664         case 1:
       
   665 			imap4Settings->SetServerAddressL(_L("someothername"));
       
   666 			imap4Settings->SetPort(111);
       
   667 			imap4Settings->SetLoginNameL(testUtils->MachineName());
       
   668 			imap4Settings->SetPasswordL(testUtils->MachineName());
       
   669 			imap4Settings->SetFolderPathL(_L8("someothername"));
       
   670 			break;
       
   671 		}
       
   672     ((CImap4ClientMtm*)theClientMtm)->SetImap4SettingsL(*imap4Settings);
       
   673     delete imap4Settings;
       
   674     }
       
   675 
       
   676 LOCAL_C TInt testVerifyServiceSettingsL()
       
   677 	{
       
   678     CImImap4Settings *imap4Settings = new(ELeave)CImImap4Settings;
       
   679     imap4Settings->CopyL(((CImap4ClientMtm*)theClientMtm)->Imap4Settings());
       
   680     
       
   681     TInt result=0;
       
   682 	result += imap4Settings->ServerAddress().Compare(_L("128.2.10.131"));
       
   683 	result += imap4Settings->Port() - (143);
       
   684 	result += imap4Settings->LoginName().Compare(testUtils->MachineName());
       
   685 	result += imap4Settings->Password().Compare(testUtils->MachineName());
       
   686 	result += imap4Settings->FolderPath().Compare(_L8(""));
       
   687     delete imap4Settings;
       
   688     return result;
       
   689 	}
       
   690 
       
   691 LOCAL_C void testCapabilitiesL()
       
   692 	{
       
   693 	// check the capabilities
       
   694 	TInt response=0;
       
   695 	// 
       
   696 	// supported
       
   697 	test(theClientMtm->QueryCapability(KUidMtmQueryMaxBodySize ,response)==KErrNone);
       
   698 	test(response==0xffff); response=0;
       
   699 	test(theClientMtm->QueryCapability(KUidMtmQueryMaxTotalMsgSize ,response)==KErrNone);
       
   700 	test(response==0xffff); response=0;
       
   701 	test(theClientMtm->QueryCapability(KUidMtmQuerySupportedBody ,response)==KErrNone);
       
   702 //	test(theClientMtm->QueryCapability(KUidMtmQueryCanSendMsg ,response)==KErrNone);
       
   703 	test(theClientMtm->QueryCapability(KUidMtmQueryCanReceiveMsg ,response)==KErrNone);
       
   704 	test(theClientMtm->QueryCapability(KUidMtmQuerySupportAttachments ,response)==KErrNone);
       
   705 	//
       
   706 	// not supported
       
   707 	test(theClientMtm->QueryCapability(KUidMtmQueryOffLineAllowed ,response)==KErrNotSupported);
       
   708 	//
       
   709 	// non-existant capability
       
   710 	test(theClientMtm->QueryCapability(KUidMsgTypeIMAP4 ,response)==KErrNotSupported);
       
   711 	}
       
   712 
       
   713 #include <cemailaccounts.h>
       
   714 #include <iapprefs.h>
       
   715 
       
   716 LOCAL_C void testStoreSettingsL()
       
   717 //
       
   718 // Dummy settings for checking that StoreSettingsL work for the client mtm
       
   719 //	
       
   720 	{
       
   721 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   722 	
       
   723 	CImImap4Settings *imap4Settings = new(ELeave)CImImap4Settings;
       
   724 	CleanupStack::PushL(imap4Settings);
       
   725 	
       
   726 	CImIAPPreferences* iapSettings = CImIAPPreferences::NewLC();
       
   727 	
       
   728 	accounts->PopulateDefaultImapSettingsL(*imap4Settings, *iapSettings);
       
   729 	
       
   730 	TImapAccount imapAccount = accounts->CreateImapAccountL(_L("ImapAccount"), *imap4Settings, *iapSettings, EFalse);
       
   731 	((CImap4ClientMtm*)theClientMtm)->SwitchCurrentEntryL(imapAccount.iImapService);
       
   732 	
       
   733     imap4Settings->CopyL(((CImap4ClientMtm*)theClientMtm)->Imap4Settings());
       
   734     imap4Settings->SetServerAddressL(KTestSettingsServerAddress);
       
   735 	imap4Settings->SetPort(KTestSettingsPort);
       
   736 	imap4Settings->SetLoginNameL(testUtils->MachineName());
       
   737 	imap4Settings->SetPasswordL(testUtils->MachineName());
       
   738 	imap4Settings->SetFolderPathL(KTestSettingsFolderPath);
       
   739     ((CImap4ClientMtm*)theClientMtm)->SetImap4SettingsL(*imap4Settings);
       
   740 	CleanupStack::PopAndDestroy(3, accounts);
       
   741 	TRAPD(err,((CImap4ClientMtm*)theClientMtm)->StoreSettingsL());
       
   742    	test(err==KErrNone);
       
   743 	}
       
   744 
       
   745 LOCAL_C TInt testVerifyStoreSettingsL()
       
   746 //
       
   747 // Comparison of the settings stored to see that the client commits after storing
       
   748 //
       
   749 	{
       
   750 	TRAPD(err,((CImap4ClientMtm*)theClientMtm)->RestoreSettingsL());
       
   751 	test(err==KErrNone);
       
   752     CImImap4Settings *imap4Settings = new(ELeave)CImImap4Settings;
       
   753 	CleanupStack::PushL(imap4Settings);
       
   754     imap4Settings->CopyL(((CImap4ClientMtm*)theClientMtm)->Imap4Settings());
       
   755     
       
   756     TInt result=0;
       
   757 	result += imap4Settings->ServerAddress().Compare(KTestSettingsServerAddress);
       
   758 	result += imap4Settings->Port() - KTestSettingsPort;
       
   759 	result += imap4Settings->LoginName().Compare(testUtils->MachineName());
       
   760 	result += imap4Settings->Password().Compare(testUtils->MachineName());
       
   761 	result += imap4Settings->FolderPath().Compare(KTestSettingsFolderPath);
       
   762     
       
   763 	imap4Settings->Reset();
       
   764     ((CImap4ClientMtm*)theClientMtm)->SetImap4SettingsL(*imap4Settings);
       
   765 	TRAP(err,((CImap4ClientMtm*)theClientMtm)->StoreSettingsL());
       
   766    	test(err==KErrNone);
       
   767 
       
   768    	TRequestStatus st;
       
   769    	TMsvId s =0;
       
   770    	TMsvPartList retPart=KMsvMessagePartBody;
       
   771    	TUint id=0;
       
   772    	TInt add=0;
       
   773    	
       
   774    	TBuf<1> des;
       
   775    	TBuf8<1> des8;
       
   776    		
       
   777    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->ReplyL(s,retPart,st));
       
   778    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->ForwardL(s,retPart,st));
       
   779    	((CImap4ClientMtm*)theClientMtm)->ValidateMessage(id);
       
   780    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->AddAddresseeL(des));
       
   781    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->AddAddresseeL(des));
       
   782    	((CImap4ClientMtm*)theClientMtm)->RemoveAddressee(add);
       
   783    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->AddAttachmentL(des,des8,id,st));
       
   784    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->AddAddresseeL(des));
       
   785 	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->AddEntryAsAttachmentL(s,st));
       
   786    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->AddEntryAsAttachmentL(s,st));
       
   787    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->DefaultServiceL());
       
   788    	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->RemoveDefaultServiceL());
       
   789 	TRAP_IGNORE(((CImap4ClientMtm*)theClientMtm)->ChangeDefaultServiceL(s));
       
   790 
       
   791 	CleanupStack::PopAndDestroy(imap4Settings);
       
   792     return result;
       
   793 	}
       
   794 
       
   795 	
       
   796 void TestForErrorL(TInt aError)
       
   797 	{
       
   798 	if (aError)
       
   799 		{
       
   800 		test.Printf(_L("Trap returned error %d\n"),aError);
       
   801         log->AppendError(_L8("Trap returned error"),aError);
       
   802         test.Getch();
       
   803 		}
       
   804 	test(aError==KErrNone);
       
   805 	}
       
   806 
       
   807 #define TEST(x)  TRAP(err,x);TestForErrorL(err)
       
   808 #define TESTNEXT(x) test.Next(_L(x));log->AppendComment(_L8(x));log->AppendComment(_L8(""))
       
   809 
       
   810 LOCAL_C void InitL()
       
   811 	{
       
   812 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
   813 	CActiveScheduler::Install(scheduler);
       
   814 	CleanupStack::PushL(scheduler);
       
   815 
       
   816 	testUtils = CEmailTestUtils::NewLC(test);
       
   817 
       
   818 	testUtils->CleanMessageFolderL();
       
   819 	testUtils->ClearEmailAccountsL();	
       
   820 
       
   821 	testUtils->WriteComment(_L("IMAP4 Client MTM Tests"));
       
   822 	log = CImLog::NewL(_L("c:\\logs\\email\\T_IMCM.log"), EAppend);
       
   823 	CleanupStack::PushL(log);
       
   824 	log->AppendComment(_L8("********* T_IMPC Test IMAP4 Client MTM *********"));
       
   825 	TBuf8<80> buf;
       
   826 
       
   827 #if defined(__WINS__)	
       
   828 	buf.Append(_L8("WINS "));
       
   829 #else
       
   830 	buf.Append(_L8("MARM "));
       
   831 #endif
       
   832 #if defined(_UNICODE)
       
   833 	buf.Append(_L8("U"));
       
   834 #endif
       
   835 #if defined(_DEBUG)
       
   836 	buf.Append(_L8("DEB"));
       
   837 #else
       
   838 	buf.Append(_L8("REL"));
       
   839 #endif
       
   840 	log->AppendComment(buf);
       
   841 	}
       
   842 
       
   843 LOCAL_C void Closedown()
       
   844 	{
       
   845 	log->AppendComment(_L8("**********    T_IMPC Tests Complete    **********"));
       
   846 	log->AppendComment(_L8(""));
       
   847 
       
   848 	testUtils->TestHarnessCompleted();
       
   849 	CleanupStack::PopAndDestroy(3);  //testUtils, log, scheduler
       
   850 	User::After(5000000);
       
   851 	}
       
   852 
       
   853 LOCAL_C void doMainL()
       
   854     {
       
   855 	InitL();
       
   856     TInt err=0;
       
   857 
       
   858 // Create a file with the group data (the UIDs of the dll's that
       
   859 // belong to this MTM group).
       
   860     
       
   861 	TInt testNo = 1;
       
   862     TESTNEXT("Create Data Component FileStore");
       
   863 	testUtils->TestStart(testNo++);
       
   864 	TEST( CreateDataComponentFileStoreL()					);
       
   865 	testUtils->TestFinish(testNo-1);
       
   866 // Get the client mtm, by using the just created file
       
   867 	TESTNEXT("Create Client Registry");
       
   868 	testUtils->TestStart(testNo++);
       
   869 	TEST( CreateClientRegistryL()							);
       
   870 	testUtils->TestFinish(testNo-1);
       
   871 
       
   872 // Show some information on the client side
       
   873 	UseClientRegistry(); // Doesn't leave.
       
   874 
       
   875 	testUtils->TestStart(testNo++);
       
   876     TEST( testCapabilitiesL()                               );
       
   877 	testUtils->TestFinish(testNo-1);
       
   878 
       
   879 	TESTNEXT("Clear service entry");
       
   880 	testUtils->TestStart(testNo++);
       
   881 	TEST( testClearServiceEntry()							);
       
   882 	testUtils->TestFinish(testNo-1);
       
   883 
       
   884 	TESTNEXT("Set service settings");
       
   885 	TInt result = 0;
       
   886 	testUtils->TestStart(testNo++);
       
   887 	TEST( testSetServiceSettings(0)							);
       
   888 	testUtils->TestFinish(testNo-1);
       
   889 	testUtils->TestStart(testNo++);
       
   890 	TEST( result = testVerifyServiceSettingsL()				);
       
   891 	test (result == 0);
       
   892 	testUtils->TestFinish(testNo-1);
       
   893 
       
   894 	TESTNEXT("Store service entry");
       
   895 	testUtils->TestStart(testNo++);
       
   896 	TEST( testStoreServiceEntryL()							);
       
   897 	testUtils->TestFinish(testNo-1);
       
   898 
       
   899 	TESTNEXT("Set (incorrect) service settings");
       
   900 	testUtils->TestStart(testNo++);
       
   901 	TEST( testSetServiceSettings(1)							);
       
   902 	testUtils->TestFinish(testNo-1);
       
   903 	testUtils->TestStart(testNo++);
       
   904 	TEST( result = testVerifyServiceSettingsL()				);
       
   905 	test (result != 0);
       
   906 	testUtils->TestFinish(testNo-1);
       
   907 
       
   908 /*	TESTNEXT("Restore service entry");
       
   909 	testUtils->TestStart(testNo++);
       
   910 	TEST( testRestoreServiceEntryL()						);
       
   911 	testUtils->TestFinish(testNo-1);
       
   912 	testUtils->TestStart(testNo++);
       
   913 	TEST( result = testVerifyServiceSettingsL()				);
       
   914 	test (result == 0);
       
   915 	testUtils->TestFinish(testNo-1);
       
   916 */
       
   917 	// Test of StoreSettingsL so that the store don't get corrupted.
       
   918 	TESTNEXT("Testing storing settings");
       
   919 	testUtils->TestStart(testNo++);
       
   920 	TEST( testStoreSettingsL()								);
       
   921 	testUtils->TestFinish(testNo-1);
       
   922 	testUtils->TestStart(testNo++);
       
   923 	TEST( result = testVerifyStoreSettingsL()				);
       
   924 	test( result == 0);
       
   925 	testUtils->TestFinish(testNo-1);
       
   926 
       
   927     // Testing passing on commands to the server....
       
   928 	TESTNEXT("Check that there is no connection yet");
       
   929     testUtils->TestStart(testNo++);
       
   930 	TEST( testCheckForConnectionL(EFalse));
       
   931 	testUtils->TestFinish(testNo-1);
       
   932 
       
   933 	test.Next(_L("Creating folders"));
       
   934 	testUtils->TestStart(testNo++);
       
   935 	TEST( testClearInboxL()					);
       
   936 	testUtils->TestFinish(testNo-1);
       
   937 
       
   938 	test.Next(_L("Creating folders"));
       
   939 	testUtils->TestStart(testNo++);
       
   940 	TEST( testCreateFoldersL()							);
       
   941 	testUtils->TestFinish(testNo-1);
       
   942 
       
   943 	TESTNEXT("Give folders queued operations");
       
   944 	testUtils->TestStart(testNo++);
       
   945 	TEST( testPopulateFoldersWithQueuedOperationsL()	);
       
   946 	testUtils->TestFinish(testNo-1);
       
   947 
       
   948 	TESTNEXT("Testing queued operations access");
       
   949 	testUtils->TestStart(testNo++);
       
   950 	TEST( testGetQueListL()								);
       
   951 	test (theQueue->Count() == (KNrFolders + KNrSubFolders)*KNrQueuedPerFolder);
       
   952 	testUtils->TestFinish(testNo-1);
       
   953 	testUtils->TestStart(testNo++);
       
   954 	TEST( testExpungeQueListL()							);
       
   955 	testUtils->TestFinish(testNo-1);
       
   956 	testUtils->TestStart(testNo++);
       
   957 	TEST( testFreeQueListL()							);
       
   958 	testUtils->TestFinish(testNo-1);
       
   959 
       
   960 #define KNrToDelete 5
       
   961 
       
   962 	TESTNEXT("Testing rewrite of queued operations");
       
   963 	testUtils->TestStart(testNo++);
       
   964 	TEST( testGetQueListL()								);
       
   965 	test (theQueue->Count() == (KNrFolders + KNrSubFolders)*KNrQueuedPerFolder);
       
   966 	testDeleteQueuedL(0,4,KNrToDelete);
       
   967 	test (theQueue->Count() == (KNrFolders + KNrSubFolders)*KNrQueuedPerFolder-KNrToDelete);
       
   968 	testUtils->TestFinish(testNo-1);
       
   969 	testUtils->TestStart(testNo++);
       
   970 	TEST( testFreeQueListL()							);
       
   971 	testUtils->TestFinish(testNo-1);
       
   972 
       
   973 	TESTNEXT("Testing removal queued operations");
       
   974 	testUtils->TestStart(testNo++);
       
   975 	TEST( testGetQueListL()								);
       
   976 	test (theQueue->Count() == (KNrFolders + KNrSubFolders)*KNrQueuedPerFolder);
       
   977 	testDeleteQueuedL(0,4,KNrToDelete);
       
   978 	testUtils->TestFinish(testNo-1);
       
   979 	testUtils->TestStart(testNo++);
       
   980 	TEST( testExpungeQueListL()							);
       
   981 	testUtils->TestFinish(testNo-1);
       
   982 	testUtils->TestStart(testNo++);
       
   983 	TEST( testFreeQueListL()							);
       
   984 	testUtils->TestFinish(testNo-1);
       
   985 
       
   986 	testUtils->TestStart(testNo++);
       
   987 	TEST( testGetQueListL()								);
       
   988 	TInt nr = theQueue->Count();
       
   989 	test (nr == (KNrFolders + KNrSubFolders)*KNrQueuedPerFolder-KNrToDelete);
       
   990 	testUtils->TestFinish(testNo-1);
       
   991 	testUtils->TestStart(testNo++);
       
   992 	TEST( testFreeQueListL()							);
       
   993 	testUtils->TestFinish(testNo-1);
       
   994 
       
   995 	test.Next(_L("Deleting folders"));
       
   996 	testUtils->TestStart(testNo++);
       
   997 	TEST( testDeleteFoldersL()							);
       
   998 	testUtils->TestFinish(testNo-1);
       
   999 
       
  1000 	// Finished. Clean up all objects
       
  1001 	TESTNEXT("Deleting used objects");
       
  1002 	testUtils->TestStart(testNo++);
       
  1003 	TEST( DeleteClientRegistry()						);
       
  1004 	testUtils->TestFinish(testNo-1);
       
  1005 
       
  1006 	Closedown();
       
  1007     }
       
  1008 
       
  1009 GLDEF_C TInt E32Main()
       
  1010 	{	
       
  1011 	TInt err;
       
  1012 	__UHEAP_MARK;
       
  1013     test.Start(_L("T_IMPC Test harness"));
       
  1014 	theCleanup=CTrapCleanup::New();
       
  1015     TRAP(err,doMainL());		
       
  1016     test(err == KErrNone);
       
  1017 	delete theCleanup;	
       
  1018 	test.End();
       
  1019 	test.Close();
       
  1020 	__UHEAP_MARKEND;
       
  1021 	User::Heap().Check();
       
  1022 	return(KErrNone);
       
  1023 	}