1 # $Id: 2-ZOOM.t,v 1.13 2007-09-14 10:36:13 mike Exp $
3 # Before `make install' is performed this script should be runnable with
4 # `make test'. After `make install' it should work as `perl 2-ZOOM.t'
8 use Test::More tests => 23;
9 BEGIN { use_ok('ZOOM') };
11 my $msg = ZOOM::diag_str(ZOOM::Error::INVALID_QUERY);
12 ok($msg eq "Invalid query", "diagnostic string lookup works");
14 $msg = ZOOM::diag_srw_str(27);
15 ok($msg eq "Empty term unsupported", "SRW diagnostic string lookup works");
17 my $host = "no.such.host";
19 eval { $conn = new ZOOM::Connection($host, 0) };
20 ok($@ && $@->isa("ZOOM::Exception") &&
21 $@->code() == ZOOM::Error::CONNECT && $@->addinfo() eq $host,
22 "connection to non-existent host '$host' fails : \$\@=$@");
24 $host = "z3950.indexdata.com/gils";
25 eval { $conn = new ZOOM::Connection($host, 0) };
26 ok(!$@, "connection to '$host'");
29 ok(1, "destroyed connection");
31 eval { $conn = create ZOOM::Connection() };
32 ok(!$@, "unconnected connection object created");
33 eval { $conn->connect($host, 0) };
34 ok(!$@, "delayed connection to '$host'");
37 my $val2 = "$val1\0bar";
38 $conn->option(xyz => $val2);
39 my $val = $conn->option("xyz");
40 ok($val eq $val1, "option() treats value as NUL-terminated");
41 $conn->option_binary(xyz => $val2, length($val2));
42 $val = $conn->option_binary("xyz");
43 ok($val eq $val2, "option_setl() treats value as opaque chunk, val='$val'");
45 my $syntax = "usmarc";
46 $conn->option(preferredRecordSyntax => $syntax);
47 $val = $conn->option("preferredRecordSyntax");
48 ok($val eq $syntax, "preferred record syntax set to '$val'");
50 my $query = '@attr @and 1=4 minerals';
52 eval { $rs = $conn->search_pqf($query) };
53 ok($@ && $@->isa("ZOOM::Exception") &&
54 $@->code() == ZOOM::Error::INVALID_QUERY,
55 "search for invalid query '$query' fails");
57 my($xcode, $xmsg, $xinfo, $xset) = $conn->error_x();
58 ok($xcode == $@->code() && $xmsg eq $@->message() && $xinfo eq $@->addinfo() &&
59 $xset eq $@->diagset(), "error_x() consistent with exception");
60 ok($conn->errcode() == $@->code(),
61 "errcode() consistent with exception");
62 ok($conn->errmsg() eq $@->message(),
63 "errmsg() consistent with exception");
64 ok($conn->addinfo() eq $@->addinfo(),
65 "addinfo() consistent with exception");
66 ok($conn->diagset() eq $@->diagset(),
67 "diagset() consistent with exception");
69 $query = '@attr 1=4 minerals';
70 eval { $rs = $conn->search_pqf($query) };
71 ok(!$@, "search for '$query'");
73 my $n = $rs->size($rs);
74 ok($n == 1, "found 1 record as expected");
76 my $rec = $rs->record(0);
77 my $data = $rec->render();
78 ok($data =~ /^245 +\$a ISOTOPIC DATES OF ROCKS AND MINERALS$/m,
79 "rendered record has expected title");
80 my $raw = $rec->raw();
81 ok($raw =~ /^00966n/, "raw record contains expected header");
84 ok(1, "destroyed result-set");
86 ok(1, "destroyed connection");