test appears to be ass_u_ming sizeof(long) == sizeof(IV), which
[p5sagit/p5-mst-13.2.git] / ext / Storable / t / blessed.t
CommitLineData
7a6a85bf 1#!./perl
2
9e21b3d0 3# $Id: blessed.t,v 1.0 2000/09/01 19:40:41 ram Exp $
7a6a85bf 4#
5# Copyright (c) 1995-2000, Raphael Manfredi
6#
9e21b3d0 7# You may redistribute only under the same terms as Perl 5, as specified
8# in the README file that comes with the distribution.
7a6a85bf 9#
10# $Log: blessed.t,v $
9e21b3d0 11# Revision 1.0 2000/09/01 19:40:41 ram
12# Baseline for first official release.
7a6a85bf 13#
14
15sub BEGIN {
0c384302 16 if ($ENV{PERL_CORE}){
17 chdir('t') if -d 't';
18 @INC = '.';
19 push @INC, '../lib';
20 }
9f233367 21 require Config; import Config;
0c384302 22 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 23 print "1..0 # Skip: Storable was not built\n";
24 exit 0;
25 }
7a6a85bf 26 require 'lib/st-dump.pl';
27}
28
29sub ok;
30
31use Storable qw(freeze thaw);
32
33print "1..10\n";
34
35package SHORT_NAME;
36
37sub make { bless [], shift }
38
39package SHORT_NAME_WITH_HOOK;
40
41sub make { bless [], shift }
42
43sub STORABLE_freeze {
44 my $self = shift;
45 return ("", $self);
46}
47
48sub STORABLE_thaw {
49 my $self = shift;
50 my $cloning = shift;
51 my ($x, $obj) = @_;
52 die "STORABLE_thaw" unless $obj eq $self;
53}
54
55package main;
56
57# Still less than 256 bytes, so long classname logic not fully exercised
58# Wait until Perl removes the restriction on identifier lengths.
59my $name = "LONG_NAME_" . 'xxxxxxxxxxxxx::' x 14 . "final";
60
61eval <<EOC;
62package $name;
63
64\@ISA = ("SHORT_NAME");
65EOC
66die $@ if $@;
67ok 1, $@ eq '';
68
69eval <<EOC;
70package ${name}_WITH_HOOK;
71
72\@ISA = ("SHORT_NAME_WITH_HOOK");
73EOC
74ok 2, $@ eq '';
75
76# Construct a pool of objects
77my @pool;
78
79for (my $i = 0; $i < 10; $i++) {
80 push(@pool, SHORT_NAME->make);
81 push(@pool, SHORT_NAME_WITH_HOOK->make);
82 push(@pool, $name->make);
83 push(@pool, "${name}_WITH_HOOK"->make);
84}
85
86my $x = freeze \@pool;
87ok 3, 1;
88
89my $y = thaw $x;
90ok 4, ref $y eq 'ARRAY';
91ok 5, @{$y} == @pool;
92
93ok 6, ref $y->[0] eq 'SHORT_NAME';
94ok 7, ref $y->[1] eq 'SHORT_NAME_WITH_HOOK';
95ok 8, ref $y->[2] eq $name;
96ok 9, ref $y->[3] eq "${name}_WITH_HOOK";
97
98my $good = 1;
99for (my $i = 0; $i < 10; $i++) {
100 do { $good = 0; last } unless ref $y->[4*$i] eq 'SHORT_NAME';
101 do { $good = 0; last } unless ref $y->[4*$i+1] eq 'SHORT_NAME_WITH_HOOK';
102 do { $good = 0; last } unless ref $y->[4*$i+2] eq $name;
103 do { $good = 0; last } unless ref $y->[4*$i+3] eq "${name}_WITH_HOOK";
104}
105ok 10, $good;
106