/[SWISH-Split]/trunk/t/01api.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/t/01api.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Fri Dec 17 18:32:34 2004 UTC (19 years, 4 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3678 byte(s)
a lot of changes:
- better testing framework
- changed put_slice API (to actually confirm with documentation)
- use swish-e stdin instead of external cat utility
- added tags target

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More tests => 75;
6 use Test::Exception;
7 use File::Temp qw/ :mktemp /;
8 use blib;
9
10 BEGIN {
11 use_ok('SWISH::Split');
12 use_ok('SWISH::API');
13 };
14
15 # FIXME debug
16 system "rm -Rf /tmp/swish?????";
17 system "rm -Rf /tmp/swish?????.prop";
18 system "rm -Rf /tmp/swish?????.temp";
19
20 my %param;
21
22 throws_ok { SWISH::Split->open(%param) } qr/slice_name/, "slice_name";
23
24 sub slice_hash {
25 return $_[0];
26 };
27
28 $param{'slice_name'} = \&slice_hash;
29 throws_ok { SWISH::Split->open(%param) } qr/slices/, "need slices";
30
31 $param{'slices'} = 3;
32 throws_ok { SWISH::Split->open(%param) } qr/index/, "need index";
33
34 ok($param{'index'} = mktemp("/tmp/swishXXXXX"), "index name");
35
36 diag "index path: $param{'index'}\n";
37
38 ok(open(F, "> $param{'index'}"), "touch");
39 close(F);
40
41 throws_ok { SWISH::Split->open(%param) } qr/dir/, "need dir";
42
43 ok(unlink($param{'index'}), "rm");
44
45 ok(mkdir($param{'index'}), "mkdir");
46
47 $param{'swish_config'} = qq{
48 PropertyNames foo
49 };
50
51 ok(my $i=SWISH::Split->open(%param), "open");
52
53 cmp_ok(my $s = $i->in_slice("swishpath"), '==', 1, "open");
54
55 ok(my $config = $i->make_config($s), "make_config");
56 diag "swish config: $config";
57
58 # make temporary index and data names
59
60 ok(my $test_index = mktemp("/tmp/swishXXXXX"), "test index name");
61 diag "test index: $test_index";
62 ok(my $test_data = mktemp("/tmp/swishXXXXX"), "test data name");
63 diag "test data: $test_data";
64
65 ok(my $xml = $i->to_xml({ foo => 'bar' }), "to_xml");
66
67 sub write_test_data($$) {
68 my ($path,$xml) = @_;
69
70 use bytes;
71 my $l = length($xml);
72
73 diag "xml: $xml [$l bytes]";
74 ok(open(DATA, "> $test_data"), "write to test data");
75 print DATA "Path-name: $path\nContent-length: $l\n\n$xml";
76 ok(close(DATA), "close");
77 }
78
79 write_test_data('testpath',$xml);
80
81 # test swish-e binary
82 ok(my $out =`cat $test_data | swish-e -S prog -f $test_index -c $config 2>&1`, "test config");
83
84 like($out, qr/foo/, "found foo");
85 like($out, qr/testpath/, "found testpath");
86
87 diag "swish-e binary o.k.";
88
89 # test compatiblity of produced index with SWISH::API
90
91 sub swish_search {
92 my ($index, $query, $hits, $path, $size, $prop, $val) = @_;
93
94 my $swish = SWISH::API->new($index);
95 ok(! $swish->Error, "SWISH::API->new $index");
96
97 ok(my $results = $swish->Query($query), "SWISH::API->Query $query");
98 ok(! $swish->Error, "no error");
99
100 cmp_ok($results->Hits, '==', $hits, "got $hits hits");
101
102 ok(my $result = $results->NextResult, "get result");
103
104 SKIP: {
105 skip "no results found, skipping property test", 3 unless ($result);
106
107 cmp_ok($result->Property('swishdocpath'), '==', $path, "correct swishdocpath") if ($path);
108 cmp_ok($result->Property('swishdocsize'), '==', $size, "correct swishdocsize") if (defined($size));
109 cmp_ok($result->Property($prop), '==', $val, "correct data") if (defined($prop) && defined($val));
110 }
111 }
112
113 swish_search($test_index, "foo=(bar)", 1, "testpath", length($xml), "foo", "bar");
114
115 diag "SWISH::API o.k.";
116
117 # now, test slice handling
118
119 ok($s = $i->create_slice('testpath'), "create_slice $s");
120
121 ok($s = $i->put_slice('testpath', $xml), "put_slice $s");
122
123 ok($i->close_slice($s), "close_slice $s");
124
125 swish_search($param{'index'}."/$s", "foo=(bar)", 1, "testpath", length($xml)+1, "foo", "bar");
126
127 diag "slice $s handling o.k.";
128
129 my %slice_files;
130 ok($s = $i->add('testpath',{ foo => 'bar' }),"add foo [slice $s]");
131 $slice_files{$s}++;
132
133 foreach (1..$param{'slices'} * 10) {
134 ok($s = $i->add('testpath'.$_,{ 'foo' => sprintf("bar%04d", $_) }), "add $_ [slice $s]");
135 $slice_files{$s}++;
136 }
137
138 cmp_ok($i->done, '==', 3, "finish");
139
140 foreach (1..$param{'slices'}) {
141 swish_search( $param{'index'}."/$_", "foo=(bar*)", $slice_files{$_}, "testpath", length($xml)+4, "foo", "bar");
142 }
143
144 #diag "$out";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26