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