searchengine/cpix/tsrc/cpixunittest/src/aggregatetests.cpp
changeset 3 ae3f1779f6da
parent 0 671dee74050a
child 24 65456528cac2
equal deleted inserted replaced
2:6c1a2771f4b7 3:ae3f1779f6da
    30 #include "testutils.h"
    30 #include "testutils.h"
    31 #include "setupsentry.h"
    31 #include "setupsentry.h"
    32 
    32 
    33 #include "testcorpus.h"
    33 #include "testcorpus.h"
    34 
    34 
       
    35 #include "std_log_result.h"
    35 
    36 
    36 cpix_FieldDesc MultiFieldSchema[] = {
    37 cpix_FieldDesc MultiFieldSchema[] = {
    37     
    38     
    38     // filter field
    39     // filter field
    39     {
    40     {
    77     L"rabid happening",
    78     L"rabid happening",
    78     L"look, important and happy robot",
    79     L"look, important and happy robot",
    79     L"christmas for ever",
    80     L"christmas for ever",
    80     L"christmas is an important and happy happening"
    81     L"christmas is an important and happy happening"
    81 };
    82 };
       
    83 
    82 
    84 
    83 
    85 
    84 class MultiFieldIdxUtil : public FileIdxUtil
    86 class MultiFieldIdxUtil : public FileIdxUtil
    85 {
    87 {
    86 public:
    88 public:
   344     // Test operations
   346     // Test operations
   345     //
   347     //
   346     void testAddFiles(Itk::TestMgr * testMgr)
   348     void testAddFiles(Itk::TestMgr * testMgr)
   347     {
   349     {
   348         testMgr_ = testMgr;
   350         testMgr_ = testMgr;
   349 
   351         char *xml_file = (char*)__FUNCTION__;
       
   352         assert_failed = 0;
   350         Cpt::traverse(FILE_TEST_CORPUS_PATH "\\en",
   353         Cpt::traverse(FILE_TEST_CORPUS_PATH "\\en",
   351                       this);
   354                       this);
   352 
   355 
   353         util_->flush();
   356         util_->flush();
       
   357         testResultXml(xml_file);
   354     }
   358     }
   355 
   359 
   356 
   360 
   357     void testSearchForHappy(Itk::TestMgr * testMgr)
   361     void testSearchForHappy(Itk::TestMgr * testMgr)
   358     {
   362     {
   359         const wchar_t
   363         const wchar_t
   360             * word = L"happy";
   364             * word = L"happy";
   361 
   365             char *xml_file = (char*)__FUNCTION__;
       
   366             assert_failed = 0;
   362         testSearchFor(testMgr,
   367         testSearchFor(testMgr,
   363                       word);
   368                       word);
       
   369         testResultXml(xml_file);
       
   370         
   364     }
   371     }
   365 
   372 
   366     void testSearchForImportant(Itk::TestMgr * testMgr)
   373     void testSearchForImportant(Itk::TestMgr * testMgr)
   367     {
   374     {
   368         const wchar_t
   375         const wchar_t
   369             * word = L"important";
   376             * word = L"important";
   370 
   377         char *xml_file = (char*)__FUNCTION__;
       
   378         assert_failed = 0;
   371         testSearchFor(testMgr,
   379         testSearchFor(testMgr,
   372                       word);
   380                       word);
       
   381         testResultXml(xml_file);
   373     }
   382     }
   374 
   383 
   375     void testSearchForHappening(Itk::TestMgr * testMgr)
   384     void testSearchForHappening(Itk::TestMgr * testMgr)
   376     {
   385     {
   377         const wchar_t
   386         const wchar_t
   378             * word = L"happening";
   387             * word = L"happening";
   379 
   388         char *xml_file = (char*)__FUNCTION__;
       
   389         assert_failed = 0;
   380         testSearchFor(testMgr,
   390         testSearchFor(testMgr,
   381                       word);
   391                       word);
       
   392         testResultXml(xml_file);
   382     }
   393     }
   383 
   394 
   384     void testSearchForLook(Itk::TestMgr * testMgr)
   395     void testSearchForLook(Itk::TestMgr * testMgr)
   385     {
   396     {
   386         const wchar_t
   397         const wchar_t
   387             * word = L"look";
   398             * word = L"look";
   388 
   399         char *xml_file = (char*)__FUNCTION__;
       
   400         assert_failed = 0;
   389         testSearchFor(testMgr,
   401         testSearchFor(testMgr,
   390                       word);
   402                       word);
       
   403         testResultXml(xml_file);
   391     }
   404     }
   392 
   405 
   393     void testSearchForChristmas(Itk::TestMgr * testMgr)
   406     void testSearchForChristmas(Itk::TestMgr * testMgr)
   394     {
   407     {
   395         const wchar_t
   408         const wchar_t
   396             * word = L"christmas";
   409             * word = L"christmas";
   397 
   410         char *xml_file = (char*)__FUNCTION__;
       
   411         assert_failed = 0;
   398         testSearchFor(testMgr,
   412         testSearchFor(testMgr,
   399                       word);
   413                       word);
       
   414         testResultXml(xml_file);
   400     }
   415     }
   401 
   416 
   402 
   417 
   403 private:
   418 private:
   404     //
   419     //
   405     // private methods
   420     // private methods
   406     //
   421     //
   407     void testSearchFor(Itk::TestMgr  * testMgr,
   422     void testSearchFor(Itk::TestMgr  * testMgr,
   408                        const wchar_t * word)
   423                        const wchar_t * word, int expected = 1)
   409     {
   424     {
   410         wchar_t
   425         wchar_t
   411             report[512];
   426             report[512];
   412 
   427 
   413         cpix_Query
   428         cpix_Query
   428                 else
   443                 else
   429                     {
   444                     {
   430                         cpix_Error_report(util_->idxDb()->err_,
   445                         cpix_Error_report(util_->idxDb()->err_,
   431                                           report,
   446                                           report,
   432                                           sizeof(report)/sizeof(wchar_t));
   447                                           sizeof(report)/sizeof(wchar_t));
       
   448                         if(expected)
       
   449                             assert_failed = 1;
       
   450                         else
       
   451                             assert_failed = 0;  
   433                         ITK_EXPECT(testMgr,
   452                         ITK_EXPECT(testMgr,
   434                                    false,
   453                                    false,
   435                                    "Failed to search: %S",
   454                                    "Failed to search: %S",
   436                                    report);
   455                                    report);
   437                         cpix_ClearError(util_->idxDb());
   456                         cpix_ClearError(util_->idxDb());
   442         else
   461         else
   443             {
   462             {
   444                 cpix_Error_report(query->err_,
   463                 cpix_Error_report(query->err_,
   445                                   report,
   464                                   report,
   446                                   sizeof(report)/sizeof(wchar_t));
   465                                   sizeof(report)/sizeof(wchar_t));
   447 
   466                 if(expected)
       
   467                     assert_failed = 1;
       
   468                 else
       
   469                     assert_failed = 0;  
   448                 ITK_EXPECT(testMgr,
   470                 ITK_EXPECT(testMgr,
   449                            false,
   471                            false,
   450                            "Failed to parse '%S': %S",
   472                            "Failed to parse '%S': %S",
   451                            word,
   473                            word,
   452                            report);
   474                            report);