#!./perl -w
BEGIN {
chdir 't' if -d 't';
}
use strict;
use warnings;
use Config;
return @result;
}
}
my ($l, $r) = @_;
return 0 unless @$l == @$r;
for my $i (0..$#$l) {
} else {
return 0 if defined $r->[$i]
}
}
return 1;
}
##############################################################################
#
# Here starteth the tests
#
{
# Need the expression in here to force ary[5] to be numeric. This avoids
# test2 failing because ary2 goes str->numeric->str and ary doesn't.
my @ary = (1,-100,127,128,32767,987.654321098 / 100.0,12345,123456,
"abcdef");
# Using long double NVs may introduce greater accuracy than wanted.
$out1 =~ s/:9\.87654321097999\d*:/:9.87654321098:/;
$out2 =~ s/:9\.87654321097999\d*:/:9.87654321098:/;
}
# How about counting bits?
{
my $x;
}
{
my $sum = 129; # ASCII
$sum = 103 if $Is_EBCDIC;
my $x;
my $foo;
}
{
my $x;
}
{
# check 'w'
my @x = (5,130,256,560,32000,3097152,268435455,1073741844, 2**33,
'4503599627365785','23728385234614992549757750638446');
'0800087ffffffffffdb19caefe8e1eeeea0c2e1e3e8ede1ee6e';
my $a;
my $b = pop @y;
}
eval {
};
if (~0 - 1 == (~0) - 2) {
} else {
}
# These should spot that pack 'w' is using NV, not double, on platforms
# where IVs are smaller than doubles, and harmlessly pass elsewhere.
# (tests for change 16861)
my $x0 = 2**54+3;
my $y0 = 2**54-2;
} else {
}
}
{
print "# test exceptions\n";
my $x;
SKIP: {
# Is this a stupid thing to do on VMS, VOS and other unusual platforms?
if (
||
||
);
$TODO = "VOS needs a fix for posix-1022 to pass this test."
}
SKIP: {
# This should be about the biggest thing possible on an IEEE double
# I'm getting about 1e-16 on FreeBSD
}
}
print "# test the 'p' template\n";
# literals
# scalars
# temps
{
use warnings;
my $warning;
$warning = $_[0];
};
}
# undef should give null pointer
# Check for optimizer bug (e.g. Digital Unix GEM cc with -O4 on DU V4.0B gives
# 4294967295 instead of -1)
# see #ifdef __osf__ in pp.c pp_unpack
print "# test the pack lengths of s S i I l L n N v V\n";
} else {
}
}
print "# test unpack-pack lengths\n";
SKIP: {
# quads not supported everywhere
SKIP: {
}
}
}
{
# Note that first uuencoding known 'text' data and then checking the
# binary values of the uuencoded version would not be portable between
# character sets. Uuencoding is meant for encoding binary data, not
# text data.
# just to be anal, we do some random tr/`/ /
MAXB)BHN,C8Z/D)&2DY25EI>8F9J;G)V>GZ"AHJ.DI::GJ*FJJZRMKJ^PL;*S
MM+6VM[BYNKN\O;Z_P,'"P\3%QL?(R<K+S,W.S]#1TM/4U=;7V-G:V]S=WM_@
?X>+CY.7FY^CIZNOL[>[O\/'R\_3U]O?X^?K[_/W^_P `
$_ = $uu;
tr/ /`/;
is(pack('u', $in), $_);
$in = "\x1f\x8b\x08\x08\x58\xdc\xc4\x35\x02\x03\x4a\x41\x50\x55\x00\xf3\x2a\x2d\x2e\x51\x48\xcc\xcb\x2f\xc9\x48\x2d\x52\x08\x48\x2d\xca\x51\x28\x2d\x4d\xce\x4f\x49\x2d\xe2\x02\x00\x64\x66\x60\x5c\x1a\x00\x00\x00";
$uu = <<'EOUU';
M'XL("%C<Q#4"`TI!4%4`\RHM+E%(S,LOR4@M4@A(+<I1*"U-SD])+>("`&1F
&8%P:````
# This is identical to the above except that backquotes have been
# changed to spaces
M'XL("%C<Q#4" TI!4%4 \RHM+E%(S,LOR4@M4@A(+<I1*"U-SD])+>(" &1F
&8%P:
EOUU
# ' # Grr
}
# test the ascii template types (A, a, Z)
foreach (
['p', 'A*', "foo\0bar\0 ", "foo\0bar\0 "],
['p', 'A11', "foo\0bar\0 ", "foo\0bar\0 "],
['u', 'A*', "foo\0bar \0", "foo\0bar"],
['u', 'A8', "foo\0bar \0", "foo\0bar"],
['p', 'a*', "foo\0bar\0 ", "foo\0bar\0 "],
['p', 'a11', "foo\0bar\0 ", "foo\0bar\0 \0\0"],
['u', 'a*', "foo\0bar \0", "foo\0bar \0"],
['u', 'a8', "foo\0bar \0", "foo\0bar "],
['p', 'Z*', "foo\0bar\0 ", "foo\0bar\0 \0"],
['p', 'Z11', "foo\0bar\0 ", "foo\0bar\0 \0\0"],
['p', 'Z3', "foo", "fo\0"],
['u', 'Z*', "foo\0bar \0", "foo"],
['u', 'Z8', "foo\0bar \0", "foo"],
)
{
}
}
sub numbers {
my $format = shift;
}
sub numbers_with_total {
my $format = shift;
my $total = shift;
foreach (@_) {
$total += $_;
}
}
foreach (@_) {
SKIP: {
}
}
my $skip_if_longer_than = ~0; # "Infinity"
if (~0 - 1 == ~0) {
# If we're running with -DNO_PERLPRESERVE_IVUV and NVs don't preserve all
# UVs (in which case ~0 is NV, ~0-1 will be the same NV) then we can't
# correctly in perl calculate UV totals for long checksums, as pp_unpack
# is using UV maths, and we've only got NVs.
}
foreach ('', 1, 2, 3, 15, 16, 17, 31, 32, 33, 53, 54, 63, 64, 65) {
SKIP: {
my $len = $_; # Copy, so that we can reassign ''
SKIP: {
if $len > $skip_if_longer_than;
# Our problem with testing this portably is that the checksum code in
# pp_unpack is able to cast signed to unsigned, and do modulo 2**n
# arithmetic in unsigned ints, which perl has no operators to do.
# (use integer; does signed ints, which won't wrap on UTS, which is just
# fine with ANSI, but not with most people's assumptions.
# This is why we need to supply the totals for 'Q' as there's no way in
# perl to calculate them, short of unpack '%0Q' (is that documented?)
# ** returns NVs; make sure it's IV.
$max_p1_is_integer = 1 unless $max_p1 + 1 == $max_p1;
$max_is_integer = 1 if $max - 1 < ~0;
my $calc_sum;
} else {
# Shift into range by some multiple of the total
# Need this to make sure that -1 + (~0+1) is ~0 (ie still integer)
$calc_sum += 1;
}
}
# we're into floating point (either by getting out of the range of
# UV arithmetic, or because we're doing a floating point checksum)
# and our calculation of the checksum has become rounded up to
# max_checksum + 1
$calc_sum = 0;
}
} else {
my $delta = 1.000001;
} else {
fail;
}
}
}
}
}
}
# All these should have exact binary representations:
## These don't, but 'd' is NV. XXX wrong, it's double
#numbers ('d', -1, 0, 1, 1-exp(-1), -exp(1));
-9223372036854775808, -1, 0, 1,9223372036854775807);
# This total is icky, but the true total is 2**65-1, and need a way to generate
# the epxected checksum on any system including those where NVs can preserve
# 65 bits. (long double is 128 bits on sparc, so they certainly can)
# or where rounding is down not up on binary conversion (crays)
my $len = shift;
return $total; # NVs still accurate to nearest integer
},
0, 1,9223372036854775807, 9223372036854775808,
18446744073709551615);
print "# pack nvNV byteorders\n";
{
# /
my ($x, $y, $z);
undef $x;
undef $x;
undef $z;
undef $x;
undef $x;
undef $x;
undef $x;
# Doing this in scalar context used to fail.
foreach (
['a/a*/a*', '212ab345678901234567','ab3456789012'],
['a/a*/a*', '3012ab345678901234567', 'ab3456789012'],
)
{
undef $x;
undef $x;
}
# / with #
a3/A # Count in ASCII
C/a* # Count in a C char
C/Z # Count in a C char but skip after \0
$x = $y = $z =undef;
undef $x;
n/a* # Count as network short
w/A* # Count a BER integer
}
SKIP: {
}
# does pack U create Unicode?
# does unpack U deref Unicode?
# is unpack U the reverse of pack U for Unicode string?
# is unpack U the reverse of pack U for byte string?
SKIP: {
# does unpack C unravel pack U?
# does pack U0C create Unicode?
# does pack C0U create characters?
# does unpack U0U on byte data warn?
{
}
}
{
my (@a);
# bug - % had to be at the start of the pattern, no leading whitespace or
# comments. %i! didn't work at all.
'%32i!*', ' %32i!*', "\n#\n#\n\r \t\f%32i!*", '%32i!*#') {
}
# Multiline patterns in scalar context failed.
# On the Ning Nang Nong
# Where the Cows go Bong!
# And the Monkeys all say Boo!
I
EOPOEMSNIPPET
}
# shorts (of all flavours) didn't calculate checksums > 32 bits with floating
# point, so a pathologically long pattern would wrap at 32 bits.
foreach (4,3,2,1,0) {
my $len = 65534 + $_;
}
}
# pack x X @
foreach (
['x', "N", "\0"],
['xX', "N", ""],
['xXa*', "Nick", "Nick"],
['a5Xa5', "cameL", "llama", "camellama"],
['a*@8a*', 'Camel', 'Dromedary', "Camel\0\0\0Dromedary"],
['a*@4a', 'Perl rules', '!', 'Perl!'],
)
{
}
# unpack x X @
foreach (
['x', "N"],
['xX', "N"],
['xXa*', "Nick", "Nick"],
['a5Xa5', "camellama", "camel", "llama"],
['@3', "ice"],
['@2a2', "water", "te"],
['a*@1a3', "steam", "steam", "tea"],
)
{
}
{
my $t = 'Z*Z*';
}
{
# "w/a*" should be seen as one unit
}
{
# from Wolfgang Laun: fix in change #13163
my $s = 'ABC' x 10;
my $t = '*';
my $y;
my $h = $buf;
$h =~ s/[^[:print:]]/./g;
}
{
# from Wolfgang Laun: fix in change #13288
}
{ # Grouping constructs
my (@a, @b);
@b = (67..72);
@b = (67..74);
}
{ # more on grouping (W.Laun)
use warnings;
my $warning;
$warning = $_[0];
};
# @ absolute within ()-group
my @b = ( 1, 2, 3 );
# unpack full length - ok
# \0002 \0001 a \0003 AAA \0001 b \0003 BBB
# 2 4 5 7 10 1213
# postfix repeat count
# \0001 a \0003 AAA \0001 b \0003 BBB
# 2 3c 5 8 10 11 13 16
}
{ # syntax checks (W.Laun)
use warnings;
my @warning;
};
# white space where possible
# white space in 4 wrong places
}
# warning for commas
# comma warning only once
# forbidden code in []
# @ repeat default 1
# no unpack code after /
}
{ # Repeat count [SUBEXPR]
s! S! i! I! l! L! j J);
my $G;
} else {
}
} else {
}
my %val;
| C (?{ 214 })
| c (?{ 114 })
/x; $^R } @codes;
my @end = (0x12345678, 0x23456781, 0x35465768, 0x15263748);
my $c = 1;
$c = 1;
# print "# junk1=$junk1\n";
# print "# junk='$junk', list=(@list2)\n";
}
}
}
}
}
# / is recognized after spaces in scalar context
# XXXX no spaces are allowed in pack... In pack only before the slash...
{ # X! and x!
my $t = 'C[3] x!8 C[2]';
my @a = (0x73..0x77);
my @b = unpack $t, $p;
$t = 'x[5] C[6] X!8 C[2]';
@a = (0x73..0x7a);
@b = unpack $t, $p;
@a = (0x73..0x75, 0x79, 0x7a, 0x79, 0x7a);
}
{ # struct {char c1; double d; char cc[2];}
my $t = 'C x![d] d C[2]';
my @a = (173, 1.283476517e-45, 42, 215);
my $p = pack $t, @a;
$b = "@b";
my $warning;
$warning = $_[0];
};
$b = "@b";
}
SKIP: {
}
# Maybe this knowledge needs to be "global" for all of pack.t
# Or a "can checksum" which would effectively be all the number types"
# not a b B h H
SKIP: {
if ($@) {
$cant_checksum{$template} ? 4 : 8);
}
);
);
}
}
}
}
{
my $a = "X\t01234567\n" x 100;
}