searcher/tsrc/cpixsearchertest/src/cpixindexertester.cpp
changeset 0 671dee74050a
child 1 6f2c1c46032b
equal deleted inserted replaced
-1:000000000000 0:671dee74050a
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #include "cpixindexerterster.h"
       
    18 #include "ccpixsearcher.h"
       
    19 #include "CSearchDocument.h"
       
    20 #include "CCPixIndexer.h"
       
    21 #include "common.h"
       
    22 
       
    23 #define TS_ASSERT( a ) \
       
    24     if ( !(a) ) User::Leave( KErrGeneral )
       
    25 
       
    26 _LIT(KUniqueSearchTermInAct0Txt, "uniquewordonlyfoundonceincorpus");
       
    27 _LIT(KQueryString, "act");
       
    28 
       
    29 _LIT(KFileBaseAppClassC, "@c:test root file");
       
    30 _LIT(KNonExistentField, "_foo");
       
    31 _LIT(KAppClassMp3, MP3APPCLASS);
       
    32 
       
    33 _LIT(KTestFileAct0, "c:\\Data\\cpixS60unittest\\act0.txt");
       
    34 _LIT(KTestFileAct1, "c:\\Data\\cpixS60unittest\\act1.txt");
       
    35 _LIT(KTestFileAct2, "c:\\Data\\cpixS60unittest\\act2.txt");
       
    36 _LIT(KTestFileAct3, "c:\\Data\\cpixS60unittest\\act3.txt");
       
    37 _LIT(KTestFileAct4, "c:\\Data\\cpixS60unittest\\act4.txt");
       
    38 _LIT(KTestFileAct5, "c:\\Data\\cpixS60unittest\\act5.txt");
       
    39 _LIT(KTestFileAct6, "c:\\Data\\cpixS60unittest\\act6.txt");
       
    40 _LIT(KTestFileActComplete, "c:\\Data\\cpixS60unittest\\complete.txt");
       
    41 _LIT(KTestFileActIndex, "c:\\Data\\cpixS60unittest\\index.txt");
       
    42 _LIT(KTestFileActIntro, "c:\\Data\\cpixS60unittest\\introduction.txt");
       
    43 // UCS-2 Little Endian
       
    44 _LIT(KTestFileInvalidEncoding, "c:\\Data\\cpixS60unittest\\invalidEncoding.txt");
       
    45 _LIT(KTestFileMp3, "c:\\Data\\cpixS60unittest\\One Step For Man.mp3");
       
    46 
       
    47 CHandleIndexingResultLeaves::CHandleIndexingResultLeaves()
       
    48     {
       
    49     // iWait will cause waiting until some asynchronous event has happened
       
    50     iWait = new (ELeave) CActiveSchedulerWait;
       
    51     }
       
    52 
       
    53 CHandleIndexingResultLeaves::~CHandleIndexingResultLeaves()
       
    54     {
       
    55     delete iWait;
       
    56     }
       
    57 
       
    58 void CHandleIndexingResultLeaves::HandleIndexingResultL(TInt /*aError */)
       
    59     {
       
    60     iWait->AsyncStop();
       
    61     User::Leave(KErrCancel);
       
    62     }
       
    63 
       
    64 void CTestIndexer::setUp()
       
    65     {
       
    66     User::LeaveIfError(iSession.Connect());
       
    67     iSession.DefineVolume(KFileBaseAppClassC, KNullDesC);
       
    68 
       
    69     iIndexer = CCPixIndexer::NewL(iSession);
       
    70     iIndexer->OpenDatabaseL(KFileBaseAppClassC);
       
    71     iIndexer->ResetL();
       
    72     
       
    73     iSearcher = CCPixSearcher::NewL(iSession);
       
    74     iSearcher->OpenDatabaseL(KFileBaseAppClassC);
       
    75     
       
    76     iHandleResultLeaves = new (ELeave) CHandleIndexingResultLeaves;
       
    77     
       
    78     // iWait will cause waiting until some asynchronous event has happened
       
    79     iWait = new (ELeave) CActiveSchedulerWait;
       
    80     iMyAOClass = CAOTestClass::NewL(this);
       
    81     
       
    82     iCurrentIndex = 0;
       
    83     }
       
    84 
       
    85 void CTestIndexer::tearDown()
       
    86     {
       
    87     iCurrentIndex = 0;
       
    88 
       
    89     iIndexer->ResetL();
       
    90 
       
    91     if( iMyAOClass )
       
    92         {
       
    93         delete iMyAOClass;
       
    94         iMyAOClass = NULL;
       
    95         }
       
    96     
       
    97     delete iIndexer;
       
    98     iIndexer = NULL;
       
    99     
       
   100     delete iSearcher;
       
   101     iSearcher = NULL;
       
   102 
       
   103     delete iHandleResultLeaves;
       
   104     iHandleResultLeaves = NULL;
       
   105 
       
   106     delete iWait;
       
   107 
       
   108     iSession.UnDefineVolume(KFileBaseAppClassC);
       
   109     iSession.Close();
       
   110     }
       
   111 
       
   112 void CTestIndexer::CreateFileIndexItemL(const TDesC& aFilename)
       
   113     {
       
   114     
       
   115     // creating CSearchDocument object with unique ID for this application
       
   116     CSearchDocument* index_item = CSearchDocument::NewLC(aFilename, KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   117     
       
   118     // Send for indexing
       
   119     if (iIndexer)
       
   120         {
       
   121         iIndexer->AddL(*index_item);
       
   122         }
       
   123     CleanupStack::PopAndDestroy(index_item);
       
   124     }
       
   125 
       
   126 
       
   127 TInt CTestIndexer::SearchForTextL(const TDesC& aQueryString, const TDesC& aDefaultField)
       
   128     {
       
   129     TInt estimatedDocumentCount(KErrNotFound);
       
   130     
       
   131     // Make sure CPix flush is done before searching
       
   132     if (iIndexer)
       
   133         {
       
   134         iIndexer->FlushL();
       
   135         }
       
   136     
       
   137     // Send for indexing
       
   138     if ( iSearcher )
       
   139         {
       
   140         estimatedDocumentCount = iSearcher->SearchL(aQueryString, aDefaultField);
       
   141         }
       
   142         
       
   143     return estimatedDocumentCount;
       
   144     }
       
   145 
       
   146 TBool CTestIndexer::CheckBaseAppClassIsExpectedL(const TDesC& aExpectedAppClass, 
       
   147                                                  const TDesC& aDocUid)
       
   148     {
       
   149     TBool result(EFalse);
       
   150 
       
   151     iIndexer->FlushL();
       
   152     const TInt count = iSearcher->SearchL(aDocUid, TPtrC((TUint16*)LCPIX_DOCUID_FIELD));
       
   153     //  TODO XXX TIM why is count==2? This is not an expected result and needs 
       
   154     //  understanding.
       
   155 #if 0
       
   156     // as searching with DocUid, the result count must be 1
       
   157     TS_ASSERT(count==1);
       
   158 #endif // 0
       
   159 
       
   160     CSearchDocument* doc = iSearcher->GetDocumentL(0);
       
   161     TS_ASSERT(doc); // Not NULL
       
   162 
       
   163     const TInt cmp = aExpectedAppClass.Compare(doc->AppClass());
       
   164     if (cmp == KErrNone)
       
   165         {
       
   166         result = ETrue;
       
   167         }
       
   168     delete doc;
       
   169     doc = NULL;
       
   170     return result;
       
   171     }
       
   172 
       
   173 void CTestIndexer::HandleOpenDatabaseResultL( TInt /* aError */ )
       
   174     {
       
   175     if (iWait && iWait->IsStarted())
       
   176         {
       
   177         // All done, signal that can continue now.
       
   178         iWait->AsyncStop();
       
   179         }
       
   180     }
       
   181 
       
   182 void CTestIndexer::HandleSetAnalyzerResultL(TInt /*aError*/)
       
   183     {
       
   184     if (iWait && iWait->IsStarted())
       
   185         {
       
   186         // All done, signal that can continue now.
       
   187         iWait->AsyncStop();
       
   188         }
       
   189     }
       
   190 
       
   191 void CTestIndexer::HandleIndexingResultL(TInt aError)
       
   192     {
       
   193     TS_ASSERT(aError == KErrNone);
       
   194     
       
   195     // if the test case started iWait, then stop it
       
   196     if (iWait && iWait->IsStarted())
       
   197         {
       
   198         iWait->AsyncStop();
       
   199         }
       
   200     }
       
   201 
       
   202 // Timeout callback
       
   203 void CTestIndexer::CallCompleted( int /* i */ )
       
   204     {
       
   205     if (iWait && iWait->IsStarted())
       
   206         {
       
   207         iWait->AsyncStop();
       
   208         }
       
   209     }
       
   210 
       
   211 void CTestIndexer::testOpenIndexDb()
       
   212     {
       
   213     // Make sure cannot open an invalid index db
       
   214     _LIT(KInvalidQualifiedBaseAppClass, "@x:test invalid");
       
   215     CCPixIndexer* indexer = CCPixIndexer::NewLC(iSession);
       
   216     TRAPD(err, indexer->OpenDatabaseL(KInvalidQualifiedBaseAppClass) );
       
   217     TS_ASSERT(!indexer->IsDatabaseOpen());
       
   218     TS_ASSERT(err == KErrCannotOpenDatabase);
       
   219     CleanupStack::PopAndDestroy(indexer);
       
   220 
       
   221     indexer = NULL; 
       
   222 
       
   223     // check that same indexer object can open a second indexDb
       
   224     indexer = CCPixIndexer::NewLC(iSession);
       
   225     TRAP(err, indexer->OpenDatabaseL(KFileBaseAppClassC));
       
   226     TS_ASSERT(indexer->IsDatabaseOpen());
       
   227     TS_ASSERT(err == KErrNone);
       
   228 
       
   229     TRAP(err, indexer->OpenDatabaseL(KFileBaseAppClassC));
       
   230     TS_ASSERT(err == KErrNone);
       
   231     TS_ASSERT(indexer->IsDatabaseOpen());
       
   232     CleanupStack::PopAndDestroy(indexer);
       
   233 
       
   234     indexer = NULL; 
       
   235 
       
   236     // check that asynchronous open works as expected
       
   237     indexer = CCPixIndexer::NewLC(iSession);
       
   238     TRAP(err, indexer->OpenDatabaseL(*this, KFileBaseAppClassC));
       
   239 
       
   240     // If want to set a maximum timeout value for this test case then
       
   241     // uncomment this line, which will cause CTestSearcher::CallCompleted
       
   242     // to be triggered.
       
   243     iMyAOClass->StartL(1000000*10); //Async call: Maximum TimeOut time 10 seconds
       
   244 
       
   245     iWait->Start();
       
   246     TS_ASSERT(indexer->IsDatabaseOpen());
       
   247     CleanupStack::PopAndDestroy(indexer);
       
   248     }
       
   249 
       
   250 void CTestIndexer::testAddL()
       
   251     {
       
   252     // There should be plenty of terms "act"  EXPECTED RESULTS > 0
       
   253     TInt result = SearchForTextL(KQueryString, KNullDesC);
       
   254     TS_ASSERT(result == 0);
       
   255     
       
   256     // Shakespeare's corpus files have no terms "ipod" in them EXPECTED RESULTS IS ZERO
       
   257     result = SearchForTextL(_L("ipod"), KNullDesC);
       
   258     TS_ASSERT(result == 0);
       
   259 
       
   260     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS == 0, but not in this field
       
   261     result = SearchForTextL(KQueryString, KNonExistentField);
       
   262     TS_ASSERT(result == 0);
       
   263 
       
   264     TRAPD(err, CreateFileIndexItemL(KTestFileAct0));
       
   265     TS_ASSERT(err == KErrNone);
       
   266     TRAP(err, CreateFileIndexItemL(KTestFileAct1));
       
   267     TS_ASSERT(err == KErrNone);
       
   268     TRAP(err, CreateFileIndexItemL(KTestFileAct2));
       
   269     TS_ASSERT(err == KErrNone);
       
   270     TRAP(err, CreateFileIndexItemL(KTestFileAct3));
       
   271     TS_ASSERT(err == KErrNone);
       
   272     TRAP(err, CreateFileIndexItemL(KTestFileAct4));
       
   273     TS_ASSERT(err == KErrNone);
       
   274     TRAP(err, CreateFileIndexItemL(KTestFileAct5));
       
   275     TS_ASSERT(err == KErrNone);
       
   276     TRAP(err, CreateFileIndexItemL(KTestFileAct6));
       
   277     TS_ASSERT(err == KErrNone);
       
   278 
       
   279     // Attempting to add a document with invalid encoding must fail
       
   280     TRAP(err, CreateFileIndexItemL(KTestFileInvalidEncoding));
       
   281     TS_ASSERT(err == KErrCannotAddDocument);
       
   282 
       
   283     // Add a MP3 and test that the base app class is MP3APPCLASS.
       
   284     TRAP(err, CreateFileIndexItemL(KTestFileMp3));
       
   285     TS_ASSERT(err == KErrNone);
       
   286     const TBool isMp3 = CheckBaseAppClassIsExpectedL(
       
   287                             KAppClassMp3, KTestFileMp3);
       
   288     TS_ASSERT(isMp3);
       
   289 
       
   290     TRAP(err, CreateFileIndexItemL(KTestFileActComplete));
       
   291     TS_ASSERT(err == KErrNone);
       
   292     TRAP(err, CreateFileIndexItemL(KTestFileActIndex));
       
   293     TS_ASSERT(err == KErrNone);
       
   294     TRAP(err, CreateFileIndexItemL(KTestFileActIntro));
       
   295     TS_ASSERT(err == KErrNone);
       
   296 
       
   297     // There should be plenty of terms "act"  EXPECTED RESULTS > 0
       
   298     result = SearchForTextL(KQueryString, KNullDesC);
       
   299     TS_ASSERT(result > 0);
       
   300     
       
   301     // Shakespeare's corpus files have no terms "ipod" in them EXPECTED RESULTS IS ZERO
       
   302     result = SearchForTextL(_L("ipod"), KNullDesC);
       
   303     TS_ASSERT(result == 0);
       
   304 
       
   305     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS == 0, but not in this field
       
   306     result = SearchForTextL(KQueryString, KNonExistentField);
       
   307     TS_ASSERT(result == 0);
       
   308     }
       
   309 
       
   310 void CTestIndexer::testAsyncAddL()
       
   311     {
       
   312     // At the start this term will not be in the indexDb
       
   313     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   314     TS_ASSERT(result == 0); 
       
   315 
       
   316     //Improve code coverage
       
   317     CSearchDocument* index_item = CSearchDocument::NewL(KTestFileAct0, KNullDesC, _L("excerpt"), CSearchDocument::EFileParser);
       
   318     CleanupStack::PushL(index_item);
       
   319     //CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   320     
       
   321     iIndexer->AddL(*this, *index_item);
       
   322     CleanupStack::PopAndDestroy(index_item);
       
   323 
       
   324     iWait->Start();
       
   325 
       
   326     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   327     TS_ASSERT(result == 1);
       
   328     CSearchDocument* doc = iSearcher->GetDocumentL(0);
       
   329     TS_ASSERT(doc != NULL);
       
   330     //TS_ASSERT(doc->Excerpt() != KNullDesC);//Should not be NULL
       
   331     delete doc;
       
   332     CDocumentField* docField = CDocumentField::NewL(_L("test"),_L("test"));
       
   333     TS_ASSERT(docField != NULL);
       
   334     delete docField;
       
   335     }
       
   336 
       
   337 void CTestIndexer::testCancelAddL()
       
   338     {
       
   339     // At the start this term will not be in the indexDb
       
   340     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   341     TS_ASSERT(result == 0); 
       
   342 
       
   343     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   344 
       
   345     iIndexer->AddL(*this, *index_item);
       
   346     iIndexer->Cancel(); // AddL is an atomic action, cannot cancel it
       
   347     CleanupStack::PopAndDestroy(index_item);
       
   348 
       
   349     // Cancelled, but the document will still have been added to the IndexDB
       
   350     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   351     TS_ASSERT(result == 1);
       
   352     }
       
   353 
       
   354 void CTestIndexer::testUpdateL()
       
   355     {
       
   356     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   357     TS_ASSERT(result == 0);
       
   358 
       
   359     // add the file once
       
   360     CreateFileIndexItemL(KTestFileAct0);
       
   361     
       
   362     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   363     TS_ASSERT(result == 1);
       
   364 
       
   365     // now update the same document
       
   366     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, 
       
   367             KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   368     iIndexer->UpdateL(*index_item);
       
   369     CleanupStack::PopAndDestroy(index_item);
       
   370     
       
   371     // As the document has been updated the amount of search hits
       
   372     // must remain the same as before.
       
   373     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   374     TS_ASSERT(result == 1);
       
   375     }
       
   376 
       
   377 
       
   378 void CTestIndexer::testAsyncUpdateL()
       
   379     {
       
   380     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   381     TS_ASSERT(result == 0);
       
   382 
       
   383     // add the file once
       
   384     CreateFileIndexItemL(KTestFileAct0);
       
   385     
       
   386     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   387     TS_ASSERT(result == 1);
       
   388 
       
   389     // now update the same document
       
   390     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, 
       
   391             KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   392     iIndexer->UpdateL(*this, *index_item);
       
   393     CleanupStack::PopAndDestroy(index_item);
       
   394 
       
   395     iWait->Start();
       
   396 
       
   397     // As the document has been updated the amount of search hits
       
   398     // must remain the same as before.
       
   399     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   400     TS_ASSERT(result == 1);
       
   401     }
       
   402 
       
   403 void CTestIndexer::testDeleteL()
       
   404     {
       
   405     // At the start this term will not be in the indexDb
       
   406     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   407     TS_ASSERT(result == 0); 
       
   408 
       
   409     CreateFileIndexItemL(KTestFileAct0);
       
   410     CreateFileIndexItemL(KTestFileAct1);
       
   411     CreateFileIndexItemL(KTestFileAct2);
       
   412     CreateFileIndexItemL(KTestFileAct3);
       
   413     CreateFileIndexItemL(KTestFileAct4);
       
   414     CreateFileIndexItemL(KTestFileAct5);
       
   415     CreateFileIndexItemL(KTestFileAct6);
       
   416     CreateFileIndexItemL(KTestFileActComplete);
       
   417     CreateFileIndexItemL(KTestFileActIndex);
       
   418     CreateFileIndexItemL(KTestFileActIntro);
       
   419 
       
   420     // This term should only result in one result in (KTestFileAct0)
       
   421     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   422     TS_ASSERT(result == 1); 
       
   423 
       
   424     // Now delete the DocUid containing the above search result.
       
   425     if (iIndexer)
       
   426         {
       
   427         iIndexer->DeleteL(KTestFileAct0);
       
   428         }
       
   429 
       
   430     // Now that deleted act0.txt, the same search must yield zero results.
       
   431     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   432     TS_ASSERT(result == 0);
       
   433     }
       
   434 
       
   435 void CTestIndexer::testAsyncDeleteL()
       
   436     {
       
   437     // At the start this term will not be in the indexDb
       
   438     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   439     TS_ASSERT(result == 0); 
       
   440 
       
   441     CreateFileIndexItemL(KTestFileAct0);
       
   442     CreateFileIndexItemL(KTestFileAct1);
       
   443     CreateFileIndexItemL(KTestFileAct2);
       
   444     CreateFileIndexItemL(KTestFileAct3);
       
   445     CreateFileIndexItemL(KTestFileAct4);
       
   446     CreateFileIndexItemL(KTestFileAct5);
       
   447     CreateFileIndexItemL(KTestFileAct6);
       
   448     CreateFileIndexItemL(KTestFileActComplete);
       
   449     CreateFileIndexItemL(KTestFileActIndex);
       
   450     CreateFileIndexItemL(KTestFileActIntro);
       
   451 
       
   452     // This term should only result in one result in (KTestFileAct0)
       
   453     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   454     TS_ASSERT(result == 1); 
       
   455 
       
   456     // Now delete the DocUid containing the above search result.
       
   457     if (iIndexer)
       
   458         {
       
   459         iIndexer->DeleteL(*this, KTestFileAct0);
       
   460         }
       
   461     iWait->Start();
       
   462 
       
   463     // Now that deleted act0.txt, the same search must yield zero results.
       
   464     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   465     TS_ASSERT(result == 0);
       
   466     }
       
   467 
       
   468 void CTestIndexer::testResetL()
       
   469     {
       
   470     // At the start this term will not be in the indexDb
       
   471     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   472     TS_ASSERT(result == 0); 
       
   473 
       
   474     CreateFileIndexItemL(KTestFileAct0);
       
   475 
       
   476     // This term should only result in one result in (KTestFileAct0)
       
   477     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   478     TS_ASSERT(result == 1); 
       
   479 
       
   480     iIndexer->ResetL();
       
   481 
       
   482     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   483     TS_ASSERT(result == 0);
       
   484     }
       
   485 
       
   486 void CTestIndexer::testFlushL()
       
   487     {
       
   488     // At the start this term will not be in the indexDb
       
   489     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   490     TS_ASSERT(result == 0); 
       
   491 
       
   492     // creating CSearchDocument object with unique ID for this application
       
   493     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   494 
       
   495     // Send for indexing
       
   496     if (iIndexer)
       
   497         {
       
   498         iIndexer->AddL(*index_item);
       
   499         }
       
   500     CleanupStack::PopAndDestroy(index_item);
       
   501     
       
   502     // No flush. Term should not be in the indexDb
       
   503     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   504     
       
   505     // TODO: Feature not yet in CPix. Change when flush is required.
       
   506     //TS_ASSERT(result == 0); 
       
   507     TS_ASSERT(result == 1); 
       
   508 
       
   509     iIndexer->FlushL();
       
   510 
       
   511     // After flush there should be one result.
       
   512     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   513     TS_ASSERT(result == 1); 
       
   514     }
       
   515 
       
   516 void CTestIndexer::testAsyncFlushL()
       
   517     {
       
   518     // At the start this term will not be in the indexDb
       
   519     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   520     TS_ASSERT(result == 0); 
       
   521 
       
   522     // creating CSearchDocument object with unique ID for this application
       
   523     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   524 
       
   525     // Send for indexing
       
   526     if (iIndexer)
       
   527         {
       
   528         iIndexer->AddL(*index_item);
       
   529         }
       
   530     CleanupStack::PopAndDestroy(index_item);
       
   531     
       
   532     // No flush. Term should not be in the indexDb
       
   533     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   534     
       
   535     // TODO: Feature not yet in CPix. Change when flush is required.
       
   536     //TS_ASSERT(result == 0); 
       
   537     TS_ASSERT(result == 1); 
       
   538 
       
   539     iIndexer->FlushL(*this);
       
   540     iWait->Start();
       
   541 
       
   542     // After flush term should be in the indexDb
       
   543     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   544     TS_ASSERT(result == 1); 
       
   545     }
       
   546 
       
   547 void CTestIndexer::testAsyncResetL()
       
   548     {
       
   549     // At the start this term will not be in the indexDb
       
   550     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   551     TS_ASSERT(result == 0); 
       
   552 
       
   553     CreateFileIndexItemL(KTestFileAct0);
       
   554 
       
   555     // This term should only result in one result in (KTestFileAct0)
       
   556     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   557     TS_ASSERT(result == 1); 
       
   558 
       
   559     iIndexer->ResetL(*this);
       
   560     
       
   561     iWait->Start();
       
   562 
       
   563     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   564     TS_ASSERT(result == 0);
       
   565     }
       
   566 
       
   567 void CTestIndexer::testHandleIndexingResultL_Leaves()
       
   568     {
       
   569     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   570 
       
   571     iIndexer->AddL(*iHandleResultLeaves, *index_item);
       
   572 
       
   573     CleanupStack::PopAndDestroy(index_item);
       
   574 
       
   575     iHandleResultLeaves->iWait->Start();
       
   576     // There should be no panic !!!
       
   577     }
       
   578 
       
   579 void CTestIndexer::testSetAnalyzerAsync()
       
   580     {
       
   581     TInt result = 0;//pass default
       
   582     if(iIndexer->IsDatabaseOpen())
       
   583         {
       
   584         const TDesC& db = iIndexer->GetBaseAppClass();//Increase Coverage
       
   585         if(db.Length() == 0)
       
   586             {
       
   587             //Set result to Zero
       
   588             result = 1; //DB failed
       
   589             }
       
   590         }
       
   591     else
       
   592         {
       
   593         const TDesC& db = iIndexer->GetBaseAppClass();//Increase Coverage
       
   594         }
       
   595     iIndexer->SetAnalyzerL(*this,_L( "" CPIX_ANALYZER_STANDARD ));
       
   596     iWait->Start();//wait till it returns
       
   597     TS_ASSERT(result == 0);
       
   598     }
       
   599 
       
   600 void CTestIndexer::testSearchSession()
       
   601     {
       
   602     TInt result = 0;//pass default
       
   603     result = iSession.ForceHouseKeeping();
       
   604     TS_ASSERT(result == KErrNone);
       
   605     result = iSession.ContinueHouseKeeping();
       
   606     TS_ASSERT(result == KErrNone);
       
   607     result = iSession.StopHouseKeeping();
       
   608     TS_ASSERT(result == KErrNone);
       
   609     }