--- trunk/t/SWISH-Split.t 2004/08/08 10:53:04 3 +++ trunk/t/SWISH-Split.t 2004/08/08 19:22:56 4 @@ -2,34 +2,36 @@ use strict; -use Test::More tests => 11; +use Test::More tests => 51; use Test::Exception; use File::Temp qw/ :mktemp /; use blib; -BEGIN { use_ok('SWISH::Split') }; +BEGIN { + use_ok('SWISH::Split'); + use_ok('SWISH::API'); +}; # FIXME debug system "rm -Rf /tmp/swish?????"; +system "rm -Rf /tmp/swish?????.prop"; +system "rm -Rf /tmp/swish?????.temp"; my %param; throws_ok { SWISH::Split->open(%param) } qr/slice_name/, "slice_name"; -sub slice_1st_char { - return substr($_[0],0,1); +sub slice_hash { + return $_[0]; }; -use Data::Dumper; -print Dumper(\&slice_1st_char); - -$param{'slice_name'} = \&slice_1st_char; +$param{'slice_name'} = \&slice_hash; throws_ok { SWISH::Split->open(%param) } qr/slices/, "need slices"; $param{'slices'} = 3; throws_ok { SWISH::Split->open(%param) } qr/index/, "need index"; -ok($param{'index'} = mktemp("/tmp/swishXXXXX"), "make temp name"); +ok($param{'index'} = mktemp("/tmp/swishXXXXX"), "index name"); diag "index path: $param{'index'}\n"; @@ -42,13 +44,91 @@ ok(mkdir($param{'index'}), "mkdir"); +$param{'swish_config'} = qq{ +PropertyNames foo +}; + ok(my $i=SWISH::Split->open(%param), "open"); -# methods test +cmp_ok(my $s = $i->in_slice("swishpath"), '==', 1, "open"); + +ok(my $config = $i->make_config($s), "make_config"); +diag "swish config: $config"; + +# make temporary index and data names + +ok(my $test_index = mktemp("/tmp/swishXXXXX"), "test index name"); +diag "test index: $test_index"; +ok(my $test_data = mktemp("/tmp/swishXXXXX"), "test data name"); +diag "test data: $test_data"; + +ok(my $xml = $i->to_xml({ foo => 'bar' }), "to_xml"); + +sub write_test_data($$) { + my ($path,$xml) = @_; + + use bytes; + my $l = length($xml); + + diag "xml: $xml [$l bytes]"; + ok(open(DATA, "> $test_data"), "write to test data"); + print DATA "Path-name: $path\nContent-length: $l\n\n$xml"; + ok(close(DATA), "close"); +} + +write_test_data('testpath',$xml); + +# test swish-e binary +ok(my $out =`cat $test_data | swish-e -S prog -f $test_index -c $config 2>&1`, "test config"); + +like($out, qr/foo/, "found foo"); +like($out, qr/testpath/, "found testpath"); + +diag "swish-e binary o.k."; + +# test compatiblity of produced index with SWISH::API + +sub swish_search { + my ($index, $query, $hits, $path, $size, $prop, $val) = @_; + + my $swish = SWISH::API->new($index); + ok(! $swish->Error, "SWISH::API->new $index"); + + ok(my $results = $swish->Query($query), "SWISH::API->Query $query"); + ok(! $swish->Error, "no error"); + + cmp_ok($results->Hits, '==', $hits, "got $hits hits"); + + ok(my $result = $results->NextResult, "get result"); + + cmp_ok($result->Property('swishdocpath'), '==', $path, "correct swishdocpath") if ($path); + cmp_ok($result->Property('swishdocsize'), '==', $size, "correct swishdocsize") if (defined($size)); + cmp_ok($result->Property($prop), '==', $val, "correct data") if (defined($prop) && defined($val)); +} + +swish_search($test_index, "foo=(bar)", 1, "testpath", length($xml), "foo", "bar"); + +diag "SWISH::API o.k."; + +# now, test slice handling + +ok(my $slice = $i->create_slice('testpath'), "create_slice"); + +ok($i->put_slice('testpath', $xml), "put_slice"); + +ok($i->close_slice($slice), "close_slice"); + +swish_search($param{'index'}."/$slice", "foo=(bar)", 1, "testpath", length($xml)+1, "foo", "bar"); + +diag "slice handling o.k."; +ok($i->add('testpath',{ foo => 'bar' }),"add foo"); +foreach (1..$param{'slices'} * 3) { + ok($i->add('testpath'.$_,{ 'foo'.$_ => 'bar'.$_ }), "add $_"); +} -# internal functions test +cmp_ok($i->finish, '==', 3, "finish"); -cmp_ok($i->in_slice("swishpath"), '==', 2, "open"); +#diag "$out";