From: Raghubansh Kumar Date: Thu, 21 Jun 2007 21:12:18 +0000 (+0000) Subject: New tests for file system handling functions X-Git-Tag: php-5.2.4RC1~313 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e647140a8267ec5c1daff26d76990d0289bf43b6;p=php New tests for file system handling functions --- diff --git a/ext/standard/tests/file/filesize_variation-win32.phpt b/ext/standard/tests/file/filesize_variation-win32.phpt new file mode 100644 index 0000000000..ed215c02cb --- /dev/null +++ b/ext/standard/tests/file/filesize_variation-win32.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test filesize() function: usage variations +--SKIPIF-- +=-1200; $size-=1200) { + $file_handle = fopen($filename, "r+"); + var_dump( ftruncate($file_handle, $size) ); + fclose($file_handle); + var_dump( filesize($filename) ); + clearstatcache(); +} + +echo "-- Testing filesize() with the data of possible chars --\n"; +$filename2 = $file_path."/filesize_variation1.tmp"; +$string = "Test 2 test the filesize() fn, with data containing all the types like !@@##$%^&*():<>?|~+!;',.\][{}(special) chars, 12345(numeric) chars, and \n(newline char), \t(tab), \0, \r and so on........\0"; +echo "-- opening the file in 'w' mode and get the size --\n"; +$file_handle = fopen($filename2, "w"); +var_dump( strlen($string) ); //strlen of the string +fwrite($file_handle, $string); +fclose($file_handle); +var_dump( filesize($filename2) ); //size of the file = strlen of string +clearstatcache(); + +echo "-- opening the file in 'wt' mode and get the size --\n"; +$file_handle = fopen($filename2, "wt"); +var_dump( strlen($string) ); //strlen of the string = 191 bytes +fwrite($file_handle, $string); +fclose($file_handle); +/* '\n' treated as '\r\n' i.e two chars in 'wt' mode */ +var_dump( filesize($filename2) ); //size of the file = 192 bytes != strlen of string +clearstatcache(); + +echo "-- opening the file in 'a' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello, world"); +fclose($file_handle); +/* '\n' treated as '\r\n' i.e two chars in 'wt' mode */ +var_dump( filesize($filename2) ); //204 bytes +clearstatcache(); + +echo "-- opening the file in 'at' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "at"); +fwrite($file_handle, "Hello, world\n"); +fclose($file_handle); +/* '\n' treated as '\r\n' i.e two chars in 'wt' mode */ +var_dump( filesize($filename2) ); //218 bytes +clearstatcache(); + +echo "-- creating a hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +var_dump( ftruncate($file_handle, 220) ); //creating 4 bytes of hole +fclose($file_handle); +var_dump( filesize($filename2) ); //220 bytes +clearstatcache(); + +echo "-- writing data after hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello\0"); //wrting 6 bytes of data +fclose($file_handle); +var_dump( filesize($filename2) ); //226 bytes +clearstatcache(); + +echo "-- opening the existing file in write mode --\n"; +fclose( fopen($filename2, "w") ); +var_dump( filesize($filename2) ); //0 bytes +clearstatcache(); + +echo "-- with empty file --\n"; +$filename3 = dirname(__FILE__)."/filesize_variation_empty.tmp"; +fclose( fopen($filename3, "w") ); +var_dump( filesize($filename3) ); //0 bytes + +echo "*** Done ***\n"; +?> +--CLEAN-- + +--EXPECTF-- +*** Testing filesize(): usage variations *** +*** Checking filesize() with different size of files *** +int(1024) +int(1025024) +int(2049024) +int(3073024) +int(4097024) +int(5121024) +int(6145024) +int(7169024) +int(8193024) +int(9217024) + +*** Testing size of a dir, sub-dir and file with filesize() *** +-- Creating a base dir, and checking its size -- +int(0) +-- Creating a file inside base dir, and checking dir & file size -- +int(0) +int(1024) +-- Creating an empty sub-dir in base-dir, and checking size of base and sub dir -- +int(0) +int(0) +-- Creating a file inside sub-dir, and checking size of base, subdir and file created -- +int(0) +int(0) +int(12000) +-- Testing filesize() after truncating the file to a new length -- +bool(true) +int(12000) +bool(true) +int(10800) +bool(true) +int(9600) +bool(true) +int(8400) +bool(true) +int(7200) +bool(true) +int(6000) +bool(true) +int(4800) +bool(true) +int(3600) +bool(true) +int(2400) +bool(true) +int(1200) +bool(true) +int(0) +bool(false) +int(0) +-- Testing filesize() with the data of possible chars -- +-- opening the file in 'w' mode and get the size -- +int(191) +int(191) +-- opening the file in 'wt' mode and get the size -- +int(191) +int(192) +-- opening the file in 'a' mode, adding data and checking the file -- +int(204) +-- opening the file in 'at' mode, adding data and checking the file -- +int(218) +-- creating a hole and checking the size -- +bool(true) +int(220) +-- writing data after hole and checking the size -- +int(226) +-- opening the existing file in write mode -- +int(0) +-- with empty file -- +int(0) +*** Done *** \ No newline at end of file diff --git a/ext/standard/tests/file/filesize_variation.phpt b/ext/standard/tests/file/filesize_variation.phpt new file mode 100644 index 0000000000..883bb8c8a5 --- /dev/null +++ b/ext/standard/tests/file/filesize_variation.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test filesize() function: usage variations +--SKIPIF-- +=-1200; $size-=1200) { + $file_handle = fopen($filename, "r+"); + var_dump( ftruncate($file_handle, $size) ); + fclose($file_handle); + var_dump( filesize($filename) ); + clearstatcache(); +} + +echo "-- Testing filesize() with the data of possible chars --\n"; +$filename2 = $file_path."/filesize_variation1.tmp"; +$string = "Test 2 test the filesize() fn, with data containing all the types like !@@##$%^&*():<>?|~+!;',.\][{}(special) chars, 12345(numeric) chars, and \n(newline char), \t(tab), \0, \r and so on........\0"; +echo "-- opening the file in 'w' mode and get the size --\n"; +$file_handle = fopen($filename2, "w"); +var_dump( strlen($string) ); //strlen of the string +fwrite($file_handle, $string); +fclose($file_handle); +var_dump( filesize($filename2) ); //size of the file = strlen of string +clearstatcache(); + +echo "-- opening the file in 'wt' mode and get the size --\n"; +$file_handle = fopen($filename2, "wt"); +var_dump( strlen($string) ); //strlen of the string = 191 bytes +fwrite($file_handle, $string); +fclose($file_handle); +var_dump( filesize($filename2) ); //size of the file = strlen of string = 191 bytes +clearstatcache(); + +echo "-- opening the file in 'a' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello, world"); +fclose($file_handle); +var_dump( filesize($filename2) ); //203 bytes +clearstatcache(); + +echo "-- opening the file in 'at' mode, adding data and checking the file --\n"; +$file_handle = fopen($filename2, "at"); +fwrite($file_handle, "Hello, world\n"); +fclose($file_handle); +var_dump( filesize($filename2) ); //216 bytes +clearstatcache(); + +echo "-- creating a hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +var_dump( ftruncate($file_handle, 220) ); //creating 4 bytes of hole +fclose($file_handle); +var_dump( filesize($filename2) ); //220 bytes +clearstatcache(); + +echo "-- writing data after hole and checking the size --\n"; +$file_handle = fopen($filename2, "a"); +fwrite($file_handle, "Hello\0"); //wrting 6 bytes of data +fclose($file_handle); +var_dump( filesize($filename2) ); //226 bytes +clearstatcache(); + +echo "-- opening the existing file in write mode --\n"; +fclose( fopen($filename2, "w") ); +var_dump( filesize($filename2) ); //0 bytes +clearstatcache(); + +echo "-- with empty file --\n"; +$filename3 = dirname(__FILE__)."/filesize_variation_empty.tmp"; +fclose( fopen($filename3, "w") ); +var_dump( filesize($filename3) ); //0 bytes + +echo "*** Done ***\n"; +?> +--CLEAN-- + +--EXPECTF-- +*** Testing filesize(): usage variations *** +*** Checking filesize() with different size of files *** +int(1024) +int(1025024) +int(2049024) +int(3073024) +int(4097024) +int(5121024) +int(6145024) +int(7169024) +int(8193024) +int(9217024) + +*** Testing size of a dir, sub-dir and file with filesize() *** +-- Creating a base dir, and checking its size -- +int(4096) +-- Creating a file inside base dir, and checking dir & file size -- +int(4096) +int(1024) +-- Creating an empty sub-dir in base-dir, and checking size of base and sub dir -- +int(4096) +int(4096) +-- Creating a file inside sub-dir, and checking size of base, subdir and file created -- +int(4096) +int(4096) +int(12000) +-- Testing filesize() after truncating the file to a new length -- +bool(true) +int(12000) +bool(true) +int(10800) +bool(true) +int(9600) +bool(true) +int(8400) +bool(true) +int(7200) +bool(true) +int(6000) +bool(true) +int(4800) +bool(true) +int(3600) +bool(true) +int(2400) +bool(true) +int(1200) +bool(true) +int(0) +bool(false) +int(0) +-- Testing filesize() with the data of possible chars -- +-- opening the file in 'w' mode and get the size -- +int(191) +int(191) +-- opening the file in 'wt' mode and get the size -- +int(191) +int(191) +-- opening the file in 'a' mode, adding data and checking the file -- +int(203) +-- opening the file in 'at' mode, adding data and checking the file -- +int(216) +-- creating a hole and checking the size -- +bool(true) +int(220) +-- writing data after hole and checking the size -- +int(226) +-- opening the existing file in write mode -- +int(0) +-- with empty file -- +int(0) +*** Done *** diff --git a/ext/standard/tests/file/lstat_stat_basic.phpt b/ext/standard/tests/file/lstat_stat_basic.phpt new file mode 100644 index 0000000000..aa00cf4c4b --- /dev/null +++ b/ext/standard/tests/file/lstat_stat_basic.phpt @@ -0,0 +1,315 @@ +--TEST-- +Test lstat() & stat() functions: basic functionality +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing lstat() & stat() : basic functionality *** +*** Testing stat() and lstat() : validating the values stored in stat *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Testing stat() and lstat() : comparing stats (recorded before and after file/link creation) *** +-- comparing difference in dir stats before and after creating file in it -- +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +bool(true) +-- comparing difference in file stats before and after creating link to it -- +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(%d) + [12]=> + int(%d) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(%d) + ["blocks"]=> + int(%d) +} +bool(true) +Done diff --git a/ext/standard/tests/file/lstat_stat_error.phpt b/ext/standard/tests/file/lstat_stat_error.phpt new file mode 100644 index 0000000000..e5a971461e --- /dev/null +++ b/ext/standard/tests/file/lstat_stat_error.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test lstat() and stat() functions: error conditions +--SKIPIF-- + +--FILE-- + expected +var_dump( lstat("$file_path/temp.tmp") ); // non existing file +var_dump( lstat(22) ); // scalar argument +$arr = array(__FILE__); +var_dump( lstat($arr) ); // array argument + +echo "\n*** Testing stat() for error conditions ***\n"; +var_dump( stat() ); // args < expected +var_dump( stat(__FILE__, 2) ); // file, args > expected +var_dump( stat(dirname(__FILE__), 2) ); //dir, args > expected + +var_dump( stat("$file_path/temp.tmp") ); // non existing file +var_dump( stat("$file_path/temp/") ); // non existing dir +var_dump( stat(22) ); // scalar argument +var_dump( stat($arr) ); // array argument + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing lstat() for error conditions *** + +Warning: Wrong parameter count for lstat() in %s on line %d +NULL + +Warning: Wrong parameter count for lstat() in %s on line %d +NULL + +Warning: lstat(): Lstat failed for %s in %s on line %d +bool(false) + +Warning: lstat(): Lstat failed for 22 in %s on line %d +bool(false) + +Notice: Array to string conversion in %s on line %d + +Warning: lstat(): Lstat failed for Array in %s on line %d +bool(false) + +*** Testing stat() for error conditions *** + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for 22 in %s on line %d +bool(false) + +Notice: Array to string conversion in %s on line %d + +Warning: stat(): stat failed for Array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/file/rename_variation-win32.phpt b/ext/standard/tests/file/rename_variation-win32.phpt new file mode 100644 index 0000000000..3cac5ccadd --- /dev/null +++ b/ext/standard/tests/file/rename_variation-win32.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing rename() : rename files across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() : renaming directory across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() by renaming a file and directory to numeric name *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +-- Renaming file to same file name -- +bool(true) + +-- Renaming directory to same directory name -- +bool(true) + +-- Renaming existing file to existing directory name -- + +Warning: rename(%s,%s): File exists in %s on line %d +bool(false) + +-- Renaming existing directory to existing file name -- + +Warning: rename(%s,%s): File exists in %s on line %d +bool(false) +Done \ No newline at end of file diff --git a/ext/standard/tests/file/rename_variation.phpt b/ext/standard/tests/file/rename_variation.phpt new file mode 100644 index 0000000000..cf1c0ff8f7 --- /dev/null +++ b/ext/standard/tests/file/rename_variation.phpt @@ -0,0 +1,311 @@ +--TEST-- +Test rename() function: usage variations +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing rename() : rename files across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- + +Warning: rename(%s,%s): Not a directory in %s on line %d +bool(false) +bool(false) +bool(false) + +Warning: unlink(%s): No such file or directory in %s on line %d +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() : renaming directory across directories *** +-- Iteration 1 -- +bool(true) +bool(false) +bool(true) +-- Iteration 2 -- +bool(true) +bool(false) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) + +*** Testing rename() on soft links *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +*** Testing rename() on hard links *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +*** Testing rename() by renaming a file, link and directory to numeric name *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(false) +bool(true) + +-- Renaming link to same link name -- +bool(true) + +-- Renaming file to same file name -- +bool(true) + +-- Renaming directory to same directory name -- +bool(true) + +-- Renaming existing link to existing directory name -- + +Warning: rename(%s,%s): Is a directory in %s on line %d +bool(false) + +-- Renaming existing link to existing file name -- +bool(true) + +-- Renaming existing file to existing directory name -- + +Warning: rename(%s,%s): Is a directory in %s on line %d +bool(false) + +-- Renaming existing file to existing link name -- +bool(true) + +-- Renaming existing directory to existing file name -- + +Warning: rename(%s,%s): Not a directory in %s on line %d +bool(false) + +-- Renaming existing directory to existing link name -- + +Warning: rename(%s,%s): Not a directory in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/file/stat_basic-win32.phpt b/ext/standard/tests/file/stat_basic-win32.phpt new file mode 100644 index 0000000000..9f2e5cc256 --- /dev/null +++ b/ext/standard/tests/file/stat_basic-win32.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test stat() function: basic functionality +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECTF-- +*** Testing stat() : basic functionality *** +*** Testing stat(): validating the values stored in stat *** +bool(true) +bool(true) +bool(true) +*** Testing stat(): comparing stats (recorded before and after file creation) *** +-- comparing difference in dir stats before and after creating file in it -- +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(-1) + [12]=> + int(-1) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(-1) + ["blocks"]=> + int(-1) +} +array(26) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) + [10]=> + int(%d) + [11]=> + int(-1) + [12]=> + int(-1) + ["dev"]=> + int(%d) + ["ino"]=> + int(%d) + ["mode"]=> + int(%d) + ["nlink"]=> + int(%d) + ["uid"]=> + int(%d) + ["gid"]=> + int(%d) + ["rdev"]=> + int(%d) + ["size"]=> + int(%d) + ["atime"]=> + int(%d) + ["mtime"]=> + int(%d) + ["ctime"]=> + int(%d) + ["blksize"]=> + int(-1) + ["blocks"]=> + int(-1) +} +bool(true) +*** Testing stat(): for the return value *** +bool(true) + +---Done--- diff --git a/ext/standard/tests/file/stat_error-win32.phpt b/ext/standard/tests/file/stat_error-win32.phpt new file mode 100644 index 0000000000..fcbac5ff0b --- /dev/null +++ b/ext/standard/tests/file/stat_error-win32.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test stat() function: error conditions +--SKIPIF-- + +--FILE-- + expected +var_dump( stat(dirname(__FILE__), 2) ); //dir, args > expected + +var_dump( stat("$file_path/temp.tmp") ); // non existing file +var_dump( stat("$file_path/temp/") ); // non existing dir +var_dump( stat(22) ); // scalar argument +var_dump( stat($arr) ); // array argument + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing stat() for error conditions *** + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: Wrong parameter count for stat() in %s on line %d +NULL + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for %s in %s on line %d +bool(false) + +Warning: stat(): stat failed for 22 in %s on line %d +bool(false) + +Notice: Array to string conversion in %s on line %d + +Warning: stat(): stat failed for Array in %s on line %d +bool(false) +Done