symhelp/helpmodel/tsrc/TSearch.cpp
changeset 0 1f04cf54edd8
equal deleted inserted replaced
-1:000000000000 0:1f04cf54edd8
       
     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 // Test Help Model module to check the PlatSec search order.
       
    15 // This test uses and additional drive typically F: It should be mapped in the epoc.ini file.
       
    16 // Mapping is achieved for example thus: _EPOC_DRIVE_F c:\temp
       
    17 // 
       
    18 //
       
    19 
       
    20 // System includes
       
    21 #include <e32std.h>
       
    22 #include <e32def.h>
       
    23 
       
    24 
       
    25 #include <e32test.h>
       
    26 #include <e32math.h>
       
    27 #include <f32file.h>
       
    28 #include <coehelp.h>
       
    29 
       
    30 // User includes
       
    31 #include <bautils.h>
       
    32 #include "HLPMODEL.H"
       
    33 #include <coreappstest/testserver.h>
       
    34 #include "SearchOrderTest.h"
       
    35 
       
    36 // Globals
       
    37 static TInt64				TheSeed;
       
    38 static RFs					TheFs;
       
    39 static RTest				TheTest(_L("TSearch - Test Help Model Searching"));
       
    40 static CTrapCleanup*		TheTrapCleanup;
       
    41 static CActiveScheduler*	TheScheduler;
       
    42 
       
    43 // Constants
       
    44 const TInt KTestCleanupStack=0x20;
       
    45 
       
    46 
       
    47 // Panic enum
       
    48 enum THlpPanic
       
    49 	{
       
    50 	EHlpPanicNoBossFile,
       
    51 	EHlpPanicLast
       
    52 	};
       
    53 
       
    54 
       
    55 //
       
    56 // ---------> Global functions
       
    57 //
       
    58 
       
    59 static void Panic(THlpPanic aPanic)
       
    60 	{
       
    61 	_LIT(KHlpPanicCategory, "TSearch");
       
    62 	User::Panic(KHlpPanicCategory, aPanic);
       
    63 	}
       
    64 
       
    65 
       
    66 static TInt Rand(const TInt aLow, const TInt aHigh)
       
    67 //
       
    68 //	Generate a random number based upon a seed and a range
       
    69 //
       
    70 	{
       
    71 	TReal initialRand = (Math::FRand(TheSeed) * (aHigh - aLow));
       
    72 	TInt32 rand;
       
    73 
       
    74 	// Round to 0 decimal places, ie. the nearest whole numer
       
    75 	Math::Round(initialRand, initialRand, 0);
       
    76 	Math::Int(rand, initialRand);
       
    77 
       
    78 	//aSeed = seed;
       
    79 	return (aLow + rand);
       
    80 	}
       
    81 
       
    82 
       
    83 
       
    84 //
       
    85 // ---------> CHlpSearchTest (header)
       
    86 //
       
    87 class CHlpSearchTest: public CBase, public MHlpModelObserver
       
    88 	{
       
    89 public: // CONSTRUCT / DESTRUCT
       
    90 	static void TestHelpModelLD(TBool aOomTesting = EFalse);
       
    91 	~CHlpSearchTest();
       
    92 
       
    93 private:
       
    94 	CHlpSearchTest();	
       
    95 
       
    96 public: // NEW
       
    97 	void TestL(TBool aOomTesting = EFalse);
       
    98 
       
    99 public: // FROM MHlpModelObserver
       
   100 	void HandleModelEventL(TInt aEvent);
       
   101 
       
   102 private: // TESTING METHODS
       
   103 	void BasicCreateAndCloseL();
       
   104 	void IndexListL(TBool aOomTesting = EFalse);
       
   105 	void CategoryListL(TBool aOomTesting = EFalse);
       
   106 	void TopicListForCategoryL();
       
   107 	void ContextSearchL(TBool aOomTesting = EFalse);
       
   108 	void IndexSearchL();
       
   109 	void TextSearchL(TBool aOomTesting = EFalse);
       
   110 	void CategoryUidSearchL(TBool aOomTesting = EFalse);
       
   111 
       
   112 private:
       
   113 	void Reset();
       
   114 	TBool FileExists(const TDesC& aFileName);
       
   115 	CDesCArray* CategoryListLC();
       
   116 	
       
   117 private: // MEMBER DATA
       
   118 	TInt iResponseCount;
       
   119 	TInt iLastHelpModelResponse;
       
   120 	TInt iSearchProgressCount;
       
   121 	TInt iSearchCancelValue;
       
   122 	TBool iIsAsynchronous;
       
   123 	TBool iSchedulerStarted;
       
   124 	CHlpModel* iModel;
       
   125 	};
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 
       
   131 
       
   132 //
       
   133 // ---------> CHlpSearchTest (source)
       
   134 //
       
   135 
       
   136 CHlpSearchTest::CHlpSearchTest()
       
   137 	{
       
   138 	}
       
   139 
       
   140 
       
   141 CHlpSearchTest::~CHlpSearchTest()
       
   142 	{
       
   143 	delete iModel;
       
   144 	}
       
   145 
       
   146 
       
   147 void CHlpSearchTest::TestHelpModelLD(TBool aOomTesting)
       
   148 	{
       
   149 	CHlpSearchTest* self = new(ELeave) CHlpSearchTest();
       
   150 	CleanupStack::PushL(self);
       
   151 	self->TestL(aOomTesting);
       
   152 	CleanupStack::PopAndDestroy();
       
   153 	}
       
   154 
       
   155 
       
   156 //
       
   157 //
       
   158 //
       
   159 
       
   160 
       
   161 void CHlpSearchTest::TestL(TBool aOomTesting)
       
   162 	{
       
   163 	iModel = CHlpModel::NewL(TheFs, this);
       
   164 	iModel->OpenL();
       
   165 
       
   166 
       
   167 	BasicCreateAndCloseL();
       
   168 	IndexListL(aOomTesting);
       
   169 	CategoryListL(aOomTesting);
       
   170 	TopicListForCategoryL();
       
   171 	ContextSearchL(aOomTesting);
       
   172 	TextSearchL(aOomTesting);
       
   173 	CategoryUidSearchL(aOomTesting);
       
   174 	}
       
   175 
       
   176 
       
   177 //
       
   178 //
       
   179 //
       
   180 
       
   181 void CHlpSearchTest::BasicCreateAndCloseL()
       
   182 	{
       
   183 	TheTest.Console()->ClearScreen();
       
   184 	TheTest.Printf(_L("Testing basic open, close and destruction\n"));
       
   185 
       
   186 	__UHEAP_MARK;
       
   187 	CHlpModel::NewLC(TheFs, NULL);
       
   188 	CleanupStack::PopAndDestroy(); // model
       
   189 	__UHEAP_MARKEND;
       
   190 
       
   191 	__UHEAP_MARK;
       
   192 	CHlpModel* model = CHlpModel::NewLC(TheFs, NULL);
       
   193 	model->OpenL();
       
   194 	CleanupStack::PopAndDestroy(); // model
       
   195 	__UHEAP_MARKEND;
       
   196 	}
       
   197 
       
   198 void CHlpSearchTest::IndexListL(TBool aOomTesting)
       
   199 	{
       
   200 	TheTest.Console()->ClearScreen();
       
   201 	TheTest.Printf(_L("Testing index listing\n"));
       
   202 	Reset();
       
   203 	
       
   204 	iModel->SearchL(EIndexList);
       
   205 
       
   206 	if(!aOomTesting)
       
   207 		{
       
   208 		TheTest(iLastHelpModelResponse == EIndexListAvailable);
       
   209 		}
       
   210 	TheTest(iResponseCount == 1);
       
   211 
       
   212 	// Load the complete list of entries for all help files
       
   213 	CHlpList* list = CHlpList::NewLC();
       
   214 	iModel->LoadListL(list);
       
   215 	TheTest.Printf(_L("\tComplete index listing for all help files..."));
       
   216 	TInt i=0;
       
   217 	for(i=0; i<list->MdcaCount(); i++)
       
   218 		{
       
   219 		CHlpItem* item = list->Item(i);
       
   220 		TPtrC pItem(item->Title());
       
   221 		TheTest.Printf(_L("\nIndex list [0x%08x][indexId=%d]: %S "), item->HelpFileUid(), item->Id(), &pItem);
       
   222 		}
       
   223 	TheTest.Printf(_L("\n"));
       
   224 
       
   225 	// Next select an item from the complete list (at random)
       
   226 
       
   227 	if(list->MdcaCount()!=0)
       
   228 		{
       
   229 		CHlpItem* item = list->Item(Rand(0, list->MdcaCount()-1));
       
   230 		
       
   231 		// Save these for later...
       
   232 		TUint helpFileUid = item->HelpFileUid().iUid;
       
   233 		TUint indexId = item->Id();
       
   234 
       
   235 		// Next perform a topic search based on this item
       
   236 		iModel->IndexSearchL(*item);
       
   237 		TheTest(iLastHelpModelResponse == EIndexSearchListAvailable);
       
   238 		CleanupStack::PopAndDestroy(); // list
       
   239 
       
   240 		// Next load the list of topics which match the index id
       
   241 		list = CHlpList::NewLC();
       
   242 		iModel->LoadListL(list);
       
   243 		TheTest.Printf(_L("\tTopic listing in help file 0x%08x, whose index id = %d"), helpFileUid, indexId);
       
   244 		for(i=0; i<list->MdcaCount(); i++)
       
   245 			{
       
   246 			CHlpItem* item = list->Item(i);
       
   247 			TPtrC pItem(item->Title());
       
   248 			TheTest.Printf(_L("\nTopic [Uid: 0x%08x]: %S "), item->HelpFileUid(), &pItem);
       
   249 			}
       
   250 	}
       
   251 	TheTest.Printf(_L("\n"));
       
   252 
       
   253 	CleanupStack::PopAndDestroy(); // list
       
   254 	}
       
   255 
       
   256 
       
   257 void CHlpSearchTest::CategoryListL(TBool aOomTesting)
       
   258 	{
       
   259 	TheTest.Console()->ClearScreen();
       
   260 	TheTest.Printf(_L("Testing category listing\n"));
       
   261 
       
   262 	Reset();
       
   263 	iModel->SearchL(ECategoryList);
       
   264 	if(!aOomTesting)
       
   265 		{
       
   266 		TheTest(iLastHelpModelResponse == ECategoryListAvailable);
       
   267 		}
       
   268 
       
   269 	// Display the index listing...
       
   270 	CHlpList* list = CHlpList::NewLC();
       
   271 	iModel->LoadListL(list);
       
   272 
       
   273 	for(TInt i=0; i<list->MdcaCount(); i++)
       
   274 		{
       
   275 		TPtrC pItem(list->MdcaPoint(i));
       
   276 		TheTest.Printf(_L("\nCategory item %d: %S"), i, &pItem);
       
   277 		}
       
   278 	TheTest.Printf(_L("\n"));
       
   279 	CleanupStack::PopAndDestroy(); // list
       
   280 	}
       
   281 
       
   282 
       
   283 void CHlpSearchTest::TopicListForCategoryL()
       
   284 	{
       
   285 	TheTest.Printf(_L("Testing topic listing\n"));
       
   286 	Reset();
       
   287 
       
   288 	// First get a category listing, then get the list of topics
       
   289 	// for each specified category.
       
   290 	CDesCArrayFlat* array = STATIC_CAST(CDesCArrayFlat*, CategoryListLC());
       
   291 	const TInt count = array->Count();
       
   292 	for(TInt i=0; i<count; i++)
       
   293 		{
       
   294 		TPtrC pItem = array->MdcaPoint(i);
       
   295 		TheTest.Printf(_L("\nTopics for Category %S\n"), &pItem);
       
   296 
       
   297 		// Calling this will result in the topics for this category
       
   298 		// being printed out in the mixin handler
       
   299 		iModel->SearchL(ETopicListForCategory, pItem);
       
   300 		}
       
   301 	CleanupStack::PopAndDestroy(); // array
       
   302 	}
       
   303 
       
   304 
       
   305 void CHlpSearchTest::ContextSearchL(TBool aOomTesting)
       
   306 	{
       
   307 	TheTest.Printf(_L("Testing context searching\n"));
       
   308 	Reset();
       
   309 
       
   310 	// Context search for an item we know exists
       
   311 	_LIT(KContext1,	"This_is_a_multi_word_context2");
       
   312 
       
   313 	TUid uid = { 16777216 };
       
   314 	TCoeHelpContext coeSearchContext(uid, KContext1);
       
   315 	iModel->ContextSearchL(coeSearchContext);
       
   316 	if(!aOomTesting)
       
   317 		{
       
   318 		TheTest(iLastHelpModelResponse == ETopicAvailable);
       
   319 		}
       
   320 
       
   321 	
       
   322 	// Context search for an item we know doesn't exist
       
   323 	_LIT(KContext2,	"ABCDEFG");
       
   324 
       
   325 	TUid uid2 = { 00000000 };
       
   326 	TCoeHelpContext coeSearchContext2(uid2, KContext2);
       
   327 	iModel->ContextSearchL(coeSearchContext2);
       
   328 	TheTest(iLastHelpModelResponse == ETopicNotFound);
       
   329 	}
       
   330 
       
   331 
       
   332 void CHlpSearchTest::TextSearchL(TBool aOomTesting)
       
   333 	{
       
   334 	if(aOomTesting)
       
   335 		return;
       
   336 
       
   337 	_LIT(KFullTextShouldNotBeFound,	"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
       
   338 	TheTest.Printf(_L("Testing text searching (when item shouldn't be found)\n"));
       
   339 
       
   340 	Reset();
       
   341 	iSchedulerStarted = EFalse;
       
   342 	iIsAsynchronous = ETrue;
       
   343 	iModel->SearchL(EFullTextSearch, KFullTextShouldNotBeFound);
       
   344 	iSchedulerStarted = ETrue;
       
   345 	CActiveScheduler::Start();
       
   346 	TheTest(iLastHelpModelResponse == ESearchListNoneFound);
       
   347 
       
   348 	_LIT(KFullTextShouldBeFound,	"boss");
       
   349 	TheTest.Printf(_L("Testing text searching (when item should be found)\n"));
       
   350 
       
   351 	Reset();
       
   352 	iSchedulerStarted = EFalse;
       
   353 	iIsAsynchronous = ETrue;
       
   354 	iModel->SearchL(EFullTextSearch, KFullTextShouldBeFound);
       
   355 	iSchedulerStarted = ETrue;
       
   356 	CActiveScheduler::Start();
       
   357 	TheTest(iLastHelpModelResponse == ESearchListAvailable);
       
   358 
       
   359 	TheTest.Printf(_L("\tTesting asynch cancel function\n"));
       
   360 	TInt searchCancelValue = Max(1, iSearchProgressCount / 2); // stop half way through
       
   361 
       
   362 	Reset();
       
   363 	iSearchCancelValue = searchCancelValue;
       
   364 	iSchedulerStarted = EFalse;
       
   365 	iIsAsynchronous = ETrue;
       
   366 	iModel->SearchL(EFullTextSearch, KFullTextShouldBeFound);
       
   367 	iSchedulerStarted = ETrue;
       
   368 	CActiveScheduler::Start();
       
   369 	}
       
   370 
       
   371 
       
   372 void CHlpSearchTest::CategoryUidSearchL(TBool aOomTesting)
       
   373 	{
       
   374 	TheTest.Console()->ClearScreen();
       
   375 	TheTest.Printf(_L("Testing category uid searching - *requires boss help file*\n"));
       
   376 	
       
   377 
       
   378     if	((!FileExists(_L("C:\\Resource\\Help\\Boss-1.hlp"))) && (!FileExists(_L("Z:\\Resource\\Help\\Boss-1.hlp"))))
       
   379 		Panic(EHlpPanicNoBossFile);
       
   380 	
       
   381 
       
   382 	Reset();
       
   383 	iModel->CategoryUIDSearchL(TUid::Uid(16777216)); // hard coded category uid from Boss1.hlp
       
   384 	if(!aOomTesting)
       
   385 		{
       
   386 		TheTest(iLastHelpModelResponse == ETopicListAvailable);
       
   387 		}
       
   388 	TheTest(iResponseCount == 1);
       
   389 
       
   390 	// Display the index listing...
       
   391 	CHlpList* list = CHlpList::NewLC();
       
   392 	iModel->LoadListL(list);
       
   393 
       
   394 	for(TInt i=0; i<list->MdcaCount(); i++)
       
   395 		{
       
   396 		TPtrC pItem(list->MdcaPoint(i));
       
   397 		TheTest.Printf(_L("\nCategory item %d: %S"), i, &pItem);
       
   398 		}
       
   399 	CleanupStack::PopAndDestroy(); // list
       
   400 	TheTest.Printf(_L("\n"));
       
   401 
       
   402 	// Test for a category that we know doesn't exist
       
   403 	Reset();
       
   404 	iModel->CategoryUIDSearchL(KNullUid);
       
   405 	TheTest(iLastHelpModelResponse == ETopicListNoneFound);
       
   406 	TheTest(iResponseCount == 1);
       
   407 	}
       
   408 
       
   409 
       
   410 //
       
   411 //
       
   412 //
       
   413 
       
   414 
       
   415 void CHlpSearchTest::Reset()
       
   416 	{
       
   417 	iResponseCount = 0;
       
   418 	iLastHelpModelResponse = KErrGeneral;
       
   419 	iIsAsynchronous = EFalse;
       
   420 	iSearchProgressCount = 0;
       
   421 	iSearchCancelValue = KErrNone-1; // Anything less that KErrNone
       
   422 	}
       
   423 
       
   424 TBool CHlpSearchTest::FileExists(const TDesC& aFileName)
       
   425 	{
       
   426 	TEntry entry;
       
   427 	TInt error = TheFs.Entry(aFileName, entry);
       
   428 	if	(error == KErrInUse)
       
   429 		return ETrue;
       
   430 	if	(error < KErrNone)
       
   431 		return EFalse;
       
   432 	return (!entry.IsDir());
       
   433 	}
       
   434 
       
   435 CDesCArray* CHlpSearchTest::CategoryListLC()
       
   436 	{
       
   437 	// Get and print the category listing
       
   438 	CDesCArrayFlat* array = new(ELeave) CDesCArrayFlat(5);
       
   439 	CleanupStack::PushL(array);
       
   440 	iModel->CategoryListL(array);
       
   441 	return array;
       
   442 	}
       
   443 
       
   444 
       
   445 //
       
   446 //
       
   447 //
       
   448 
       
   449 
       
   450 void CHlpSearchTest::HandleModelEventL(TInt aEvent)
       
   451 	{
       
   452 	iResponseCount++;
       
   453 	iLastHelpModelResponse = aEvent;
       
   454 
       
   455 	// If this test included an asynch search, and there was a cancel value set
       
   456 	// then cancel the asynch searcher
       
   457 	if	(++iSearchProgressCount == iSearchCancelValue && iIsAsynchronous)
       
   458 		{
       
   459 		// Reset this otherwise we'll get stuck in a loop
       
   460 		iSearchCancelValue = KErrNone-1;
       
   461 
       
   462 		// Only works for full test searching as this is the only search type 
       
   463 		// which uses an active object, and even then it doesn't use them properly.
       
   464 		TheTest(iModel->CancelSearch() == KErrNone);
       
   465 		}
       
   466 
       
   467 	switch (aEvent)
       
   468 		{
       
   469 	case ESearchListAvailable:		// text searches
       
   470 		TheTest.Printf(_L("\n\tESearchListAvailable\n"));
       
   471 		break;
       
   472 	
       
   473 	case ECategoryListAvailable:
       
   474 		{
       
   475 		TheTest.Printf(_L("\n\tECategoryListAvailable\n"));
       
   476 
       
   477 		// Get and print the category listing
       
   478 		CDesCArrayFlat* array = STATIC_CAST(CDesCArrayFlat*, CategoryListLC());
       
   479 		const TInt count = array->Count();
       
   480 		for(TInt i=0; i<count; i++)
       
   481 			{
       
   482 			TPtrC pItem = array->MdcaPoint(i);
       
   483 			TheTest.Printf(_L("Category %d: %S\n"), i, &pItem);
       
   484 			}
       
   485 		CleanupStack::PopAndDestroy(); // array
       
   486 		break;
       
   487 		}
       
   488 	case ECategoryListNoneFound:
       
   489 		TheTest.Printf(_L("\n\tECategoryListNoneFound\n"));
       
   490 		break;
       
   491 
       
   492 
       
   493 	case ETopicListAvailable:		// category expansion
       
   494 		{
       
   495 		TheTest.Printf(_L("\n\tETopicListAvailable\n"));
       
   496 		CHlpList* list = CHlpList::NewLC();
       
   497 		iModel->LoadListL(list);
       
   498 		TInt count = list->MdcaCount();
       
   499 		for(TInt i=0; i<count; i++)
       
   500 			{
       
   501 			CHlpItem* item = list->Item(i);
       
   502 			TPtrC pTitle(*item->iTitle);
       
   503 			TheTest.Printf(_L("Topic %d: %S (id = %d)\n"), i, &pTitle, item->iId);
       
   504 			}
       
   505 		CleanupStack::PopAndDestroy(); // list
       
   506 		break;
       
   507 		}
       
   508 	case ETopicListNoneFound:
       
   509 		TheTest.Printf(_L("\n\tETopicListNoneFound\n"));
       
   510 		break;
       
   511 
       
   512 	
       
   513 	case ETopicAvailable:			// topic text
       
   514 		TheTest.Printf(_L("\n\tETopicAvailable\n"));
       
   515 		break;
       
   516 	case ETopicNotFound:
       
   517 		TheTest.Printf(_L("\n\tETopicNotFound\n"));
       
   518 		break;
       
   519 
       
   520 
       
   521 	case EIndexListAvailable:		// index list
       
   522 		TheTest.Printf(_L("\n\tEIndexListAvailable\n"));
       
   523 		break;
       
   524 	case EIndexListNoneFound:
       
   525 		TheTest.Printf(_L("\n\tEIndexListNoneFound\n"));
       
   526 		break;
       
   527 	case EIndexSearchListAvailable:	// topic list from index phrase
       
   528 		TheTest.Printf(_L("\n\tEIndexSearchListAvailable\n"));
       
   529 		break;
       
   530 	case EIndexSearchListNoneFound:
       
   531 		TheTest.Printf(_L("\n\tEIndexSearchListNoneFound\n"));
       
   532 		break;
       
   533 
       
   534 
       
   535 	case EHlpSearchCancelled:
       
   536 		TheTest.Printf(_L("<SEARCH CANCELLED>"));
       
   537 		break;
       
   538 	case EModelSearchInProgress:
       
   539 		TheTest.Printf(_L("..."));
       
   540 		return;
       
   541 	case ESearchListNoneFound:
       
   542 		TheTest.Printf(_L("\n\tESearchListNoneFound\n"));
       
   543 		break;
       
   544 		}
       
   545 
       
   546 	if	(iIsAsynchronous && iSchedulerStarted)
       
   547 		CActiveScheduler::Stop();
       
   548 	}
       
   549 	
       
   550 /**
       
   551 	doSearchOrderTest
       
   552 	
       
   553 	All help files used in this part of the test use the Category UID of 0x01007000
       
   554 	Within each source RTF file the Category is defined as the drive name.
       
   555 	Hence the File copied to c:\resource\help has the Category "Drive C:"
       
   556 	There are 3 help files used in this test:
       
   557 		PlatSecSearchTestC.hlp - initially resides in z:\System\Programs\THlpmodel\
       
   558 		PlatSecSearchTestF.hlp - initially resides in z:\System\Programs\THlpmodel\
       
   559 		PlatSecSearchTest.hlp - (with Category "Drive Z:") resides in z:\Resoruce\Help
       
   560 	The exports are specified in the Hlpmodel BLD.INF file.
       
   561 	
       
   562 	As part of the building process the help files are exported to the
       
   563 	corresponding directories.
       
   564 
       
   565 	Thus initially only PlatSecSearchTest.hlp with be visible presenting 
       
   566 	the Category "Drive Z:". As the test progresses so the 2 remaining files are
       
   567 	copied (with a change in name) from z:\System\Programs\THlpmodel\ to their corresponding drive.
       
   568 	Thus PlatSecSearchTestC.hlp becomes PlatSecSearchTest.hlp in c:\Resource\Help
       
   569 	and PlatSecSearchTestF.hlp becomes PlatSecSearchTest.hlp in f:\Resource\Help
       
   570 	
       
   571 	Given the search order, the higher drive letter takes presidence (however z: is last),
       
   572 	so when there are is a file called PlatSecSearchTest.hlp on z:, c: and f: only f: 
       
   573 	will be seen.
       
   574 	
       
   575 	Note: That the test looks for a drive of type EMediaHardDisk: on Lubbock this will be F:
       
   576 	on the H2 it is likely to be E: this is managed within CSearchOrderTest.
       
   577 */
       
   578 
       
   579 
       
   580 
       
   581 static void doSearchOrderTestL()
       
   582 	{
       
   583 	__UHEAP_MARK;
       
   584 	TheTest.Printf(_L("-------------------------------------------\n"));				
       
   585 	TheTest.Printf(_L("   Testing PlatSec drive search Order.\n"));			
       
   586 	TheTest.Printf(_L("-------------------------------------------\n"));				
       
   587 
       
   588 	// Initialise the array of mapped drives.
       
   589 	CSearchOrderTest* sort = CSearchOrderTest::NewL(TheTest);
       
   590 	CleanupStack::PushL( sort );
       
   591 	
       
   592 	TheTest.Next(_L("Test category listing"));
       
   593 	
       
   594 	CHlpModel* model = CHlpModel::NewLC(TheFs, NULL);
       
   595 
       
   596 	CDesCArray* catList = new(ELeave) CDesCArrayFlat(2);
       
   597 	CleanupStack::PushL(catList);
       
   598 		
       
   599 	// Iterate around Drive Loop
       
   600 	TBool found = EFalse;
       
   601 	for( TInt operation =CSearchOrderTest::EInitial_DeleteAll;
       
   602 		 operation<=CSearchOrderTest::EFinal_DeleteAll; 
       
   603 		 operation++)
       
   604 		{
       
   605 		sort->MoveHelpFileL( operation );
       
   606 		model->OpenL();
       
   607 		// Get the new gategory list, resulting from the repositioned file.
       
   608 		model->CategoryListL(catList);
       
   609 		// Close help model to release file handles.
       
   610 		model->CloseL();
       
   611 		// Check listed categories given the current index.
       
   612 		found = sort->CheckCategoryListL( operation, catList );
       
   613 		if( found )
       
   614 			{
       
   615 			TheTest.Printf(_L("The Correct Category was found."));			
       
   616 			}
       
   617 		TheTest(found);
       
   618 		// Remove the old contents, otherwise new 
       
   619 		// categories are simply added.
       
   620 		catList->Reset();
       
   621 		}
       
   622 	CleanupStack::PopAndDestroy( catList );
       
   623 	CleanupStack::PopAndDestroy( model );
       
   624 	CleanupStack::PopAndDestroy( sort );
       
   625 	__UHEAP_MARKEND;
       
   626 	}
       
   627 
       
   628 static void PerformOOMTestL()
       
   629 	{
       
   630 	TInt ret=KErrNoMemory;
       
   631 	TInt failAt=0;	  
       
   632 	while (ret!=KErrNone)
       
   633 		{
       
   634 		failAt++;
       
   635 		__UHEAP_SETFAIL(RHeap::EDeterministic,failAt);
       
   636 		__UHEAP_MARK;			
       
   637 		TRAP(ret, CHlpSearchTest::TestHelpModelLD(ETrue));
       
   638 		if (ret!=KErrNone)
       
   639 			{
       
   640 			__UHEAP_MARKEND;
       
   641 			}
       
   642 		__UHEAP_RESET;
       
   643 		TheTest(ret==KErrNoMemory||ret==KErrNone);
       
   644 		}
       
   645 	}
       
   646 
       
   647 static void setupFileServerAndSchedulerL()
       
   648 //
       
   649 // Initialise the cleanup stack.
       
   650 //
       
   651 	{
       
   652 	TTime time;
       
   653 	time.HomeTime();
       
   654 	TheSeed = time.Int64();
       
   655 
       
   656 	TheTest(TheFs.Connect() == KErrNone);
       
   657 	TheScheduler = new (ELeave) CActiveScheduler;
       
   658 	CActiveScheduler::Install(TheScheduler);
       
   659 	}
       
   660 
       
   661 
       
   662 static void setupCleanup()
       
   663 //
       
   664 // Initialise the cleanup stack.
       
   665 //
       
   666     {
       
   667 	TheTrapCleanup = CTrapCleanup::New();
       
   668 	TheTest(TheTrapCleanup!=NULL);
       
   669 	TRAPD(r,
       
   670 		{
       
   671 		for (TInt i=KTestCleanupStack;i>0;i--)
       
   672 			CleanupStack::PushL((TAny*) 0);
       
   673 		CleanupStack::Pop(KTestCleanupStack);
       
   674 		});
       
   675 	TheTest(r==KErrNone);
       
   676 	}
       
   677 
       
   678 /**
       
   679 @SYMTestCaseID PIM-TSEARCH-0001
       
   680 */	
       
   681 GLDEF_C TInt E32Main()
       
   682 //
       
   683 // Test Help Model API
       
   684 //
       
   685     {
       
   686 	__UHEAP_MARK;
       
   687 
       
   688 	TheTest.Title();
       
   689 	TheTest.Start(_L("@SYMTestCaseID PIM-TSEARCH-0001"));
       
   690 	setupCleanup();
       
   691 	
       
   692 	__UHEAP_MARK;
       
   693 	TRAPD(r, 
       
   694 			setupFileServerAndSchedulerL();
       
   695 			CHlpSearchTest::TestHelpModelLD();
       
   696 			);
       
   697 	
       
   698 	TheTest(r==KErrNone);
       
   699 	__UHEAP_MARKEND;
       
   700 	
       
   701 	TRAP(r, PerformOOMTestL());
       
   702 	TheTest(r==KErrNone);
       
   703 	
       
   704 	// PlatSec search order test.
       
   705 	TRAP(r, doSearchOrderTestL());
       
   706 	TheTest(r==KErrNone);
       
   707 
       
   708 
       
   709 	delete TheScheduler;
       
   710 	delete TheTrapCleanup;
       
   711 	TheFs.Close();
       
   712 	TheTest.End();
       
   713 	TheTest.Close();
       
   714 
       
   715 	__UHEAP_MARKEND;
       
   716 	return KErrNone;
       
   717     }