Annotation of embedaddon/php/ext/standard/tests/file/fgetc_variation3.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test fgetc() function : usage variations - write only modes (Bug #42036)
! 3: --FILE--
! 4: <?php
! 5: /*
! 6: Prototype: string fgetc ( resource $handle );
! 7: Description: Gets character from file pointer
! 8: */
! 9:
! 10: /* try fgetc on files which are opened in non readable modes
! 11: w, wb, wt,
! 12: a, ab, at,
! 13: x, xb, xt
! 14: */
! 15: // include the header for common test function
! 16: include ("file.inc");
! 17:
! 18: echo "*** Testing fgetc() with file opened in write only mode ***\n";
! 19:
! 20: $file_modes = array("w", "wb", "wt", "a", "ab", "at", "x", "xb", "xt");
! 21: $filename = dirname(__FILE__)."/fgetc_variation3.tmp";
! 22: foreach ($file_modes as $file_mode ) {
! 23: echo "-- File opened in mode : $file_mode --\n";
! 24:
! 25: $file_handle = fopen($filename, $file_mode);
! 26: if(!$file_handle) {
! 27: echo "Error: failed to open file $filename!\n";
! 28: exit();
! 29: }
! 30: $data = "fgetc_variation test";
! 31: fwrite($file_handle, $data);
! 32:
! 33: // rewind the file pointer to begining of the file
! 34: var_dump( rewind($file_handle) );
! 35: var_dump( ftell($file_handle) );
! 36: var_dump( feof($file_handle) );
! 37:
! 38: // read from file
! 39: var_dump( fgetc($file_handle) ); // expected : no chars should be read
! 40: var_dump( ftell($file_handle) ); // ensure that file pointer position is not changed
! 41: var_dump( feof($file_handle) ); // check if end of file pointer is set
! 42:
! 43: // close the file
! 44: fclose($file_handle);
! 45:
! 46: // delete the file
! 47: unlink($filename);
! 48: }
! 49:
! 50: echo "Done\n";
! 51: ?>
! 52: --EXPECTF--
! 53: *** Testing fgetc() with file opened in write only mode ***
! 54: -- File opened in mode : w --
! 55: bool(true)
! 56: int(0)
! 57: bool(false)
! 58: bool(false)
! 59: int(0)
! 60: bool(false)
! 61: -- File opened in mode : wb --
! 62: bool(true)
! 63: int(0)
! 64: bool(false)
! 65: bool(false)
! 66: int(0)
! 67: bool(false)
! 68: -- File opened in mode : wt --
! 69: bool(true)
! 70: int(0)
! 71: bool(false)
! 72: bool(false)
! 73: int(0)
! 74: bool(false)
! 75: -- File opened in mode : a --
! 76: bool(true)
! 77: int(0)
! 78: bool(false)
! 79: bool(false)
! 80: int(0)
! 81: bool(false)
! 82: -- File opened in mode : ab --
! 83: bool(true)
! 84: int(0)
! 85: bool(false)
! 86: bool(false)
! 87: int(0)
! 88: bool(false)
! 89: -- File opened in mode : at --
! 90: bool(true)
! 91: int(0)
! 92: bool(false)
! 93: bool(false)
! 94: int(0)
! 95: bool(false)
! 96: -- File opened in mode : x --
! 97: bool(true)
! 98: int(0)
! 99: bool(false)
! 100: bool(false)
! 101: int(0)
! 102: bool(false)
! 103: -- File opened in mode : xb --
! 104: bool(true)
! 105: int(0)
! 106: bool(false)
! 107: bool(false)
! 108: int(0)
! 109: bool(false)
! 110: -- File opened in mode : xt --
! 111: bool(true)
! 112: int(0)
! 113: bool(false)
! 114: bool(false)
! 115: int(0)
! 116: bool(false)
! 117: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>