searcher/tsrc/cpixsearchertest/src/cpixsearchertester.cpp
changeset 1 6f2c1c46032b
parent 0 671dee74050a
child 14 8bd192d47aaa
equal deleted inserted replaced
0:671dee74050a 1:6f2c1c46032b
    24 #include "CSearchDocument.h"
    24 #include "CSearchDocument.h"
    25 #include "CCPixIndexer.h"
    25 #include "CCPixIndexer.h"
    26 #include "common.h"
    26 #include "common.h"
    27 
    27 
    28 #define TS_ASSERT(a) \
    28 #define TS_ASSERT(a) \
    29     if ( !a ) return KErrNotFound 
    29     if ( !a ) User::Leave(KErrNotFound) 
    30 
    30 
    31 _LIT(KQueryString, "act");
    31 _LIT(KQueryString, "act");
    32 
    32 
    33 _LIT(KCpixRegFile, "c:\\private\\2001f6f7\\cpixreg.txt");
    33 _LIT(KCpixRegFile, "c:\\private\\2001f6f7\\cpixreg.txt");
    34 
    34 
    67     CSearchDocument* doc = CSearchDocument::NewLC(aFileName, KNullDesC, KNullDesC, CSearchDocument::EFileParser);   
    67     CSearchDocument* doc = CSearchDocument::NewLC(aFileName, KNullDesC, KNullDesC, CSearchDocument::EFileParser);   
    68     iIndexer->AddL(*doc);
    68     iIndexer->AddL(*doc);
    69     CleanupStack::PopAndDestroy(doc);
    69     CleanupStack::PopAndDestroy(doc);
    70     }
    70     }
    71 
    71 
    72 void CTestSearcher::setUp()
    72 void CTestSearcher::initialsetUp()
    73     {
    73     {
    74     iFs.Connect();
       
    75     User::LeaveIfError(iSession.Connect());
    74     User::LeaveIfError(iSession.Connect());
    76 
       
    77     
       
    78     iSession.UnDefineVolume(KTestFileBaseAppClassC);
    75     iSession.UnDefineVolume(KTestFileBaseAppClassC);
    79     // define a test volume
    76     // define a test volume
    80     iSession.DefineVolume(KTestFileBaseAppClassC, KNullDesC);
    77     iSession.DefineVolume(KTestFileBaseAppClassC, KNullDesC);
    81 
    78     }
       
    79 
       
    80 void CTestSearcher::createandinitindexer()
       
    81     {
    82     iIndexer = CCPixIndexer::NewL(iSession);
    82     iIndexer = CCPixIndexer::NewL(iSession);
    83     iIndexer->OpenDatabaseL(KTestFileBaseAppClassC);
    83     iIndexer->OpenDatabaseL(KTestFileBaseAppClassC);
    84     iIndexer->ResetL();
    84     iIndexer->ResetL();
    85     
    85     }
    86     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act0.txt")); 
    86 
    87     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act1.txt")); 
    87 void CTestSearcher::createsearcher()
    88     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act2.txt")); 
    88     {
    89     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act3.txt")); 
       
    90     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act4.txt")); 
       
    91     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act5.txt")); 
       
    92     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act6.txt")); 
       
    93     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\complete.txt")); 
       
    94     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\index.txt"));    
       
    95     AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\introduction.txt")); 
       
    96 
       
    97     iSearcher = CCPixSearcher::NewL(iSession);
    89     iSearcher = CCPixSearcher::NewL(iSession);
    98     iSearcher->OpenDatabaseL(KTestFileBaseAppClassC);
    90     iSearcher->OpenDatabaseL(KTestFileBaseAppClassC);
    99 
    91     }
       
    92 
       
    93 void CTestSearcher::harvesttestcontent( TInt aCount )
       
    94     {
       
    95     for (int i = 0; i < aCount; i++)
       
    96         {
       
    97         switch (i)
       
    98             {
       
    99             case 0:
       
   100                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act0.txt")); 
       
   101                 break;
       
   102             case 1:
       
   103                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act1.txt")); 
       
   104                 break;
       
   105             case 2:
       
   106                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act2.txt")); 
       
   107                 break;
       
   108             case 3:
       
   109                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act3.txt")); 
       
   110                 break;
       
   111             case 4:
       
   112                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act4.txt")); 
       
   113                 break;
       
   114             case 5:
       
   115                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act5.txt")); 
       
   116                 break;
       
   117             case 6:
       
   118                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\act6.txt")); 
       
   119                 break;
       
   120             case 7:
       
   121                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\complete.txt")); 
       
   122                 break;
       
   123             case 8:
       
   124                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\index.txt"));    
       
   125                 break;
       
   126             default:
       
   127                 AddFileToIndexL(_L("c:\\Data\\cpixS60unittest\\introduction.txt"));
       
   128                 break;
       
   129             }
       
   130         }
       
   131     }
       
   132 
       
   133 void CTestSearcher::InitAsyncComponents()
       
   134     {
       
   135     
   100     // iWait will cause waiting until some asynchronous event has happened
   136     // iWait will cause waiting until some asynchronous event has happened
   101     iWait = new (ELeave) CActiveSchedulerWait;
   137     iWait = new (ELeave) CActiveSchedulerWait;
   102     iMyAOClass = CAOTestClass::NewL(this);
   138     iMyAOClass = CAOTestClass::NewL(this);
   103     iDocumentCount = 0;
   139     iDocumentCount = 0;
   104     iDocument = NULL;
   140     iDocument = NULL;
   105     iHandleDocumentLFunctionCalled = EFalse;
   141     iHandleDocumentLFunctionCalled = EFalse;
   106     iHandleSetAnalyzerCalled = EFalse;
   142     iHandleSetAnalyzerCalled = EFalse;
   107     }
   143     }
   108 
   144 
   109 void CTestSearcher::tearDown()
   145 void CTestSearcher::ReleaseIndexer()
   110     {
   146     {
   111     iDocumentCount = 0;
   147     if (iIndexer)
   112 
   148         {
       
   149         iIndexer->ResetL();
       
   150         }
       
   151     delete iIndexer;
       
   152     iIndexer = NULL;
       
   153     }
       
   154 void CTestSearcher::ReleaseSearcher()
       
   155     {
   113     delete iSearcher;
   156     delete iSearcher;
   114     iSearcher = NULL;
   157     iSearcher = NULL;
   115 
   158     }
       
   159 
       
   160 void CTestSearcher::ReleaseAsyncComponents()
       
   161     {
       
   162     iDocumentCount = 0;
   116     if ( iDocument )
   163     if ( iDocument )
   117         {
   164         {
   118         delete iDocument;
   165         delete iDocument;
   119         iDocument = NULL;
   166         iDocument = NULL;
   120         }
   167         }
   121 
       
   122     if (iIndexer)
       
   123         {
       
   124         iIndexer->ResetL();
       
   125         }
       
   126 
       
   127     if( iWait )
   168     if( iWait )
   128         {
   169         {
   129         delete iWait;
   170         delete iWait;
   130         iWait = NULL;
   171         iWait = NULL;
   131         }
   172         }
   132     
   173         
   133     if( iMyAOClass )
   174     if( iMyAOClass )
   134         {
   175         {
   135         delete iMyAOClass;
   176         delete iMyAOClass;
   136         iMyAOClass = NULL;
   177         iMyAOClass = NULL;
   137         }
   178         }
   138 
   179     }
   139     delete iIndexer;
   180 void CTestSearcher::tearDown()
   140     iIndexer = NULL;
   181     {    
   141 
       
   142     // undefine a test volume
   182     // undefine a test volume
   143     iSession.UnDefineVolume(KTestFileBaseAppClassC);
   183     iSession.UnDefineVolume(KTestFileBaseAppClassC);
   144 
   184 
   145     iSession.Close();
   185     iSession.Close();
   146     iFs.Close();
   186     iFs.Close();
   202         {
   242         {
   203         iWait->AsyncStop();
   243         iWait->AsyncStop();
   204         }
   244         }
   205     }
   245     }
   206 
   246 
   207 TInt CTestSearcher::testKnownTermTestsL()
   247 void CTestSearcher::testKnownTermTestsL()
   208     {
   248     {
   209     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS > 0
   249     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS > 0
   210     TInt result = SearchForTextL(KQueryString, KNullDesC);
   250     TInt result = SearchForTextL(KQueryString, KNullDesC);
   211     TS_ASSERT(result > 0);
   251     TS_ASSERT(result > 0);
   212     
   252     
   217     if(result > 0)
   257     if(result > 0)
   218         {
   258         {
   219         for (TInt i=0; i<result; i++)
   259         for (TInt i=0; i<result; i++)
   220             {
   260             {
   221             CSearchDocument* document = iSearcher->GetDocumentL(i);     
   261             CSearchDocument* document = iSearcher->GetDocumentL(i);     
   222             //TS_ASSERT(document != NULL);
   262             TS_ASSERT(document != NULL);
   223             delete document;
   263             delete document;
   224             }
   264             }
   225         }
   265         }
   226         
   266         
   227     
   267     
   232     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS == 0, but not in this field
   272     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS == 0, but not in this field
   233     result = SearchForTextL(KQueryString, KNonExistentField);
   273     result = SearchForTextL(KQueryString, KNonExistentField);
   234     TS_ASSERT(result == 0);
   274     TS_ASSERT(result == 0);
   235 
   275 
   236     // can search for a known value in a different field
   276     // can search for a known value in a different field
   237     result = SearchForTextL(KRootFileUserTxt, KAppClassField);
   277     result = SearchForTextL(_L("usrdoc"), KAppClassField);
   238     TS_ASSERT(result > 0);
   278     TS_ASSERT(result > 0);
   239 
   279 
   240     // can search for a known value in a different field
   280     // can search for a known value in a different field
   241 //  result = SearchForTextL(KRootFileUserTxt, KNonExistentField);
   281     result = SearchForTextL(_L("usrdoc"), KNonExistentField);
   242 //  TS_ASSERT(result == 0); // TODO XXX TIM why does searching for an existing term in a non-existent field return a non-zero value
   282     TS_ASSERT(result == 0); // TODO XXX TIM why does searching for an existing term in a non-existent field return a non-zero value    
   243     return KErrNone;
       
   244     }
   283     }
   245 
   284 
   246 void CTestSearcher::testWildcardTermTests()
   285 void CTestSearcher::testWildcardTermTests()
   247     {
   286     {
   248     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS > 0
   287     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS > 0
   249     TInt result = SearchForTextL(_L("a*t"), KNullDesC);
   288     TInt result = SearchForTextL(_L("a*t"), KNullDesC);
   250     //TS_ASSERT(result > 0);
   289     TS_ASSERT(result > 0);
   251 
   290 
   252     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS > 0
   291     // Shakespeare's corpus files have plenty of terms "act" in them EXPECTED RESULTS > 0
   253     result = SearchForTextL(_L("sc*ne"), KNullDesC);
   292     result = SearchForTextL(_L("sc*ne"), KNullDesC);
   254    // TS_ASSERT(result > 0);
   293     TS_ASSERT(result > 0);
   255     }
   294     }
   256 
   295 
   257 void CTestSearcher::testDefineVolumeWorksNonEmptyPath()
   296 void CTestSearcher::testDefineVolumeWorksNonEmptyPath()
   258     {
   297     {
   259     TBuf8<KMaxFileSize> cpixRegBuf;
   298     TBuf8<KMaxFileSize> cpixRegBuf;
   260 
   299     iFs.Connect();
   261     // open up the cpixreg.txt file again and make sure 
   300     // open up the cpixreg.txt file again and make sure 
   262     // that it IS NOT in there
   301     // that it IS NOT in there
   263     TInt err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   302     TInt err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   264     iFile.Read(0, cpixRegBuf);
   303     iFile.Read(0, cpixRegBuf);
   265     err = cpixRegBuf.Find(KRootMapsGbr8());
   304     err = cpixRegBuf.Find(KRootMapsGbr8());
   266    // TS_ASSERT(KErrNotFound == err);
   305     TS_ASSERT(KErrNotFound == err);
   267     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   306     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   268    // TS_ASSERT(KErrNotFound == err);
   307     TS_ASSERT(KErrNotFound == err);
   269     iFile.Close();
   308     iFile.Close();
   270 
   309 
   271     // define a new volume
   310     // define a new volume
   272     err = iSession.DefineVolume(KRootMapsGbr, KRootMapsGbrPath);
   311     err = iSession.DefineVolume(KRootMapsGbr, KRootMapsGbrPath);
   273    // TS_ASSERT(err == KErrNone);
   312     TS_ASSERT(err == KErrNone);
   274 
   313 
   275     // open up the cpixreg.txt file and make sure that it IS in there
   314     // open up the cpixreg.txt file and make sure that it IS in there
   276     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   315     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   277     iFile.Read(0, cpixRegBuf);
   316     iFile.Read(0, cpixRegBuf);
   278     err = cpixRegBuf.Find(KRootMapsGbr8());
   317     err = cpixRegBuf.Find(KRootMapsGbr8());
   279    // TS_ASSERT(KErrNotFound != err);
   318     TS_ASSERT(KErrNotFound != err);
   280     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   319     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   281    // TS_ASSERT(KErrNotFound != err);
   320     TS_ASSERT(KErrNotFound != err);
   282     iFile.Close();
   321     iFile.Close();
   283 
   322 
   284     // now undefine the same volume
   323     // now undefine the same volume
   285     err = iSession.UnDefineVolume(KRootMapsGbr);
   324     err = iSession.UnDefineVolume(KRootMapsGbr);
   286    // TS_ASSERT(err == KErrNone);
   325     TS_ASSERT(err == KErrNone);
   287 
   326 
   288     // open up the cpixreg.txt file again and make sure 
   327     // open up the cpixreg.txt file again and make sure 
   289     // that it IS NOT in there
   328     // that it IS NOT in there
   290     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   329     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   291     iFile.Read(0, cpixRegBuf);
   330     iFile.Read(0, cpixRegBuf);
   292     err = cpixRegBuf.Find(KRootMapsGbr8());
   331     err = cpixRegBuf.Find(KRootMapsGbr8());
   293    // TS_ASSERT(KErrNotFound == err);
   332     TS_ASSERT(KErrNotFound == err);
   294     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   333     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   295    // TS_ASSERT(KErrNotFound == err);
   334     TS_ASSERT(KErrNotFound == err);
   296     iFile.Close();
   335     iFile.Close();
   297     }
   336     }
   298 
   337 
   299 void CTestSearcher::testDefineVolumeWorksWithEmptyPath()
   338 void CTestSearcher::testDefineVolumeWorksWithEmptyPath()
   300     {
   339     {
   301     TBuf8<KMaxFileSize> cpixRegBuf;
   340     TBuf8<KMaxFileSize> cpixRegBuf;
   302 
   341     iFs.Connect();
   303     // open up the cpixreg.txt file again and make sure 
   342     // open up the cpixreg.txt file again and make sure 
   304     // that it IS NOT in there
   343     // that it IS NOT in there
   305     TInt err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   344     TInt err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   306     iFile.Read(0, cpixRegBuf);
   345     iFile.Read(0, cpixRegBuf);
   307     err = cpixRegBuf.Find(KRootMapsGbr8());
   346     err = cpixRegBuf.Find(KRootMapsGbr8());
   308   //  TS_ASSERT(KErrNotFound == err);
   347     TS_ASSERT(KErrNotFound == err);
   309     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   348     err = cpixRegBuf.Find(KRootMapsGbrPath8());
   310   //  TS_ASSERT(KErrNotFound == err);
   349     TS_ASSERT(KErrNotFound == err);
   311     iFile.Close();
   350     iFile.Close();
   312 
   351 
   313     // define a new volume
   352     // define a new volume
   314     err = iSession.DefineVolume(KRootMapsGbr, KNullDesC);
   353     err = iSession.DefineVolume(KRootMapsGbr, KNullDesC);
   315   //  TS_ASSERT(err == KErrNone);
   354     TS_ASSERT(err == KErrNone);
   316 
   355 
   317     // open up the cpixreg.txt file and make sure that it IS in there
   356     // open up the cpixreg.txt file and make sure that it IS in there
   318     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   357     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   319     iFile.Read(0, cpixRegBuf);
   358     iFile.Read(0, cpixRegBuf);
   320     err = cpixRegBuf.Find(KRootMapsGbr8());
   359     err = cpixRegBuf.Find(KRootMapsGbr8());
   321   //  TS_ASSERT(KErrNotFound != err);
   360     TS_ASSERT(KErrNotFound != err);
   322     iFile.Close();
   361     iFile.Close();
   323 
   362 
   324     // now try to redefine the same volume again
   363     // now try to redefine the same volume again
   325     err = iSession.DefineVolume(KRootMapsGbr, KNullDesC);
   364     err = iSession.DefineVolume(KRootMapsGbr, KNullDesC);
   326   //  TS_ASSERT(err == KErrNone);
   365     TS_ASSERT(err == KErrNone);
   327 
   366 
   328     // now undefine the same volume
   367     // now undefine the same volume
   329     err = iSession.UnDefineVolume(KRootMapsGbr);
   368     err = iSession.UnDefineVolume(KRootMapsGbr);
   330   //  TS_ASSERT(err == KErrNone);
   369     TS_ASSERT(err == KErrNone);
   331 
   370 
   332     // open up the cpixreg.txt file again and make sure 
   371     // open up the cpixreg.txt file again and make sure 
   333     // that it IS NOT in there
   372     // that it IS NOT in there
   334     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   373     err = iFile.Open(iFs, KCpixRegFile, EFileStreamText);
   335     iFile.Read(0, cpixRegBuf);
   374     iFile.Read(0, cpixRegBuf);
   336     err = cpixRegBuf.Find(KRootMapsGbr8());
   375     err = cpixRegBuf.Find(KRootMapsGbr8());
   337   //  TS_ASSERT(KErrNotFound == err);
   376     TS_ASSERT(KErrNotFound == err);
   338     iFile.Close();
   377     iFile.Close();
   339     }
   378     }
   340 
   379 
   341 void CTestSearcher::testDefineVolumeErrorScenarios()
   380 void CTestSearcher::testDefineVolumeErrorScenarios()
   342     {
   381     {
   343     // Attempt to define a volume for a invalid qualified base app classes.
   382     // Attempt to define a volume for a invalid qualified base app classes.
   344     TInt result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass1, KNullDesC);
   383     TInt result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass1, KNullDesC);
   345  //   TS_ASSERT(result == KErrCannotDefineVolume);
   384     TS_ASSERT(result == KErrCannotDefineVolume);
   346 
   385 
   347     result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass2, KNullDesC);
   386     result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass2, KNullDesC);
   348  //   TS_ASSERT(result == KErrCannotDefineVolume);
   387     TS_ASSERT(result == KErrCannotDefineVolume);
   349 
   388 
   350     result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass3, KNullDesC);
   389     result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass3, KNullDesC);
   351   //  TS_ASSERT(result == KErrCannotDefineVolume);
   390     TS_ASSERT(result == KErrCannotDefineVolume);
   352 
   391 
   353     result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass4, KNullDesC);
   392     result = iSession.DefineVolume(KInvalidQualifiedBaseAppClass4, KNullDesC);
   354   //  TS_ASSERT(result == KErrCannotDefineVolume);
   393     TS_ASSERT(result == KErrCannotDefineVolume);
   355 
   394 
   356     // Attempt to undefine a volume that was not defined.
   395     // Attempt to undefine a volume that was not defined.
   357     result = iSession.UnDefineVolume(KRootMapsGbr);
   396     result = iSession.UnDefineVolume(KRootMapsGbr);
   358   //  TS_ASSERT(result == KErrNone);
   397     TS_ASSERT(result == KErrNone);
   359     }
   398     }
   360 
   399 
   361 void CTestSearcher::testSearchCancellation()
   400 void CTestSearcher::testSearchCancellation()
   362     {
   401     {
   363     // Test basic cancellation of search request
   402     // Test basic cancellation of search request
   369     // to be triggered.
   408     // to be triggered.
   370     iMyAOClass->StartL(1000000*20); //Async call: Maximum TimeOut time 20 seconds
   409     iMyAOClass->StartL(1000000*20); //Async call: Maximum TimeOut time 20 seconds
   371 
   410 
   372     // Wait until either HandleSearchResultsL or Timeout exceeded
   411     // Wait until either HandleSearchResultsL or Timeout exceeded
   373     iWait->Start();
   412     iWait->Start();
   374    // TS_ASSERT(iDocumentCount == 0);
   413     TS_ASSERT(iDocumentCount == 0);
   375 
   414 
   376     // Now make sure that subsequent searches work correctly
   415     // Now make sure that subsequent searches work correctly
   377     iSearcher->SearchL(*this, KQueryString);
   416     iSearcher->SearchL(*this, KQueryString);
   378     // Wait until HandleSearchResultsL completes
   417     // Wait until HandleSearchResultsL completes
   379     iWait->Start();
   418     iWait->Start();
   380 
   419 
   381    // TS_ASSERT(iDocumentCount > 0);
   420     TS_ASSERT(iDocumentCount > 0);
   382     }
   421     }
   383 
   422 
   384 void CTestSearcher::testSearchAsynchronous()
   423 void CTestSearcher::testSearchAsynchronous()
   385     {
   424     {
   386     iSearcher->SearchL(*this, KQueryString);
   425     iSearcher->SearchL(*this, KQueryString);
   387     // Wait until HandleSearchResultsL completes
   426     // Wait until HandleSearchResultsL completes
   388     iWait->Start();
   427     iWait->Start();
   389 
   428 
   390   //  TS_ASSERT(iDocumentCount > 0);
   429     TS_ASSERT(iDocumentCount > 0);
   391     }
   430     }
   392 
   431 
   393 void CTestSearcher::testSearchLeavesIfNotCancelled()
   432 void CTestSearcher::testSearchLeavesIfNotCancelled()
   394     {
   433     {
   395     // Perform first search
   434     // Perform first search
   396     TRAPD(err, iSearcher->SearchL(*this, KQueryString) );
   435     TRAPD(err, iSearcher->SearchL(*this, KQueryString) );
   397    // TS_ASSERT(iDocumentCount == 0);
   436     TS_ASSERT(iDocumentCount == 0);
   398    // TS_ASSERT(err == KErrNone);
   437     TS_ASSERT(err == KErrNone);
   399 
   438 
   400     // before ::HandleSearchResults has been called, 
   439     // before ::HandleSearchResults has been called, 
   401     // initiate a second search. 
   440     // initiate a second search. 
   402     TRAP(err, iSearcher->SearchL(*this, KQueryString));
   441     TRAP(err, iSearcher->SearchL(*this, KQueryString));
   403   //  TS_ASSERT(err == KErrInUse);
   442     TS_ASSERT(err == KErrInUse);
   404 
   443 
   405     // Wait until HandleSearchResultsL completes
   444     // Wait until HandleSearchResultsL completes
   406     iWait->Start();
   445     iWait->Start();
   407 
   446 
   408    // TS_ASSERT(iDocumentCount > 0);
   447     TS_ASSERT(iDocumentCount > 0);
   409     }
   448     }
   410 
   449 
   411 void CTestSearcher::testOpenIndexDb()
   450 void CTestSearcher::testOpenIndexDb()
   412     {
   451     {
   413     // Make sure cannot open an invalid index db
   452     // Make sure cannot open an invalid index db
   414     _LIT(KInvalidQualifiedBaseAppClass, "@x:test invalid");
   453     _LIT(KInvalidQualifiedBaseAppClass, "@x:test invalid");
   415     CCPixSearcher* searcher = CCPixSearcher::NewLC(iSession);
   454     CCPixSearcher* searcher = CCPixSearcher::NewLC(iSession);
   416     TRAPD(err, searcher->OpenDatabaseL(KInvalidQualifiedBaseAppClass) );
   455     TRAPD(err, searcher->OpenDatabaseL(KInvalidQualifiedBaseAppClass) );
   417    // TS_ASSERT(!searcher->IsDatabaseOpen());
   456     TS_ASSERT(!searcher->IsDatabaseOpen());
   418    // TS_ASSERT(err == KErrCannotOpenDatabase);
   457     TS_ASSERT(err == KErrCannotOpenDatabase);
   419     TRAP(err, searcher->SearchL(KQueryString));
   458     TRAP(err, searcher->SearchL(KQueryString));
   420    // TS_ASSERT(err == KErrNotReady);
   459     TS_ASSERT(err == KErrNotReady);
   421     CleanupStack::PopAndDestroy(searcher);
   460     CleanupStack::PopAndDestroy(searcher);
   422 
   461 
   423     searcher = NULL; 
   462     searcher = NULL; 
   424 
   463 
   425     // check that same searcher object can open a second indexDb
   464     // check that same searcher object can open a second indexDb
   426     searcher = CCPixSearcher::NewLC(iSession);
   465     searcher = CCPixSearcher::NewLC(iSession);
   427     TRAP(err, searcher->OpenDatabaseL(_L("root")));
   466     TRAP(err, searcher->OpenDatabaseL(_L("root")));
   428   //  TS_ASSERT(searcher->IsDatabaseOpen());
   467     TS_ASSERT(searcher->IsDatabaseOpen());
   429     searcher->SearchL(KQueryString);
   468     searcher->SearchL(KQueryString);
   430   //  TS_ASSERT(err == KErrNone);
   469     TS_ASSERT(err == KErrNone);
   431 
   470 
   432     TRAP(err, searcher->OpenDatabaseL(KTestFileBaseAppClassC));
   471     TRAP(err, searcher->OpenDatabaseL(KTestFileBaseAppClassC));
   433    // TS_ASSERT(err == KErrNone);
   472     TS_ASSERT(err == KErrNone);
   434    // TS_ASSERT(searcher->IsDatabaseOpen());
   473     TS_ASSERT(searcher->IsDatabaseOpen());
   435     const TInt docCount = searcher->SearchL(KQueryString);
   474     const TInt docCount = searcher->SearchL(KQueryString);
   436   //  TS_ASSERT(docCount > 0);
   475     TS_ASSERT(docCount > 0);
   437     CleanupStack::PopAndDestroy(searcher);
   476     CleanupStack::PopAndDestroy(searcher);
   438 
   477 
   439     searcher = NULL; 
   478     searcher = NULL; 
   440 
   479 
   441     // check that asynchronous open works as expected
   480     // check that asynchronous open works as expected
   446     // uncomment this line, which will cause CTestSearcher::CallCompleted
   485     // uncomment this line, which will cause CTestSearcher::CallCompleted
   447     // to be triggered.
   486     // to be triggered.
   448     iMyAOClass->StartL(1000000*10); //Async call: Maximum TimeOut time 10 seconds
   487     iMyAOClass->StartL(1000000*10); //Async call: Maximum TimeOut time 10 seconds
   449 
   488 
   450     iWait->Start();
   489     iWait->Start();
   451   //  TS_ASSERT(searcher->IsDatabaseOpen());
   490     TS_ASSERT(searcher->IsDatabaseOpen());
   452     CleanupStack::PopAndDestroy(searcher);
   491     CleanupStack::PopAndDestroy(searcher);
   453     }
   492     }
   454 
   493 
   455 void CTestSearcher::testDeleteIndexDbWhileSearching()
   494 void CTestSearcher::testDeleteIndexDbWhileSearching()
   456     {
   495     {
   457     CCPixSearcher* searcher = CCPixSearcher::NewLC(iSession);
   496     CCPixSearcher* searcher = CCPixSearcher::NewLC(iSession);
   458     TRAPD(err, searcher->OpenDatabaseL(KTestFileBaseAppClassC) );
   497     TRAPD(err, searcher->OpenDatabaseL(KTestFileBaseAppClassC) );
   459    // TS_ASSERT(searcher->IsDatabaseOpen());
   498     TS_ASSERT(searcher->IsDatabaseOpen());
   460   //  TS_ASSERT(searcher->GetBaseAppClass() != KNullDesC);
   499     //TS_ASSERT(searcher->GetBaseAppClass() != KNullDesC);
       
   500     TS_ASSERT( (searcher->GetBaseAppClass().Compare( KNullDesC)) );
   461     //Set Standard Analyzer to improve code coverage of search
   501     //Set Standard Analyzer to improve code coverage of search
   462     searcher->SetAnalyzerL(*this,_L( "" CPIX_ANALYZER_STANDARD ));
   502     searcher->SetAnalyzerL(*this,_L( "" CPIX_ANALYZER_STANDARD ));
   463     iWait->Start(); //Start Wait AO
   503     iWait->Start(); //Start Wait AO
   464    // TS_ASSERT(iHandleSetAnalyzerCalled);
   504     TS_ASSERT(iHandleSetAnalyzerCalled);
   465     TRAP(err, searcher->SearchL(*this, KQueryString));
   505     TRAP(err, searcher->SearchL(*this, KQueryString));
   466     // don't wait for the search results.
   506     // don't wait for the search results.
   467     CleanupStack::PopAndDestroy(searcher);
   507     CleanupStack::PopAndDestroy(searcher);
   468     searcher = NULL; 
   508     searcher = NULL; 
   469     // is there a panic???
   509     // is there a panic???
   470     }
   510     }
   471 
   511 
   472 void CTestSearcher::testGetDocumentAsync()
   512 void CTestSearcher::testGetDocumentAsync()
   473     {
   513     {
   474     const TInt result = SearchForTextL(KQueryString, KNullDesC);
   514     const TInt result = SearchForTextL(KQueryString, KNullDesC);
   475   //  TS_ASSERT(result > 0);
   515     TS_ASSERT(result > 0);
   476 
   516 
   477     TInt loopCount(0);
   517     TInt loopCount(0);
   478 
   518 
   479     for (loopCount=0; loopCount<result; loopCount++)
   519     for (loopCount=0; loopCount<result; loopCount++)
   480         {
   520         {
   481         iSearcher->GetDocumentL(loopCount, *this);
   521         iSearcher->GetDocumentL(loopCount, *this);
   482         iWait->Start();
   522         iWait->Start();
   483    //     TS_ASSERT(iDocument != NULL);
   523         TS_ASSERT(iDocument != NULL);
   484         delete iDocument;
   524         delete iDocument;
   485         iDocument = NULL;
   525         iDocument = NULL;
   486         }
   526         }
   487 
   527 
   488   //  TS_ASSERT(loopCount == result);
   528     TS_ASSERT(loopCount == result);
   489     }
   529     }
   490 
   530 
   491 void CTestSearcher::testGetInvalidDocumentAsync()
   531 void CTestSearcher::testGetInvalidDocumentAsync()
   492     {
   532     {
   493     const TInt result = SearchForTextL(KQueryString, KNullDesC);
   533     const TInt result = SearchForTextL(KQueryString, KNullDesC);
   494   //  TS_ASSERT(result > 0);
   534     TS_ASSERT(result > 0);
   495 
   535 
   496     // request a document that does not exist. 
   536     // request a document that does not exist. 
   497     TRAPD(err, iSearcher->GetDocumentL(result+1, *this));
   537     TRAPD(err, iSearcher->GetDocumentL(result+1, *this));
   498     // above call is not exepected to leave
   538     // above call is not exepected to leave
   499  //   TS_ASSERT(err == KErrNone);
   539     TS_ASSERT(err == KErrNone);
   500 
   540 
   501    iMyAOClass->StartL(1000000*10); //Async call: Maximum TimeOut time 10 seconds
   541    iMyAOClass->StartL(1000000*10); //Async call: Maximum TimeOut time 10 seconds
   502 
   542 
   503     iWait->Start();
   543     iWait->Start();
   504 
   544 
   505     // Either the iMyAOClass Timeout executed or the the HandleDocumentL
   545     // Either the iMyAOClass Timeout executed or the the HandleDocumentL
   506     // function. If the HandleDocumentL function was executed, then
   546     // function. If the HandleDocumentL function was executed, then
   507     // this assert will be true.
   547     // this assert will be true.
   508   //  TS_ASSERT(iHandleDocumentLFunctionCalled);
   548     TS_ASSERT(iHandleDocumentLFunctionCalled);
   509     // as requested an invalid document, this must be NULL
   549     // as requested an invalid document, this must be NULL
   510   //  TS_ASSERT(iDocument == NULL);
   550     TS_ASSERT(iDocument == NULL);
   511     }
   551     }
       
   552 
       
   553 TInt CTestSearcher::testEcerptLenth()
       
   554     {
       
   555     TInt length = 0;
       
   556     _LIT(KExcerpt , "Transfer the binary output file (found under the traces on the same drive as your activation file, or on the system drive if the drive is a ROM drive) to the PC for viewing." );
       
   557     _LIT ( KFileName , "c:\\Data\\cpixS60unittest\\act0.txt");
       
   558     iIndexer->ResetL();
       
   559     CSearchDocument* doc = CSearchDocument::NewLC( KFileName, KNullDesC, KNullDesC, CSearchDocument::EFileParser );
       
   560     doc->AddExcerptL( KExcerpt );
       
   561     iIndexer->AddL( *doc );
       
   562     CleanupStack::PopAndDestroy( doc );
       
   563     User::After((TTimeIntervalMicroSeconds32)30000000);
       
   564     TInt result = SearchForTextL(KQueryString, KNullDesC);
       
   565     if(result > 0)
       
   566         {
       
   567         CSearchDocument* document = iSearcher->GetDocumentL(0);     
       
   568         TS_ASSERT(document != NULL);
       
   569         length = document->Excerpt().Length();
       
   570         delete document;           
       
   571         }
       
   572     return ( length > 125 )?KErrGeneral:KErrNone;
       
   573     }