messagingfw/biomsgfw/BDBTSRC/T_BdbHF.CPP
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2003-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: Test code for test CBioDatabase with Heap Failure
       
    14 //
       
    15 // Author	March 2000
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <e32test.h>
       
    20 #include <e32hal.h>
       
    21 #include <f32fsys.h>
       
    22 #include <s32file.h>
       
    23 #include <barsc.h>
       
    24 #include "biotestutils.h"
       
    25 
       
    26 #include <e32uid.h>
       
    27 
       
    28 #include "BIODB.H"	
       
    29 #include <biouids.h>
       
    30 #include <bifchangeobserver.h>	
       
    31 
       
    32 //----------------------------------------------------------------------------------------
       
    33 
       
    34 // Id array
       
    35 const TBioMsgIdType										KId0Type=EBioMsgIdIana;
       
    36 const CApaDataRecognizerType::TRecognitionConfidence	KId0Confidence=CApaDataRecognizerType::EPossible;
       
    37 const TBioMsgIdText										KId0Text=_L("text/x-bio");
       
    38 const TInt16											KId0Port=0;
       
    39 const TUid												KId0CharacterSet={0x10003b10};
       
    40 const TInt16											KId0GeneralIdData=0x0000;
       
    41 
       
    42 const TBioMsgIdType						KId1Type=EBioMsgIdWap;
       
    43 const TBioMsgIdText										KId1Text=_L("");
       
    44 
       
    45 const TBioMsgIdText										KId2Text=_L("");
       
    46 
       
    47 const TUid KUidBioMsgTypeEmailNotification = {0x10005530};
       
    48 const TUid KUidBioMsgTypeVCal = {0x10005533};
       
    49 
       
    50 // end of test data.
       
    51 //----------------------------------------------------------------------------------------
       
    52 
       
    53 #include "CMSTD.H"
       
    54 
       
    55 
       
    56 //----------------------------------------------------------------------------------------
       
    57 RTest gTest(_L("BIODB.dll Test Harness"));
       
    58 LOCAL_D RFs				gFs;	
       
    59 LOCAL_D CBioTestUtils*	testUtils;
       
    60 CActiveScheduler		gScheduler;
       
    61 
       
    62 //----------------------------------------------------------------------------------------
       
    63 _LIT(kTestBifFile,"C:\\test\\bio\\bif\\bogus.rsc");
       
    64 #define KBifDir		_L("c:\\resource\\messaging\\bif\\")
       
    65 _LIT(kTestDestFile,"c:\\resource\\messaging\\bif\\bogus.rsc");
       
    66 
       
    67 //----------------------------------------------------------------------------------------
       
    68 //
       
    69 // Does nothing at all but is required for the CMsvSession constructor.
       
    70 class CDummyObserver : public CBase , public MBifChangeObserver
       
    71 {
       
    72 	//MBifChangeObserver
       
    73 	void HandleBifChangeL(TBifChangeEvent aEvent, TUid BioID)
       
    74 	{
       
    75 		HBufC* commentText = HBufC::NewLC(100);
       
    76 					
       
    77 		(commentText->Des()).Format(_L("HandleBifChangeL %D"), BioID);
       
    78 		testUtils->WriteComment(commentText->Des());
       
    79 
       
    80 		switch (aEvent)
       
    81 		{
       
    82 			case EBifChangeUnknown:
       
    83 				(commentText->Des()).Format(_L("HandleBifChangeL EBifChangeUnknown"));
       
    84 				break;
       
    85 			case EBifAdded:
       
    86 				(commentText->Des()).Format(_L("HandleBifChangeL EBifAdded"));
       
    87 				break;
       
    88 			case EBifDeleted:
       
    89 				(commentText->Des()).Format(_L("HandleBifChangeL EBifDeleted"));
       
    90 				break;
       
    91 			case EBifChanged:
       
    92 				(commentText->Des()).Format(_L("HandleBifChangeL EBifChanged"));
       
    93 				break;
       
    94 		}
       
    95 		CleanupStack::PopAndDestroy();	// commentText
       
    96 		CActiveScheduler::Stop();
       
    97 
       
    98 	};
       
    99 };
       
   100 
       
   101 //----------------------------------------------------------------------------------------
       
   102 //----------------------------------------------------------------------------------------
       
   103 //----------------------------------------------------------------------------------------
       
   104 //----------------------------------------------------------------------------------------
       
   105 class CFileCopyTimer : public CTimer
       
   106     {
       
   107 public:
       
   108     static CFileCopyTimer* NewL(const CBifChangeObserver* const );
       
   109 private:
       
   110     CFileCopyTimer(const CBifChangeObserver* const);
       
   111     void RunL();
       
   112 	TBool iDeleteObserver;
       
   113 	const CBifChangeObserver * const iBifChangeObserver;
       
   114     };
       
   115 //----------------------------------------------------------------------------------------
       
   116 
       
   117 //----------------------------------------------------------------------------------------
       
   118 CFileCopyTimer::CFileCopyTimer(const CBifChangeObserver* const observer) : 
       
   119 	CTimer(EPriorityLow),
       
   120 	iBifChangeObserver(observer)		
       
   121 {
       
   122 	// If an observer is provided then it will need to be deleted later
       
   123 
       
   124 	iDeleteObserver = (observer!=NULL);
       
   125 
       
   126 	CActiveScheduler::Add(this);
       
   127 }
       
   128 
       
   129 //----------------------------------------------------------------------------------------
       
   130 CFileCopyTimer* CFileCopyTimer::NewL(const CBifChangeObserver* const observer)
       
   131 //----------------------------------------------------------------------------------------
       
   132 	{
       
   133 	CFileCopyTimer* self = new(ELeave) CFileCopyTimer(observer);
       
   134 	CleanupStack::PushL(self);
       
   135 	self->ConstructL(); // CTimer
       
   136 	self->After(1000000);
       
   137 	CleanupStack::Pop();
       
   138 	return self;
       
   139 	}
       
   140 
       
   141 //----------------------------------------------------------------------------------------
       
   142 void CFileCopyTimer::RunL()
       
   143 //----------------------------------------------------------------------------------------
       
   144 {
       
   145 	// Check whether the observer needs to be deleted
       
   146 	
       
   147 	if (iDeleteObserver)
       
   148 	{
       
   149 		delete iBifChangeObserver;
       
   150 
       
   151 		iDeleteObserver = EFalse;
       
   152 
       
   153 		After(1000000);
       
   154 	}
       
   155 	else
       
   156 	{
       
   157 		// Copy a test file in
       
   158 		CFileMan *cfMan = CFileMan::NewL(gFs);
       
   159 		CleanupStack::PushL(cfMan);
       
   160 		User::LeaveIfError(cfMan->Copy(kTestBifFile,kTestDestFile)); 
       
   161 		CleanupStack::PopAndDestroy();	// cfMan
       
   162 	}
       
   163 }
       
   164 
       
   165 //----------------------------------------------------------------------------------------
       
   166 void TestScheduler::ErrorL( TInt anError ) const
       
   167 //----------------------------------------------------------------------------------------
       
   168 	{
       
   169 	User::Leave( anError );
       
   170 	}
       
   171 
       
   172 
       
   173 //----------------------------------------------------------------------------------------
       
   174 LOCAL_C void InitTestUtils()
       
   175 //----------------------------------------------------------------------------------------
       
   176 	{
       
   177 	testUtils = CBioTestUtils::NewLC(gTest,ETuCleanMessageFolder);
       
   178 	gTest.Start(_L("CBIODatabase"));
       
   179 	gTest.Console()->ClearScreen();
       
   180 	}
       
   181 
       
   182 //----------------------------------------------------------------------------------------
       
   183 LOCAL_C void CloseTestUtils()
       
   184 //----------------------------------------------------------------------------------------
       
   185 	{
       
   186 	testUtils->TestHarnessCompleted();
       
   187 	CleanupStack::PopAndDestroy(testUtils);
       
   188 	//gTest.Console()->SetPos(0, 13);
       
   189 	gTest.End();
       
   190 	gTest.Close();
       
   191 	}
       
   192 
       
   193 //----------------------------------------------------------------------------------------
       
   194 LOCAL_C void OpenFileSession() 
       
   195 //----------------------------------------------------------------------------------------
       
   196 	{
       
   197 	gFs.Connect();
       
   198 	gFs.MkDir(KBifDir);
       
   199 	gFs.SetSessionPath(KBifDir);
       
   200 
       
   201 
       
   202 	CActiveScheduler::Install( &gScheduler );
       
   203 	}
       
   204 
       
   205 
       
   206 //----------------------------------------------------------------------------------------
       
   207 LOCAL_C void CloseFileSession()
       
   208 //----------------------------------------------------------------------------------------
       
   209 	{
       
   210 	gFs.Close( );
       
   211 	}
       
   212 
       
   213 //----------------------------------------------------------------------------------------
       
   214 LOCAL_C void GetBearerText(TInt aBearer, TBuf<100>& rBearerString)
       
   215 //----------------------------------------------------------------------------------------
       
   216 {
       
   217 	switch (aBearer)
       
   218 	{
       
   219 	case EBioMsgIdIana:
       
   220 		rBearerString.Copy(_L("Iana"));
       
   221 		break;
       
   222 	case EBioMsgIdNbs:
       
   223 		rBearerString.Copy(_L("Nbs"));
       
   224 		break;
       
   225 	case EBioMsgIdWap:
       
   226 		rBearerString.Copy(_L("Wap"));
       
   227 		break;
       
   228 	case EBioMsgIdWapSecure:
       
   229 		rBearerString.Copy(_L("WapSecure"));
       
   230 		break;
       
   231 	case EBioMsgIdUnknown:
       
   232 	default:
       
   233 		rBearerString.Copy(_L("Unknown"));
       
   234 		break;
       
   235 	}
       
   236 }
       
   237 //----------------------------------------------------------------------------------------
       
   238 LOCAL_C void CreateBDBWithHeapFailure(TInt aTestNumber)
       
   239 {
       
   240 	gTest.Printf(_L("Create BDB With Heap Failure\n"));
       
   241 	testUtils->TestStart(aTestNumber, _L("Opening & Failing CBioDB"));
       
   242 
       
   243 	// Testing for heap failure in the client
       
   244 	TInt error;
       
   245 #ifdef _DEBUG
       
   246 	TInt failCount = 0;
       
   247 #endif
       
   248 	TBool finished = EFalse;
       
   249 	CBIODatabase* bioDB = NULL;
       
   250 
       
   251 	while(!finished)
       
   252 		{
       
   253 		__UHEAP_FAILNEXT(failCount++);
       
   254 
       
   255 		TRAP(error, bioDB = CBIODatabase::NewL(gFs));
       
   256 
       
   257 		__UHEAP_RESET;
       
   258 
       
   259 		// Did an error occur?
       
   260 		if (error == KErrNone)
       
   261 			{
       
   262 			// Check that the CMsvEntry has been updated
       
   263 			// Exit the loop
       
   264 			finished = ETrue;
       
   265 			}
       
   266 		else
       
   267 			{
       
   268 			// Check we failed correctly
       
   269 			gTest(error == KErrNoMemory);
       
   270 			}
       
   271 		}
       
   272 	delete bioDB;
       
   273 	
       
   274 	testUtils->TestFinish(aTestNumber,0 );
       
   275 
       
   276 }
       
   277 //----------------------------------------------------------------------------------------
       
   278 LOCAL_C void CreateBioObserverWithHeapFailure(TInt aTestNumber)
       
   279 //----------------------------------------------------------------------------------------
       
   280 {
       
   281 	gTest.Printf(_L("Create CBioObserver With Heap Failure\n"));
       
   282 	testUtils->TestStart(aTestNumber, _L("Opening & Failing CBioObserver"));
       
   283 
       
   284 	// Testing for heap failure in the client
       
   285 	TInt error;
       
   286 #ifdef _DEBUG
       
   287 	TInt failCount = 0;
       
   288 #endif
       
   289 	TBool finished = EFalse;
       
   290 	CBifChangeObserver* bioObserver = NULL;
       
   291 	CDummyObserver dumObserver;
       
   292 	
       
   293 		while(!finished)
       
   294 		{
       
   295 		__UHEAP_FAILNEXT(failCount++);
       
   296 
       
   297 		TRAP(error, bioObserver = CBifChangeObserver::NewL(dumObserver, gFs));
       
   298 
       
   299 		__UHEAP_RESET;
       
   300 
       
   301 		// Did an error occur?
       
   302 		if (error == KErrNone)
       
   303 			{
       
   304 			// Check that the CMsvEntry has been updated
       
   305 			// Exit the loop
       
   306 			finished = ETrue;
       
   307 			}
       
   308 		else
       
   309 			{
       
   310 			// Check we failed correctly
       
   311 			gTest(error == KErrNoMemory);
       
   312 			}
       
   313 		}
       
   314 	delete bioObserver;
       
   315 
       
   316 	testUtils->TestFinish(aTestNumber,0 );
       
   317 }	
       
   318 
       
   319 //----------------------------------------------------------------------------------------
       
   320 LOCAL_C void DumpBifFiles(TInt aTestNumber)
       
   321 //----------------------------------------------------------------------------------------
       
   322 {
       
   323 	HBufC* commentText = HBufC::NewLC(100);
       
   324 	
       
   325 	gTest.Printf(_L("Opening & Searching DB\n"));
       
   326 	testUtils->TestStart(aTestNumber, _L("Opening & Searching DB"));
       
   327 
       
   328 	
       
   329 
       
   330 	CBIODatabase* bioDB = CBIODatabase::NewL(gFs);
       
   331 	CleanupStack::PushL( bioDB );
       
   332 	gTest.Printf(_L("Opened DB Successfully!\n"));
       
   333 	
       
   334 	(commentText->Des()).Format(_L("<%D> Bif files read\n"), bioDB->BIOCount());
       
   335 	testUtils->WriteComment(commentText->Des());
       
   336 	gTest.Printf(commentText->Des());
       
   337 
       
   338 	const CArrayFix<TBioMsgId>* ent = NULL;
       
   339 
       
   340 	for (TInt i=0; i < bioDB->BIOCount(); i++)
       
   341 	{
       
   342 		const CBioInfoFileReader& bifReader = bioDB->BifReader(i);
       
   343 
       
   344 		TPtrC desc;
       
   345 		desc.Set(bifReader.Description());
       
   346 		gTest.Printf(_L("File: %d: "), i);
       
   347 		gTest.Printf(_L("Desc: %S "), &desc);
       
   348 	
       
   349 		(commentText->Des()).Format(_L("%D: '%S'"), i, &desc);
       
   350 		testUtils->WriteComment(commentText->Des());
       
   351 		
       
   352 		ent = bioDB->BIOEntryLC(i);
       
   353 		gTest.Printf(_L("Has %d identifiers \n"), ent->Count());
       
   354 		CleanupStack::PopAndDestroy();	// ent
       
   355 	}
       
   356 
       
   357 	//
       
   358 	gTest.Printf(_L("Looking for all Wap Ports to Watch\n"));
       
   359 	testUtils->WriteComment(_L("Looking for all Wap Ports to Watch\n"));
       
   360 
       
   361 	TPtrC desc;
       
   362 	TInt pos;
       
   363 	ent = bioDB->BioEntryByTypeLC(CBIODatabase::EStart, EBioMsgIdWap, pos);
       
   364 	
       
   365 	while(pos < bioDB->BIOCount())
       
   366 	{
       
   367 		desc.Set(bioDB->BifReader(pos).Description());
       
   368 		gTest.Printf(_L("Desc: %S \n"), &desc);
       
   369 
       
   370 		for (TInt i = 0; ent && i < ent->Count(); i++)
       
   371 		{
       
   372 			if ((*ent)[i].iType == EBioMsgIdWap)
       
   373 			{
       
   374 				gTest.Printf(_L("Wap Port number %D\n"), (*ent)[i].iPort);
       
   375 				(commentText->Des()).Format(_L("%D: '%S' Port#:%D"), i, &desc, (*ent)[i].iPort);
       
   376 				testUtils->WriteComment(commentText->Des());
       
   377 			}
       
   378 			
       
   379 		}
       
   380 		if (ent)
       
   381 			CleanupStack::PopAndDestroy();	// ent
       
   382 		ent = bioDB->BioEntryByTypeLC(CBIODatabase::ENext, EBioMsgIdWap, pos);
       
   383 	}
       
   384 
       
   385 	if (ent)
       
   386 		CleanupStack::PopAndDestroy();	// ent
       
   387 	//
       
   388 
       
   389 	gTest.Printf(_L("Looking for all NBS Ports to Watch\n"));
       
   390 	testUtils->WriteComment(_L("Looking for all NBS Ports to Watch\n"));
       
   391 
       
   392 	ent = bioDB->BioEntryByTypeLC(CBIODatabase::EStart, EBioMsgIdNbs, pos);
       
   393 	
       
   394 	while(pos < bioDB->BIOCount())
       
   395 	{
       
   396 		desc.Set(bioDB->BifReader(pos).Description());
       
   397 		gTest.Printf(_L("Desc: %S \n"), &desc);
       
   398 
       
   399 		for (TInt i = 0; ent && i < ent->Count(); i++)
       
   400 		{
       
   401 			if ((*ent)[i].iType == EBioMsgIdNbs)
       
   402 			{
       
   403 				gTest.Printf(_L("Wap Port number %D\n"), (*ent)[i].iPort);
       
   404 				(commentText->Des()).Format(_L("%D: '%S' String:%S"), i, &desc, &((*ent)[i].iText));
       
   405 				testUtils->WriteComment(commentText->Des());
       
   406 			}
       
   407 			
       
   408 		}
       
   409 		if (ent)
       
   410 			CleanupStack::PopAndDestroy();	// ent
       
   411 		ent = bioDB->BioEntryByTypeLC(CBIODatabase::ENext, EBioMsgIdNbs, pos);
       
   412 	}
       
   413 
       
   414 	if (ent)
       
   415 		CleanupStack::PopAndDestroy();	// ent
       
   416 
       
   417 
       
   418 
       
   419 
       
   420 	CleanupStack::PopAndDestroy();	// bioDB
       
   421 	CleanupStack::PopAndDestroy();  // commentText
       
   422 	
       
   423 	testUtils->TestFinish(aTestNumber,0 );
       
   424 }
       
   425 
       
   426 //----------------------------------------------------------------------------------------
       
   427 LOCAL_C void TestAPIs(TInt aTestNumber)
       
   428 //----------------------------------------------------------------------------------------
       
   429 {
       
   430 	CBIODatabase* bioDB = CBIODatabase::NewL(gFs);
       
   431 	CleanupStack::PushL( bioDB );
       
   432 
       
   433 	testUtils->TestStart(aTestNumber, _L("Testing APIs"));
       
   434 
       
   435 	testUtils->WriteComment(_L("RemoveBifL"));
       
   436 	TUid msgID;
       
   437 	TInt error = 0;
       
   438 	while (bioDB->BIOCount())
       
   439 	{
       
   440 		bioDB->GetBioMsgID(0,msgID);
       
   441 		TRAP(error, bioDB->RemoveBifL(msgID));
       
   442 		if (error)
       
   443 			testUtils->TestFinish(aTestNumber,error );
       
   444 			break;
       
   445 	}
       
   446 	CleanupStack::PopAndDestroy();	// bioDB
       
   447 	testUtils->TestFinish(aTestNumber,error );
       
   448 }
       
   449 
       
   450 
       
   451 //----------------------------------------------------------------------------------------
       
   452 LOCAL_C void DumpWapBifFiles(TInt aTestNumber)
       
   453 //----------------------------------------------------------------------------------------
       
   454 {
       
   455 	// gets a list of port numbers for WAP Port type
       
   456 	TInt pos;
       
   457 
       
   458 	HBufC* commentText = HBufC::NewLC(100);
       
   459 	CBIODatabase* bioDB = CBIODatabase::NewL(gFs);
       
   460 	CleanupStack::PushL( bioDB );
       
   461 	
       
   462 	gTest.Printf(_L("Dump WAP Bif Files...\n"));
       
   463 	testUtils->TestStart(aTestNumber, _L("Dump WAP Bif Files..."));
       
   464 
       
   465 	const CArrayFix<TBioMsgId>* bioMsgIDs = bioDB->BioEntryByTypeLC(
       
   466 							CBIODatabase::EStart,
       
   467 							EBioMsgIdWap, pos);
       
   468 	while (bioMsgIDs)
       
   469 	{
       
   470 		TUid msgUID;
       
   471 		bioDB->GetBioMsgID(pos, msgUID);
       
   472 		gTest.Printf(_L("Message %D "),msgUID );
       
   473 
       
   474 		TFileName parserName(bioDB->GetBioParserNameL(msgUID));
       
   475 		gTest.Printf(_L("Parser %S\n"), &parserName );
       
   476 
       
   477 		TPtrC ext;
       
   478 		ext.Set(bioDB->GetFileExtL(msgUID));
       
   479 		gTest.Printf(_L("File Extension '%S'\n"),&ext );
       
   480 	
       
   481 		TPtrC desc;
       
   482 		desc.Set(bioDB->BifReader(pos).Description());
       
   483 		(commentText->Des()).Format(_L("<%S> BioUID:%D\tParserName:%S\tFileExt:%S"), &desc, msgUID, &parserName, &ext);
       
   484 		testUtils->WriteComment(commentText->Des());
       
   485 
       
   486 		for (TInt i = 0; i < bioMsgIDs->Count(); i++)
       
   487 		{
       
   488 			// Really should make a copy contructor & = operator
       
   489 			gTest.Printf(_L("Type\t: %D\n"),bioMsgIDs->At(i).iType );
       
   490 			gTest.Printf(_L("Confidence\t:%D\n"),bioMsgIDs->At(i).iConfidence );
       
   491 			gTest.Printf(_L("IANA\t:%S\n"),&(bioMsgIDs->At(i).iText) );
       
   492 			gTest.Printf(_L("Wap Port\t: %D\n"),bioMsgIDs->At(i).iPort );
       
   493 			gTest.Printf(_L("CharSet\t: %D\n"),bioMsgIDs->At(i).iCharacterSet );
       
   494 		
       
   495 			TBuf<100> bearerString;
       
   496 			GetBearerText(bioMsgIDs->At(i).iType, bearerString);
       
   497 			(commentText->Des()).Format(_L("\tType:%S\tConf:%D\tIANA:%S\tPort:%D\t"),
       
   498 					&bearerString,
       
   499 					bioMsgIDs->At(i).iConfidence,
       
   500 					&(bioMsgIDs->At(i).iText),
       
   501 					bioMsgIDs->At(i).iPort);
       
   502 			
       
   503 			testUtils->WriteComment(commentText->Des());
       
   504 		}
       
   505 		CleanupStack::PopAndDestroy();	// bioMsgID
       
   506 		
       
   507 		bioMsgIDs = bioDB->BioEntryByTypeLC(
       
   508 							CBIODatabase::ENext,
       
   509 							EBioMsgIdWap, pos);
       
   510 	}
       
   511 
       
   512 
       
   513 	TInt portNumber = 0;
       
   514 	TRAP_IGNORE(bioDB->GetPortNumberL(KUidBioMsgTypeEmailNotification, 
       
   515 							EBioMsgIdWap, 
       
   516 							portNumber));
       
   517 	
       
   518 	gTest.Printf(_L("Email Notify is Wap Port %d \n"), portNumber);
       
   519 	(commentText->Des()).Format(_L("Email Notify is Wap Port %d"),portNumber);
       
   520 	testUtils->WriteComment(commentText->Des());
       
   521 
       
   522 	TBioMsgIdText ianaString;
       
   523 	TRAP_IGNORE(bioDB->GetIdentifierTextL(KUidBioMsgTypeEmailNotification, 
       
   524 							EBioMsgIdIana, 
       
   525 							ianaString));
       
   526 	gTest.Printf(_L("Email Notify is IANA String %S \n"), &ianaString);
       
   527 	(commentText->Des()).Format(_L("Email Notify is IANA String %d"), &ianaString);
       
   528 	testUtils->WriteComment(commentText->Des());
       
   529 		
       
   530 	
       
   531 	CleanupStack::PopAndDestroy();	// bioDB
       
   532 	CleanupStack::PopAndDestroy();	// commentText
       
   533 	
       
   534 	testUtils->TestFinish(aTestNumber,0 );
       
   535 }
       
   536 
       
   537 //----------------------------------------------------------------------------------------
       
   538 LOCAL_C void CheckBioness(TInt aTestNumber)
       
   539 //----------------------------------------------------------------------------------------
       
   540 {
       
   541 	HBufC* commentText = HBufC::NewLC(100);
       
   542 	testUtils->TestStart(aTestNumber, _L("Check Bioness..."));
       
   543 
       
   544 	// Check if message is bio
       
   545 	CBIODatabase* bioDB = CBIODatabase::NewL(gFs);
       
   546 	CleanupStack::PushL( bioDB );
       
   547 	TUid bioMsgId;
       
   548 	
       
   549 	gTest.Printf(_L("Searching if this data type is a BIO Message\n"));
       
   550 	(commentText->Des()).Format(_L("Searching if this data type is a BIO Message"));
       
   551 	testUtils->WriteComment(commentText->Des());
       
   552 	
       
   553 	TBioMsgId bioMessageData;
       
   554 	bioMessageData.iType=			KId0Type;
       
   555 	bioMessageData.iConfidence=		KId0Confidence;
       
   556 	bioMessageData.iText=			KId0Text;
       
   557 	bioMessageData.iPort=			KId0Port;
       
   558 	bioMessageData.iCharacterSet=	KId0CharacterSet;
       
   559 	bioMessageData.iGeneralIdData=	KId0GeneralIdData;
       
   560 
       
   561 	if (bioDB->IsBioMessageL(bioMessageData, bioMsgId))
       
   562 	{
       
   563 		gTest.Printf(_L("This is a BIO Message\n"));
       
   564 	}
       
   565 	else
       
   566 	{
       
   567 		gTest.Printf(_L("This is not a BIO Message\n"));
       
   568 	}
       
   569 
       
   570 
       
   571 
       
   572 	bioMessageData.iType = KId1Type;
       
   573 	
       
   574 	bioDB->IsBioMessageL(bioMessageData, bioMsgId);
       
   575 	if (bioMsgId != KNullUid)
       
   576 		gTest.Printf(_L("This is a BIO Message\n"));
       
   577 	else
       
   578 		gTest.Printf(_L("This is not a BIO Message\n"));
       
   579 
       
   580 	TBioMsgIdText text  = _L("//MLAP11");
       
   581 
       
   582 	bioDB->IsBioMessageL(EBioMsgIdNbs, text, 0, bioMsgId);
       
   583 	if (bioMsgId != KNullUid)
       
   584 		gTest.Printf(_L("%S is a BIO Message with Uid: %D\n"), &text, bioMsgId);
       
   585 	else
       
   586 		gTest.Printf(_L("%S is NOT a BIO Message\n"), &text);
       
   587 
       
   588 	text = _L("Some Bogus Text");
       
   589 	bioDB->IsBioMessageL(EBioMsgIdWapSecure, text, 9, bioMsgId);
       
   590 	if (bioMsgId != KNullUid)
       
   591 		gTest.Printf(_L("%S is a BIO Message with Uid: %D\n"), &text, bioMsgId );
       
   592 	else
       
   593 		gTest.Printf(_L("%S is NOT a BIO Message\n"), &text);
       
   594 
       
   595 	CleanupStack::PopAndDestroy();	// bioDB
       
   596 	CleanupStack::PopAndDestroy();	// commentText
       
   597 	testUtils->TestFinish(aTestNumber,0 );
       
   598 }
       
   599 
       
   600 //----------------------------------------------------------------------------------------
       
   601 LOCAL_C void DefaultSendBearer(TInt aTestNumber)
       
   602 //----------------------------------------------------------------------------------------
       
   603 {
       
   604 	HBufC* commentText = HBufC::NewLC(100);
       
   605 	TBuf<100> bearerString;
       
   606 	testUtils->TestStart(aTestNumber, _L("DefaultSendBearer..."));
       
   607 
       
   608 	// Check if message is bio
       
   609 	CBIODatabase* bioDB = CBIODatabase::NewL(gFs);
       
   610 	CleanupStack::PushL( bioDB );
       
   611 	
       
   612 	gTest.Printf(_L("Getting Default Send Bearer info\n"));
       
   613 	
       
   614 	TBioMsgId aBioMsgIdentifier;
       
   615 	TRAPD(err, bioDB->GetDefaultSendBearerL(KUidBioMsgTypeEmailNotification, aBioMsgIdentifier));
       
   616 	if (!err)
       
   617 	{
       
   618 		GetBearerText(aBioMsgIdentifier.iType, bearerString);
       
   619 		(commentText->Des()).Format(_L("Default Send Bearer for EmailNotifciation: %S"),&bearerString);
       
   620 		gTest.Printf(_L("Default Send Bearer for EmailNotifciation %d \n"), aBioMsgIdentifier.iType);
       
   621 	}
       
   622 	else if (err == KErrNotFound)
       
   623 	{
       
   624 		gTest.Printf(_L("Default Send Bearer for EmailNotifciation cannot be found \n"));
       
   625 		(commentText->Des()).Format(_L("Default Send Bearer for EmailNotifciation cannot be found"));
       
   626 	}
       
   627 	else 
       
   628 	{
       
   629 		gTest.Printf(_L("Unexepect Error %d"), err);
       
   630 		(commentText->Des()).Format(_L("Unexepect Error %d"), err);
       
   631 	}
       
   632 
       
   633 	testUtils->WriteComment(commentText->Des());
       
   634 
       
   635 	TBioMsgIdType aPortType = EBioMsgIdWap;
       
   636 	TRAP( err, bioDB->GetDefaultSendBearerTypeL(KUidBioMsgTypeVCal, aPortType));
       
   637 	if (!err)
       
   638 	{
       
   639 		gTest.Printf(_L("Default Send Bearer for KUidBioMsgTypeVCal %d \n"), aPortType);
       
   640 		GetBearerText(aPortType, bearerString);
       
   641 		(commentText->Des()).Format(_L("Default Send Bearer for vCalendar %S"),&bearerString);
       
   642 	}
       
   643 	else if (err == KErrNotFound)
       
   644 	{
       
   645 		gTest.Printf(_L("Default Send Bearer for KUidBioMsgTypeVCal cannot be found\n"));
       
   646 		(commentText->Des()).Format(_L("Default Send Bearer for KUidBioMsgTypeVCal cannot be found"));
       
   647 	}
       
   648 	else 
       
   649 	{
       
   650 		gTest.Printf(_L("Unexepect Error %d"), err);
       
   651 		(commentText->Des()).Format(_L("Unexepect Error %d"), err);
       
   652 	}
       
   653 	testUtils->WriteComment(commentText->Des());
       
   654 	
       
   655 
       
   656 	TRAP(err, bioDB->GetDefaultSendBearerByTypeL(KUidBioMsgTypeEmailNotification, EBioMsgIdWapSecure, aBioMsgIdentifier));
       
   657 	if (!err) 
       
   658 	{
       
   659 		gTest.Printf(_L(" Send Bearer for KUidBioMsgTypeVCard, WAPSecure: Port %d \n"), aBioMsgIdentifier.iPort);
       
   660 		(commentText->Des()).Format(_L("Secure WAP Bearer for vCalendar %d"),aBioMsgIdentifier.iPort);
       
   661 	
       
   662 	}
       
   663 	else if (err == KErrNotFound)
       
   664 	{
       
   665 		gTest.Printf(_L("Default Send Bearer for KUidBioMsgTypeVCard cannot be found \n"));
       
   666 	}
       
   667 	else
       
   668 	{
       
   669 		gTest.Printf(_L("Unexepect Error %d"), err);
       
   670 		(commentText->Des()).Format(_L("Unexepect Error %d"), err);
       
   671 	}
       
   672 		
       
   673 	testUtils->WriteComment(commentText->Des());
       
   674 
       
   675 
       
   676 	CleanupStack::PopAndDestroy();	// bioDB
       
   677 	CleanupStack::PopAndDestroy();	// commentText
       
   678 	testUtils->TestFinish(aTestNumber,0 );
       
   679 }
       
   680 
       
   681 
       
   682 //----------------------------------------------------------------------------------------
       
   683 LOCAL_C void TestBifObserver(TInt aTestNumber)
       
   684 //----------------------------------------------------------------------------------------
       
   685 {
       
   686 	HBufC* commentText = HBufC::NewLC(100);
       
   687 	testUtils->TestStart(aTestNumber, _L("Testing the Bif Change Observer..."));
       
   688 
       
   689 	// See if we have a test file and if we do - test...
       
   690 	TEntry entry;
       
   691 	TInt err = gFs.Entry(kTestBifFile, entry);
       
   692 	if (err)
       
   693 		{
       
   694 		gTest.Printf(_L("No test files installed on kTestBifFile\n"));
       
   695 		(commentText->Des()).Format(_L("No test files installed on %S"), &kTestBifFile);
       
   696 		testUtils->WriteComment(commentText->Des());
       
   697 		}
       
   698 	else 
       
   699 		{
       
   700 		// Delete old file if it's there
       
   701 		CFileMan *cfMan = CFileMan::NewL(gFs);
       
   702 		CleanupStack::PushL(cfMan);
       
   703 		cfMan->Delete(kTestDestFile); 
       
   704 		CleanupStack::PopAndDestroy();	// cfMan
       
   705 
       
   706 		CBifChangeObserver* bioObserver = NULL;
       
   707 		CDummyObserver dumObserver;
       
   708 		
       
   709 		// Create a BifObserver
       
   710 		gTest.Printf(_L("Creating a BifObserver\n"));
       
   711 		(commentText->Des()).Format(_L("Creating a BifObserver"));
       
   712 		testUtils->WriteComment(commentText->Des());
       
   713 		
       
   714 		bioObserver = CBifChangeObserver::NewL(dumObserver, gFs);
       
   715 		CleanupStack::PushL(bioObserver);
       
   716 
       
   717 		(commentText->Des()).Format(_L("Starting a BifObserver\n"));
       
   718 		testUtils->WriteComment(commentText->Des());
       
   719 		bioObserver->Start();
       
   720 
       
   721 		// Add A Bif
       
   722 		gTest.Printf(_L("Adding a Bif\n"));
       
   723 		(commentText->Des()).Format(_L("Adding a Bif"));
       
   724 		testUtils->WriteComment(commentText->Des());
       
   725 		
       
   726 		CFileCopyTimer *ct = CFileCopyTimer::NewL(NULL);
       
   727 		CleanupStack::PushL(ct);
       
   728 		
       
   729 		CActiveScheduler::Start();
       
   730 
       
   731 
       
   732 		// wait for the bif to show up
       
   733 
       
   734 		// Remove a Bif
       
   735 		gTest.Printf(_L("Removing a Bif"));
       
   736 		(commentText->Des()).Format(_L("Removing a Bif"));
       
   737 		testUtils->WriteComment(commentText->Des());
       
   738 
       
   739 		// Clean Up
       
   740 		gTest.Printf(_L("Cleaning Up"));
       
   741 		(commentText->Des()).Format(_L("Cleaning Up"));
       
   742 		testUtils->WriteComment(commentText->Des());
       
   743 			
       
   744 		CleanupStack::PopAndDestroy(2);	// bioObserver, ct
       
   745 		}
       
   746 	CleanupStack::PopAndDestroy(); //commentText
       
   747 
       
   748 	testUtils->TestFinish(aTestNumber,0 );
       
   749 }
       
   750 
       
   751 //----------------------------------------------------------------------------------------
       
   752 // This test creates 2 CBifChangeObservers and starts them up.
       
   753 // It also creates a CFileCopyTimer object, specifying the first
       
   754 // CBifChangeObserver to be deleted.
       
   755 // When CFileCopyTimer times out it deletes the first observer.
       
   756 // This will cancel the change notification request that the first
       
   757 // observer has issued to the File Server. However, it should not
       
   758 // cancel the change notification request that the second observer
       
   759 // has issued to the File Server. Therefore, when the CFileCopyTimer
       
   760 // times out for the second time and copies the Bif file over, the
       
   761 // second observer should notice the new Bif file.
       
   762 //
       
   763 LOCAL_C void TestCancelOfBifObserver(TInt aTestNumber)
       
   764 {
       
   765 	HBufC* commentText = HBufC::NewLC(100);
       
   766 	testUtils->TestStart(aTestNumber, _L("Testing the Bif Change Observer Cancel..."));
       
   767 
       
   768 	// See if we have a test file and if we do - test...
       
   769 	TEntry entry;
       
   770 	TInt err = gFs.Entry(kTestBifFile, entry);
       
   771 	if (err)
       
   772 		{
       
   773 		gTest.Printf(_L("No test files installed on kTestBifFile\n"));
       
   774 		(commentText->Des()).Format(_L("No test files installed on %S"), &kTestBifFile);
       
   775 		testUtils->WriteComment(commentText->Des());
       
   776 		}
       
   777 	else 
       
   778 		{
       
   779 		// Delete old file if it's there
       
   780 		CFileMan *cfMan = CFileMan::NewL(gFs);
       
   781 		CleanupStack::PushL(cfMan);
       
   782 		cfMan->Delete(kTestDestFile); 
       
   783 		CleanupStack::PopAndDestroy();	// cfMan
       
   784 
       
   785 		CBifChangeObserver* bioObserver1 = NULL;
       
   786 		CBifChangeObserver* bioObserver2 = NULL;
       
   787 		CDummyObserver dumObserver;
       
   788 		
       
   789 		// Create a BifObserver
       
   790 		gTest.Printf(_L("Creating the first BifObserver\n"));
       
   791 		(commentText->Des()).Format(_L("Creating a BifObserver"));
       
   792 		testUtils->WriteComment(commentText->Des());
       
   793 		
       
   794 		bioObserver1 = CBifChangeObserver::NewL(dumObserver, gFs);
       
   795 		CleanupStack::PushL(bioObserver1);
       
   796 
       
   797 		gTest.Printf(_L("Creating the second BifObserver\n"));
       
   798 		(commentText->Des()).Format(_L("Creating a BifObserver"));
       
   799 		testUtils->WriteComment(commentText->Des());
       
   800 		
       
   801 		bioObserver2 = CBifChangeObserver::NewL(dumObserver, gFs);
       
   802 		CleanupStack::PushL(bioObserver2);
       
   803 
       
   804 		(commentText->Des()).Format(_L("Starting the first BifObserver\n"));
       
   805 		testUtils->WriteComment(commentText->Des());
       
   806 		bioObserver1->Start();
       
   807 
       
   808 		(commentText->Des()).Format(_L("Starting the second BifObserver\n"));
       
   809 		testUtils->WriteComment(commentText->Des());
       
   810 		bioObserver2->Start();
       
   811 
       
   812 		// Add A Bif
       
   813 		gTest.Printf(_L("Adding a Bif\n"));
       
   814 		(commentText->Des()).Format(_L("Adding a Bif"));
       
   815 		testUtils->WriteComment(commentText->Des());
       
   816 		
       
   817 		// Specify that the first observer should be deleted
       
   818 
       
   819 		CFileCopyTimer *ct = CFileCopyTimer::NewL(bioObserver1);
       
   820 		
       
   821 		CleanupStack::PushL(ct);
       
   822 		
       
   823 		CActiveScheduler::Start();
       
   824 
       
   825 		// wait for the bif to show up
       
   826 
       
   827 		// Remove a Bif
       
   828 		gTest.Printf(_L("Removing a Bif"));
       
   829 		(commentText->Des()).Format(_L("Removing a Bif"));
       
   830 		testUtils->WriteComment(commentText->Des());
       
   831 
       
   832 		// Clean Up
       
   833 		gTest.Printf(_L("Cleaning Up"));
       
   834 		(commentText->Des()).Format(_L("Cleaning Up"));
       
   835 		testUtils->WriteComment(commentText->Des());
       
   836 			
       
   837 		CleanupStack::PopAndDestroy(2);	// bioObserver2, ct
       
   838 		
       
   839 		CleanupStack::Pop();			// bioObserver1, it has
       
   840 										// already been deleted by
       
   841 										// CFileCopyTimer
       
   842 		}
       
   843 	CleanupStack::PopAndDestroy(); //commentText
       
   844 
       
   845 	testUtils->TestFinish(aTestNumber,0 );
       
   846 }
       
   847 
       
   848 //----------------------------------------------------------------------------------------
       
   849 LOCAL_C void doMainL()
       
   850 //----------------------------------------------------------------------------------------
       
   851 	{
       
   852 	TInt testNumber = 1;
       
   853 
       
   854 	OpenFileSession();
       
   855 	InitTestUtils();
       
   856 	
       
   857 
       
   858 	__UHEAP_MARK;
       
   859 	CreateBDBWithHeapFailure(testNumber++);
       
   860 
       
   861 	CreateBioObserverWithHeapFailure(testNumber++);
       
   862 
       
   863 	DumpBifFiles(testNumber++);
       
   864 
       
   865 	TestAPIs(testNumber++);
       
   866 
       
   867 	DumpWapBifFiles(testNumber++);
       
   868 	
       
   869 	CheckBioness(testNumber++);
       
   870 
       
   871 	DefaultSendBearer(testNumber++);
       
   872 
       
   873 	TestBifObserver(testNumber++);
       
   874 
       
   875 	TestCancelOfBifObserver(testNumber++);
       
   876 
       
   877 	__UHEAP_MARKEND;
       
   878 	CloseFileSession();
       
   879 	CloseTestUtils();
       
   880 	}
       
   881 
       
   882 
       
   883 
       
   884 GLDEF_C TInt E32Main()
       
   885 	{	
       
   886 	__UHEAP_MARK;
       
   887 	CTrapCleanup*	theCleanup = CTrapCleanup::New();
       
   888 	TRAPD(ret,doMainL());		
       
   889 	gTest(ret==KErrNone);
       
   890 	delete theCleanup;	
       
   891 	__UHEAP_MARKEND;
       
   892 	return(KErrNone);
       
   893 	}