diff options
| author | Raghubansh Kumar <kraghuba@php.net> | 2007-07-22 12:35:03 +0000 |
|---|---|---|
| committer | Raghubansh Kumar <kraghuba@php.net> | 2007-07-22 12:35:03 +0000 |
| commit | 66e901b9d59a98ff9924208428550834044410d0 (patch) | |
| tree | 8b49dc6fe885ff1c67b3c438a66e1433b4862253 /ext/standard | |
| parent | 6b81cef3550de3f6bae471b331bb029e4e075300 (diff) | |
| download | php-git-66e901b9d59a98ff9924208428550834044410d0.tar.gz | |
New testcases for ftruncate() function
Diffstat (limited to 'ext/standard')
| -rw-r--r-- | ext/standard/tests/file/ftruncate_error.phpt | 124 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation1-win32.phpt | 461 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation1.phpt | 461 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation2-win32.phpt | 462 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation2.phpt | 462 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation3-win32.phpt | 461 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation3.phpt | 461 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation4-win32.phpt | 462 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation4.phpt | 462 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation5-win32.phpt | 463 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation5.phpt | 463 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation6-win32.phpt | 482 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation6.phpt | 482 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation7-win32.phpt | 463 | ||||
| -rw-r--r-- | ext/standard/tests/file/ftruncate_variation7.phpt | 463 |
15 files changed, 6632 insertions, 0 deletions
diff --git a/ext/standard/tests/file/ftruncate_error.phpt b/ext/standard/tests/file/ftruncate_error.phpt new file mode 100644 index 0000000000..182ade5ffc --- /dev/null +++ b/ext/standard/tests/file/ftruncate_error.phpt @@ -0,0 +1,124 @@ +--TEST-- +Test ftruncate() function : error conditions +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: truncates a file to a given length +*/ + +echo "*** Testing ftruncate() : error conditions ***\n"; + +$filename = dirname(__FILE__)."/ftruncate_error.tmp"; +$file_handle = fopen($filename, "w" ); +fwrite($file_handle, "Testing ftruncate error conditions \n"); +fflush($file_handle); +echo "\n Initial file size = ".filesize($filename)."\n"; + +echo "-- Testing ftruncate() with less than expected number of arguments --\n"; + +// zero arguments +var_dump( ftruncate() ); + +// arguments less than expected numbers +var_dump( ftruncate( $file_handle ) ); +// check the first size +var_dump( filesize($filename) ); + +echo "-- Testing ftruncate() with more than expected number of arguments --\n"; +// more than expected number of arguments +var_dump( ftruncate($file_handle, 10, 20) ); +// check the first size +var_dump( filesize($filename) ); + +// test invalid arguments : non-resources +echo "-- Testing ftruncate() with invalid file pointer --\n"; +$invalid_args = array ( + "string", + 10, + 10.5, + true, + array(1,2,3), + new stdclass, +); +/* loop to test ftruncate() with different invalid type of args */ +for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) { + echo "-- Iteration $loop_counter --\n"; + var_dump( ftruncate($invalid_args[$loop_counter - 1], 10) ); +} + +// ftruncate() on a file handle which is already closed/unset +echo "-- Testing ftruncate() with closed/unset file handle --\n"; + +// ftruncate on close file handle +fclose($file_handle); +var_dump( ftruncate($file_handle,10) ); +// check the first size +var_dump( filesize($filename) ); + +// ftruncate on a file handle which is unset +$fp = fopen($filename, "w"); +unset($fp); //unset file handle +var_dump( ftruncate(@$fp,10)); +// check the first size +var_dump( filesize($filename) ); + +echo "Done\n"; +?> +--CLEAN-- +<?php +$filename = dirname(__FILE__)."/ftruncate_error.tmp"; +unlink( $filename ); +?> +--EXPECTF-- +*** Testing ftruncate() : error conditions *** + + Initial file size = 36 +-- Testing ftruncate() with less than expected number of arguments -- + +Warning: Wrong parameter count for ftruncate() in %s on line %d +NULL + +Warning: Wrong parameter count for ftruncate() in %s on line %d +NULL +int(36) +-- Testing ftruncate() with more than expected number of arguments -- + +Warning: Wrong parameter count for ftruncate() in %s on line %d +NULL +int(36) +-- Testing ftruncate() with invalid file pointer -- +-- Iteration 1 -- + +Warning: ftruncate(): supplied argument is not a valid stream resource in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: ftruncate(): supplied argument is not a valid stream resource in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: ftruncate(): supplied argument is not a valid stream resource in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: ftruncate(): supplied argument is not a valid stream resource in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: ftruncate(): supplied argument is not a valid stream resource in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: ftruncate(): supplied argument is not a valid stream resource in %s on line %d +bool(false) +-- Testing ftruncate() with closed/unset file handle -- + +Warning: ftruncate(): 5 is not a valid stream resource in %s on line %d +bool(false) +int(36) + +Warning: ftruncate(): supplied argument is not a valid stream resource in %s on line %d +bool(false) +int(36) +Done diff --git a/ext/standard/tests/file/ftruncate_variation1-win32.phpt b/ext/standard/tests/file/ftruncate_variation1-win32.phpt new file mode 100644 index 0000000000..22a766742f --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation1-win32.phpt @@ -0,0 +1,461 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate filesize to zero +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation1.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation"); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + /* truncate it to size 0 */ + echo "-- Testing ftruncate(): truncate file to size = 0 --\n"; + $new_size = 0; + var_dump( filesize($filename) ); // check the current file size + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // check the file size, should be 0 + + //delete all files created + delete_file($filename); + } //end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/ftruncate_variation1.phpt b/ext/standard/tests/file/ftruncate_variation1.phpt new file mode 100644 index 0000000000..cf51e2092c --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation1.phpt @@ -0,0 +1,461 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate filesize to zero +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation1.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation"); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + /* truncate it to size 0 */ + echo "-- Testing ftruncate(): truncate file to size = 0 --\n"; + $new_size = 0; + var_dump( filesize($filename) ); // check the current file size + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // check the file size, should be 0 + + //delete all files created + delete_file($filename); + } //end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = 0 -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(0) +Done diff --git a/ext/standard/tests/file/ftruncate_variation2-win32.phpt b/ext/standard/tests/file/ftruncate_variation2-win32.phpt new file mode 100644 index 0000000000..b2051d5bfd --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation2-win32.phpt @@ -0,0 +1,462 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to current size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation2.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 2); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): truncate file to size = current size --\n"; + /* truncate the file to its current filesize, size should not change*/ + + $new_size = filesize($filename); + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size, should be same as before truncating + + //delete all files created + delete_file($filename); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/ftruncate_variation2.phpt b/ext/standard/tests/file/ftruncate_variation2.phpt new file mode 100644 index 0000000000..e01a167a38 --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation2.phpt @@ -0,0 +1,462 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to current size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation2.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 2); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): truncate file to size = current size --\n"; + /* truncate the file to its current filesize, size should not change*/ + + $new_size = filesize($filename); + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size, should be same as before truncating + + //delete all files created + delete_file($filename); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to size = current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1024) +Done diff --git a/ext/standard/tests/file/ftruncate_variation3-win32.phpt b/ext/standard/tests/file/ftruncate_variation3-win32.phpt new file mode 100644 index 0000000000..c3304e20e4 --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation3-win32.phpt @@ -0,0 +1,461 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to half size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation3.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 3); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): truncate file to half of its current size --\n"; + /* truncate it to half of its current size */ + $new_size = filesize($filename)/2; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size = $new_size + + // delete file + delete_file($filename); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(568) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(568) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(568) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(568) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/ftruncate_variation3.phpt b/ext/standard/tests/file/ftruncate_variation3.phpt new file mode 100644 index 0000000000..cdbeb8e57f --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation3.phpt @@ -0,0 +1,461 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to half size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation3.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 3); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): truncate file to half of its current size --\n"; + /* truncate it to half of its current size */ + $new_size = filesize($filename)/2; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size = $new_size + + // delete file + delete_file($filename); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate file to half of its current size -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(512) +Done diff --git a/ext/standard/tests/file/ftruncate_variation4-win32.phpt b/ext/standard/tests/file/ftruncate_variation4-win32.phpt new file mode 100644 index 0000000000..d61a29c275 --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation4-win32.phpt @@ -0,0 +1,462 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to negative size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation4.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 4); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): try truncating file to a negative size --\n"; + /* try to truncate it to a negative size, size should not change*/ + + $new_size = -1000; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size = actual size, no change + + //delete all files created + delete_file( $filename ); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1137) +int(0) +bool(false) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1137) +int(0) +bool(false) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1137) +int(0) +bool(false) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1137) +int(0) +bool(false) +int(0) +bool(false) +int(1137) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/ftruncate_variation4.phpt b/ext/standard/tests/file/ftruncate_variation4.phpt new file mode 100644 index 0000000000..4a5a36236c --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation4.phpt @@ -0,0 +1,462 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to negative size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation4.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 4); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): try truncating file to a negative size --\n"; + /* try to truncate it to a negative size, size should not change*/ + + $new_size = -1000; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size = actual size, no change + + //delete all files created + delete_file( $filename ); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to a negative size -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +Done diff --git a/ext/standard/tests/file/ftruncate_variation5-win32.phpt b/ext/standard/tests/file/ftruncate_variation5-win32.phpt new file mode 100644 index 0000000000..3156027b5b --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation5-win32.phpt @@ -0,0 +1,463 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to bigger size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation5.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 5); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): try truncating file to size, bigger than existing --\n"; + /* try to truncate it to size bigger then current */ + + $new_size = filesize($filename) + 100; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size = actual size, no change + + //delete all files created + delete_file($filename); + }//end of inner for loop + +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1237) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1237) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1237) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1137) +int(0) +bool(true) +int(0) +bool(false) +int(1237) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/ftruncate_variation5.phpt b/ext/standard/tests/file/ftruncate_variation5.phpt new file mode 100644 index 0000000000..5d282d13de --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation5.phpt @@ -0,0 +1,463 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to bigger size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation5.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 5); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): try truncating file to size, bigger than existing --\n"; + /* try to truncate it to size bigger then current */ + + $new_size = filesize($filename) + 100; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); // new file size = actual size, no change + + //delete all files created + delete_file($filename); + }//end of inner for loop + +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(false) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): try truncating file to size, bigger than existing -- +int(1024) +int(0) +bool(true) +int(0) +bool(false) +int(1124) +Done diff --git a/ext/standard/tests/file/ftruncate_variation6-win32.phpt b/ext/standard/tests/file/ftruncate_variation6-win32.phpt new file mode 100644 index 0000000000..7009e61f62 --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation6-win32.phpt @@ -0,0 +1,482 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to smaller size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +/* truncate the file to smaller size and display the content */ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation6.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 6); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): truncate to smaller size and display the file content --\n"; + /* try to truncate it and display the file content */ + + $new_size = 15; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + if(ftruncate($file_handle, $new_size) ){// truncate it + echo "File content after truncating file to $new_size size : "; + var_dump( file_get_contents($filename) ); + } + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); + + //delete all files created + delete_file( $filename ); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1137) +int(0) +File content after truncating file to 15 size : string(15) "line +line of t" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1137) +int(0) +File content after truncating file to 15 size : string(15) "line +line of t" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1137) +int(0) +File content after truncating file to 15 size : string(15) "line +line of t" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1137) +int(0) +File content after truncating file to 15 size : string(15) "line +line of t" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/ftruncate_variation6.phpt b/ext/standard/tests/file/ftruncate_variation6.phpt new file mode 100644 index 0000000000..e9d5eb3c94 --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation6.phpt @@ -0,0 +1,482 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate file to smaller size +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +/* truncate the file to smaller size and display the content */ + +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation6.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 6); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): truncate to smaller size and display the file content --\n"; + /* try to truncate it and display the file content */ + + $new_size = 15; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + if(ftruncate($file_handle, $new_size) ){// truncate it + echo "File content after truncating file to $new_size size : "; + var_dump( file_get_contents($filename) ); + } + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); + + //delete all files created + delete_file( $filename ); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "222222222222222" +int(0) +bool(false) +int(15) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +int(0) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): truncate to smaller size and display the file content -- +int(1024) +int(0) +File content after truncating file to 15 size : string(15) "line +line of te" +int(0) +bool(false) +int(15) +Done diff --git a/ext/standard/tests/file/ftruncate_variation7-win32.phpt b/ext/standard/tests/file/ftruncate_variation7-win32.phpt new file mode 100644 index 0000000000..e6424a729e --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation7-win32.phpt @@ -0,0 +1,463 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate when file pointer at EOF +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip.. only valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +/* truncate the file when file pointer is positioned at end of the file */ +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation7.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 7); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): File pointer at the end --\n"; + /* try to truncate it to while file pointer at the end */ + fseek($file_handle, 0, SEEK_END); + $new_size = 200; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); + + //delete all files created + delete_file($filename); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1137) +int(1137) +bool(true) +int(1137) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1137) +int(1137) +bool(true) +int(1137) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1137) +int(1137) +bool(true) +int(1137) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1137) +int(1137) +bool(true) +int(1137) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +Done
\ No newline at end of file diff --git a/ext/standard/tests/file/ftruncate_variation7.phpt b/ext/standard/tests/file/ftruncate_variation7.phpt new file mode 100644 index 0000000000..5b38adf8bf --- /dev/null +++ b/ext/standard/tests/file/ftruncate_variation7.phpt @@ -0,0 +1,463 @@ +--TEST-- +Test ftruncate() function : usage variations - truncate when file pointer at EOF +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip.. Not valid for Windows'); +} +?> +--FILE-- +<?php +/* + Prototype: bool ftruncate ( resource $handle, int $size ); + Description: Truncates a file to a given length +*/ + +/* truncate the file when file pointer is positioned at end of the file */ +// include common file related test functions +include ("file.inc"); + +echo "*** Testing ftruncate() : usage variations ***\n"; + +/* test ftruncate with file opened in different modes */ +$file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t", + "w", "wb", "wt", "w+", "w+b", "w+t", + "x", "xb", "xt", "x+", "x+b", "x+t", + "a", "ab", "at", "a+", "a+b", "a+t"); + +$file_content_types = array("numeric","text_with_new_line"); + +foreach($file_content_types as $file_content_type) { + echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n"; + + for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) { + echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n"; + + // create 1 file with some contents + $filename = dirname(__FILE__)."/ftruncate_variation7.tmp"; + if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) { + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + fill_file($file_handle, $file_content_type, 1024); + } else { + create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 7); + // fopen the file using the $file_modes + $file_handle = fopen($filename, $file_modes[$mode_counter]); + } + if (!$file_handle) { + echo "Error: failed to open file $filename!\n"; + exit(); + } + + rewind($file_handle); // file pointer to 0 + + echo "-- Testing ftruncate(): File pointer at the end --\n"; + /* try to truncate it to while file pointer at the end */ + fseek($file_handle, 0, SEEK_END); + $new_size = 200; + var_dump( filesize($filename) ); // current filesize + var_dump( ftell($file_handle) ); + var_dump( ftruncate($file_handle, $new_size) ); // truncate it + var_dump( ftell($file_handle) ); + var_dump( feof($file_handle) ); + fclose($file_handle); + clearstatcache(); // clear previous size value in cache + var_dump( filesize($filename) ); + + //delete all files created + delete_file($filename); + }//end of inner for loop +}//end of outer foreach loop +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ftruncate() : usage variations *** + +-- Testing ftruncate() with file having data of type numeric -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) + +-- Testing ftruncate() with file having data of type text_with_new_line -- +-- Testing ftruncate() with file opening using r mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using rt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(false) +int(1024) +bool(false) +int(1024) +-- Testing ftruncate() with file opening using r+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using r+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using wt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using w+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xb mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using xt mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using x+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using ab mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using at mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+ mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+b mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +-- Testing ftruncate() with file opening using a+t mode -- +-- Testing ftruncate(): File pointer at the end -- +int(1024) +int(1024) +bool(true) +int(1024) +bool(false) +int(200) +Done |
