• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xapian.test.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include <ept/test.h>
00003 #include <ept/core/list.h>
00004 #include <ept/core/xapian.h>
00005 
00006 // TODO temporary, for building test database
00007 #include <ept/apt/apt.h>
00008 #include <ept/textsearch/textsearch.h>
00009 #include <ept/textsearch/maint/path.h>
00010 
00011 using namespace ept;
00012 using namespace core;
00013 
00014 namespace ept {
00015 namespace textsearch {
00016 extern size_t max_index;
00017 }
00018 }
00019 
00020 struct XapianTestEnvironment : AptTestEnvironment {
00021     textsearch::Path::OverrideIndexDir oid;
00022     textsearch::TextSearch textsearch;
00023     apt::Apt apt;
00024     XapianTestEnvironment()
00025         : oid( TEST_ENV_DIR "xapian" )
00026     {
00027         ept::textsearch::max_index = 1000;
00028         textsearch.rebuildIfNeeded(apt);
00029     }
00030 };
00031 
00032 struct TestXapian : XapianTestEnvironment {
00033     xapian::Source xap;
00034     xapian::Query query;
00035 
00036     TestXapian() : query( xap.db() )
00037     {
00038         query = xap.query( "sgml tool" );
00039     }
00040 
00041     Test enquire() {
00042         query.updateEnquire();
00043     Xapian::MSet matches = query.m_enq.get_mset(0, 100);
00044         assert( matches.size() > 0 );
00045         assert_eq( matches.begin().get_document().get_data(), "psgml" );
00046     }
00047 
00048     Test listCount() {
00049         xapian::List l( query.results() );
00050     Xapian::MSet matches = query.m_enq.get_mset(0, 6000);
00051         assert_eq( list::count( l ), matches.size() );
00052     }
00053 
00054     template< typename List >
00055     void checkXapianList( List l, Xapian::MSet m ) {
00056         Xapian::MSet::const_iterator i = m.begin();
00057         while (! l.empty() ) {
00058             assert_eq( l.token().package(), i.get_document().get_data() );
00059             l = l.tail();
00060             ++ i;
00061         }
00062     }
00063 
00064     Test list() {
00065         xapian::List l( query.results() );
00066     Xapian::MSet matches = query.m_enq.get_mset(0, 6000);
00067         checkXapianList( l, matches );
00068     }
00069 
00070     Test checkQuery() {
00071         assert_eq( xap.query( "sgml tool" ).results().token().package(), "psgml" );
00072     }
00073 
00074 };

Generated on Thu Aug 18 2016 17:48:34 for libept by  doxygen 1.7.1