searcher/tsrc/cpixsearchertest/src/cpixindexertester.cpp
changeset 1 6f2c1c46032b
parent 0 671dee74050a
equal deleted inserted replaced
0:671dee74050a 1:6f2c1c46032b
    67     iSession.DefineVolume(KFileBaseAppClassC, KNullDesC);
    67     iSession.DefineVolume(KFileBaseAppClassC, KNullDesC);
    68 
    68 
    69     iIndexer = CCPixIndexer::NewL(iSession);
    69     iIndexer = CCPixIndexer::NewL(iSession);
    70     iIndexer->OpenDatabaseL(KFileBaseAppClassC);
    70     iIndexer->OpenDatabaseL(KFileBaseAppClassC);
    71     iIndexer->ResetL();
    71     iIndexer->ResetL();
    72     
    72     }
       
    73 
       
    74 void CTestIndexer::InitSearcher()
       
    75     {
    73     iSearcher = CCPixSearcher::NewL(iSession);
    76     iSearcher = CCPixSearcher::NewL(iSession);
    74     iSearcher->OpenDatabaseL(KFileBaseAppClassC);
    77     iSearcher->OpenDatabaseL(KFileBaseAppClassC);
    75     
    78     }
       
    79 
       
    80 void CTestIndexer::ReleaseSearcher()
       
    81     {
       
    82     delete iSearcher;
       
    83     iSearcher = NULL;
       
    84     }
       
    85 void CTestIndexer::InitAsyncModules()
       
    86     {
    76     iHandleResultLeaves = new (ELeave) CHandleIndexingResultLeaves;
    87     iHandleResultLeaves = new (ELeave) CHandleIndexingResultLeaves;
    77     
    88     iIndexerWait = new (ELeave) CActiveSchedulerWait;
    78     // iWait will cause waiting until some asynchronous event has happened
       
    79     iWait = new (ELeave) CActiveSchedulerWait;
       
    80     iMyAOClass = CAOTestClass::NewL(this);
    89     iMyAOClass = CAOTestClass::NewL(this);
    81     
    90     }
    82     iCurrentIndex = 0;
    91 void CTestIndexer::ReleaseAsyncModules()
    83     }
    92     {
    84 
       
    85 void CTestIndexer::tearDown()
       
    86     {
       
    87     iCurrentIndex = 0;
       
    88 
       
    89     iIndexer->ResetL();
       
    90 
       
    91     if( iMyAOClass )
    93     if( iMyAOClass )
    92         {
    94         {
    93         delete iMyAOClass;
    95         delete iMyAOClass;
    94         iMyAOClass = NULL;
    96         iMyAOClass = NULL;
    95         }
    97         }
    96     
    98     delete iHandleResultLeaves;
       
    99     iHandleResultLeaves = NULL;
       
   100 
       
   101     delete iIndexerWait;
       
   102     }
       
   103 void CTestIndexer::tearDown()
       
   104     {
       
   105     iIndexer->ResetL();    
    97     delete iIndexer;
   106     delete iIndexer;
    98     iIndexer = NULL;
   107     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);
   108     iSession.UnDefineVolume(KFileBaseAppClassC);
   109     iSession.Close();
   109     iSession.Close();
   110     }
   110     }
   111 
   111 
   112 void CTestIndexer::CreateFileIndexItemL(const TDesC& aFilename)
   112 void CTestIndexer::CreateFileIndexItemL(const TDesC& aFilename)
   122         }
   122         }
   123     CleanupStack::PopAndDestroy(index_item);
   123     CleanupStack::PopAndDestroy(index_item);
   124     }
   124     }
   125 
   125 
   126 
   126 
   127 TInt CTestIndexer::SearchForTextL(const TDesC& aQueryString, const TDesC& aDefaultField)
   127 TInt CTestIndexer::SearchForTextL(const TDesC& aQueryString, const TDesC& aDefaultField, TBool aFlush )
   128     {
   128     {
   129     TInt estimatedDocumentCount(KErrNotFound);
   129     TInt estimatedDocumentCount(KErrNotFound);
   130     
   130     
   131     // Make sure CPix flush is done before searching
   131     // Make sure CPix flush is done before searching
   132     if (iIndexer)
   132     if ( aFlush && iIndexer)
   133         {
   133         {
   134         iIndexer->FlushL();
   134         iIndexer->FlushL();
   135         }
   135         }
   136     
   136     
   137     // Send for indexing
   137     // Send for indexing
   170     return result;
   170     return result;
   171     }
   171     }
   172 
   172 
   173 void CTestIndexer::HandleOpenDatabaseResultL( TInt /* aError */ )
   173 void CTestIndexer::HandleOpenDatabaseResultL( TInt /* aError */ )
   174     {
   174     {
   175     if (iWait && iWait->IsStarted())
   175     if (iIndexerWait && iIndexerWait->IsStarted())
   176         {
   176         {
   177         // All done, signal that can continue now.
   177         // All done, signal that can continue now.
   178         iWait->AsyncStop();
   178         iIndexerWait->AsyncStop();
   179         }
   179         }
   180     }
   180     }
   181 
   181 
   182 void CTestIndexer::HandleSetAnalyzerResultL(TInt /*aError*/)
   182 void CTestIndexer::HandleSetAnalyzerResultL(TInt /*aError*/)
   183     {
   183     {
   184     if (iWait && iWait->IsStarted())
   184     if (iIndexerWait && iIndexerWait->IsStarted())
   185         {
   185         {
   186         // All done, signal that can continue now.
   186         // All done, signal that can continue now.
   187         iWait->AsyncStop();
   187         iIndexerWait->AsyncStop();
   188         }
   188         }
   189     }
   189     }
   190 
   190 
   191 void CTestIndexer::HandleIndexingResultL(TInt aError)
   191 void CTestIndexer::HandleIndexingResultL(TInt aError)
   192     {
   192     {
   193     TS_ASSERT(aError == KErrNone);
   193     TS_ASSERT(aError == KErrNone);
   194     
   194     
   195     // if the test case started iWait, then stop it
   195     // if the test case started iIndexerWait, then stop it
   196     if (iWait && iWait->IsStarted())
   196     if (iIndexerWait && iIndexerWait->IsStarted())
   197         {
   197         {
   198         iWait->AsyncStop();
   198         iIndexerWait->AsyncStop();
   199         }
   199         }
   200     }
   200     }
   201 
   201 
   202 // Timeout callback
   202 // Timeout callback
   203 void CTestIndexer::CallCompleted( int /* i */ )
   203 void CTestIndexer::CallCompleted( int /* i */ )
   204     {
   204     {
   205     if (iWait && iWait->IsStarted())
   205     if (iIndexerWait && iIndexerWait->IsStarted())
   206         {
   206         {
   207         iWait->AsyncStop();
   207         iIndexerWait->AsyncStop();
   208         }
   208         }
   209     }
   209     }
   210 
   210 
   211 void CTestIndexer::testOpenIndexDb()
   211 void CTestIndexer::testOpenIndexDb()
   212     {
   212     {
   240     // If want to set a maximum timeout value for this test case then
   240     // If want to set a maximum timeout value for this test case then
   241     // uncomment this line, which will cause CTestSearcher::CallCompleted
   241     // uncomment this line, which will cause CTestSearcher::CallCompleted
   242     // to be triggered.
   242     // to be triggered.
   243     iMyAOClass->StartL(1000000*10); //Async call: Maximum TimeOut time 10 seconds
   243     iMyAOClass->StartL(1000000*10); //Async call: Maximum TimeOut time 10 seconds
   244 
   244 
   245     iWait->Start();
   245     iIndexerWait->Start();
   246     TS_ASSERT(indexer->IsDatabaseOpen());
   246     TS_ASSERT(indexer->IsDatabaseOpen());
   247     CleanupStack::PopAndDestroy(indexer);
   247     CleanupStack::PopAndDestroy(indexer);
   248     }
   248     }
   249 
   249 
   250 void CTestIndexer::testAddL()
   250 void CTestIndexer::testAddL()
   312     // At the start this term will not be in the indexDb
   312     // At the start this term will not be in the indexDb
   313     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   313     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   314     TS_ASSERT(result == 0); 
   314     TS_ASSERT(result == 0); 
   315 
   315 
   316     //Improve code coverage
   316     //Improve code coverage
   317     CSearchDocument* index_item = CSearchDocument::NewL(KTestFileAct0, KNullDesC, _L("excerpt"), CSearchDocument::EFileParser);
   317     CSearchDocument* index_item = CSearchDocument::NewL(KTestFileAct0, KNullDesC, _L("excerpt"), CSearchDocument::EFileParser);    
   318     CleanupStack::PushL(index_item);
   318     CleanupStack::PushL(index_item);
   319     //CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, KNullDesC, KNullDesC, CSearchDocument::EFileParser);
       
   320     
       
   321     iIndexer->AddL(*this, *index_item);
   319     iIndexer->AddL(*this, *index_item);
   322     CleanupStack::PopAndDestroy(index_item);
   320     CleanupStack::PopAndDestroy(index_item);
   323 
   321 
   324     iWait->Start();
   322     iIndexerWait->Start();
   325 
   323     User::After( 30000000 );
   326     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   324     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC, false);
   327     TS_ASSERT(result == 1);
   325     TS_ASSERT(result == 1);
   328     CSearchDocument* doc = iSearcher->GetDocumentL(0);
   326     CSearchDocument* doc = iSearcher->GetDocumentL(0);
   329     TS_ASSERT(doc != NULL);
   327     TS_ASSERT(doc != NULL);
   330     //TS_ASSERT(doc->Excerpt() != KNullDesC);//Should not be NULL
   328     TS_ASSERT(doc->Excerpt() != KNullDesC);//Should not be NULL
   331     delete doc;
   329     delete doc;    
   332     CDocumentField* docField = CDocumentField::NewL(_L("test"),_L("test"));
       
   333     TS_ASSERT(docField != NULL);
       
   334     delete docField;
       
   335     }
   330     }
   336 
   331 
   337 void CTestIndexer::testCancelAddL()
   332 void CTestIndexer::testCancelAddL()
   338     {
   333     {
   339     // At the start this term will not be in the indexDb
   334     // At the start this term will not be in the indexDb
   390     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, 
   385     CSearchDocument* index_item = CSearchDocument::NewLC(KTestFileAct0, 
   391             KNullDesC, KNullDesC, CSearchDocument::EFileParser);
   386             KNullDesC, KNullDesC, CSearchDocument::EFileParser);
   392     iIndexer->UpdateL(*this, *index_item);
   387     iIndexer->UpdateL(*this, *index_item);
   393     CleanupStack::PopAndDestroy(index_item);
   388     CleanupStack::PopAndDestroy(index_item);
   394 
   389 
   395     iWait->Start();
   390     iIndexerWait->Start();
   396 
   391 
   397     // As the document has been updated the amount of search hits
   392     // As the document has been updated the amount of search hits
   398     // must remain the same as before.
   393     // must remain the same as before.
   399     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   394     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   400     TS_ASSERT(result == 1);
   395     TS_ASSERT(result == 1);
   456     // Now delete the DocUid containing the above search result.
   451     // Now delete the DocUid containing the above search result.
   457     if (iIndexer)
   452     if (iIndexer)
   458         {
   453         {
   459         iIndexer->DeleteL(*this, KTestFileAct0);
   454         iIndexer->DeleteL(*this, KTestFileAct0);
   460         }
   455         }
   461     iWait->Start();
   456     iIndexerWait->Start();
   462 
   457 
   463     // Now that deleted act0.txt, the same search must yield zero results.
   458     // Now that deleted act0.txt, the same search must yield zero results.
   464     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   459     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   465     TS_ASSERT(result == 0);
   460     TS_ASSERT(result == 0);
   466     }
   461     }
   528         iIndexer->AddL(*index_item);
   523         iIndexer->AddL(*index_item);
   529         }
   524         }
   530     CleanupStack::PopAndDestroy(index_item);
   525     CleanupStack::PopAndDestroy(index_item);
   531     
   526     
   532     // No flush. Term should not be in the indexDb
   527     // No flush. Term should not be in the indexDb
   533     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   528     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC, false);
   534     
   529     
   535     // TODO: Feature not yet in CPix. Change when flush is required.
   530     // TODO: Feature not yet in CPix. Change when flush is required.
   536     //TS_ASSERT(result == 0); 
   531     //TS_ASSERT(result == 0); 
       
   532     TS_ASSERT(result == 0); 
       
   533 
       
   534     iIndexer->FlushL(*this);
       
   535     iIndexerWait->Start();
       
   536 
       
   537     // After flush term should be in the indexDb
       
   538     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   537     TS_ASSERT(result == 1); 
   539     TS_ASSERT(result == 1); 
   538 
   540     }
   539     iIndexer->FlushL(*this);
   541 
   540     iWait->Start();
   542 void CTestIndexer::testAsyncResetL()
   541 
   543     {
   542     // After flush term should be in the indexDb
   544     // At the start this term will not be in the indexDb
       
   545     TInt result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
       
   546     TS_ASSERT(result == 0); 
       
   547 
       
   548     CreateFileIndexItemL(KTestFileAct0);
       
   549 
       
   550     // This term should only result in one result in (KTestFileAct0)
   543     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   551     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   544     TS_ASSERT(result == 1); 
   552     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 
   553 
   559     iIndexer->ResetL(*this);
   554     iIndexer->ResetL(*this);
   560     
   555     
   561     iWait->Start();
   556     iIndexerWait->Start();
   562 
   557 
   563     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   558     result = SearchForTextL(KUniqueSearchTermInAct0Txt, KNullDesC);
   564     TS_ASSERT(result == 0);
   559     TS_ASSERT(result == 0);
   565     }
   560     }
   566 
   561 
   591     else
   586     else
   592         {
   587         {
   593         const TDesC& db = iIndexer->GetBaseAppClass();//Increase Coverage
   588         const TDesC& db = iIndexer->GetBaseAppClass();//Increase Coverage
   594         }
   589         }
   595     iIndexer->SetAnalyzerL(*this,_L( "" CPIX_ANALYZER_STANDARD ));
   590     iIndexer->SetAnalyzerL(*this,_L( "" CPIX_ANALYZER_STANDARD ));
   596     iWait->Start();//wait till it returns
   591     iIndexerWait->Start();//wait till it returns
   597     TS_ASSERT(result == 0);
   592     TS_ASSERT(result == 0);
   598     }
   593     }
   599 
   594 
   600 void CTestIndexer::testSearchSession()
   595 void CTestIndexer::testSearchSession()
   601     {
   596     {