searchengine/cpix/tsrc/cpixunittest/src/querytest.cpp
changeset 3 ae3f1779f6da
parent 2 6c1a2771f4b7
child 24 65456528cac2
equal deleted inserted replaced
2:6c1a2771f4b7 3:ae3f1779f6da
    29 //#include "xmllog.h"
    29 //#include "xmllog.h"
    30 #include "config.h"
    30 #include "config.h"
    31 #include "testutils.h"
    31 #include "testutils.h"
    32 #include "suggestion.h"
    32 #include "suggestion.h"
    33 
    33 
       
    34 #include "std_log_result.h"
    34 
    35 
    35 const char * docsToIndex[5] = {
    36 const char * docsToIndex[5] = {
    36 CORPUS_PATH "\\query\\query1.txt",
    37 CORPUS_PATH "\\query\\query1.txt",
    37 CORPUS_PATH "\\query\\query2.txt",
    38 CORPUS_PATH "\\query\\query2.txt",
    38 CORPUS_PATH "\\query\\query3.txt",
    39 CORPUS_PATH "\\query\\query3.txt",
   133                 queryParser = cpix_QueryParser_create(&result,LCPIX_DEFAULT_FIELD,analyzer );
   134                 queryParser = cpix_QueryParser_create(&result,LCPIX_DEFAULT_FIELD,analyzer );
   134                 break;
   135                 break;
   135         }
   136         }
   136         if (queryParser == NULL)
   137         if (queryParser == NULL)
   137             {
   138             {
       
   139                 assert_failed = 1;
   138                 cpix_Analyzer_destroy( analyzer );
   140                 cpix_Analyzer_destroy( analyzer );
   139                 ITK_PANIC("Could not create query parser");
   141                 ITK_PANIC("Could not create query parser");
   140             }
   142             }
   141         
   143         
   142 
   144 
   144         cpix_Query* query = cpix_QueryParser_parse(queryParser,
   146         cpix_Query* query = cpix_QueryParser_parse(queryParser,
   145                                                    qryStr);
   147                                                    qryStr);
   146         if (cpix_Failed(queryParser)
   148         if (cpix_Failed(queryParser)
   147             || query == NULL)
   149             || query == NULL)
   148             {
   150             {
       
   151                 assert_failed = 1;
   149                 cpix_Analyzer_destroy(analyzer);
   152                 cpix_Analyzer_destroy(analyzer);
   150                 cpix_ClearError(queryParser);
   153                 cpix_ClearError(queryParser);
   151                 cpix_QueryParser_destroy(queryParser);
   154                 cpix_QueryParser_destroy(queryParser);
   152                 ITK_PANIC("Could not parse query string");
   155                 ITK_PANIC("Could not parse query string");
   153             }
   156             }
   167                    
   170                    
   168                     ITK_MSG(testMgr, "Query %S, returned %d hits. Passed \n",qryStr,hitsLength );
   171                     ITK_MSG(testMgr, "Query %S, returned %d hits. Passed \n",qryStr,hitsLength );
   169                     }
   172                     }
   170                 else
   173                 else
   171                     {
   174                     {
   172                    
   175                     assert_failed = 1;
   173                     ITK_MSG(testMgr, "Query %S, didnt return expected hits. Expected is %d hits. Returned is %d. Failed \n",qryStr,hitLen,hitsLength);
   176                     ITK_MSG(testMgr, "Query %S, didnt return expected hits. Expected is %d hits. Returned is %d. Failed \n",qryStr,hitLen,hitsLength);
   174                     }
   177                     }
   175                     
   178                     
   176         cpix_Query_destroy( query ); 
   179         cpix_Query_destroy( query ); 
   177         
   180         
   180 
   183 
   181 
   184 
   182 
   185 
   183 void CreatePlainQueryTest(Itk::TestMgr * testMgr) 
   186 void CreatePlainQueryTest(Itk::TestMgr * testMgr) 
   184 {
   187 {
       
   188     char *xml_file = (char*)__FUNCTION__;
       
   189     assert_failed = 0;
   185     setupPlainQuery(testMgr);
   190     setupPlainQuery(testMgr);
   186     testQuery(testMgr,L"Nokia", 2);
   191     testQuery(testMgr,L"Nokia", 2);
   187     testQuery(testMgr,L"iNdia", 1);
   192     testQuery(testMgr,L"iNdia", 1);
   188     testQuery(testMgr,L"\"London Finland\"", 1);
   193     testQuery(testMgr,L"\"London Finland\"", 1);
   189     testQuery(testMgr,L"Contents:Nokia", 2);
   194     testQuery(testMgr,L"Contents:Nokia", 2);
   213     testQuery(testMgr,L"nokia NOT country", 1);
   218     testQuery(testMgr,L"nokia NOT country", 1);
   214     testQuery(testMgr,L"nokia NOT basker", 2);
   219     testQuery(testMgr,L"nokia NOT basker", 2);
   215     testQuery(testMgr,L"NOT India", 1);
   220     testQuery(testMgr,L"NOT India", 1);
   216     testQuery(testMgr,L"(india OR Mobile) AND Nokia", 2);
   221     testQuery(testMgr,L"(india OR Mobile) AND Nokia", 2);
   217     testQuery(testMgr,L"(india OR Mobile) AND Country", 1);
   222     testQuery(testMgr,L"(india OR Mobile) AND Country", 1);
   218   //  create_xml(val,__func__,__FILE__,__LINE__);
   223     testResultXml(xml_file);
   219 }
   224 }
   220 
   225 
   221 void CreatePrefixQueryTest(Itk::TestMgr * testMgr) 
   226 void CreatePrefixQueryTest(Itk::TestMgr * testMgr) 
   222 {
   227 {
       
   228     char *xml_file = (char*)__FUNCTION__;
       
   229     assert_failed = 0;
   223     setupPrefixQuery(testMgr);
   230     setupPrefixQuery(testMgr);
   224     testQuery(testMgr,L"$prefix(\"new-notes\")", 1);
   231     testQuery(testMgr,L"$prefix(\"new-notes\")", 1);
   225     testQuery(testMgr,L"$prefix(\"notes\")", 1);
   232     testQuery(testMgr,L"$prefix(\"notes\")", 1);
   226     testQuery(testMgr,L"$prefix(\"new\")", 1);
   233     testQuery(testMgr,L"$prefix(\"new\")", 1);
   227     testQuery(testMgr,L"$prefix(\"-india\")", 1);
   234     testQuery(testMgr,L"$prefix(\"-india\")", 1);
   259     testQuery(testMgr,L"$prefix(\"[squarebracket]\")", 1);
   266     testQuery(testMgr,L"$prefix(\"[squarebracket]\")", 1);
   260     testQuery(testMgr,L"$prefix(\"{flowerbracket}\")", 1);
   267     testQuery(testMgr,L"$prefix(\"{flowerbracket}\")", 1);
   261     testQuery(testMgr,L"$prefix(\"<lessthan\")", 1);
   268     testQuery(testMgr,L"$prefix(\"<lessthan\")", 1);
   262     testQuery(testMgr,L"$prefix(\">greaterthan\")", 1);
   269     testQuery(testMgr,L"$prefix(\">greaterthan\")", 1);
   263     testQuery(testMgr,L"$prefix(\"worked for motorola .\")", 1);
   270     testQuery(testMgr,L"$prefix(\"worked for motorola .\")", 1);
   264     
   271     testResultXml(xml_file);
   265 }
   272 }
   266 
   273 
   267 void CreatePrefixOptimiseQueryTest(Itk::TestMgr * testMgr)
   274 void CreatePrefixOptimiseQueryTest(Itk::TestMgr * testMgr)
   268     {
   275     {
       
   276     char *xml_file = (char*)__FUNCTION__;
       
   277     assert_failed = 0;
   269     setupPrefixOptimiseQuery(testMgr);
   278     setupPrefixOptimiseQuery(testMgr);
   270     testQuery(testMgr,L"i*", 3,LCPIX_DEFAULT_PREFIX );
   279     testQuery(testMgr,L"i*", 3,LCPIX_DEFAULT_PREFIX );
   271     testQuery(testMgr,L"in*", 2,LCPIX_DEFAULT_PREFIX );
   280     testQuery(testMgr,L"in*", 2,LCPIX_DEFAULT_PREFIX );
   272     testQuery(testMgr,L"i?", 3,LCPIX_DEFAULT_PREFIX );
   281     testQuery(testMgr,L"i?", 3,LCPIX_DEFAULT_PREFIX );
   273     testQuery(testMgr,L"id*", 2,LCPIX_DEFAULT_PREFIX );
   282     testQuery(testMgr,L"id*", 2,LCPIX_DEFAULT_PREFIX );
   286     testQuery(testMgr,L"pr*", 1,LCPIX_DEFAULT_PREFIX );
   295     testQuery(testMgr,L"pr*", 1,LCPIX_DEFAULT_PREFIX );
   287     testQuery(testMgr,L"r*", 3,LCPIX_DEFAULT_PREFIX );
   296     testQuery(testMgr,L"r*", 3,LCPIX_DEFAULT_PREFIX );
   288     testQuery(testMgr,L"ru*", 2,LCPIX_DEFAULT_PREFIX );
   297     testQuery(testMgr,L"ru*", 2,LCPIX_DEFAULT_PREFIX );
   289     testQuery(testMgr,L"ra*", 2,LCPIX_DEFAULT_PREFIX );
   298     testQuery(testMgr,L"ra*", 2,LCPIX_DEFAULT_PREFIX );
   290     testQuery(testMgr,L"ri*", 2,LCPIX_DEFAULT_PREFIX );
   299     testQuery(testMgr,L"ri*", 2,LCPIX_DEFAULT_PREFIX );
       
   300     testResultXml(xml_file);
   291     }
   301     }
   292 Itk::TesterBase * CreateQueryTests()
   302 Itk::TesterBase * CreateQueryTests()
   293 {
   303 {
   294     using namespace Itk;
   304     using namespace Itk;
   295 
   305 
   296     ContextTester
   306     SuiteTester
   297         * qryTests = new ContextTester("Query Tests", NULL);
   307         * qryTests = new SuiteTester("querytests");
   298 
   308 
   299     qryTests->add("PlainQueryTest", &CreatePlainQueryTest);
   309     qryTests->add("plainquerytest", &CreatePlainQueryTest, "plainquerytest");
   300     qryTests->add("PrefixQueryTest", &CreatePrefixQueryTest);
   310     qryTests->add("prefixquerytest", &CreatePrefixQueryTest, "prefixquerytest");
   301     qryTests->add("PrefixOptimiseQueryTest", &CreatePrefixOptimiseQueryTest);
   311     qryTests->add("prefixoptimisequerytest", &CreatePrefixOptimiseQueryTest, "prefixoptimisequerytest");
   302     
   312     
   303     return qryTests;
   313     return qryTests;
   304 }
   314 }
   305 
   315 
   306 
   316