Remove extraneous output.
[ZOOM-Perl-moved-to-github.git] / t / 1-Net-Z3950-ZOOM.t
1 # $Id: 1-Net-Z3950-ZOOM.t,v 1.8 2005-10-13 13:33:55 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 => 15;
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 $msg = Net::Z3950::ZOOM::diag_str(Net::Z3950::ZOOM::ERROR_INVALID_QUERY);
20 ok($msg eq "Invalid query", "diagnostic string lookup works");
21
22 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
23
24 my $host = "no.such.host";
25 my $conn = Net::Z3950::ZOOM::connection_new($host, 0);
26 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
27 ok($errcode == Net::Z3950::ZOOM::ERROR_CONNECT && $addinfo eq $host,
28    "connection to non-existent host '$host' fails");
29
30 $host = "indexdata.com/gils";
31 $conn = Net::Z3950::ZOOM::connection_new($host, 0);
32 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
33 ok($errcode == 0, "connection to '$host'");
34
35 Net::Z3950::ZOOM::connection_destroy($conn);
36 ok(1, "destroyed connection");
37
38 my $options = Net::Z3950::ZOOM::options_create();
39 $conn = Net::Z3950::ZOOM::connection_create($options);
40 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
41 ok($errcode == 0, "unconnected connection object created");
42 Net::Z3950::ZOOM::connection_connect($conn, $host, 0);
43 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
44 ok($errcode == 0, "delayed connection to '$host'");
45
46 my $syntax = "usmarc";
47 Net::Z3950::ZOOM::connection_option_set($conn,
48                                         preferredRecordSyntax => $syntax);
49 my $val = Net::Z3950::ZOOM::connection_option_get($conn,
50                                                   "preferredRecordSyntax");
51 ok($val eq $syntax, "preferred record syntax set to '$val'");
52
53 my $query = '@attr @and 1=4 minerals';
54 my $rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query);
55 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
56 ok($errcode == Net::Z3950::ZOOM::ERROR_INVALID_QUERY,
57    "search for invalid query '$query' fails");
58
59 $query = '@attr 1=4 minerals';
60 $rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query);
61 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
62 ok($errcode == 0, "search for '$query'");
63
64 my $n = Net::Z3950::ZOOM::resultset_size($rs);
65 ok($n == 1, "found 1 record as expected");
66
67 my $rec = Net::Z3950::ZOOM::resultset_record($rs, 0);
68 my $len = 0;
69 my $data = Net::Z3950::ZOOM::record_get($rec, "render", $len);
70 ok($data =~ /245 +\$a ISOTOPIC DATES OF ROCKS AND MINERALS/,
71    "rendered record has expected title");
72 my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len);
73 ok($raw =~ /^00981n/, "raw record contains expected header");
74
75 Net::Z3950::ZOOM::resultset_destroy($rs);
76 ok(1, "destroyed result-set");
77 Net::Z3950::ZOOM::connection_destroy($conn);
78 ok(1, "destroyed connection");