1 # $Id: 3-simpleserver.t,v 1.1 2007-10-05 12:12:10 mike Exp $
8 use Test::More tests => 52;
9 BEGIN { use_ok('Net::Z3950::PQF') };
11 my $parser = new Net::Z3950::PQF();
12 ok(defined $parser, "created parser");
13 my $top = $parser->parse(
14 '@and @or @set 123 @attr 1=1023 frog @attr 2=3 @attr zthes 1=magic bar');
16 my $ss = $top->toSimpleServer();
17 check_node($ss, "top node", "Net::Z3950::RPN::And", "an AND node");
18 is(@$ss, 2, "top has two subtrees");
21 check_node($sub, "first subtree", "Net::Z3950::RPN::Or", "an OR node");
22 is(@$sub, 2, "first subnode has two subtrees");
24 my $subsub = $sub->[0];
25 check_node($subsub, "first subsubtree", "Net::Z3950::RPN::RSID", "an RSID");
26 is($subsub->{id}, 123, "RSID value");
27 check_attributes($subsub->{attributes}, "first subsubtree", 0);
30 check_node($subsub, "second subsubtree", "Net::Z3950::RPN::Term", "a Term");
31 is($subsub->{term}, "frog", "term value");
32 check_attributes($subsub->{attributes}, "second subsubtree", 1);
33 check_attribute($subsub->{attributes}->[0],
34 "second subsubtree, only attribute", "bib-1", 1 => 1023);
37 check_node($sub, "second subtree", "Net::Z3950::RPN::Term", "a Term");
38 is($sub->{term}, "bar", "term value");
39 check_attributes($sub->{attributes}, "second subtree", 2);
40 check_attribute($sub->{attributes}->[0],
41 "second subtree, second attribute", "bib-1", 2 => 3);
42 check_attribute($sub->{attributes}->[1],
43 "second subtree, first attribute", "zthes", 1 => "magic");
45 #use YAML; print Dump($ss);
49 my($node, $caption, $class, $description) = @_;
51 ok(defined $node, "$caption is defined");
52 ok(ref $node, "$caption is a reference");
53 ok($node->isa($class), "$caption is $description");
57 sub check_attributes {
58 my($attrs, $caption, $count) = @_;
60 ok(defined $attrs, "$caption has attributes");
61 ok(ref $attrs, "$caption attributes are a reference");
62 ok($attrs->isa("Net::Z3950::RPN::Attributes"), "$caption attributes type");
63 is(@{ $attrs }, $count, "$caption attribute count = $count");
68 my($attr, $caption, $set, $type, $value) = @_;
70 ok(defined $attr, "$caption is defined");
71 ok(ref $attr, "$caption is a reference");
72 ok($attr->isa("Net::Z3950::RPN::Attribute"), "$caption type");
73 is($attr->{attributeSet}, $set, "$caption attribute set");
74 is($attr->{attributeType}, $type, "$caption attribute set");
75 is($attr->{attributeValue}, $value, "$caption attribute set");