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 #########################
7 # change 'tests => 1' to 'tests => last_test_to_print';
11 BEGIN { plan tests => 40 };
12 use Search::Xapian qw(:all);
14 #########################
16 # Insert your test code below, the Test module is use()ed here so read
17 # its man page ( perldoc Test ) for help writing this test script.
19 sub mset_expect_order (\@@) {
21 my @m = map { $_->get_docid() } @{$m};
22 is( scalar @m, scalar @a );
23 for my $j (0 .. (scalar @a - 1)) {
29 ok( $db = Search::Xapian::WritableDatabase->new(), "test db opened ok" );
32 ok( $enquire = Search::Xapian::Enquire->new( $db ), "enquire object created" );
35 ok( $doc = Search::Xapian::Document->new() );
36 $doc->add_term("foo");
37 $doc->add_value(0, "ABB");
38 $db->add_document($doc);
39 $doc->add_value(0, "ABC");
40 $db->add_document($doc);
41 $doc->add_value(0, "ABC\0");
42 $db->add_document($doc);
43 $doc->add_value(0, "ABCD");
44 $db->add_document($doc);
45 $doc->add_value(0, "ABC\xff");
46 $db->add_document($doc);
48 $enquire->set_query(Search::Xapian::Query->new("foo"));
52 my $sorter = Search::Xapian::MultiValueSorter->new();
54 $enquire->set_sort_by_key($sorter);
56 my @matches = $enquire->matches(0, 10);
57 mset_expect_order(@matches, (5, 4, 3, 2, 1));
61 my $sorter = Search::Xapian::MultiValueSorter->new();
63 $enquire->set_sort_by_key($sorter);
64 my @matches = $enquire->matches(0, 10);
65 mset_expect_order(@matches, (1, 2, 3, 4, 5));
69 my $sorter = Search::Xapian::MultiValueSorter->new();
72 $enquire->set_sort_by_key($sorter);
73 my @matches = $enquire->matches(0, 10);
74 mset_expect_order(@matches, (5, 4, 3, 2, 1));
78 my $sorter = Search::Xapian::MultiValueSorter->new();
81 $enquire->set_sort_by_key($sorter);
82 my @matches = $enquire->matches(0, 10);
83 mset_expect_order(@matches, (1, 2, 3, 4, 5));
87 my $sorter = Search::Xapian::MultiValueSorter->new();
90 $enquire->set_sort_by_key($sorter);
91 my @matches = $enquire->matches(0, 10);
92 mset_expect_order(@matches, (5, 4, 3, 2, 1));
96 my $sorter = Search::Xapian::MultiValueSorter->new();
99 $enquire->set_sort_by_key($sorter);
100 my @matches = $enquire->matches(0, 10);
101 mset_expect_order(@matches, (1, 2, 3, 4, 5));
105 my $count = Devel::Leak::NoteSV($handle);
107 my $enq = Search::Xapian::Enquire->new($db);
108 $enq->set_sort_by_key(Search::Xapian::MultiValueSorter->new(3, 1, 4));
110 ok( $count == Devel::Leak::CheckSV($handle) );