searchengine/cpix/tsrc/cpixunittest/src/randomtest.cpp
changeset 15 cf5c74390b98
parent 3 ae3f1779f6da
child 24 65456528cac2
equal deleted inserted replaced
10:afe194b6b1cd 15:cf5c74390b98
    18 #include "CPixdoc.h"
    18 #include "CPixdoc.h"
    19 
    19 
    20 #include <sstream>
    20 #include <sstream>
    21 #include <time.h>
    21 #include <time.h>
    22 #include "std_log_result.h"
    22 #include "std_log_result.h"
       
    23 #include "testutils.h"
    23 
    24 
    24 using namespace std;
    25 using namespace std;
    25 using namespace Itk;
    26 using namespace Itk;
    26 
    27 
    27 SuiteTester* CreateSuiteTesterRandom()
    28 SuiteTester* CreateSuiteTesterRandom()
   454                     if ( indexed( item ) )
   455                     if ( indexed( item ) )
   455                         {
   456                         {
   456                             bool found = false;
   457                             bool found = false;
   457                             for ( int i = 0; i < cpix_Hits_length( hits ); i++ )
   458                             for ( int i = 0; i < cpix_Hits_length( hits ); i++ )
   458                                 {
   459                                 {
   459                                     cpix_Document doc;
   460                                     cpix_Document **doc;
   460                                     cpix_Hits_doc( hits, i, &doc );
   461                                     ALLOC_DOC (doc, 1);
   461 
   462                                     cpix_Hits_doc( hits, i, doc, 1 );
   462                                     const wchar_t* id = cpix_Document_getFieldValue( &doc, LCPIX_DOCUID_FIELD );
   463                                     if (doc[0]->ptr_ != NULL) {
       
   464                                         const wchar_t* id = cpix_Document_getFieldValue( doc[0], LCPIX_DOCUID_FIELD );
   463 
   465 
   464                                     if ( id )
   466                                     if ( id )
   465                                         {
   467                                         {
   466                                             wstring str( id );
   468                                             wstring str( id );
   467                                             if ( GetItemIndex( str.c_str() ) == item )
   469                                             if ( GetItemIndex( str.c_str() ) == item )
   468                                                 {
   470                                                 {
   469                                                     found = true;
   471                                                     found = true;
   470                                                     break;
   472                                                     break;
   471                                                 }
   473                                                 }
   472                                         }
   474                                         }
       
   475                                     }
       
   476                                     FREE_DOC(doc, 1);
   473                                 }
   477                                 }
   474                             if ( !found )
   478                             if ( !found )
   475                                 {
   479                                 {
   476                                     assert_failed = 1;
   480                                     assert_failed = 1;
   477                                     ITK_MSG( testMgr, "Failed content %d", item );
   481                                     ITK_MSG( testMgr, "Failed content %d", item );
   536 		cpix_IdxDb_search(idxUtil_->idxDb(),
   540 		cpix_IdxDb_search(idxUtil_->idxDb(),
   537 				query);
   541 				query);
   538 
   542 
   539 		if ( hits )
   543 		if ( hits )
   540 			{
   544 			{
   541 			for ( int i = 0; i < cpix_Hits_length( hits ); i++ )
   545 			for ( int i = 0; i < cpix_Hits_length( hits ); i++ ) {
   542 				{
   546 			
   543 				cpix_Document doc;
   547 				cpix_Document **doc;
   544 				cpix_Hits_doc( hits, i, &doc );
   548 				ALLOC_DOC(doc, 1);
   545 
   549 				cpix_Hits_doc( hits, i, doc, 1 );
   546 				const wchar_t* id = cpix_Document_getFieldValue( &doc, LCPIX_DOCUID_FIELD );
   550 
   547 
   551 				if (doc[0]->ptr_ != NULL) {
   548 				if ( id )
   552 				    
   549 					{
   553                     const wchar_t* id = cpix_Document_getFieldValue(doc[0],
   550 					wstring str( id );
   554                             LCPIX_DOCUID_FIELD);
   551 					size_t index = GetItemIndex( str.c_str() );
   555 
   552 					wstring content( testCorpus_.item( index ) );
   556                     if (id)
   553 
   557                         {
   554                                         // TODO expect instead of
   558                         wstring str(id);
   555                                         // assert otherwise cpix_Hits
   559                         size_t index = GetItemIndex(str.c_str());
   556                                         // instance leaks
   560                         wstring content(testCorpus_.item(index));
   557 					ITK_ASSERT( testMgr,
   561 
   558 								containsTerm( content, term ),
   562                         // TODO expect instead of
   559 								"False positive? Term %S not found in %S", term.c_str(), content.c_str() );
   563                         // assert otherwise cpix_Hits
   560 					matches++;
   564                         // instance leaks
   561 					}
   565                         ITK_ASSERT( testMgr,
       
   566                                 containsTerm( content, term ),
       
   567                                 "False positive? Term %S not found in %S", term.c_str(), content.c_str() );
       
   568                         matches++;
       
   569                         }
       
   570                     }
       
   571                 FREE_DOC(doc, 1);
   562 				}
   572 				}
   563 			cpix_Hits_destroy( hits );
   573 			cpix_Hits_destroy( hits );
   564 			}
   574 			}
   565 		cpix_Query_destroy( query );
   575 		cpix_Query_destroy( query );
   566 		}
   576 		}