2 # Before 'make install' is performed this script should be runnable with
3 # 'make test'. After 'make install' it should work as 'perl test.pl'
5 #########################
9 BEGIN {$SIG{__WARN__} = sub { die "Terminating test due to warning: $_[0]" } };
13 # Perl 5.8.7 added CLONE_SKIP which is required to implement the behaviour
14 # which this test case tests.
15 plan skip_all => 'Test requires Perl >= 5.8.7 for CLONE_SKIP';
21 plan skip_all => 'Test requires Perl with thread support';
24 # Number of test cases to run - increase this if you add more testcases.
27 use Xapian qw(:standard);
29 # TODO: check these classes too:
34 my ($wdb, $db, $doc, $bm25wt, $boolwt, $tradwt, $enq, $qp, $q, $stem);
35 my ($eset, $mset, $rset, $esetit, $msetit, $postit, $posit, $termit, $valueit);
36 my ($sstop, $tg, $rp);
39 # Check that calling a method fails, and that it isn't a Xapian object.
40 eval { $wdb->get_doccount(); };
41 return 0 unless $@ && ref($wdb) !~ 'Xapian';
42 # Check that calling a method fails, and that it isn't a Xapian object.
43 eval { $db->get_doccount(); };
44 return 0 unless $@ && ref($db) !~ 'Xapian';
45 # Check that calling a method fails, and that it isn't a Xapian object.
46 eval { $doc->get_data(); };
47 return 0 unless $@ && ref($doc) !~ 'Xapian';
48 # Check that it isn't a Xapian object.
49 return 0 unless ref($bm25wt) !~ 'Xapian';
50 # Check that it isn't a Xapian object.
51 return 0 unless ref($boolwt) !~ 'Xapian';
52 # Check that it isn't a Xapian object.
53 return 0 unless ref($tradwt) !~ 'Xapian';
54 # Check that calling a method fails, and that it isn't a Xapian object.
55 eval { $enq->get_query(); };
56 return 0 unless $@ && ref($enq) !~ 'Xapian';
57 # Check that calling a method fails, and that it isn't a Xapian object.
58 eval { $qp->get_default_op(); };
59 return 0 unless $@ && ref($qp) !~ 'Xapian';
60 # Check that calling a method fails, and that it isn't a Xapian object.
61 eval { $q->empty(); };
62 return 0 unless $@ && ref($q) !~ 'Xapian';
63 # Check that calling a method fails, and that it isn't a Xapian object.
64 eval { $stem->stem_word("testing"); };
65 return 0 unless $@ && ref($stem) !~ 'Xapian';
66 # Check that calling a method fails, and that it isn't a Xapian object.
67 eval { $eset->empty(); };
68 return 0 unless $@ && ref($eset) !~ 'Xapian';
69 # Check that calling a method fails, and that it isn't a Xapian object.
70 eval { $mset->empty(); };
71 return 0 unless $@ && ref($mset) !~ 'Xapian';
72 # Check that calling a method fails, and that it isn't a Xapian object.
73 eval { $rset->empty(); };
74 return 0 unless $@ && ref($rset) !~ 'Xapian';
75 # Check that it isn't a Xapian object.
76 return 0 unless ref($esetit) !~ 'Xapian';
77 # Check that it isn't a Xapian object.
78 return 0 unless ref($msetit) !~ 'Xapian';
79 # Check that it isn't a Xapian object.
80 return 0 unless ref($postit) !~ 'Xapian';
81 # Check that it isn't a Xapian object.
82 return 0 unless ref($posit) !~ 'Xapian';
83 # Check that it isn't a Xapian object.
84 return 0 unless ref($termit) !~ 'Xapian';
85 # Check that it isn't a Xapian object.
86 return 0 unless ref($valueit) !~ 'Xapian';
87 # Check that it isn't a Xapian object.
88 return 0 unless ref($sstop) !~ 'Xapian';
89 # Check that it isn't a Xapian object.
90 return 0 unless ref($tg) !~ 'Xapian';
91 # Check that it isn't a Xapian object.
92 return 0 unless ref($rp) !~ 'Xapian';
95 ok( $wdb = Xapian::WritableDatabase->new(), 'create WritableDatabase' );
96 is( $wdb->get_doccount(), 0, 'check WritableDatabase' );
98 ok( $db = Xapian::Database->new('testdb'), 'create Database' );
99 is( $db->get_doccount(), 2, 'check Database' );
101 ok( $doc = $db->get_document(1), 'create Document' );
102 is( $doc->get_data(), 'test one', 'check Document' );
104 ok( $bm25wt = Xapian::BM25Weight->new(), 'create BM25Weight' );
105 is( ref($bm25wt), 'Xapian::BM25Weight', 'check BM25Weight' );
107 ok( $boolwt = Xapian::BoolWeight->new(), 'create BoolWeight' );
108 is( ref($boolwt), 'Xapian::BoolWeight', 'check BoolWeight' );
110 ok( $tradwt = Xapian::TradWeight->new(), 'create TradWeight' );
111 is( ref($tradwt), 'Xapian::TradWeight', 'check TradWeight' );
113 ok( $enq = Xapian::Enquire->new($db), 'create Enquire' );
114 ok( $enq->get_query()->empty(), 'check Enquire' );
116 ok( $qp = Xapian::QueryParser->new(), 'create QueryParser' );
117 is( $qp->get_default_op(), OP_OR, 'check QueryParser' );
119 ok( $q = $qp->parse_query("foo"), 'create Query' );
120 ok( !$q->empty(), 'check Query' );
122 ok( $stem = Xapian::Stem->new('en'), 'create Stem' );
123 is( $stem->stem_word('testing'), 'test', 'check Stem' );
125 ok( $eset = Xapian::ESet->new(), 'create ESet' );
126 ok( $eset->empty(), 'check ESet' );
128 ok( $mset = Xapian::MSet->new(), 'create MSet' );
129 ok( $mset->empty(), 'check MSet' );
131 ok( $rset = Xapian::RSet->new(), 'create RSet' );
132 ok( $rset->empty(), 'check RSet' );
134 ok( $esetit = $eset->begin(), 'create ESetIterator' );
135 is( ref($esetit), 'Xapian::ESetIterator', 'check ESetIterator' );
137 ok( $msetit = $mset->begin(), 'create MSetIterator' );
138 is( ref($msetit), 'Xapian::MSetIterator', 'check MSetIterator' );
140 ok( $postit = $db->postlist_begin("one"), 'create PostingIterator' );
141 is( ref($postit), 'Xapian::PostingIterator', 'check PostingIterator' );
143 ok( $posit = $db->positionlist_begin(1, "one"), 'create PositionIterator' );
144 is( ref($posit), 'Xapian::PositionIterator', 'check PositionIterator' );
146 ok( $termit = $db->termlist_begin(1), 'create TermIterator' );
147 is( ref($termit), 'Xapian::TermIterator', 'check TermIterator' );
149 ok( $valueit = $doc->values_begin(), 'create ValueIterator' );
150 is( $valueit->get_valueno(), 0, 'check ValueIterator' );
152 ok( $sstop = Xapian::SimpleStopper->new(), 'create SimpleStopper' );
153 is( ref($sstop), 'Xapian::SimpleStopper', 'check SimpleStopper' );
155 ok( $tg = Xapian::TermGenerator->new(), 'create TermGenerator' );
156 is( ref($tg), 'Xapian::TermGenerator', 'check TermGenerator' );
158 ok( $rp = Xapian::RangeProcessor->new(0), 'create RangeProcessor' );
159 is( ref($rp), 'Xapian::RangeProcessor', 'check RangeProcessor' );
161 my $thread1 = threads->create(sub { thread_proc(); });
162 my $thread2 = threads->create(sub { thread_proc(); });
163 ok( $thread1->join, 'check thread1' );
164 ok( $thread2->join, 'check thread2' );
166 is( $wdb->get_doccount(), 0, 'check WritableDatabase' );
167 is( $db->get_doccount(), 2, 'check Database' );
168 is( $doc->get_data(), 'test one', 'check Document' );
169 is( ref($bm25wt), 'Xapian::BM25Weight', 'check BM25Weight' );
170 is( ref($boolwt), 'Xapian::BoolWeight', 'check BoolWeight' );
171 is( ref($tradwt), 'Xapian::TradWeight', 'check TradWeight' );
172 ok( $enq->get_query()->empty(), 'check Enquire' );
173 is( $qp->get_default_op(), OP_OR, 'check QueryParser' );
174 ok( !$q->empty(), 'check Query' );
175 is( $stem->stem_word('testing'), 'test', 'check Stem' );
176 ok( $eset->empty(), 'check ESet' );
177 ok( $mset->empty(), 'check MSet' );
178 ok( $rset->empty(), 'check RSet' );
179 is( ref($esetit), 'Xapian::ESetIterator', 'check ESetIterator' );
180 is( ref($msetit), 'Xapian::MSetIterator', 'check MSetIterator' );
181 is( ref($postit), 'Xapian::PostingIterator', 'check PostingIterator' );
182 is( ref($posit), 'Xapian::PositionIterator', 'check PositionIterator' );
183 is( ref($termit), 'Xapian::TermIterator', 'check TermIterator' );
184 is( $valueit->get_valueno(), 0, 'check ValueIterator' );
185 is( ref($sstop), 'Xapian::SimpleStopper', 'check SimpleStopper' );
186 is( ref($tg), 'Xapian::TermGenerator', 'check TermGenerator' );
187 is( ref($rp), 'Xapian::RangeProcessor', 'check RangeProcessor' );