/[Search-Estraier]/trunk/t/5_Node.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

Diff of /trunk/t/5_Node.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 140 by dpavlin, Wed May 10 14:08:34 2006 UTC revision 151 by dpavlin, Tue May 16 11:39:53 2006 UTC
# Line 3  Line 3 
3  use strict;  use strict;
4  use blib;  use blib;
5    
6  use Test::More tests => 142;  use Test::More tests => 270;
7  use Test::Exception;  use Test::Exception;
8  use Data::Dumper;  use Data::Dumper;
9    
10  BEGIN { use_ok('Search::Estraier') };  BEGIN { use_ok('Search::Estraier') };
11    
12  my $debug = 0;  my $debug = shift @ARGV;
13    
14  # name of node for test  # name of node for test
15  my $test1_node = '_test1_' . $$;  my $test1_node = '_test1_' . $$;
# Line 32  cmp_ok($node->status, '==', -1, 'status' Line 32  cmp_ok($node->status, '==', -1, 'status'
32    
33  # test master functionality  # test master functionality
34    
35  #diag "not testing shutdown\n";  diag("node->master shutdown not tested");
36    
37  my $msg;  diag("node->master backup not tested");
   
 ok($msg = $node->master( action => 'sync' ), "sync: $msg");  
   
 #diag "not testing backup\n";  
38    
39  ok(my @users = $node->master( action => 'userlist' ), 'userlist');  ok(my @users = $node->master( action => 'userlist' ), 'userlist');
40    
# Line 52  my $user = { Line 48  my $user = {
48          misc => 'test user',          misc => 'test user',
49  };  };
50    
51    my $msg;
52  ok($msg = $node->master(  ok($msg = $node->master(
53          action => 'useradd',          action => 'useradd',
54          %{ $user },          %{ $user },
# Line 109  foreach my $node_name ( $test1_node , $t Line 106  foreach my $node_name ( $test1_node , $t
106  }  }
107    
108  ok($msg = $node->master(  ok($msg = $node->master(
         action => 'nodeclr',  
         name => $temp_node,  
 ), "nodeclr $temp_node: $msg");  
   
 ok($msg = $node->master(  
109          action => 'nodedel',          action => 'nodedel',
110          name => $temp_node,          name => $temp_node,
111  ), "nodedel $temp_node: $msg");  ), "nodedel $temp_node: $msg");
# Line 123  ok($msg = $node->master( Line 115  ok($msg = $node->master(
115  # test document creation  # test document creation
116    
117  my $draft = <<'_END_OF_DRAFT_';  my $draft = <<'_END_OF_DRAFT_';
118  @uri=data001  @uri=data0
119  @title=Material Girl  @title=Material Girl
120    
121  Living in a material world  Living in a material world
# Line 137  ok(my $doc = new Search::Estraier::Docum Line 129  ok(my $doc = new Search::Estraier::Docum
129    
130  ok( $node->put_doc($doc), "put_doc data001");  ok( $node->put_doc($doc), "put_doc data001");
131    
132  for ( 1 .. 10 ) {  for ( 1 .. 17 ) {
133          $doc->add_attr('@uri', 'test' . $_);          $doc->add_attr('@uri', 'test' . $_);
134          ok( $node->put_doc($doc), "put_doc test$_");          ok( $node->put_doc($doc), "put_doc test$_");
135          #diag $doc->dump_draft;          #diag $doc->dump_draft;
136            cmp_ok( $node->doc_num, '==', ($_ + 1), "node->doc_num " . ($_ + 1));
137  }  }
138    
139  my $id;  ok(! $node->uri_to_id( 'does-not-exists' ), "non-existant uri_to_id");
 ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id");  
   
 my $data_max = 5;  
140    
141  for ( 1 .. $data_max ) {  my $id;
142          ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");  ok($id = $node->uri_to_id( 'data0' ), "uri_to_id(data0)");
 }  
143    
144  ok($doc = $node->get_doc( $id ), 'get_doc for edit');  ok($doc = $node->get_doc( $id ), "get_doc($id) for edit");
145  $doc->add_attr('foo', 'bar');  $doc->add_attr('foo', 'bar');
146  #diag Dumper($doc);  #diag Dumper($doc);
147  ok( $node->edit_doc( $doc ), 'edit_doc');  ok( $node->edit_doc( $doc ), 'edit_doc');
148    
149  ok( $node->out_doc( $id ), "out_doc $id");  my $doc_num;
150    ok( $doc_num = $node->doc_num, "node->doc_num $doc_num");
151    
152    ok( $node->out_doc( $id ), "out_doc($id)");
153    
154    cmp_ok( $node->doc_num, '==', --$doc_num, "node->doc_num " . $doc_num);
155    
156    ok( ! $node->edit_doc( $doc ), "edit_doc of removed doc");
157    
158    my $delete_num = 5;
159    
160  ok( ! $node->edit_doc( $doc ), "edit removed");  for ( 1 .. $delete_num ) {
161            ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_");
162            cmp_ok( $node->doc_num, '==', $doc_num - $_, "node->doc_num " . ($doc_num - $_));
163    }
164    
165    my $doc_num2 = $doc_num - $delete_num;
166    cmp_ok($node->doc_num, '==', $doc_num2, "node->doc_num $doc_num2");
167    
168  my $max = 3;  my $max = int($doc_num2 / 2);
169    
170  ok(my $cond = new Search::Estraier::Condition, 'new cond');  ok(my $cond = new Search::Estraier::Condition, 'new cond');
171  ok($cond->set_phrase('girl'), 'cond set_phrase');  ok($cond->set_phrase('girl'), 'cond set_phrase');
172  ok($cond->set_max($max), "cond set_max $max");  ok($cond->set_max($max), "cond set_max($max)");
173  ok($cond->set_order('@uri ASCD'), 'cond set_order');  ok($cond->set_order('@uri ASCD'), 'cond set_order');
174  ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');  ok($cond->add_attr('@title STRINC Material'), 'cond add_attr');
175    
# Line 175  ok( my $nres = $node->search( $cond, 0 ) Line 179  ok( my $nres = $node->search( $cond, 0 )
179    
180  isa_ok( $nres, 'Search::Estraier::NodeResult' );  isa_ok( $nres, 'Search::Estraier::NodeResult' );
181    
182  cmp_ok($nres->doc_num, '==', $max, "doc_num = $max");  cmp_ok($nres->doc_num, '==', $max, "nres->doc_num $max");
183    
184  cmp_ok($nres->hits, '==', $data_max, "hits");  cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2");
185    
186    # upper limit is $nres->hits and not $nres->doc_num because we
187    # check all documents, not just results!
188  for my $i ( 0 .. ($nres->hits - 1) ) {  for my $i ( 0 .. ($nres->hits - 1) ) {
189          my $uri = 'test' . ($i + $data_max + 1);          my $num = $i + $delete_num + 1;
190            my $uri = 'test' . $num;
191    
192          if ($i < $nres->doc_num) {          if ($i < $nres->doc_num) {
193                  ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i");                  ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i");
194    
195                  cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");                  cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");
196                    cmp_ok( $node->uri_to_id( $uri ), '==', $num + 1, "uri_to_id($uri)");
197    
198                  ok( my $k = $rdoc->keywords( $id ), "rdoc keywords");                  ok( my $k = $rdoc->keywords( $id ), "rdoc keywords");
199            } else {
200                    ok( ! $nres->get_doc( $i ), "nres->get_doc doesn't exist");
201          }          }
202    
203          ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id");          ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri)");
204          ok( $node->get_doc( $id ), "get_doc $id");          ok( $node->get_doc( $id ), "get_doc($id)");
205          ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri");          ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri($uri)");
206          cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");          cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id");
207          cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");          cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id");
208          ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri");          ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri");
# Line 214  ok($v = $node->size, "size: $v"); Line 225  ok($v = $node->size, "size: $v");
225    
226  ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");  ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width");
227    
228    # test skip
229    my $skip = int($max / 2) || die "skip is zero, can't test";
230    ok($cond->set_skip( $skip ), "cond set_skip($skip)");
231    
232    ok( $nres = $node->search( $cond, 0 ), 'search');
233    isa_ok( $nres, 'Search::Estraier::NodeResult' );
234    cmp_ok($nres->doc_num, '==', $max, "nres->doc_num " . ($max - $skip));
235    cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2");
236    
237    for my $i ( 0 .. ($nres->doc_num - 1) ) {
238            my $uri = 'test' . ($i + $delete_num + 1);
239            ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i");
240            if ($rdoc) {
241                    cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri");
242            } else {
243                    fail('no rdoc');
244            }
245    }
246    
247    
248  # user doesn't exist  # user doesn't exist
249  ok(! $node->set_user('foobar', 1), 'set_user');  ok(! $node->set_user('foobar', 1), 'set_user');
250    
# Line 251  cmp_ok($#{$links}, '==', 0, 'one link'); Line 282  cmp_ok($#{$links}, '==', 0, 'one link');
282  like($links->[0], qr/^$link_url/, 'link correct');  like($links->[0], qr/^$link_url/, 'link correct');
283  ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");  ok($node->set_link("http://localhost:1978/node/$test2_node", $test2_label, 0), "set_link $test2_node ($test2_label) delete");
284    
285    ok($msg = $node->master(
286            action => 'nodeclr',
287            name => $node->name,
288    ), "nodeclr $node->name: $msg");
289    
290    cmp_ok($node->doc_num, '==', 0, 'no documents');
291    
292  # cleanup test nodes  # cleanup test nodes
293  foreach my $node_name ( $test1_node , $test2_node ) {  foreach my $node_name ( $test1_node , $test2_node ) {
294          ok($msg = $node->master(          ok($msg = $node->master(
# Line 310  ok($msg = $node->master( Line 348  ok($msg = $node->master(
348          name => $node_name,          name => $node_name,
349  ), "nodedel $node_name: $msg");  ), "nodedel $node_name: $msg");
350    
351    ok($msg = $node->master( action => 'sync' ), "sync: $msg");
352    
353  diag "over";  diag "over";

Legend:
Removed from v.140  
changed lines
  Added in v.151

  ViewVC Help
Powered by ViewVC 1.1.26