4 # Copyright 2002, Larry Wall.
6 # You may redistribute only under the same terms as Perl 5, as specified
7 # in the README file that comes with the distribution.
10 # I ought to keep this test easily backwards compatible to 5.004, so no
13 # This test checks whether the kludge to interwork with 5.6 Storables compiled
14 # on Unix systems with IV as long long works.
19 @INC = ('.', '../lib');
23 require Config; import Config;
24 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
25 print "1..0 # Skip: Storable was not built\n";
28 unless ($Config{ivsize} and $Config{ivsize} > $Config{longsize}) {
29 print "1..0 # Skip: Your IVs are no larger than your longs\n";
34 use Storable qw(freeze thaw);
36 use Test::More tests=>30;
41 local $/ = "\n\nend\n";
44 unless (/begin ([0-7]{3}) ([^\n]*)\n(.*)$/s) {
46 warn "Dodgy data in section starting '$_'";
49 next unless oct $1 == ord 'A'; # Skip ASCII on EBCDIC, and vice versa
50 my $data = unpack 'u', $3;
55 # perl makes easy things easy, and hard things possible:
56 my $test = freeze \'Hell';
58 my $header = Storable::read_magic ($test);
60 is ($header->{byteorder}, $Config{byteorder},
61 "header's byteorder and Config.pm's should agree");
63 my $result = eval {thaw $test};
64 isa_ok ($result, 'SCALAR', "Check thawing test data");
65 is ($@, '', "causes no errors");
66 is ($$result, 'Hell', 'and gives the expected data');
68 my $kingdom = $Config{byteorder} =~ /23/ ? "Lillput" : "Belfuscu";
70 my $name = join ',', $kingdom, @$header{qw(intsize longsize ptrsize nvsize)};
73 my $real_thing = $tests{$name};
74 if (!defined $real_thing) {
76 # No test data for Storable 1.x for:
78 # byteorder '$Config{byteorder}'
79 # sizeof(int) $$header{intsize}
80 # sizeof(long) $$header{longsize}
81 # sizeof(char *) $$header{ptrsize}
82 # sizeof(NV) $$header{nvsize}
84 # If you have Storable 1.x built with perl 5.6.x on this platform, please
85 # make_56_interwork.pl to generate test data, and append the test data to
87 # You may find that make_56_interwork.pl reports that your platform has no
88 # interworking problems, in which case you need do nothing.
90 skip "# No 1.x test file", 9;
92 my $result = eval {thaw $real_thing};
93 is ($result, undef, "By default should not be able to thaw");
94 like ($@, qr/Byte order is not compatible/,
95 "because the header byte order strings differ");
96 local $Storable::interwork_56_64bit = 1;
97 $result = eval {thaw $real_thing};
98 isa_ok ($result, 'ARRAY', "With flag should now thaw");
99 is ($@, '', "with no errors");
101 # However, as the file is written with Storable pre 2.01, it's a known
102 # bug that large (positive) UVs become IVs
103 my $value = (~0 ^ (~0 >> 1) ^ 2);
105 is (@$result, 4, "4 elements in array");
107 qr/^This file was written with [0-9.]+ on perl [0-9.]+\z/,
109 is ($$result[1], "$kingdom was correct", "2nd element");
110 cmp_ok ($$result[2] ^ $value, '==', 0, "3rd element") or
111 printf "# expected %#X, got %#X\n", $value, $$result[2];
112 is ($$result[3], "The End", "4th element");
115 $result = eval {thaw $test};
116 isa_ok ($result, 'SCALAR', "CHORUS: check thawing test data");
117 is ($@, '', " causes no errors");
118 is ($$result, 'Hell', " and gives the expected data");
122 local $Storable::interwork_56_64bit = 1;
123 $test_kludge = freeze \'Heck';
126 my $header_kludge = Storable::read_magic ($test_kludge);
128 cmp_ok (length ($header_kludge->{byteorder}), '==', $Config{longsize},
129 "With 5.6 interwork kludge byteorder string should be same size as long"
131 $result = eval {thaw $test_kludge};
132 is ($result, undef, "By default should not be able to thaw");
133 like ($@, qr/Byte order is not compatible/,
134 "because the header byte order strings differ");
136 $result = eval {thaw $test};
137 isa_ok ($result, 'SCALAR', "CHORUS: check thawing test data");
138 is ($@, '', " causes no errors");
139 is ($$result, 'Hell', " and gives the expected data");
142 local $Storable::interwork_56_64bit = 1;
144 $result = eval {thaw $test_kludge};
145 isa_ok ($result, 'SCALAR', "should be able to thaw kludge data");
146 is ($@, '', "with no errors");
147 is ($$result, 'Heck', "and gives expected data");
149 $result = eval {thaw $test};
150 is ($result, undef, "But now can't thaw real data");
151 like ($@, qr/Byte order is not compatible/,
152 "because the header byte order strings differ");
156 $result = eval {thaw $test};
157 isa_ok ($result, 'SCALAR', "CHORUS: check thawing test data");
158 is ($@, '', " causes no errors");
159 is ($$result, 'Hell', " and gives the expected data");
162 # A whole run of 1.1.14 freeze data, uuencoded. The "mode bits" are the octal
163 # value of 'A', the "file name" is the test name. Use make_56_interwork.pl
164 # with a copy of Storable 1.X generate these.
171 begin 101 Lillput,4,4,4,8
172 M!`0$,3(S-`0$!`@"!`````HQ5&AI<R!F:6QE('=A<R!W<FET=&5N('=I=&@@
173 M,2XP,30@;VX@<&5R;"`U+C`P-C`P,0H33&EL;'!U="!W87,@8V]R<F5C=`8"
174 0````````@`H'5&AE($5N9```
183 begin 101 Belfuscu,4,4,4,8
184 M!`0$-#,R,00$!`@"````!`HQ5&AI<R!F:6QE('=A<R!W<FET=&5N('=I=&@@
185 M,2XP,30@;VX@<&5R;"`U+C`P-C`P,0H40F5L9G5S8W4@=V%S(&-O<G)E8W0&
186 1@`````````(*!U1H92!%;F0`