1N/A#!/usr/bin/perl
1N/A#
1N/A# Tests for various caching errors
1N/A#
1N/A
1N/A$|=1;
1N/Amy $file = "tf$$.txt";
1N/A$: = Tie::File::_default_recsep();
1N/Amy $data = join $:, "rec0" .. "rec9", "";
1N/Amy $V = $ENV{INTEGRITY}; # Verbose integrity checking?
1N/A
1N/Aprint "1..55\n";
1N/A
1N/Amy $N = 1;
1N/Ause Tie::File;
1N/Aprint "ok $N\n"; $N++;
1N/A
1N/Aopen F, "> $file" or die $!;
1N/Abinmode F;
1N/Aprint F $data;
1N/Aclose F;
1N/A
1N/Amy $o = tie @a, 'Tie::File', $file;
1N/Aprint $o ? "ok $N\n" : "not ok $N\n";
1N/A$N++;
1N/A
1N/A# (3) Through 0.18, this 'splice' call would corrupt the cache.
1N/Amy @z = @a; # force cache to contain all ten records
1N/Asplice @a, 0, 0, "x";
1N/Aprint $o->_check_integrity($file, $V) ? "ok $N\n" : "not ok $N\n";
1N/A$N++;
1N/A
1N/A# Here we redo *all* the splice tests, with populate()
1N/A# calls before each one, to make sure that splice() does not botch the cache.
1N/A
1N/A# (4-14) splicing at the beginning
1N/Acheck();
1N/Asplice(@a, 0, 0, "rec4");
1N/Acheck();
1N/Asplice(@a, 0, 1, "rec5"); # same length
1N/Acheck();
1N/Asplice(@a, 0, 1, "record5"); # longer
1N/Acheck();
1N/Asplice(@a, 0, 1, "r5"); # shorter
1N/Acheck();
1N/Asplice(@a, 0, 1); # removal
1N/Acheck();
1N/Asplice(@a, 0, 0); # no-op
1N/Acheck();
1N/A
1N/Asplice(@a, 0, 0, 'r7', 'rec8'); # insert more than one
1N/Acheck();
1N/Asplice(@a, 0, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
1N/Acheck();
1N/Asplice(@a, 0, 3, 'record9', 'rec10'); # delete more than insert
1N/Acheck();
1N/Asplice(@a, 0, 2); # delete more than one
1N/Acheck();
1N/A
1N/A
1N/A# (15-24) splicing in the middle
1N/Asplice(@a, 1, 0, "rec4");
1N/Acheck();
1N/Asplice(@a, 1, 1, "rec5"); # same length
1N/Acheck();
1N/Asplice(@a, 1, 1, "record5"); # longer
1N/Acheck();
1N/Asplice(@a, 1, 1, "r5"); # shorter
1N/Acheck();
1N/Asplice(@a, 1, 1); # removal
1N/Acheck();
1N/Asplice(@a, 1, 0); # no-op
1N/Acheck();
1N/A
1N/Asplice(@a, 1, 0, 'r7', 'rec8'); # insert more than one
1N/Acheck();
1N/Asplice(@a, 1, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
1N/Acheck();
1N/Asplice(@a, 1, 3, 'record9', 'rec10'); # delete more than insert
1N/Acheck();
1N/Asplice(@a, 1, 2); # delete more than one
1N/Acheck();
1N/A
1N/A# (25-34) splicing at the end
1N/Asplice(@a, 3, 0, "rec4");
1N/Acheck();
1N/Asplice(@a, 3, 1, "rec5"); # same length
1N/Acheck();
1N/Asplice(@a, 3, 1, "record5"); # longer
1N/Acheck();
1N/Asplice(@a, 3, 1, "r5"); # shorter
1N/Acheck();
1N/Asplice(@a, 3, 1); # removal
1N/Acheck();
1N/Asplice(@a, 3, 0); # no-op
1N/Acheck();
1N/A
1N/Asplice(@a, 3, 0, 'r7', 'rec8'); # insert more than one
1N/Acheck();
1N/Asplice(@a, 3, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
1N/Acheck();
1N/Asplice(@a, 3, 3, 'record9', 'rec10'); # delete more than insert
1N/Acheck();
1N/Asplice(@a, 3, 2); # delete more than one
1N/Acheck();
1N/A
1N/A# (35-44) splicing with negative subscript
1N/Asplice(@a, -1, 0, "rec4");
1N/Acheck();
1N/Asplice(@a, -1, 1, "rec5"); # same length
1N/Acheck();
1N/Asplice(@a, -1, 1, "record5"); # longer
1N/Acheck();
1N/Asplice(@a, -1, 1, "r5"); # shorter
1N/Acheck();
1N/Asplice(@a, -1, 1); # removal
1N/Acheck();
1N/Asplice(@a, -1, 0); # no-op
1N/Acheck();
1N/A
1N/Asplice(@a, -1, 0, 'r7', 'rec8'); # insert more than one
1N/Acheck();
1N/Asplice(@a, -1, 2, 'rec7', 'record8', 'rec9'); # insert more than delete
1N/Acheck();
1N/Asplice(@a, -3, 3, 'record9', 'rec10'); # delete more than insert
1N/Acheck();
1N/Asplice(@a, -4, 3); # delete more than one
1N/Acheck();
1N/A
1N/A# (45) scrub it all out
1N/Asplice(@a, 0, 3);
1N/Acheck();
1N/A
1N/A# (46) put some back in
1N/Asplice(@a, 0, 0, "rec0", "rec1");
1N/Acheck();
1N/A
1N/A# (47) what if we remove too many records?
1N/Asplice(@a, 0, 17);
1N/Acheck();
1N/A
1N/A# (48-49) In the past, splicing past the end was not correctly detected
1N/A# (1.14)
1N/Asplice(@a, 89, 3);
1N/Acheck();
1N/Asplice(@a, @a, 3);
1N/Acheck();
1N/A
1N/A# (50-51) Also we did not emulate splice's freaky behavior when inserting
1N/A# past the end of the array (1.14)
1N/Asplice(@a, 89, 0, "I", "like", "pie");
1N/Acheck();
1N/Asplice(@a, 89, 0, "pie pie pie");
1N/Acheck();
1N/A
1N/A# (52-54) Test default arguments
1N/Asplice @a, 0, 0, (0..11);
1N/Acheck();
1N/Asplice @a, 4;
1N/Acheck();
1N/Asplice @a;
1N/Acheck();
1N/A
1N/A# (55) This was broken on 20030507 when you moved the cache management
1N/A# stuff out of _oadjust back into _splice without also putting it back
1N/A# into _store.
1N/A@a = (0..11);
1N/Acheck();
1N/A
1N/Asub init_file {
1N/A my $data = shift;
1N/A open F, "> $file" or die $!;
1N/A binmode F;
1N/A print F $data;
1N/A close F;
1N/A}
1N/A
1N/Asub check {
1N/A my $integrity = $o->_check_integrity($file, $ENV{INTEGRITY});
1N/A print $integrity ? "ok $N\n" : "not ok $N\n";
1N/A $N++;
1N/A repopulate();
1N/A}
1N/A
1N/A
1N/Asub ctrlfix {
1N/A for (@_) {
1N/A s/\n/\\n/g;
1N/A s/\r/\\r/g;
1N/A }
1N/A}
1N/A
1N/Asub repopulate {
1N/A $o->{cache}->empty;
1N/A my @z = @a; # refill the cache with correct data
1N/A}
1N/A
1N/AEND {
1N/A undef $o;
1N/A untie @a;
1N/A 1 while unlink $file;
1N/A}
1N/A
1N/A
1N/A