1 # $Id: 2-ZOOM.t,v 1.5 2005-10-13 13:27:27 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 ZOOM.t'
6 #########################
8 # change 'tests => 1' to 'tests => last_test_to_print';
11 use Test::More tests => 12;
12 BEGIN { use_ok('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 $msg = ZOOM::diag_str(ZOOM::Error::INVALID_QUERY);
20 ok($msg eq "Invalid query", "diagnostic string lookup works");
22 my $host = "no.such.host";
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");
29 $host = "indexdata.com/gils";
30 eval { $conn = new ZOOM::Connection($host, 0) };
31 ok(!$@, "connection to '$host'");
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'");
38 my $query = '@attr @and 1=4 minerals';
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");
45 $query = '@attr 1=4 minerals';
46 eval { $rs = $conn->search_pqf($query) };
47 ok(!$@, "search for '$query'");
49 my $n = $rs->size($rs);
50 ok($n == 1, "found 1 record as expected");
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");
60 ok(1, "destroyed result-set");
62 ok(1, "destroyed connection");