Remove repeated "my".
[ZOOM-Perl-moved-to-github.git] / t / 1-Net-Z3950-ZOOM.t
1 # $Id: 1-Net-Z3950-ZOOM.t,v 1.4 2005-10-12 14:36:17 mike Exp $
2
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'
5
6 #########################
7
8 # change 'tests => 1' to 'tests => last_test_to_print';
9
10 use strict;
11 use Test::More tests => 11;
12 BEGIN { use_ok('Net::Z3950::ZOOM') };
13
14 #########################
15
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.
18
19 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
20
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");
26
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");
31
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'");
38
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");
44
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");
49
50 my $n = Net::Z3950::ZOOM::resultset_size($rs);
51 ok($n == 1, "found 1 record as expected");
52
53 my $rec = Net::Z3950::ZOOM::resultset_record($rs, 0);
54 my $len = 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");
60
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");