mirror of
https://github.com/php/php-src.git
synced 2026-04-21 15:08:16 +02:00
d679f02295
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
109 lines
2.8 KiB
PHP
109 lines
2.8 KiB
PHP
--TEST--
|
|
Test md5_file() function with ASCII output and raw binary output
|
|
--FILE--
|
|
<?php
|
|
|
|
/* Prototype: string md5_file( string filename[, bool raw_output] )
|
|
* Description: Calculate the MD5 hash of a given file
|
|
*/
|
|
|
|
/* Creating an empty file */
|
|
if (($handle = fopen( "EmptyFile.txt", "w+")) == FALSE)
|
|
return false;
|
|
|
|
/* Creating a data file */
|
|
if (($handle2 = fopen( "DataFile.txt", "w+")) == FALSE)
|
|
return false;
|
|
|
|
/* Writing into file */
|
|
$filename = "DataFile.txt";
|
|
$content = "Add this to the file\n";
|
|
if (is_writable($filename)) {
|
|
if (fwrite($handle2, $content) === FALSE) {
|
|
echo "Cannot write to file ($filename)";
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// close the files
|
|
fclose($handle);
|
|
fclose($handle2);
|
|
|
|
/* Testing error conditions */
|
|
echo "\n*** Testing for error conditions ***\n";
|
|
|
|
/* No filename */
|
|
var_dump( md5_file("") );
|
|
|
|
/* invalid filename */
|
|
var_dump( md5_file("aZrq16u") );
|
|
|
|
/* Scalar value as filename */
|
|
var_dump( md5_file(12) );
|
|
|
|
/* NULL as filename */
|
|
var_dump( md5_file(NULL) );
|
|
|
|
/* Zero arguments */
|
|
var_dump ( md5_file() );
|
|
|
|
/* More than valid number of arguments ( valid is 2) */
|
|
var_dump ( md5_file("EmptyFile.txt", true, NULL) );
|
|
|
|
/* Hexadecimal Output for Empty file as input */
|
|
echo "\n*** Hexadecimal Output for Empty file as Argument ***\n";
|
|
var_dump( md5_file("EmptyFile.txt") );
|
|
|
|
/* Raw Binary Output for Empty file as input */
|
|
echo "\n*** Raw Binary Output for Empty file as Argument ***\n";
|
|
var_dump( md5_file("EmptyFile.txt", true) );
|
|
|
|
/* Normal operation with hexadecimal output */
|
|
echo "\n*** Hexadecimal Output for a valid file with some contents ***\n";
|
|
var_dump( md5_file("DataFile.txt") );
|
|
|
|
/* Normal operation with raw binary output */
|
|
echo "\n*** Raw Binary Output for a valid file with some contents ***\n";
|
|
var_dump ( md5_file("DataFile.txt", true) );
|
|
|
|
// remove temp files
|
|
unlink("DataFile.txt");
|
|
unlink("EmptyFile.txt");
|
|
|
|
echo "\nDone";
|
|
?>
|
|
--EXPECTF--
|
|
*** Testing for error conditions ***
|
|
|
|
Warning: md5_file(): Filename cannot be empty in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: md5_file(aZrq16u): failed to open stream: No such file or directory in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: md5_file(12): failed to open stream: No such file or directory in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: md5_file(): Filename cannot be empty in %s on line %d
|
|
bool(false)
|
|
|
|
Warning: md5_file() expects at least 1 parameter, 0 given in %s on line %d
|
|
NULL
|
|
|
|
Warning: md5_file() expects at most 2 parameters, 3 given in %s on line %d
|
|
NULL
|
|
|
|
*** Hexadecimal Output for Empty file as Argument ***
|
|
string(32) "d41d8cd98f00b204e9800998ecf8427e"
|
|
|
|
*** Raw Binary Output for Empty file as Argument ***
|
|
string(16) "Ԍ� |