1 # $Id: 1-Net-Z3950-ZOOM.t,v 1.4 2005-10-12 14:36:17 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 Net-Z3950-ZOOM.t'
6 #########################
8 # change 'tests => 1' to 'tests => last_test_to_print';
11 use Test::More tests => 11;
12 BEGIN { use_ok('Net::Z3950::ZOOM') };
14 #########################
16 # Insert your test code below, the Test::More module is use()ed here so read
17 # its man page ( perldoc Test::More ) for help writing this test script.
19 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
21 my $host = "no.such.host";
22 my $conn = Net::Z3950::ZOOM::connection_new($host, 0);
23 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
24 ok($errcode == Net::Z3950::ZOOM::ERROR_CONNECT && $addinfo eq $host,
25 "connection to non-existent host '$host' fails");
27 $host = "indexdata.com/gils";
28 $conn = Net::Z3950::ZOOM::connection_new($host, 0);
29 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
30 ok($errcode == 0, "connection to '$host' OK");
32 my $syntax = "usmarc";
33 Net::Z3950::ZOOM::connection_option_set($conn,
34 preferredRecordSyntax => $syntax);
35 my $val = Net::Z3950::ZOOM::connection_option_get($conn,
36 "preferredRecordSyntax");
37 ok($val eq $syntax, "preferred record syntax set to '$val'");
39 my $query = '@attr @and 1=4 minerals';
40 my $rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query);
41 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
42 ok($errcode == Net::Z3950::ZOOM::ERROR_INVALID_QUERY,
43 "search for invalid query '$query' fails");
45 $query = '@attr 1=4 minerals';
46 $rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query);
47 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
48 ok($errcode == 0, "search for '$query' OK");
50 my $n = Net::Z3950::ZOOM::resultset_size($rs);
51 ok($n == 1, "found 1 record as expected");
53 my $rec = Net::Z3950::ZOOM::resultset_record($rs, 0);
55 my $data = Net::Z3950::ZOOM::record_get($rec, "render", $len);
56 ok($data =~ /245 +\$a ISOTOPIC DATES OF ROCKS AND MINERALS/,
57 "rendered record has expected title");
58 my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len);
59 ok($raw =~ /^00981n/, "raw record contains expected header");
61 Net::Z3950::ZOOM::resultset_destroy($rs);
62 ok(1, "destroyed result-set");
63 Net::Z3950::ZOOM::connection_destroy($conn);
64 ok(1, "destroyed connection");