r1479@llin: dpavlin | 2007-11-02 14:59:05 +0100
[webpac2] / t / 2-input-xml.t
diff --git a/t/2-input-xml.t b/t/2-input-xml.t
new file mode 100755 (executable)
index 0000000..ff2f190
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/perl -w
+
+use strict;
+use blib;
+
+use Test::More tests => 12;
+
+BEGIN {
+use_ok( 'WebPAC::Test' );
+use_ok( 'WebPAC::Input' );
+}
+
+my $module = 'WebPAC::Input::XML';
+diag "testing with $module";
+
+ok(my $input = new WebPAC::Input(
+       module => $module,
+       no_progress_bar => 1,
+       %LOG
+), "new");
+
+throws_ok { $input->open( path => '/tmp/does_not_exit', %LOG ) } qr/can't find path/, 'open with non-existant path';
+
+ok(my $db = $input->open(
+       path => "$abs_path/data/xml/"
+), "open");
+ok(my $size = $input->size, "size");
+
+foreach my $mfn ( 1 ... $size ) {
+       my $rec = $input->fetch;
+       if ($mfn <= 10 || $mfn == 20) {
+               ok($rec, "fetch $mfn");
+       } else {
+               ok(! $rec, "empty $mfn");
+       }
+
+       cmp_ok($input->pos, '==', $mfn, "pos $mfn");
+
+       diag "rec: ", dump($rec), "\n" if $debug;
+}
+