Now runs in parallel to 1-Net-Z3950-ZOOM.t: 11 tests, no output.
[ZOOM-Perl-moved-to-github.git] / t / 2-ZOOM.t
1 # $Id: 2-ZOOM.t,v 1.3 2005-10-12 14:31:53 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 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('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 $host = "no.such.host";
20 my $conn;
21 eval { $conn = new ZOOM::Connection($host, 0) };
22 ok($@ && $@->isa("ZOOM::Exception") &&
23    $@->code() == ZOOM::Error::CONNECT && $@->addinfo() eq $host,
24    "connection to non-existent host '$host' fails");
25
26 $host = "indexdata.com/gils";
27 eval { $conn = new ZOOM::Connection($host, 0) };
28 ok(!$@, "connection to '$host' OK");
29
30 my $syntax = "usmarc";
31 $conn->option(preferredRecordSyntax => $syntax);
32 my $val = $conn->option("preferredRecordSyntax");
33 ok($val eq $syntax, "preferred record syntax set to '$val'");
34
35 my $query = '@attr @and 1=4 minerals';
36 my $rs;
37 eval { $rs = $conn->search_pqf($query) };
38 ok($@ && $@->isa("ZOOM::Exception") &&
39    $@->code() == ZOOM::Error::INVALID_QUERY,
40    "search for invalid query '$query' fails");
41
42 $query = '@attr 1=4 minerals';
43 eval { $rs = $conn->search_pqf($query) };
44 ok(!$@, "search for '$query' OK");
45
46 my $n = $rs->size($rs);
47 ok($n == 1, "found 1 record as expected");
48
49 my $rec = $rs->record(0);
50 my $data = $rec->render();
51 ok($data =~ /245 +\$a ISOTOPIC DATES OF ROCKS AND MINERALS/,
52    "rendered record has expected title");
53 my $raw = $rec->raw();
54 ok($raw =~ /^00981n/, "raw record contains expected header");
55
56 $rs->destroy();
57 ok(1, "destroyed result-set");
58 $conn->destroy();
59 ok(1, "destroyed connection");