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