#!/usr/bin/perl -w use strict; BEGIN { $| = 1; print "1..9\n"; } END { print "not ok 1\n" unless $::XBaseloaded; } print "Load the module: use XBase\n"; use XBase; $::XBaseloaded = 1; print "ok 1\n"; my $dir = ( -d "t" ? "t" : "." ); $XBase::Base::DEBUG = 1; # We want to see any problems print "Load table test.dbf\n"; my $table = new XBase("$dir/test"); print XBase->errstr(), 'not ' unless defined $table; print "ok 2\n"; exit unless defined $table; # It doesn't make sense to continue here ;-) print "Read the records, one by one\n"; my $records_expected = join "\n", '0:1:Record no 1:This is a memo for record no one::19960813', '1:2:No 2:This is a memo for record 2:1:19960814', '0:3:Message no 3:This is a memo for record 3:0:19960102'; my $records = join "\n", map { join ":", map { defined $_ ? $_ : "" } $table->get_record($_) } ( 0 .. 2 ); if ($records_expected ne $records) { print "Expected:\n$records_expected\nGot:\n$records\nnot "; } print "ok 3\n"; print "Get record 0 as hash\n"; my $hash_values_expected = 'undef, 19960813, 1, "Record no 1", "This is a memo for record no one", 0'; my %hash = $table->get_record_as_hash(0); my $hash_values = join ', ', map { defined $_ ? ( /^\d+$/ ? $_ : qq["$_"] ) : 'undef' } map { $hash{$_} } sort keys %hash; if ($hash_values_expected ne $hash_values) { print "Expected:\n\@hash{ qw( @{[sort keys %hash]} ) } =\n ($hash_values_expected)\nGot:\n$hash_values\nnot "; } print "ok 4\n"; print "Load the table rooms\n"; my $rooms = new XBase("$dir/rooms"); print XBase->errstr, 'not ' unless defined $rooms; print "ok 5\n"; print "Check the records using read_record\n"; $records_expected = join '', ; $records = join "\n", (map { join ':', map { defined $_ ? $_ : '' } $rooms->get_record($_) } (0 .. $rooms->last_record())), ''; if ($records_expected ne $records) { print "Expected:\n$records_expected\nGot:\n$records\nnot "; } print "ok 6\n"; print "Check the records using get_all_records\n"; my $all_records = $rooms->get_all_records('ROOMNAME', 'FACILITY'); if (not defined $all_records) { print $rooms->errstr, "not "; } else { $records = join "\n", (map { join ':', 0, @$_; } @$all_records), ''; if ($records_expected ne $records) { print "Expected:\n$records_expected\nGot:\n$records\nnot "; } } print "ok 7\n"; $XBase::Base::DEBUG = 0; print "Check if reading record that doesn't exist will produce error\n"; my (@result) = $table->get_record(3); print "not " if @result; print "ok 8\n"; print "Check error message\n"; my $errstr = $table->errstr(); my $errstr_expected = "Can't read record 3, there is not so many of them\n"; if ($errstr ne $errstr_expected) { print "Expected: $errstr_expected\nGot: $errstr\nnot "; } print "ok 9\n"; print <