File: 5_ntx.t

package info (click to toggle)
libdbd-xbase-perl 1%3A1.08-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 988 kB
  • sloc: perl: 7,060; makefile: 14
file content (80 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl -w

use strict;

BEGIN   { $| = 1; print "1..66\n"; }
END     { print "not ok 1\n" unless $::XBaseloaded; }

$| = 1;

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 "Open table $dir/ntx-char\n";
my $table = new XBase "$dir/ntx-char" or do
	{
	print XBase->errstr, "not ok 2\n";
	exit
	};
print "ok 2\n";

print "prepare_select\n";
my $cur = $table->prepare_select or print $table->errstr, 'not ';
print "ok 3\n";

print "fetch all rows and sort them\n";
my @expected;
while (my @row = $cur->fetch)
	{ push @expected, @row; }

my @sorted = sort @expected;
my $expected = join "\n", @sorted, '';

print "ok 4\n";

print "prepare_select_with_index $dir/ntx-char.ntx\n";
$cur = $table->prepare_select_with_index("$dir/ntx-char.ntx") or
	print $table->errstr, 'not ';
print "ok 5\n";

my $got = '';
while (my @row = $cur->fetch)
	{ $got .= "@row\n"; }

if ($got ne $expected)
	{ print "Expected:\n${expected}Got:\n${got}not "; }
print "ok 6\n";

my $test = 7;

my $prev = '';
for (my $i = 0; $i < @sorted; $i++)
	{
	next if $sorted[$i] eq $prev;
	$prev = $sorted[$i];
	print "find_eq($sorted[$i])\n";
	$cur->find_eq($sorted[$i]) or print "not ";
	print "ok $test\n";
	$test++;

	my $got = '';
	while (my @row = $cur->fetch)
		{ $got .= "@row\n"; }
	
	my $expected = join "\n", @sorted[$i .. $#sorted], '';

	print "compare results\n";
	if ($got ne $expected)
		{ print "Index $i, find_eq($sorted[$i])\nExpected:\n${expected}Got:\n${got}not "; }
	
	print "ok $test\n";
	$test++;
	}