1#!/usr/bin/perl -w 2 3use strict; 4 5END { 6 print "not ok 1\n" unless $::XBaseloaded; 7} 8BEGIN { 9 $| = 1; 10 print "1..6\n"; 11 print "Load modules: use XBase; use XBase::Index;\n"; 12} 13 14use XBase; 15use XBase::Index; 16$::XBaseloaded = 1; 17print "ok 1\n"; 18 19my $dir = ( -d "t" ? "t" : "." ); 20 21$XBase::Base::DEBUG = 1; # We want to see any problems 22 23unlink "$dir/tstidx.dbf", "$dir/tstidxid.idx", "$dir/tstidxname.idx"; 24 25my $table = create XBase('name' => "$dir/tstidx.dbf", 26 'field_names' => [ 'ID', 'NAME' ], 27 'field_types' => [ 'N', 'C' ], 28 'field_lengths' => [ 6, 100 ], 29 'field_decimals' => [ 0, undef ]) or do { 30 print XBase->errstr, "not ok 2\n"; 31 exit; 32}; 33 34print "ok 2\n"; 35 36my $i = 0; 37$table->set_record($i++, 56, 'Padesat sest'); 38$table->set_record($i++, 123, 'Stodvacettri'); 39$table->set_record($i++, 9, 'Krtek'); 40$table->set_record($i++, 88, 'Osmaosmdesat'); 41$table->set_record($i++, -7, 'minus sedm'); 42$table->set_record($i++, 7, 'plus sedm'); 43$table->set_record($i++, 15, 'Patnact'); 44$table->set_record($i++, -1000, 'Tisic pod nulou'); 45 46my $numindex = create XBase::idx($table, "$dir/tstidxid.idx", "id"); 47if (not defined $numindex) { 48 print XBase->errstr, 'not '; 49} 50print "ok 3\n"; 51 52my $got = ''; 53$numindex->prepare_select; 54while (my ($key, $num) = $numindex->fetch) { 55 $got .= "$key $num\n"; 56} 57my $expected = ''; 58while (<DATA>) { 59 last if $_ eq "__END_DATA__\n"; 60 $expected .= $_; 61} 62 63if ($got ne $expected) { 64 print "Expected:\n$expected\nGot:\n$got\nnot "; 65} 66print "ok 4\n"; 67 68 69my $charindex = create XBase::idx($table, "$dir/tstidxname.idx", "name"); 70if (not $charindex) { 71 print XBase->errstr, 'not '; 72} 73print "ok 5\n"; 74 75$got = ''; 76$charindex->prepare_select; 77while (my ($key, $num) = $charindex->fetch) { 78 $key =~ s/\s+$//; 79 $got .= "$key $num\n"; 80} 81$expected = ''; 82while (<DATA>) { 83 last if $_ eq "__END_DATA__\n"; 84 $expected .= $_; 85} 86 87if ($got ne $expected) { 88 print "Expected:\n$expected\nGot:\n$got\nnot "; 89} 90print "ok 6\n"; 91 92 93__DATA__ 94-1000 8 95-7 5 967 6 979 3 9815 7 9956 1 10088 4 101123 2 102__END_DATA__ 103Krtek 3 104Osmaosmdesat 4 105Padesat sest 1 106Patnact 7 107Stodvacettri 2 108Tisic pod nulou 8 109minus sedm 5 110plus sedm 6 111