/[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

Annotation of /trunk/t/01api.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations)
Sun Dec 19 03:06:01 2004 UTC (19 years, 4 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3744 byte(s)
new api:
- renamed open to open_index
- removed dependency on IPC::Run
- tests which all pass

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26