/[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 6 - (show annotations)
Wed Dec 8 20:35:49 2004 UTC (19 years, 3 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3337 byte(s)
better distribution packaging and html target

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More tests => 51;
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 cmp_ok($result->Property('swishdocpath'), '==', $path, "correct swishdocpath") if ($path);
105 cmp_ok($result->Property('swishdocsize'), '==', $size, "correct swishdocsize") if (defined($size));
106 cmp_ok($result->Property($prop), '==', $val, "correct data") if (defined($prop) && defined($val));
107 }
108
109 swish_search($test_index, "foo=(bar)", 1, "testpath", length($xml), "foo", "bar");
110
111 diag "SWISH::API o.k.";
112
113 # now, test slice handling
114
115 ok(my $slice = $i->create_slice('testpath'), "create_slice");
116
117 ok($i->put_slice('testpath', $xml), "put_slice");
118
119 ok($i->close_slice($slice), "close_slice");
120
121 swish_search($param{'index'}."/$slice", "foo=(bar)", 1, "testpath", length($xml)+1, "foo", "bar");
122
123 diag "slice handling o.k.";
124
125 ok($i->add('testpath',{ foo => 'bar' }),"add foo");
126
127 foreach (1..$param{'slices'} * 3) {
128 ok($i->add('testpath'.$_,{ 'foo' => 'bar'.$_ }), "add $_");
129 }
130
131 cmp_ok($i->done, '==', 3, "finish");
132
133
134 #diag "$out";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26