searchengine/cpix/tsrc/cpixunittest/src/negativetests.cpp
changeset 24 65456528cac2
parent 3 ae3f1779f6da
equal deleted inserted replaced
23:d4d56f5e7c55 24:65456528cac2
    30 #include "itk.h"
    30 #include "itk.h"
    31 #include "cpixidxdb.h"
    31 #include "cpixidxdb.h"
    32 #include "cpixdoc.h"
    32 #include "cpixdoc.h"
    33 #include "cpixsearch.h"
    33 #include "cpixsearch.h"
    34 #include "cpixidxdb.h"
    34 #include "cpixidxdb.h"
    35 #include "std_log_result.h"
    35 
    36 
    36 
    37 #define TEST_DOCUMENT_QBASEAPPCLASS "@0:root test document"
    37 #define TEST_DOCUMENT_QBASEAPPCLASS "@0:root test document"
    38 #define TEST_SAMPLE_QBASEAPPCLASS "@:root test sample"
    38 #define TEST_SAMPLE_QBASEAPPCLASS "@:root test sample"
    39 #define TEST_CORRUPTTEST1_QBASEAPPCLASS "@:root test corrupttest1"
    39 #define TEST_CORRUPTTEST1_QBASEAPPCLASS "@:root test corrupttest1"
    40 #define TEST_CORRUPTTEST2_QBASEAPPCLASS "@:root test corrupttest2"
    40 #define TEST_CORRUPTTEST2_QBASEAPPCLASS "@:root test corrupttest2"
   269 
   269 
   270 }
   270 }
   271 
   271 
   272 void testCreateDb(Itk::TestMgr* /*testMgr */)
   272 void testCreateDb(Itk::TestMgr* /*testMgr */)
   273 {
   273 {
   274     char *xml_file = (char *)__FUNCTION__;
       
   275     assert_failed = 0;
       
   276     cpix_IdxDb   *itestDb_ = NULL, *inewDb_ = NULL;                
   274     cpix_IdxDb   *itestDb_ = NULL, *inewDb_ = NULL;                
   277     cpix_Result  result;
   275     cpix_Result  result;
   278     
   276     
   279     testInit(&itestDb_, cpix_IDX_CREATE,
   277     testInit(&itestDb_, cpix_IDX_CREATE,
   280             TEST_SAMPLE_QBASEAPPCLASS, TEST_SAMPLE_INDEXDB_PATH);
   278             TEST_SAMPLE_QBASEAPPCLASS, TEST_SAMPLE_INDEXDB_PATH);
   287                                        cpix_IDX_CREATE);
   285                                        cpix_IDX_CREATE);
   288         }
   286         }
   289     if (cpix_Failed(&result))
   287     if (cpix_Failed(&result))
   290         {
   288         {
   291         ITK_PANIC("Failed to open indexDb");
   289         ITK_PANIC("Failed to open indexDb");
   292         assert_failed = 1;
   290         
   293         }
   291         }
   294      
   292      
   295      if ( itestDb_ ) 
   293      if ( itestDb_ ) 
   296          {
   294          {
   297             cpix_IdxDb_releaseDb(itestDb_);
   295             cpix_IdxDb_releaseDb(itestDb_);
   302          {
   300          {
   303             cpix_IdxDb_releaseDb(inewDb_);
   301             cpix_IdxDb_releaseDb(inewDb_);
   304             inewDb_ = 0;
   302             inewDb_ = 0;
   305          }
   303          }
   306      cpix_IdxDb_undefineVolume(TEST_SAMPLE_QBASEAPPCLASS);
   304      cpix_IdxDb_undefineVolume(TEST_SAMPLE_QBASEAPPCLASS);
   307      testResultXml(xml_file);
       
   308 }
   305 }
   309 
   306 
   310 void testOpenDb(Itk::TestMgr * testMgr)
   307 void testOpenDb(Itk::TestMgr * testMgr)
   311 {
   308 {
   312         char *xml_file = (char *)__FUNCTION__;
   309         
   313         assert_failed = 0;
       
   314         cpix_Result  result;            
   310         cpix_Result  result;            
   315         cpix_IdxDb   *idxDb_ = NULL;
   311         cpix_IdxDb   *idxDb_ = NULL;
   316         
   312         
   317         //try to open a Db an of undefined volume
   313         //try to open a Db an of undefined volume
   318         idxDb_ = cpix_IdxDb_openDb(&result,
   314         idxDb_ = cpix_IdxDb_openDb(&result,
   319                                        "@0:root test1",
   315                                        "@0:root test1",
   320                                        cpix_IDX_CREATE);
   316                                        cpix_IDX_CREATE);
   321         if(idxDb_ == NULL )
   317         if(idxDb_ == NULL )
   322             {
   318             {
   323             ITK_MSG(testMgr, "Tried to open a database of undefined volume");
   319             ITK_MSG(testMgr, "Tried to open a database of undefined volume");
   324             assert_failed = 1;
   320             
   325             }
   321             }
   326         
   322         
   327         if (idxDb_) 
   323         if (idxDb_) 
   328             {
   324             {
   329                 cpix_IdxDb_releaseDb(idxDb_);
   325                 cpix_IdxDb_releaseDb(idxDb_);
   330                 idxDb_ = 0; 
   326                 idxDb_ = 0; 
   331             }       
   327             }       
   332         testResultXml(xml_file);
   328        
   333 }
   329 }
   334 
   330 
   335 void testCorruptedIndex(Itk::TestMgr * testMgr)
   331 void testCorruptedIndex(Itk::TestMgr * testMgr)
   336 {
   332 {
   337      char *xml_file = (char *)__FUNCTION__;
   333      
   338      assert_failed = 0;
       
   339      cpix_Analyzer * analyzer_ = NULL ;       
   334      cpix_Analyzer * analyzer_ = NULL ;       
   340      cpix_IdxDb * iCrptDb1_ = NULL, *iCrptDb2_ = NULL;
   335      cpix_IdxDb * iCrptDb1_ = NULL, *iCrptDb2_ = NULL;
   341      
   336      
   342      CreateAnalyser(testMgr,
   337      CreateAnalyser(testMgr,
   343                     &analyzer_);
   338                     &analyzer_);
   381      if(iCrptDb2_)
   376      if(iCrptDb2_)
   382          hit_search2= search(&analyzer_,&iCrptDb2_, SEARCH_TERM);
   377          hit_search2= search(&analyzer_,&iCrptDb2_, SEARCH_TERM);
   383      else
   378      else
   384          {
   379          {
   385          ITK_MSG(testMgr, "Corrupted database, search not possible");
   380          ITK_MSG(testMgr, "Corrupted database, search not possible");
   386          assert_failed = 0;
   381          
   387          }
   382          }
   388      
   383      
   389      cleanUp(&analyzer_,&iCrptDb1_);
   384      cleanUp(&analyzer_,&iCrptDb1_);
   390      
   385      
   391      if(iCrptDb2_)
   386      if(iCrptDb2_)
   394          iCrptDb2_ = 0;
   389          iCrptDb2_ = 0;
   395          }
   390          }
   396      
   391      
   397      cpix_IdxDb_undefineVolume(TEST_CORRUPTTEST1_QBASEAPPCLASS);
   392      cpix_IdxDb_undefineVolume(TEST_CORRUPTTEST1_QBASEAPPCLASS);
   398      cpix_IdxDb_undefineVolume(TEST_CORRUPTTEST2_QBASEAPPCLASS);
   393      cpix_IdxDb_undefineVolume(TEST_CORRUPTTEST2_QBASEAPPCLASS);
   399      testResultXml(xml_file);
   394     
   400  }
   395  }
   401 
   396 
   402 };
   397 };
   403 
   398 
   404 Itk::TesterBase * CreateNegativeTests()
   399 Itk::TesterBase * CreateNegativeTests()
   406     using namespace Itk;
   401     using namespace Itk;
   407     
   402     
   408     NegativeTests
   403     NegativeTests
   409             *negativeTests = new NegativeTests;
   404             *negativeTests = new NegativeTests;
   410     ContextTester
   405     ContextTester
   411             * contextTester = new ContextTester("Negative Tests",
   406             * contextTester = new ContextTester("NegativeTests",
   412                                                 negativeTests);    
   407                                                 negativeTests);    
   413 #define TEST "CreateDb"
   408 #define TEST "CreateDb"
   414     contextTester->add(TEST,
   409     contextTester->add(TEST,
   415                     negativeTests,
   410                     negativeTests,
   416                     &NegativeTests::testCreateDb);
   411                     &NegativeTests::testCreateDb);