messagingfw/msgtest/testutils/server/src/Msgservertestutils.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 // msgservertestutils.cpp
       
    15 //
       
    16 
       
    17 #include "msgservertestutils.h"
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <f32fsys.h>
       
    21 #include <s32file.h>
       
    22 #include <e32uid.h>
       
    23 #include <txtrich.h>
       
    24 #include <txtfmlyr.h>
       
    25 #include <msvids.h>
       
    26 #include <msvuids.h>
       
    27 #include <msvruids.h>
       
    28 #include <e32std.h>
       
    29 #include <mtclbase.h>
       
    30 #include <mtclreg.h>
       
    31 #include <msvapi.h>
       
    32 #include <mtmuids.h>
       
    33 #include <smuthdr.h>
       
    34 #include <miutset.h>
       
    35 #include <sqldb.h>
       
    36 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS  
       
    37 #include "msvconsts.h"
       
    38 #endif
       
    39 
       
    40 _LIT(KMsvServerPattern, "!MsvServer*");
       
    41 _LIT(KMsgServerTestUtilsPanic,"MSGS-TESTS");
       
    42 #ifdef SYMBIAN_MESSAGESTORE_UNIT_TESTCODE
       
    43 _LIT(KDbFileName, "\\messaging.db");
       
    44 #else
       
    45 _LIT(KDbFileName, "[1000484B]messaging.db");
       
    46 #endif
       
    47 
       
    48 
       
    49 class CDummyObserver : public CBase, public MMsvSessionObserver
       
    50 	{
       
    51 public:
       
    52 	void HandleSessionEventL(TMsvSessionEvent, TAny*, TAny*, TAny*) {};
       
    53 	};
       
    54 
       
    55 
       
    56 EXPORT_C CMsgServerTestUtils* CMsgServerTestUtils::NewL(RTest& aRTest)
       
    57 	{
       
    58 	CMsgServerTestUtils* self = NewLC(aRTest);
       
    59 	CleanupStack::Pop();
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 EXPORT_C CMsgServerTestUtils* CMsgServerTestUtils::NewLC(RTest& aRTest)
       
    64 	{
       
    65 	CMsgServerTestUtils* self = new (ELeave) CMsgServerTestUtils(aRTest);
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL();
       
    68 	return self;
       
    69 	}
       
    70 
       
    71 
       
    72 
       
    73 CMsgServerTestUtils::CMsgServerTestUtils(RTest& aRTest)
       
    74 : CTestUtils(aRTest)
       
    75 	{
       
    76 	iTestNum=0;
       
    77 	}
       
    78 
       
    79 CMsgServerTestUtils::~CMsgServerTestUtils()
       
    80 	{
       
    81 	delete CActiveScheduler::Current();
       
    82 	}
       
    83 
       
    84 
       
    85 void CMsgServerTestUtils::ConstructL()
       
    86 	{
       
    87 	CTestUtils::ConstructL();
       
    88 	}
       
    89 
       
    90 
       
    91 void CMsgServerTestUtils::Panic(TInt aPanic)
       
    92 	{
       
    93 	User::Panic(KMsgServerTestUtilsPanic, aPanic);
       
    94 	}
       
    95 
       
    96 
       
    97 
       
    98 EXPORT_C void CMsgServerTestUtils::SetDebugL(TBool aDebug)
       
    99 	{
       
   100 	TMsvConfig config;
       
   101 	GetConfigL(config);
       
   102 	config.iDebug = aDebug;
       
   103 	SetConfigL(config);
       
   104 	}
       
   105 
       
   106 EXPORT_C void CMsgServerTestUtils::GetConfigL(TMsvConfig& aConfig)
       
   107 	{
       
   108 	// try to open system ini
       
   109 	TUint unused;        
       
   110 	TChar iDriveChar=FileSession().GetSystemDriveChar();
       
   111  	TBuf<2> systemDrive;
       
   112  	systemDrive.Append(iDriveChar);
       
   113  	systemDrive.Append(KDriveDelimiter);
       
   114  	TPath pathName(systemDrive);
       
   115 	pathName.Append(KServerINIFile);  
       
   116  	if(FileSession().Att(pathName,unused)==KErrNone)
       
   117 		{
       
   118 		CDictionaryFileStore *store = CDictionaryFileStore::OpenLC(FileSession(),pathName,KNullUid);
       
   119 		// get configuration from system ini
       
   120 		if (store->IsPresentL(KUidMsvMessageDriveStream))
       
   121 			{
       
   122 			RDictionaryReadStream readStream;
       
   123 			readStream.OpenLC(*store, KUidMsvMessageDriveStream);
       
   124 			TInt version = readStream.ReadInt8L();
       
   125 			iRTest(version <= KMsvMessageDriveStreamVersionNumber);
       
   126 
       
   127 			TBuf<2> drive;
       
   128 			readStream >> drive;
       
   129 			aConfig.iDrive = drive;
       
   130 
       
   131 			aConfig.iUniqueID = 0;
       
   132 			aConfig.iDebug = EFalse;
       
   133 
       
   134 			// The drive Id didn't exist in earlier versions
       
   135 			if (version > 1)
       
   136 				aConfig.iUniqueID = readStream.ReadUint32L();
       
   137 
       
   138 			// This debug frig wasn't in earlier versions
       
   139 			if (version > 2)
       
   140 				aConfig.iDebug = readStream.ReadInt8L();
       
   141 
       
   142 			CleanupStack::PopAndDestroy(); // readStream
       
   143 			}
       
   144 
       
   145 		CleanupStack::PopAndDestroy(); // store
       
   146                 }
       
   147 	}
       
   148 
       
   149 EXPORT_C void CMsgServerTestUtils::SetConfigL(TMsvConfig& aConfig)
       
   150 	{
       
   151 	TChar iDriveChar=FileSession().GetSystemDriveChar();
       
   152  	TBuf<2> systemDrive;
       
   153  	systemDrive.Append(iDriveChar);
       
   154  	systemDrive.Append(KDriveDelimiter);
       
   155     TPath pathName(systemDrive);
       
   156  	pathName.Append(KServerINIFile);  
       
   157  	CDictionaryFileStore *store = CDictionaryFileStore::OpenLC(FileSession(),pathName,KNullUid);
       
   158 	RDictionaryWriteStream stream;
       
   159 	stream.AssignLC(*store, KUidMsvMessageDriveStream);
       
   160 
       
   161 	stream.WriteUint8L(KMsvMessageDriveStreamVersionNumber); // version number
       
   162 	stream << aConfig.iDrive.Name();
       
   163 	stream.WriteUint32L(aConfig.iUniqueID);
       
   164 	stream.WriteInt8L(aConfig.iDebug);
       
   165 
       
   166 	stream.CommitL();
       
   167 	store->CommitL();
       
   168 	CleanupStack::PopAndDestroy(2); // stream, store
       
   169 	}
       
   170 
       
   171 
       
   172 
       
   173 EXPORT_C void CMsgServerTestUtils::SetupL()
       
   174 	{
       
   175 	CActiveScheduler::Install(new(ELeave)CTestScheduler);
       
   176 	iRTest.Printf(_L("Cleaning Message Folder\n"));
       
   177 	CleanMessageFolderL();
       
   178 	SetDriveL(EDriveC);
       
   179 	SetDebugL(ETrue);
       
   180 
       
   181 	// Try and find the removable drive
       
   182 	for (iRemovableDrive = EDriveY; iRemovableDrive > EDriveD; iRemovableDrive = TInt(iRemovableDrive) - 1)
       
   183 		{
       
   184 		TVolumeInfo info;
       
   185 		if (FileSession().Volume(info, TInt(iRemovableDrive)) == KErrNone)
       
   186 			break;
       
   187 		}
       
   188 	}
       
   189 
       
   190 
       
   191 EXPORT_C void CMsgServerTestUtils::SetDriveL(TInt aDrive, TBool aStoreId)
       
   192 	{
       
   193 	TMsvConfig config;
       
   194 	GetConfigL(config);
       
   195 
       
   196 	config.iDrive = aDrive;
       
   197 
       
   198 	if (aStoreId)
       
   199 		config.iUniqueID = (TUint)-1;
       
   200 	else
       
   201 		config.iUniqueID = 0;
       
   202 
       
   203 	SetConfigL(config);
       
   204 	}
       
   205 
       
   206 
       
   207 EXPORT_C void CMsgServerTestUtils::Close(TInt aRet)
       
   208 	{
       
   209 	if (!aRet)
       
   210 		TestHarnessCompleted();
       
   211 	else
       
   212 		TestHarnessFailed(aRet);
       
   213 	}
       
   214 
       
   215 
       
   216 EXPORT_C void CMsgServerTestUtils::CleanMessageFolderL(const TDesC& aDes)
       
   217 	{
       
   218 	CFileMan* fileMan = CFileMan::NewL(FileSession());
       
   219 	CleanupStack::PushL(fileMan);
       
   220 
       
   221 	TParse parse;
       
   222 	TFileName fileName((aDes.Length() == 0) ? KMsvDefaultFolder2 : aDes);
       
   223 	TMsvConfig config;
       
   224 
       
   225 	TChar driveChar=FileSession().GetSystemDriveChar();
       
   226  	TBuf<4> drive;
       
   227  	drive.Append(driveChar);
       
   228  	drive.Append(KDriveDelimiter);
       
   229 	config.iDrive=TDriveUnit(drive);
       
   230 	GetConfigL(config);
       
   231 	TDriveName name=config.iDrive.Name();
       
   232 	parse.Set(fileName, &name, NULL);
       
   233 
       
   234 	TInt error = fileMan->RmDir(parse.DriveAndPath());
       
   235 	CleanupStack::PopAndDestroy(); // fileMan
       
   236 
       
   237 	error = FileSession().RmDir(parse.DriveAndPath());
       
   238 	if (!(error == KErrNotFound || error == KErrNone || error==KErrPathNotFound))
       
   239 		{
       
   240 		TPtrC dir(parse.DriveAndPath());
       
   241 		iRTest.Printf(TRefByValue<const TDesC>(_L("Directory %S cannot be removed\n Exiting - press any key...\n")), &dir);
       
   242 		User::Leave(KErrNotReady);
       
   243 		}
       
   244 
       
   245 	//delete DB
       
   246 	TDriveUnit driveUnit(drive);
       
   247  	TPath pathName(driveUnit.Name());
       
   248  	pathName.Append(KDbFileName);
       
   249  	RSqlDatabase::Delete(pathName);
       
   250 	}
       
   251 
       
   252 
       
   253 EXPORT_C CMsvServer* CMsgServerTestUtils::CreateServerL(const TDesC& aIndexFile)
       
   254 	{	
       
   255 	TDesC dummy = aIndexFile; //dummy to avoid test build error when aIndexFile is not used inside
       
   256 	CMsvServer* server = CMsvServer::NewL();
       
   257 	CleanupStack::PushL(server);
       
   258 
       
   259 	CTestTimer* timer = CTestTimer::NewL();
       
   260 	timer->After(100000);
       
   261 	CActiveScheduler::Start();
       
   262 	delete timer;
       
   263 
       
   264 	CleanupStack::Pop(); // server
       
   265 	return server;
       
   266 	}
       
   267 
       
   268 
       
   269 EXPORT_C void CMsgServerTestUtils::FileExists(const TDesC& aDes)
       
   270 	{
       
   271 	TUint at;
       
   272 	iRTest(FileSession().Att(aDes, at)==KErrNone);
       
   273 	}
       
   274 
       
   275 EXPORT_C void CMsgServerTestUtils::FileMissing(const TDesC& aDes)
       
   276 	{
       
   277 	TUint at;
       
   278 	TInt error = FileSession().Att(aDes, at);
       
   279 	iRTest(error==KErrNotFound || error==KErrPathNotFound);
       
   280 	}
       
   281 
       
   282 
       
   283 EXPORT_C void CMsgServerTestUtils::CreateDataFilesL(const TDesC& aFilename, const TDesC& aMtmName, TUid aUid, const TDesC& aServerMtmFileName, const TDesC& aClientMtmFileName)
       
   284 	{
       
   285 	CMtmDllInfoArray* mtmdllinfoarray=new(ELeave) CMtmDllInfoArray();
       
   286 	CleanupStack::PushL(mtmdllinfoarray);
       
   287 
       
   288 	CMtmDllInfo* mtmdllinfo1=CMtmDllInfo::NewL(aMtmName, TUidType(KDynamicLibraryUid, KUidMtmServerComponent, TUid::Uid(KUidMtmDefaultSpecificVal)),aServerMtmFileName,1,TVersion(2,0,0));
       
   289 	mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo1);
       
   290 
       
   291 	CMtmDllInfo* mtmdllinfo2=CMtmDllInfo::NewL(aMtmName, TUidType(KDynamicLibraryUid, KUidMtmClientComponent, TUid::Uid(KUidMtmDefaultSpecificVal)),aClientMtmFileName,1,TVersion(2,0,0));
       
   292 	mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo2);
       
   293 
       
   294 	// Create an empty capability set for creating a new group data object
       
   295 	TCapabilitySet capSet;
       
   296 	capSet.SetEmpty();
       
   297 	CleanupStack::Pop(mtmdllinfoarray); // next line takes ownership
       
   298 	CMtmGroupData* mtmgroupdata=CMtmGroupData::NewL(aUid,aUid, mtmdllinfoarray, capSet);
       
   299 	CleanupStack::PushL(mtmgroupdata);
       
   300 
       
   301 	CFileStore* filestore = CPermanentFileStore::ReplaceLC(FileSession(), aFilename, EFileShareExclusive|EFileStream|EFileWrite);
       
   302 	TUidType uidtype(KPermanentFileStoreLayoutUid,KUidMsvDataComponent, aUid);
       
   303 	filestore->SetTypeL(uidtype);
       
   304 	RStoreWriteStream out;
       
   305 	TStreamId streamid=out.CreateLC(*filestore);							// Push to stack
       
   306 	mtmgroupdata->ExternalizeL(out);
       
   307 	out.CommitL();
       
   308 	CleanupStack::PopAndDestroy(); // out
       
   309 	filestore->SetRootL(streamid);
       
   310 	filestore->CommitL();
       
   311 	CleanupStack::PopAndDestroy(); // filestore
       
   312 	
       
   313 	CleanupStack::PopAndDestroy();  // mtmgroupdata
       
   314 	}
       
   315 
       
   316 EXPORT_C void CMsgServerTestUtils::InstallMtmL(const TDesC& aDataFile, const TDesC& aMtmName, TUid aId, const TDesC& aServerMtmFileName, const TDesC& aClientMtmFileName)
       
   317 	{
       
   318 	CDummyObserver* ob = new(ELeave)CDummyObserver;
       
   319 	CleanupStack::PushL(ob);
       
   320 
       
   321 	CMsvSession* session = CMsvSession::OpenSyncL(*ob);
       
   322 	CleanupStack::PushL(session);
       
   323 	
       
   324 	CreateDataFilesL(aDataFile, aMtmName, aId, aServerMtmFileName, aClientMtmFileName); 
       
   325 	session->InstallMtmGroup(aDataFile);
       
   326 
       
   327 	CleanupStack::PopAndDestroy(2); // session, ob
       
   328 	}
       
   329 
       
   330 EXPORT_C TBool CMsgServerTestUtils::WaitForKeyL(TTimeIntervalMicroSeconds32 aDelay, TKeyCode* aKeyCode)
       
   331 	{
       
   332 	iRTest(iRTest.Console() != NULL);
       
   333 
       
   334 	// Create timer
       
   335 	CTestTimer* timer = CTestTimer::NewL();
       
   336 	CleanupStack::PushL(timer);
       
   337 	timer->After(aDelay);
       
   338 
       
   339 	CTestActive* wait = new(ELeave)CTestActive;
       
   340 	CleanupStack::PushL(wait);
       
   341 	wait->StartL();
       
   342 
       
   343 	// Wait for key press
       
   344 	iRTest.Console()->Read(wait->iStatus);
       
   345 	CActiveScheduler::Start();
       
   346 
       
   347 	// If timer still active a key was pressed
       
   348 	TBool keyPressed = timer->IsActive();
       
   349 
       
   350 	if (keyPressed)
       
   351 		{
       
   352 		// Get the key pressed
       
   353 		if (aKeyCode)
       
   354 			*aKeyCode = iRTest.Console()->KeyCode();
       
   355 
       
   356 		// Cancel timer
       
   357 		timer->Cancel();
       
   358 		}
       
   359 	else
       
   360 		{
       
   361 		// Cancel wait for character
       
   362 		iRTest.Console()->ReadCancel();
       
   363 		User::WaitForRequest(wait->iStatus);
       
   364 		}
       
   365 
       
   366 	CleanupStack::PopAndDestroy(2); // wait, timer
       
   367 	return keyPressed;
       
   368 	}
       
   369 
       
   370 
       
   371 EXPORT_C void CMsgServerTestUtils::WaitForServerClose()
       
   372 	{
       
   373 	//Kill the message server if its running
       
   374 	TFindProcess findprocess(KMsvServerPattern);
       
   375 	TFullName name;
       
   376 	if(findprocess.Next(name)==KErrNone)
       
   377 		{
       
   378 		RProcess process;
       
   379     	User::LeaveIfError(process.Open(findprocess));
       
   380      	process.Kill(KErrCancel) ;
       
   381 		process.Close() ;
       
   382 		}
       
   383 		
       
   384 	FOREVER
       
   385 		{
       
   386 		TFullName name;
       
   387 		TFindProcess find(KMsvServerPattern);
       
   388 		if (find.Next(name) != KErrNone)
       
   389 			break;
       
   390 		User::After(100000);
       
   391 		}
       
   392 	}
       
   393 
       
   394 
       
   395 EXPORT_C void CMsgServerTestUtils::RemoveMailFolderL(TInt aDrive)
       
   396 	{
       
   397 	CFileMan* fileMan = CFileMan::NewL(FileSession());
       
   398 	CleanupStack::PushL(fileMan);
       
   399 
       
   400 	TDriveUnit drive(aDrive);
       
   401 	TPtrC ptr(drive.Name());
       
   402 
       
   403 	TParse parse;
       
   404 #ifdef __MESSAGING_API_V2
       
   405 	iRTest(parse.Set(ptr, &KMsvDefaultIndexFile2(), NULL) == KErrNone);
       
   406 #else
       
   407 	iRTest(parse.Set(ptr, &KMsvDefaultIndexFile(), NULL) == KErrNone);
       
   408 #endif
       
   409 
       
   410 	TInt error = fileMan->RmDir(parse.DriveAndPath());
       
   411 	iRTest(error == KErrNone || error == KErrPathNotFound);
       
   412 
       
   413 	CleanupStack::PopAndDestroy();
       
   414 	}
       
   415 
       
   416 EXPORT_C void CMsgServerTestUtils::RemoveIndexFile(TInt aDrive)
       
   417 	{
       
   418 	TDriveUnit drive(aDrive);
       
   419 	TPtrC ptr(drive.Name());
       
   420 
       
   421 	TParse parse;
       
   422 #ifdef __MESSAGING_API_V2
       
   423 	iRTest(parse.Set(ptr, &KMsvDefaultIndexFile2(), NULL) == KErrNone);
       
   424 #else
       
   425 	iRTest(parse.Set(ptr, &KMsvDefaultIndexFile(), NULL) == KErrNone);
       
   426 #endif
       
   427 
       
   428 	iRTest(FileSession().Delete(parse.FullName()) == KErrNone);
       
   429 	}
       
   430 
       
   431 EXPORT_C void CMsgServerTestUtils::CorruptIndexFileL(TInt aMode, const TDesC& aDes)
       
   432 	{
       
   433 	switch (aMode)
       
   434 		{
       
   435 		case 0: // uicode/narrow conflict
       
   436 			{
       
   437 #ifdef __MESSAGING_API_V2
       
   438 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes);
       
   439 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes, EFileShareExclusive|EFileWrite);
       
   440 #else
       
   441 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes);
       
   442 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes, EFileShareExclusive|EFileWrite);
       
   443 #endif
       
   444 			indexStore->SetTypeL(TUidType(KPermanentFileStoreLayoutUid, KNullUid)); // 2nd uid should be KUidMsvIndexFile
       
   445 			indexStore->CommitL();
       
   446 			delete indexStore;
       
   447 			break;
       
   448 			}
       
   449 		case 1: // empty index file
       
   450 			{
       
   451 #ifdef __MESSAGING_API_V2
       
   452 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes);
       
   453 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes, EFileShareExclusive|EFileWrite);
       
   454 #else
       
   455 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes);
       
   456 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes, EFileShareExclusive|EFileWrite);
       
   457 #endif
       
   458 			indexStore->SetTypeL(TUidType(KPermanentFileStoreLayoutUid, KUidMsvIndexFile)); // 2nd uid should be KUidMsvIndexFile
       
   459 			indexStore->CommitL();
       
   460 			delete indexStore;
       
   461 			break;
       
   462 			}
       
   463 		case 2: // missing index stream
       
   464 			{
       
   465 #ifdef __MESSAGING_API_V2
       
   466 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes);
       
   467 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes, EFileShareExclusive|EFileWrite);
       
   468 #else
       
   469 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes);
       
   470 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes, EFileShareExclusive|EFileWrite);
       
   471 #endif
       
   472 			indexStore->SetTypeL(TUidType(KPermanentFileStoreLayoutUid, KUidMsvIndexFile)); // 2nd uid should be KUidMsvIndexFile
       
   473 			//
       
   474 			RStoreWriteStream writeStream;
       
   475 			TStreamId rootIndexId = writeStream.CreateLC(*indexStore);
       
   476 			writeStream.WriteInt32L(TInt(rootIndexId.Value()+100));
       
   477 			writeStream.WriteInt32L(TInt(rootIndexId.Value()+101));
       
   478 			writeStream.CommitL();
       
   479 			CleanupStack::PopAndDestroy(); // writeStream
       
   480 			indexStore->SetRootL(rootIndexId);
       
   481 			//	
       
   482 			indexStore->CommitL();
       
   483 			delete indexStore;
       
   484 			break;
       
   485 			}
       
   486 		case 3: // missing entry stream
       
   487 			{
       
   488 #ifdef __MESSAGING_API_V2
       
   489 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes);
       
   490 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile2 : aDes, EFileShareExclusive|EFileWrite);
       
   491 #else
       
   492 			FileSession().Delete((aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes);
       
   493 			CPermanentFileStore* indexStore = CPermanentFileStore::CreateL(FileSession(), (aDes.Length() == 0) ? KMsvDefaultIndexFile : aDes, EFileShareExclusive|EFileWrite);
       
   494 #endif
       
   495 			indexStore->SetTypeL(TUidType(KPermanentFileStoreLayoutUid, KUidMsvIndexFile)); // 2nd uid should be KUidMsvIndexFile
       
   496 			//
       
   497 			RStoreWriteStream writeStream;
       
   498 			// store the blank stream index in file
       
   499 			TStreamId indexStreamId = writeStream.CreateLC(*indexStore);
       
   500 			writeStream.WriteInt32L(KMsvIndexStoreVersionNumber);
       
   501 			writeStream.WriteInt32L(1000000);
       
   502 			writeStream.WriteInt32L(1);
       
   503 			writeStream.WriteInt32L(122334);
       
   504 			writeStream.CommitL();
       
   505 			CleanupStack::PopAndDestroy(); // writeStream
       
   506 			// store the commit stream value
       
   507 			TStreamId commitStreamId = writeStream.CreateLC(*indexStore);
       
   508 			writeStream.WriteInt32L(12243);
       
   509 			writeStream.CommitL();
       
   510 			CleanupStack::PopAndDestroy(); // writeStream
       
   511 			//
       
   512 			TStreamId rootIndexId = writeStream.CreateLC(*indexStore);
       
   513 			writeStream << indexStreamId;
       
   514 			writeStream << commitStreamId;
       
   515 			writeStream.CommitL();
       
   516 			CleanupStack::PopAndDestroy(); // writeStream
       
   517 			indexStore->SetRootL(rootIndexId);
       
   518 			//	
       
   519 			indexStore->CommitL();
       
   520 			delete indexStore;
       
   521 			break;
       
   522 			}
       
   523 		default:
       
   524 			iRTest(EFalse);
       
   525 		}
       
   526 	}
       
   527 
       
   528 EXPORT_C TInt CMsgServerTestUtils::IndexSizeL(TInt aDrive/* = EDriveC*/, const TDesC& aIndexFile/* = KMsvDefaultIndexFile*/)
       
   529 	{
       
   530 	TDriveUnit driveUnit(aDrive);
       
   531 	TDriveName name = driveUnit.Name();
       
   532 
       
   533 	TParse parse;
       
   534 	User::LeaveIfError(parse.Set(aIndexFile, &name, NULL));
       
   535 
       
   536 	TEntry file;
       
   537 	User::LeaveIfError(FileSession().Entry(parse.FullName(), file));
       
   538 	return file.iSize;
       
   539 	}
       
   540 
       
   541 
       
   542 EXPORT_C void CMsgServerTestUtils::Start(const TDesC& aDes)
       
   543 	{
       
   544 	iRTest.Start(aDes);
       
   545 	TestStart(++iTestNum, aDes);
       
   546 	}
       
   547 
       
   548 EXPORT_C void CMsgServerTestUtils::Next(const TDesC& aDes)
       
   549 	{
       
   550 	iRTest.Next(aDes);
       
   551 	TestStart(++iTestNum, aDes);
       
   552 	}
       
   553 
       
   554 EXPORT_C void CMsgServerTestUtils::Complete()
       
   555 	{
       
   556 	TestFinish(iTestNum, KErrNone);
       
   557 	}
       
   558 
       
   559 EXPORT_C void CMsgServerTestUtils::End()
       
   560 	{
       
   561 	iRTest.End();
       
   562 	}
       
   563 
       
   564 
       
   565 EXPORT_C void CMsgServerTestUtils::ChooseDriveL(TDriveUnit &aResult)
       
   566 	{
       
   567 	CConsoleBase &cons=*iRTest.Console();
       
   568 	CArrayFixFlat<TDriveUnit> *drives=new (ELeave) CArrayFixFlat<TDriveUnit>(5);
       
   569 	CleanupStack::PushL(drives);
       
   570 	TDriveUnit drive;
       
   571 	for (drive = EDriveC; drive < EDriveY; drive = TInt(drive) + 1)
       
   572 		{
       
   573 		TVolumeInfo info;
       
   574 		if (FileSession().Volume(info, TInt(drive)) == KErrNone)
       
   575 			{
       
   576 			drives->AppendL(drive);
       
   577 			cons.Printf(_L("%d. "),drives->Count());
       
   578 			cons.Printf(drive.Name());
       
   579 			cons.Printf(_L("\n"));
       
   580 			}
       
   581 		}
       
   582 	if(drives->Count()==0) User::Leave(KErrNotFound);
       
   583 	cons.Printf(_L("\nPlease choose a drive\n"));
       
   584 	TKeyCode ch=cons.Getch();
       
   585 	while(ch<'1' && ch > ('1'+drives->Count())) ch=cons.Getch();
       
   586 	aResult=drives->At(ch-'1');
       
   587 	CleanupStack::PopAndDestroy(drives);
       
   588 	}
       
   589 
       
   590 EXPORT_C TInt CMsgServerTestUtils::ReadInteger(const TDesC& aDes,TInt &aResult)
       
   591 	{
       
   592 	CConsoleBase &cons=*iRTest.Console();
       
   593 	_LIT(KPrompt,"%S > ");
       
   594 	cons.Printf(KPrompt,&aDes);
       
   595 	TBuf<80> number;
       
   596 	TKeyCode ch;
       
   597 	while((ch=cons.Getch())!=EKeyEnter)
       
   598 		{
       
   599 		cons.Printf(_L("%c"),ch);
       
   600 		number.Append(ch);
       
   601 		}
       
   602 	cons.Printf(_L("\n"),ch);
       
   603 	TLex lex(number);
       
   604 	return(lex.Val(aResult));
       
   605 	}
       
   606 
       
   607 
       
   608 EXPORT_C CTestScheduler::CTestScheduler() : iSchedulerActive(EFalse), iPanicSchedulerOnError(ETrue)
       
   609 	{
       
   610 
       
   611 	}
       
   612 
       
   613 
       
   614 EXPORT_C void CTestScheduler::Error(TInt aError) const
       
   615 	{
       
   616 	CTestScheduler *nonConst=CONST_CAST(CTestScheduler *,this);
       
   617 	nonConst->iSchedulerError = aError;
       
   618 	if (iSchedulerActive)
       
   619 		{
       
   620 		CActiveScheduler::Halt(KErrNone);
       
   621 		nonConst->iSchedulerActive = EFalse;
       
   622 		}
       
   623 	else
       
   624 		{
       
   625 		if (iPanicSchedulerOnError)
       
   626 			CActiveScheduler::Error(aError);
       
   627 		}
       
   628 	}
       
   629 
       
   630 
       
   631