Test is split into parts now, to be used by Test::Harness
authorpop <pop>
Mon, 3 Mar 2003 00:44:39 +0000 (00:44 +0000)
committerpop <pop>
Mon, 3 Mar 2003 00:44:39 +0000 (00:44 +0000)
perl/t/01_base.t [new file with mode: 0644]
perl/t/02_directory_update.t [new file with mode: 0644]
perl/t/03_record_update.t [new file with mode: 0644]
perl/t/04_cql.t [new file with mode: 0644]
perl/t/05_search.t [new file with mode: 0644]
perl/t/06_retrieval.t [new file with mode: 0644]

diff --git a/perl/t/01_base.t b/perl/t/01_base.t
new file mode 100644 (file)
index 0000000..535d880
--- /dev/null
@@ -0,0 +1,56 @@
+#!perl -Tw
+# =============================================================================
+# $Id: 01_base.t,v 1.1 2003-03-03 00:44:39 pop Exp $
+#
+# Perl API header
+# =============================================================================
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+        chdir 't' if -d 't';
+    }
+    push (@INC,'demo','blib/lib','blib/arch');
+}
+
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+BEGIN {
+    use_ok('IDZebra');
+    IDZebra::logFile("test.log");
+    use_ok('IDZebra::Session'); 
+}
+
+use pod;
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+my $sess = IDZebra::Session->new(configFile => 'demo/zebra.cfg');
+isa_ok($sess,"IDZebra::Session");
+
+$sess->open();
+ok(defined($sess->{zh}), "Zebra handle opened");
+
+$sess->close();
+ok(!defined($sess->{zh}), "Zebra handle closed");
+
+$sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
+                              groupName  => 'demo1');
+isa_ok($sess,"IDZebra::Session");
+ok(defined($sess->{zh}), "Zebra handle opened");
+
+# ----------------------------------------------------------------------------
+# Record group tests
+ok(($sess->group->{databaseName} eq "demo1"),"Record group is selected");
+
+$sess->group(groupName => 'demo2');
+
+ok(($sess->group->{databaseName} eq "demo2"),"Record group is selected");
+
+# ----------------------------------------------------------------------------
+# Close session
+
+$sess->close;
diff --git a/perl/t/02_directory_update.t b/perl/t/02_directory_update.t
new file mode 100644 (file)
index 0000000..e641dc8
--- /dev/null
@@ -0,0 +1,81 @@
+#!perl
+# =============================================================================
+# $Id: 02_directory_update.t,v 1.1 2003-03-03 00:44:39 pop Exp $
+#
+# Perl API header
+# =============================================================================
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+        chdir 't' if -d 't';
+    }
+    push (@INC,'demo','blib/lib','blib/arch');
+}
+
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+BEGIN {
+    use_ok('IDZebra');
+    IDZebra::logFile("test.log");
+    use_ok('IDZebra::Session'); 
+    use_ok('pod');
+}
+
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
+                                 groupName => 'demo2');
+isa_ok($sess,"IDZebra::Session");
+
+SKIP: {
+    skip "Takes a while", 5 if (0);
+
+# ----------------------------------------------------------------------------
+# init repository
+$sess->init();
+
+# ----------------------------------------------------------------------------
+# repository upadte
+
+our $filecount = 6;
+$sess->begin_trans;
+$sess->update(path      =>  'lib');
+my $stat = $sess->end_trans;
+
+ok(($stat->{inserted} == $filecount), 
+   "Inserted $stat->{inserted}/$filecount records");
+
+$sess->begin_trans;
+$sess->update(groupName => 'demo1',
+             path      =>  'lib');
+
+$stat = $sess->end_trans;
+ok(($stat->{inserted} == $filecount), 
+   "Inserted $stat->{inserted}/$filecount records");
+
+$sess->begin_trans;
+$sess->delete(groupName => 'demo1',
+             path      =>  'lib');
+$stat = $sess->end_trans;
+ok(($stat->{deleted} == $filecount), 
+   "Deleted $stat->{deleted}/$filecount records");
+
+$sess->begin_trans;
+$sess->update(groupName => 'demo1',
+             path      =>  'lib');
+
+$stat = $sess->end_trans;
+ok(($stat->{inserted} == $filecount), 
+   "Inserted $stat->{inserted}/$filecount records");
+
+ok(($sess->group->{databaseName} eq "demo2"),"Original group is selected");
+
+# ----------------------------------------------------------------------------
+# Close session
+}
+$sess->close;
diff --git a/perl/t/03_record_update.t b/perl/t/03_record_update.t
new file mode 100644 (file)
index 0000000..15f0baf
--- /dev/null
@@ -0,0 +1,72 @@
+#!perl
+# =============================================================================
+# $Id: 03_record_update.t,v 1.1 2003-03-03 00:44:39 pop Exp $
+#
+# Perl API header
+# =============================================================================
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+        chdir 't' if -d 't';
+    }
+    push (@INC,'demo','blib/lib','blib/arch');
+}
+
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+BEGIN {
+    use_ok('IDZebra');
+    IDZebra::logFile("test.log");
+    use_ok('IDZebra::Session'); 
+    use_ok('pod');
+}
+
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
+                                 groupName => 'demo2');
+isa_ok($sess,"IDZebra::Session");
+
+# ----------------------------------------------------------------------------
+# per record update
+my $rec1=`cat lib/IDZebra/Data1.pm`;
+my $rec2=`cat lib/IDZebra/Filter.pm`;
+
+my ($sysno, $stat);
+
+$sess->begin_trans;
+$sysno = $sess->update_record(data       => $rec1,
+                             recordType => 'grs.perl.pod',
+                             groupName  => "demo1",
+                             );
+$stat = $sess->end_trans;
+ok(($stat->{updated} == 1), "Updated 1 records");
+
+$sess->begin_trans;
+$sysno = $sess->delete_record(data       => $rec2,
+                             recordType => 'grs.perl.pod',
+                             groupName  => "demo1",
+                             );
+$stat = $sess->end_trans;
+ok(($stat->{deleted} == 1), "Deleted 1 records");
+
+$sess->begin_trans;
+$sysno = $sess->update_record(data       => $rec2,
+                              recordType => 'grs.perl.pod',
+                              groupName  => "demo1",
+                              );
+$stat = $sess->end_trans;
+ok(($stat->{inserted} == 1), "Inserted 1 records");
+
+
+
+
+# ----------------------------------------------------------------------------
+# Close session
+
+$sess->close;
diff --git a/perl/t/04_cql.t b/perl/t/04_cql.t
new file mode 100644 (file)
index 0000000..7efb8da
--- /dev/null
@@ -0,0 +1,58 @@
+#!perl
+# =============================================================================
+# $Id: 04_cql.t,v 1.1 2003-03-03 00:44:39 pop Exp $
+#
+# Perl API header
+# =============================================================================
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+        chdir 't' if -d 't';
+    }
+    push (@INC,'demo','blib/lib','blib/arch');
+}
+
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+BEGIN {
+    use IDZebra;
+    IDZebra::logFile("test.log");
+    use_ok('IDZebra::Session'); 
+}
+
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+my $sess = IDZebra::Session->new();
+
+# ----------------------------------------------------------------------------
+# CQL stuff
+$sess->cqlmap('demo/cql.map');
+
+$SIG{__WARN__} = \&catch_warn;
+
+&check_cql($sess, "IDZebra", 0);
+&check_cql($sess, "dc.title=IDZebra", 0);
+&check_cql($sess, "dc.title=(IDZebra and Session)", 0);
+&check_cql($sess, "dc.title=IDZebra and Session)", -1);
+&check_cql($sess, "dc.title='IDZebra::Session'", 0);
+&check_cql($sess, "anything=IDZebra", 15);
+
+sub check_cql {
+    my ($sess, $query, $exp) = @_;
+    my ($rpn, $stat) = $sess->cql2pqf($query);
+    if ($exp) {
+       ok(($stat == $exp), "Wrong query ($stat): '$query'");
+    } else {
+       ok((($stat == 0) && ($rpn ne "")), "Good query query: '$query'");
+    }
+}
+
+
+sub catch_warn {
+    1;
+}
diff --git a/perl/t/05_search.t b/perl/t/05_search.t
new file mode 100644 (file)
index 0000000..e6eefa4
--- /dev/null
@@ -0,0 +1,77 @@
+#!perl
+# =============================================================================
+# $Id: 05_search.t,v 1.1 2003-03-03 00:44:39 pop Exp $
+#
+# Perl API header
+# =============================================================================
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+        chdir 't' if -d 't';
+    }
+    push (@INC,'demo','blib/lib','blib/arch');
+}
+
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+BEGIN {
+    use IDZebra;
+    IDZebra::logFile("test.log");
+    use_ok('IDZebra::Session'); 
+    use_ok('pod');
+}
+
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
+                                 groupName => 'demo2');
+isa_ok($sess,"IDZebra::Session");
+
+# ----------------------------------------------------------------------------
+# search
+our $filecount = 6;
+
+my ($hits, $expected);
+
+# Search 1 databases
+my $rs1 = $sess->search(cqlmap    => 'demo/cql.map',
+                       cql       => 'IDZebra',
+                       databases => [qw(demo1)]);
+
+$expected = $filecount;
+$hits = $rs1->count;
+ok(($hits == $expected), "CQL search - found $hits/$expected records");
+
+
+$sess->databases('demo1', 'demo2');
+my @dblist = $sess->databases;
+ok(($#dblist == 1), "Select multiple databases"); 
+
+
+# Search 2 databases
+my $rs2 = $sess->search(cqlmap    => 'demo/cql.map',
+                       cql       => 'IDZebra');
+$expected = $filecount * 2;
+$hits = $rs2->count;
+ok(($hits == $expected), "CQL search - found $hits/$expected records");
+
+# RPN search;
+my $rs3 = $sess->search(cqlmap    => 'demo/cql.map',
+                       pqf       => '@attr 1=4 IDZebra');
+$expected = $filecount * 2;
+$hits = $rs2->count;
+ok(($hits == $expected), "RPN search - found $hits/$expected records");
+
+
+# More specific search
+
+
+# ----------------------------------------------------------------------------
+# Close session
+
+$sess->close;
diff --git a/perl/t/06_retrieval.t b/perl/t/06_retrieval.t
new file mode 100644 (file)
index 0000000..edbdac4
--- /dev/null
@@ -0,0 +1,72 @@
+#!perl
+# =============================================================================
+# $Id: 06_retrieval.t,v 1.1 2003-03-03 00:44:39 pop Exp $
+#
+# Perl API header
+# =============================================================================
+BEGIN {
+    if ($ENV{PERL_CORE}) {
+        chdir 't' if -d 't';
+    }
+    push (@INC,'demo','blib/lib','blib/arch');
+}
+
+use strict;
+use warnings;
+
+use Test::More tests => 18;
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+BEGIN {
+    use IDZebra;
+    IDZebra::logFile("test.log");
+    use_ok('IDZebra::Session'); 
+    use_ok('pod');
+}
+
+
+# ----------------------------------------------------------------------------
+# Session opening and closing
+my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
+                                 groupName => 'demo2');
+# ----------------------------------------------------------------------------
+# search
+our $filecount = 6;
+
+my ($hits, $expected);
+
+# Search 1 database
+my $rs1 = $sess->search(cqlmap    => 'demo/cql.map',
+                       cql       => 'IDZebra',
+                       databases => [qw(demo1)]);
+
+$expected = $filecount;
+$hits = $rs1->count;
+ok(($hits == $expected), "CQL search - found $hits/$expected records");
+
+foreach my $rec ($rs1->records(from =>1,
+                             to   =>5)) {
+    isa_ok($rec,'IDZebra::RetrievalRecord');
+}
+
+my (@recs) = $rs1->records(from=>1,to=>1);
+
+ok ($#recs == 0, "Fetched 1 record");
+
+my $rec1 = shift(@recs);
+
+isa_ok($rec1,'IDZebra::RetrievalRecord');
+ok (($rec1->{errCode} == 0), "err: $rec1->{errCode}");
+ok (($rec1->{errString} eq ""), "errString: $rec1->{errString}");
+ok (($rec1->{position} == 1), "position: $rec1->{position}");
+ok (($rec1->{base} eq 'demo1'), "base: $rec1->{base}");
+ok (($rec1->{sysno}), "sysno: $rec1->{sysno}");
+ok (($rec1->{score}), "score: $rec1->{score}");
+ok (($rec1->{format} eq 'SUTRS'), "format: $rec1->{format}");
+ok ((length($rec1->{buf}) > 0), "buf: ". length($rec1->{buf})." bytes");
+
+# ----------------------------------------------------------------------------
+# Close session
+
+$sess->close;