Return to fgetc_variation1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fgetc() function : usage variations - read when file pointer at EOF 3: --FILE-- 4: <?php 5: /* 6: Prototype: string fgetc ( resource $handle ); 7: Description: Gets character from file pointer 8: */ 9: // include the header for common test function 10: include ("file.inc"); 11: 12: echo "*** Testing fgetc() : usage variations ***\n"; 13: echo "-- Testing fgetc() with file whose file pointer is pointing to EOF --\n"; 14: // create a file 15: create_files(dirname(__FILE__), 1, "text_with_new_line", 0755, 1, "w", "fgetc_variation"); 16: 17: $filename = dirname(__FILE__)."/fgetc_variation1.tmp"; 18: 19: // loop to check the file opened in different read modes 20: $file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t"); 21: $loop_counter =0; 22: for(; $loop_counter < count($file_modes); $loop_counter++) { 23: // print the hearder 24: echo "-- File opened in mode : $file_modes[$loop_counter] --\n"; 25: // open the file 26: $file_handle = fopen ($filename, $file_modes[$loop_counter]); 27: if (!$file_handle) { 28: echo "Error: failed to open file $filename! \n"; 29: exit(); 30: } 31: 32: // seek to end of the file and try fgetc() 33: var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof 34: var_dump( feof($file_handle) ); // expected false 35: var_dump( ftell($file_handle) ); // ensure that file pointer is at eof 36: var_dump( fgetc($file_handle) ); // try n read a char, none expected 37: var_dump( feof($file_handle) ); // ensure thta file pointer is at eof 38: var_dump( ftell($file_handle) ); // file pointer position 39: 40: // close the file handle 41: fclose($file_handle); 42: } 43: echo "Done\n"; 44: ?> 45: --CLEAN-- 46: <?php 47: unlink( dirname(__FILE__)."/fgetc_variation1.tmp"); 48: ?> 49: --EXPECTF-- 50: *** Testing fgetc() : usage variations *** 51: -- Testing fgetc() with file whose file pointer is pointing to EOF -- 52: -- File opened in mode : r -- 53: int(0) 54: bool(false) 55: int(1024) 56: bool(false) 57: bool(true) 58: int(1024) 59: -- File opened in mode : rb -- 60: int(0) 61: bool(false) 62: int(1024) 63: bool(false) 64: bool(true) 65: int(1024) 66: -- File opened in mode : rt -- 67: int(0) 68: bool(false) 69: int(1024) 70: bool(false) 71: bool(true) 72: int(1024) 73: -- File opened in mode : r+ -- 74: int(0) 75: bool(false) 76: int(1024) 77: bool(false) 78: bool(true) 79: int(1024) 80: -- File opened in mode : r+b -- 81: int(0) 82: bool(false) 83: int(1024) 84: bool(false) 85: bool(true) 86: int(1024) 87: -- File opened in mode : r+t -- 88: int(0) 89: bool(false) 90: int(1024) 91: bool(false) 92: bool(true) 93: int(1024) 94: Done