Skip to content

Commit

Permalink
Add generic pack test for 64bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ranvis committed Apr 20, 2024
1 parent e519c67 commit 66861f5
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 56 deletions.
76 changes: 20 additions & 56 deletions ext/standard/tests/strings/pack.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
--TEST--
Generic pack()/unpack() tests
--SKIPIF--
<?php
if (PHP_INT_MAX > 2147483647) {
die("skip 32bit test only");
}
?>
--FILE--
<?php
echo "A\n";
Expand All @@ -26,25 +20,25 @@ print_r(unpack("H", pack("H", 0x04)));
echo "I\n";
print_r(unpack("I", pack("I", 65534)));
print_r(unpack("I", pack("I", 0)));
print_r(unpack("I", pack("I", -1000)));
print_r(unpack("I", pack("I", -64434)));
echo bin2hex(pack("I", -1000)), "\n";
echo bin2hex(pack("I", -64434)), "\n";
print_r(unpack("I", pack("I", 4294967296)));
print_r(unpack("I", pack("I", -4294967296)));

echo "L\n";
print_r(unpack("L", pack("L", 65534)));
print_r(unpack("L", pack("L", 0)));
print_r(unpack("L", pack("L", 2147483650)));
print_r(unpack("L", pack("L", 4294967295)));
print_r(unpack("L", pack("L", -2147483648)));
echo bin2hex(pack("L", 2147483650)), "\n";
echo bin2hex(pack("L", 4294967295)), "\n";
echo bin2hex(pack("L", -2147483648)), "\n";

echo "N\n";
print_r(unpack("N", pack("N", 65534)));
print_r(unpack("N", pack("N", 0)));
print_r(unpack("N", pack("N", 2147483650)));
echo bin2hex(pack("N", 2147483650)), "\n";
print_r(unpack("N", pack("N", 4294967296)));
print_r(unpack("N", pack("N", -2147483648)));
print_r(unpack("N", pack("N", -30000)));
echo bin2hex(pack("N", -2147483648)), "\n";
echo bin2hex(pack("N", -30000)), "\n";

echo "S\n";
print_r(unpack("S", pack("S", 65534)));
Expand All @@ -57,9 +51,9 @@ print_r(unpack("S", pack("S", -65535)));
echo "V\n";
print_r(unpack("V", pack("V", 65534)));
print_r(unpack("V", pack("V", 0)));
print_r(unpack("V", pack("V", 2147483650)));
echo bin2hex(pack("V", 2147483650)), "\n";
print_r(unpack("V", pack("V", 4294967296)));
print_r(unpack("V", pack("V", -2147483648)));
echo bin2hex(pack("V", -2147483648)), "\n";

echo "a\n";
print_r(unpack("a", pack("a", "hello world")));
Expand Down Expand Up @@ -155,14 +149,8 @@ Array
(
[1] => 0
)
Array
(
[1] => -1000
)
Array
(
[1] => -64434
)
18fcffff
4e04ffff
Array
(
[1] => 0
Expand All @@ -180,18 +168,9 @@ Array
(
[1] => 0
)
Array
(
[1] => -2147483646
)
Array
(
[1] => -1
)
Array
(
[1] => -2147483648
)
02000080
ffffffff
00000080
N
Array
(
Expand All @@ -201,22 +180,13 @@ Array
(
[1] => 0
)
Array
(
[1] => -2147483646
)
80000002
Array
(
[1] => 0
)
Array
(
[1] => -2147483648
)
Array
(
[1] => -30000
)
80000000
ffff8ad0
S
Array
(
Expand Down Expand Up @@ -251,18 +221,12 @@ Array
(
[1] => 0
)
Array
(
[1] => -2147483646
)
02000080
Array
(
[1] => 0
)
Array
(
[1] => -2147483648
)
00000080
a
Array
(
Expand Down
73 changes: 73 additions & 0 deletions ext/standard/tests/strings/pack_int.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--TEST--
Int size-dependent input pack()/unpack() tests
--SKIPIF--
<?php
if (PHP_INT_SIZE > 4) {
die("skip 32bit test only");
}
?>
--FILE--
<?php
echo "I\n";
print_r(unpack("I", hex2bin('18fcffff')));
print_r(unpack("I", hex2bin('4e04ffff')));

echo "L\n";
print_r(unpack("L", hex2bin('02000080')));
print_r(unpack("L", hex2bin('ffffffff')));
print_r(unpack("L", hex2bin('00000080')));

echo "N\n";
print_r(unpack("N", hex2bin('80000002')));
print_r(unpack("N", hex2bin('80000000')));
print_r(unpack("N", hex2bin('ffff8ad0')));

echo "V\n";
print_r(unpack("V", hex2bin('02000080')));
print_r(unpack("V", hex2bin('00000080')));
?>
--EXPECT--
I
Array
(
[1] => -1000
)
Array
(
[1] => -64434
)
L
Array
(
[1] => -2147483646
)
Array
(
[1] => -1
)
Array
(
[1] => -2147483648
)
N
Array
(
[1] => -2147483646
)
Array
(
[1] => -2147483648
)
Array
(
[1] => -30000
)
V
Array
(
[1] => -2147483646
)
Array
(
[1] => -2147483648
)
73 changes: 73 additions & 0 deletions ext/standard/tests/strings/pack_int_64bit.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--TEST--
Int size-dependent input pack()/unpack() tests
--SKIPIF--
<?php
if (PHP_INT_SIZE < 8) {
die("skip 64bit test only");
}
?>
--FILE--
<?php
echo "I\n";
print_r(unpack("I", hex2bin('18fcffff')));
print_r(unpack("I", hex2bin('4e04ffff')));

echo "L\n";
print_r(unpack("L", hex2bin('02000080')));
print_r(unpack("L", hex2bin('ffffffff')));
print_r(unpack("L", hex2bin('00000080')));

echo "N\n";
print_r(unpack("N", hex2bin('80000002')));
print_r(unpack("N", hex2bin('80000000')));
print_r(unpack("N", hex2bin('ffff8ad0')));

echo "V\n";
print_r(unpack("V", hex2bin('02000080')));
print_r(unpack("V", hex2bin('00000080')));
?>
--EXPECT--
I
Array
(
[1] => 4294966296
)
Array
(
[1] => 4294902862
)
L
Array
(
[1] => 2147483650
)
Array
(
[1] => 4294967295
)
Array
(
[1] => 2147483648
)
N
Array
(
[1] => 2147483650
)
Array
(
[1] => 2147483648
)
Array
(
[1] => 4294937296
)
V
Array
(
[1] => 2147483650
)
Array
(
[1] => 2147483648
)

0 comments on commit 66861f5

Please sign in to comment.