Ticket #462: test.cpp

File test.cpp, 1.5 KB (added by Olly Betts, 15 years ago)

Testcase from mailing list

Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <xapian.h>
4
5#define DIRECTORY "/tmp/db"
6
7int main()
8{
9 system( "rm -rfv " DIRECTORY );
10 system( "mkdir " DIRECTORY );
11 system( "touch " DIRECTORY "/iamflint" );
12
13 // Write items
14 Xapian::WritableDatabase writeable( DIRECTORY, Xapian::DB_CREATE_OR_OPEN );
15 Xapian::Document doc;
16 for( int i=0; i < 100; ++i )
17 {
18 char buffer[100];
19 sprintf( buffer, "a%d", i );
20 doc.add_term( buffer );
21 }
22 for (int i = 0; i < 500; ++i)
23 writeable.add_document(doc);
24 writeable.commit();
25
26 // Create memory leak
27 Xapian::Database database( DIRECTORY );
28 for( int c=0; c < 10; ++c )
29 {
30 Xapian::Query xapian_query;
31 Xapian::QueryParser xapian_queryparser;
32 xapian_queryparser.set_database( database );
33 for( int e=0; e < 3; ++e )
34 {
35 try
36 {
37 xapian_query = xapian_queryparser.parse_query( "a", Xapian::QueryParser::FLAG_PARTIAL , "" );
38 }
39 catch( const Xapian::DatabaseModifiedError & )
40 {
41 database.reopen();
42 continue;
43 }
44 break;
45 }
46 for( Xapian::TermIterator i=xapian_query.get_terms_begin(); i != xapian_query.get_terms_end(); ++i )
47 ;
48
49 writeable.add_document(doc);
50 writeable.commit();
51 writeable.add_document(doc);
52 writeable.commit();
53 writeable.add_document(doc);
54 }
55
56 return 0;
57}
58
59
60