implement close for perl OpenIsis bindings
[webpac] / openisis / perl / test.pl
1 #
2 #/*
3 #       openisis - an open implementation of the CDS/ISIS database
4 #       Version 0.8.x (patchlevel see file Version)
5 #       Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
6 #
7 #       This library is free software; you can redistribute it and/or
8 #       modify it under the terms of the GNU Lesser General Public
9 #       License as published by the Free Software Foundation; either
10 #       version 2.1 of the License, or (at your option) any later version.
11 #
12 #       This library is distributed in the hope that it will be useful,
13 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #       Lesser General Public License for more details.
16 #
17 #       You should have received a copy of the GNU Lesser General Public
18 #       License along with this library; if not, write to the Free Software
19 #       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 #
21 #       see README for more information
22 #EOH */
23 #
24 # Before `make install' is performed this script should be runnable with
25 # `make test'. After `make install' it should work as `perl test.pl'
26
27 ######################### We start with some black magic to print on failure.
28
29 # Change 1..1 below to 1..last_test_to_print .
30 # (It may become useful if the test is moved to ./t subdirectory.)
31
32 BEGIN { $| = 1; print "1..6\n"; }
33 END {print "not ok 1\n" unless $loaded;}
34 use OpenIsis;
35 $loaded = 1;
36 print "ok 1\n";
37
38 ######################### End of black magic.
39
40 # Insert your test code below (better if it prints "ok 13"
41 # (correspondingly "not ok 13") depending on the success of chunk 13
42 # of the test code):
43
44 sub pok { print $_[1] ? '' : 'not ', 'ok ', $_[0], ' (', $_[2], ") \n"; }
45
46 OpenIsis::log(0,'');
47 pok( 2, 1, 'unfortunately the effect of logging cannot be tested here' );
48
49 $db = OpenIsis::open( "cds", "-dbpath", "../db/cds" );
50 pok( 3, $db >= 0, $db );
51
52 $maxrow = OpenIsis::maxRowid( $db );
53 pok( 4, $maxrow > 0, $maxrow );
54
55 $row = OpenIsis::read( $db, 28 );
56 for (keys(%$row)) {
57         next if 'mfn' eq $_;
58         $a = $row->{$_};
59         OpenIsis::MHL( @$a );
60         # print STDERR "\t$_=",join( "\n\t", @$a ),"\n";
61 }
62 pok( 5, "HASH" eq ref($row), $row );
63
64 $row = OpenIsis::subfields( '^ap. 233-238 ^billus.' );
65 # for (keys(%$row)) { print STDERR "\t$_=$row->{$_}\n"; }
66 pok( 6, "HASH" eq ref($row) && 'p. 233-238 ' eq $row->{'a'}, $row->{'a'} );
67
68 @res = OpenIsis::query( $db, 'plant * water' );
69 # print STDERR "mfns for 'plant * water': ", join(',',@res), "\n";
70 pok( 7, 2 == @res, scalar(@res) );
71 @res = OpenIsis::query( $db, 'devel$' );
72 # print STDERR "mfns for 'devel$': ", join(',',@res), "\n";
73 pok( 8, 18 == @res, scalar(@res) );
74
75 # test error code
76 $nodb = OpenIsis::open( "foo", "-dbpath", "/no/such/database" );
77 pok( 9, $nodb == $OpenIsis::ERR_BADF, $nodb );
78
79 # not really tests
80 for (@res) {
81         $row = OpenIsis::read( $db, $_ );
82         $title = $row->{'24'};
83         OpenIsis::MHL( @$title );
84         # print STDERR "mfn ", $row->{'mfn'}, " title: ", $title->[0], "\n";
85 }
86 @res = OpenIsis::terms( $db, 'a$' );
87 # print STDERR 'terms for "a$": ', join('; ',@res), "\n";
88
89 $str = OpenIsis::2html( 'lt: < gt: > amp: & quot: "' );
90 # print STDERR "\t$str\n";
91
92 @res = OpenIsis::query( $db, 'Dacca' );
93 for (@res) {
94         $row = OpenIsis::read( $db, $_, 'V24, V26, V26^*[..], V71,' );
95         for (sort(keys(%$row))) {
96                 $vals = $row->{$_};
97                 # for $v (@$vals) { print STDERR "\t$_=$v\n"; }
98         }
99 }