Blame t/store.t

Packit 14c646
#!./perl
Packit 14c646
#
Packit 14c646
#  Copyright (c) 1995-2000, Raphael Manfredi
Packit 14c646
#
Packit 14c646
#  You may redistribute only under the same terms as Perl 5, as specified
Packit 14c646
#  in the README file that comes with the distribution.
Packit 14c646
#
Packit 14c646
Packit 14c646
sub BEGIN {
Packit 14c646
    unshift @INC, 't';
Packit 14c646
    unshift @INC, 't/compat' if $] < 5.006002;
Packit 14c646
    require Config; import Config;
Packit 14c646
    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
Packit 14c646
        print "1..0 # Skip: Storable was not built\n";
Packit 14c646
        exit 0;
Packit 14c646
    }
Packit 14c646
    require 'st-dump.pl';
Packit 14c646
}
Packit 14c646
Packit 14c646
# $Storable::DEBUGME = 1;
Packit 14c646
use Storable qw(store retrieve store_fd nstore_fd fd_retrieve);
Packit 14c646
Packit 14c646
use Test::More tests => 25;
Packit 14c646
Packit 14c646
$a = 'toto';
Packit 14c646
$b = \$a;
Packit 14c646
$c = bless {}, CLASS;
Packit 14c646
$c->{attribute} = 'attrval';
Packit 14c646
%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
Packit 14c646
@a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
Packit 14c646
	$b, \$a, $a, $c, \$c, \%a);
Packit 14c646
Packit 14c646
isnt(store(\@a, "store$$"), undef);
Packit 14c646
Packit 14c646
$dumped = &dump(\@a);
Packit 14c646
isnt($dumped, undef);
Packit 14c646
Packit 14c646
$root = retrieve("store$$");
Packit 14c646
isnt($root, undef);
Packit 14c646
Packit 14c646
$got = &dump($root);
Packit 14c646
isnt($got, undef);
Packit 14c646
Packit 14c646
is($got, $dumped);
Packit 14c646
Packit 14c646
1 while unlink "store$$";
Packit 14c646
Packit 14c646
package FOO; @ISA = qw(Storable);
Packit 14c646
Packit 14c646
sub make {
Packit 14c646
	my $self = bless {};
Packit 14c646
	$self->{key} = \%main::a;
Packit 14c646
	return $self;
Packit 14c646
};
Packit 14c646
Packit 14c646
package main;
Packit 14c646
Packit 14c646
$foo = FOO->make;
Packit 14c646
isnt($foo->store("store$$"), undef);
Packit 14c646
Packit 14c646
isnt(open(OUT, '>>', "store$$"), undef);
Packit 14c646
binmode OUT;
Packit 14c646
Packit 14c646
isnt(store_fd(\@a, ::OUT), undef);
Packit 14c646
isnt(nstore_fd($foo, ::OUT), undef);
Packit 14c646
isnt(nstore_fd(\%a, ::OUT), undef);
Packit 14c646
Packit 14c646
isnt(close(OUT), undef);
Packit 14c646
Packit 14c646
isnt(open(OUT, "store$$"), undef);
Packit 14c646
Packit 14c646
$r = fd_retrieve(::OUT);
Packit 14c646
isnt($r, undef);
Packit 14c646
is(&dump($r), &dump($foo));
Packit 14c646
Packit 14c646
$r = fd_retrieve(::OUT);
Packit 14c646
isnt($r, undef);
Packit 14c646
is(&dump($r), &dump(\@a));
Packit 14c646
Packit 14c646
$r = fd_retrieve(main::OUT);
Packit 14c646
isnt($r, undef);
Packit 14c646
is(&dump($r), &dump($foo));
Packit 14c646
Packit 14c646
$r = fd_retrieve(::OUT);
Packit 14c646
isnt($r, undef);
Packit 14c646
is(&dump($r), &dump(\%a));
Packit 14c646
Packit 14c646
eval { $r = fd_retrieve(::OUT); };
Packit 14c646
isnt($@, '');
Packit 14c646
Packit 14c646
{
Packit 14c646
    my %test = (
Packit 14c646
        old_retrieve_array => "\x70\x73\x74\x30\x01\x0a\x02\x02\x02\x02\x00\x3d\x08\x84\x08\x85\x08\x06\x04\x00\x00\x01\x1b",
Packit 14c646
        old_retrieve_hash  => "\x70\x73\x74\x30\x01\x0a\x03\x00\xe8\x03\x00\x00\x81\x00\x00\x00\x01\x61",
Packit 14c646
        retrieve_code      => "\x70\x73\x74\x30\x05\x0a\x19\xf0\x00\xff\xe8\x03\x1a\x0a\x0e\x01",
Packit 14c646
    );
Packit 14c646
Packit 14c646
    for my $k (sort keys %test) {
Packit 14c646
        open my $fh, '<', \$test{$k};
Packit 14c646
        eval { Storable::fd_retrieve($fh); };
Packit 14c646
        is($?, 0, 'RT 130098:  no segfault in Storable::fd_retrieve()');
Packit 14c646
    }
Packit 14c646
}
Packit 14c646
Packit 14c646
{
Packit 14c646
Packit 14c646
    my $frozen =
Packit 14c646
      "\x70\x73\x74\x30\x04\x0a\x08\x31\x32\x33\x34\x35\x36\x37\x38\x04\x08\x08\x08\x03\xff\x00\x00\x00\x19\x08\xff\x00\x00\x00\x08\x08\xf9\x16\x16\x13\x16\x10\x10\x10\xff\x15\x16\x16\x16\x1e\x16\x16\x16\x16\x16\x16\x16\x16\x16\x16\x13\xf0\x16\x16\x16\xfe\x16\x41\x41\x41\x41\xe8\x03\x41\x41\x41\x41\x41\x41\x41\x41\x51\x41\xa9\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xb8\xac\xac\xac\xac\xac\xac\xac\xac\x9a\xac\xac\xac\xac\xac\xac\xac\xac\xac\x93\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\x00\x64\xac\xa8\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\x2c\xac\x41\x41\x41\x41\x41\x41\x41\x41\x41\x00\x80\x41\x80\x41\x41\x41\x41\x41\x41\x51\x41\xac\xac\xac";
Packit 14c646
    open my $fh, '<', \$frozen;
Packit 14c646
    eval { Storable::fd_retrieve($fh); };
Packit 14c646
    pass('RT 130635:  no stack smashing error when retrieving hook');
Packit 14c646
Packit 14c646
}
Packit 14c646
Packit 14c646
close OUT or die "Could not close: $!";
Packit 14c646
END { 1 while unlink "store$$" }