1
0
mirror of https://github.com/php/php-src.git synced 2026-04-22 07:28:09 +02:00
Files
archived-php-src/ext/gmp/tests/gmp_export.phpt
T
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

80 lines
2.9 KiB
PHP

--TEST--
gmp_export() basic tests
--SKIPIF--
<?php if (!extension_loaded("gmp")) echo "skip"; ?>
--FILE--
<?php
// Tests taken from GMPs own test suite.
// format is [output, size, options, expected]
$export = [
['0',1,GMP_BIG_ENDIAN,''],
['0',2,GMP_BIG_ENDIAN,''],
['0',3,GMP_BIG_ENDIAN,''],
['12345678',1,GMP_BIG_ENDIAN,'12345678'],
['12345678',4,GMP_BIG_ENDIAN,'12345678'],
['12345678',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'12345678'],
['12345678',1,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
['12345678',4,GMP_LITTLE_ENDIAN,'78563412'],
['12345678',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
['123456789ABC',2,GMP_BIG_ENDIAN,'123456789abc'],
['123456789ABC',2,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9abc56781234'],
['123456789ABC',2,GMP_LITTLE_ENDIAN,'34127856bc9a'],
['123456789ABC',2,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'bc9a78563412'],
['112233445566778899AABBCC',4,GMP_BIG_ENDIAN,'112233445566778899aabbcc'],
['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'99aabbcc5566778811223344'],
['112233445566778899AABBCC',4,GMP_LITTLE_ENDIAN,'4433221188776655ccbbaa99'],
['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'ccbbaa998877665544332211'],
['100120023003400450056006700780089009A00AB00BC00C',8,GMP_BIG_ENDIAN,'100120023003400450056006700780089009a00ab00bc00c'],
['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9009a00ab00bc00c50056006700780081001200230034004'],
['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LITTLE_ENDIAN,'044003300220011008800770066005500cc00bb00aa00990'],
['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'0cc00bb00aa0099008800770066005500440033002200110']
];
$passed = true;
foreach ($export as $k => $test) {
$gmp = gmp_init($test[0], 16);
$str = gmp_export($gmp, $test[1], $test[2]);
if (is_string($str)) {
$result = bin2hex($str);
if ($result !== $test[3]) {
echo "$k: '$result' !== '{$test[3]}'\n";
$passed = false;
}
} else {
$type = gettype($str);
echo "$k: $type !== '{$test[3]}'\n";
}
}
var_dump($passed);
// Invalid arguments (zpp failure)
var_dump(gmp_export());
// Invalid word sizes
var_dump(gmp_export(123, -1));
var_dump(gmp_export(123, 0));
// Invalid options
var_dump(gmp_export(123, 1, GMP_MSW_FIRST | GMP_LSW_FIRST));
var_dump(gmp_export(123, 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN));
--EXPECTF--
bool(true)
Warning: gmp_export() expects at least 1 parameter, 0 given in %s on line %d
NULL
Warning: gmp_export(): Word size must be positive, -1 given in %s on line %d
bool(false)
Warning: gmp_export(): Word size must be positive, 0 given in %s on line %d
bool(false)
Warning: gmp_export(): Invalid options: Conflicting word orders in %s on line %d
bool(false)
Warning: gmp_export(): Invalid options: Conflicting word endianness in %s on line %d
bool(false)