import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / ftruncate_variation1-win32.php
blobdee3c36d6c80360aeca47fa242a79d63ff7360fc
1 <?php
2 /*
3 Prototype: bool ftruncate ( resource $handle, int $size );
4 Description: Truncates a file to a given length
5 */
7 // include common file related test functions
8 include ("file.inc");
10 echo "*** Testing ftruncate() : usage variations ***\n";
12 /* test ftruncate with file opened in different modes */
13 $file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t",
14 "w", "wb", "wt", "w+", "w+b", "w+t",
15 "x", "xb", "xt", "x+", "x+b", "x+t",
16 "a", "ab", "at", "a+", "a+b", "a+t");
18 $file_content_types = array("numeric","text_with_new_line");
20 foreach($file_content_types as $file_content_type) {
21 echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n";
23 for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
24 echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n";
26 // create 1 file with some contents
27 $filename = dirname(__FILE__)."/ftruncate_variation1.tmp";
28 if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) {
29 // fopen the file using the $file_modes
30 $file_handle = fopen($filename, $file_modes[$mode_counter]);
31 fill_file($file_handle, $file_content_type, 1024);
32 } else {
33 create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "ftruncate_variation");
34 // fopen the file using the $file_modes
35 $file_handle = fopen($filename, $file_modes[$mode_counter]);
37 if (!$file_handle) {
38 echo "Error: failed to open file $filename!\n";
39 exit();
42 rewind($file_handle); // file pointer to 0
44 /* truncate it to size 0 */
45 echo "-- Testing ftruncate(): truncate file to size = 0 --\n";
46 $new_size = 0;
47 var_dump( filesize($filename) ); // check the current file size
48 var_dump( ftell($file_handle) );
49 var_dump( ftruncate($file_handle, $new_size) ); // truncate it
50 var_dump( ftell($file_handle) );
51 var_dump( feof($file_handle) );
52 fclose($file_handle);
53 clearstatcache(); // clear previous size value in cache
54 var_dump( filesize($filename) ); // check the file size, should be 0
56 //delete all files created
57 delete_file($filename);
58 } //end of inner for loop
59 }//end of outer foreach loop
60 echo "Done\n";