1N/A#!./perl -w
1N/A#
1N/A# Copyright 2002, Larry Wall.
1N/A#
1N/A# You may redistribute only under the same terms as Perl 5, as specified
1N/A# in the README file that comes with the distribution.
1N/A#
1N/A
1N/A# I ought to keep this test easily backwards compatible to 5.004, so no
1N/A# qr//;
1N/A
1N/A# This test checks whether the kludge to interwork with 5.6 Storables compiled
1N/A# on Unix systems with IV as long long works.
1N/A
1N/Asub BEGIN {
1N/A if ($ENV{PERL_CORE}){
1N/A chdir('t') if -d 't';
1N/A @INC = ('.', '../lib');
1N/A } else {
1N/A unshift @INC, 't';
1N/A }
1N/A require Config; import Config;
1N/A if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
1N/A print "1..0 # Skip: Storable was not built\n";
1N/A exit 0;
1N/A }
1N/A unless ($Config{ivsize} and $Config{ivsize} > $Config{longsize}) {
1N/A print "1..0 # Skip: Your IVs are no larger than your longs\n";
1N/A exit 0;
1N/A }
1N/A}
1N/A
1N/Ause Storable qw(freeze thaw);
1N/Ause strict;
1N/Ause Test::More tests=>30;
1N/A
1N/Ause vars qw(%tests);
1N/A
1N/A{
1N/A local $/ = "\n\nend\n";
1N/A while (<DATA>) {
1N/A next unless /\S/s;
1N/A unless (/begin ([0-7]{3}) ([^\n]*)\n(.*)$/s) {
1N/A s/\n.*//s;
1N/A warn "Dodgy data in section starting '$_'";
1N/A next;
1N/A }
1N/A next unless oct $1 == ord 'A'; # Skip ASCII on EBCDIC, and vice versa
1N/A my $data = unpack 'u', $3;
1N/A $tests{$2} = $data;
1N/A }
1N/A}
1N/A
1N/A# perl makes easy things easy, and hard things possible:
1N/Amy $test = freeze \'Hell';
1N/A
1N/Amy $header = Storable::read_magic ($test);
1N/A
1N/Ais ($header->{byteorder}, $Config{byteorder},
1N/A "header's byteorder and Config.pm's should agree");
1N/A
1N/Amy $result = eval {thaw $test};
1N/Aisa_ok ($result, 'SCALAR', "Check thawing test data");
1N/Ais ($@, '', "causes no errors");
1N/Ais ($$result, 'Hell', 'and gives the expected data');
1N/A
1N/Amy $kingdom = $Config{byteorder} =~ /23/ ? "Lillput" : "Belfuscu";
1N/A
1N/Amy $name = join ',', $kingdom, @$header{qw(intsize longsize ptrsize nvsize)};
1N/A
1N/ASKIP: {
1N/A my $real_thing = $tests{$name};
1N/A if (!defined $real_thing) {
1N/A print << "EOM";
1N/A# No test data for Storable 1.x for:
1N/A#
1N/A# byteorder '$Config{byteorder}'
1N/A# sizeof(int) $$header{intsize}
1N/A# sizeof(long) $$header{longsize}
1N/A# sizeof(char *) $$header{ptrsize}
1N/A# sizeof(NV) $$header{nvsize}
1N/A
1N/A# If you have Storable 1.x built with perl 5.6.x on this platform, please
1N/A# make_56_interwork.pl to generate test data, and append the test data to
1N/A# this test.
1N/A# You may find that make_56_interwork.pl reports that your platform has no
1N/A# interworking problems, in which case you need do nothing.
1N/AEOM
1N/A skip "# No 1.x test file", 9;
1N/A }
1N/A my $result = eval {thaw $real_thing};
1N/A is ($result, undef, "By default should not be able to thaw");
1N/A like ($@, qr/Byte order is not compatible/,
1N/A "because the header byte order strings differ");
1N/A local $Storable::interwork_56_64bit = 1;
1N/A $result = eval {thaw $real_thing};
1N/A isa_ok ($result, 'ARRAY', "With flag should now thaw");
1N/A is ($@, '', "with no errors");
1N/A
1N/A # However, as the file is written with Storable pre 2.01, it's a known
1N/A # bug that large (positive) UVs become IVs
1N/A my $value = (~0 ^ (~0 >> 1) ^ 2);
1N/A
1N/A is (@$result, 4, "4 elements in array");
1N/A like ($$result[0],
1N/A qr/^This file was written with [0-9.]+ on perl [0-9.]+\z/,
1N/A "1st element");
1N/A is ($$result[1], "$kingdom was correct", "2nd element");
1N/A cmp_ok ($$result[2] ^ $value, '==', 0, "3rd element") or
1N/A printf "# expected %#X, got %#X\n", $value, $$result[2];
1N/A is ($$result[3], "The End", "4th element");
1N/A}
1N/A
1N/A$result = eval {thaw $test};
1N/Aisa_ok ($result, 'SCALAR', "CHORUS: check thawing test data");
1N/Ais ($@, '', " causes no errors");
1N/Ais ($$result, 'Hell', " and gives the expected data");
1N/A
1N/Amy $test_kludge;
1N/A{
1N/A local $Storable::interwork_56_64bit = 1;
1N/A $test_kludge = freeze \'Heck';
1N/A}
1N/A
1N/Amy $header_kludge = Storable::read_magic ($test_kludge);
1N/A
1N/Acmp_ok (length ($header_kludge->{byteorder}), '==', $Config{longsize},
1N/A "With 5.6 interwork kludge byteorder string should be same size as long"
1N/A );
1N/A$result = eval {thaw $test_kludge};
1N/Ais ($result, undef, "By default should not be able to thaw");
1N/Alike ($@, qr/Byte order is not compatible/,
1N/A "because the header byte order strings differ");
1N/A
1N/A$result = eval {thaw $test};
1N/Aisa_ok ($result, 'SCALAR', "CHORUS: check thawing test data");
1N/Ais ($@, '', " causes no errors");
1N/Ais ($$result, 'Hell', " and gives the expected data");
1N/A
1N/A{
1N/A local $Storable::interwork_56_64bit = 1;
1N/A
1N/A $result = eval {thaw $test_kludge};
1N/A isa_ok ($result, 'SCALAR', "should be able to thaw kludge data");
1N/A is ($@, '', "with no errors");
1N/A is ($$result, 'Heck', "and gives expected data");
1N/A
1N/A $result = eval {thaw $test};
1N/A is ($result, undef, "But now can't thaw real data");
1N/A like ($@, qr/Byte order is not compatible/,
1N/A "because the header byte order strings differ");
1N/A}
1N/A
1N/A# All together now:
1N/A$result = eval {thaw $test};
1N/Aisa_ok ($result, 'SCALAR', "CHORUS: check thawing test data");
1N/Ais ($@, '', " causes no errors");
1N/Ais ($$result, 'Hell', " and gives the expected data");
1N/A
1N/A__END__
1N/A# A whole run of 1.1.14 freeze data, uuencoded. The "mode bits" are the octal
1N/A# value of 'A', the "file name" is the test name. Use make_56_interwork.pl
1N/A# with a copy of Storable 1.X generate these.
1N/A
1N/A# byteorder '1234'
1N/A# sizeof(int) 4
1N/A# sizeof(long) 4
1N/A# sizeof(char *) 4
1N/A# sizeof(NV) 8
1N/Abegin 101 Lillput,4,4,4,8
1N/AM!`0$,3(S-`0$!`@"!`````HQ5&AI<R!F:6QE('=A<R!W<FET=&5N('=I=&@@
1N/AM,2XP,30@;VX@<&5R;"`U+C`P-C`P,0H33&EL;'!U="!W87,@8V]R<F5C=`8"
1N/A0````````@`H'5&AE($5N9```
1N/A
1N/Aend
1N/A
1N/A# byteorder '4321'
1N/A# sizeof(int) 4
1N/A# sizeof(long) 4
1N/A# sizeof(char *) 4
1N/A# sizeof(NV) 8
1N/Abegin 101 Belfuscu,4,4,4,8
1N/AM!`0$-#,R,00$!`@"````!`HQ5&AI<R!F:6QE('=A<R!W<FET=&5N('=I=&@@
1N/AM,2XP,30@;VX@<&5R;"`U+C`P-C`P,0H40F5L9G5S8W4@=V%S(&-O<G)E8W0&
1N/A1@`````````(*!U1H92!%;F0`
1N/A
1N/Aend
1N/A
1N/A# byteorder '1234'
1N/A# sizeof(int) 4
1N/A# sizeof(long) 4
1N/A# sizeof(char *) 4
1N/A# sizeof(NV) 12
1N/Abegin 101 Lillput,4,4,4,12
1N/AM!`0$,3(S-`0$!`P"!`````HQ5&AI<R!F:6QE('=A<R!W<FET=&5N('=I=&@@
1N/AM,2XP,30@;VX@<&5R;"`U+C`P-C`P,0H33&EL;'!U="!W87,@8V]R<F5C=`8"
1N/A0````````@`H'5&AE($5N9```
1N/A
1N/Aend
1N/A