Return to fgets_variation6-win32.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fgets() function : usage variations - read when file pointer at EOF 3: --SKIPIF-- 4: <?php 5: if (substr(PHP_OS, 0, 3) != 'WIN') { 6: die('skip only valid for Windows'); 7: } 8: ?> 9: --FILE-- 10: <?php 11: /* 12: Prototype: string fgets ( resource $handle [, int $length] ); 13: Description: Gets a line from file pointer 14: */ 15: 16: // include the file.inc for common test funcitons 17: include ("file.inc"); 18: 19: $file_modes = array("w+", "w+b", "w+t", 20: "a+", "a+b", "a+t", 21: "x+", "x+b", "x+t"); 22: 23: $file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric"); 24: 25: echo "*** Testing fgets() : usage variations ***\n"; 26: 27: $filename = dirname(__FILE__)."/fgets_variation4.tmp"; 28: 29: foreach($file_modes as $file_mode) { 30: echo "\n-- Testing fgets() with file opened using mode $file_mode --\n"; 31: 32: foreach($file_content_types as $file_content_type) { 33: echo "-- File content type : $file_content_type --\n"; 34: 35: /* create files with $file_content_type */ 36: $file_handle = fopen($filename, $file_mode); 37: $data = fill_file($file_handle, $file_content_type, 50); 38: 39: if ( !$file_handle ) { 40: echo "Error: failed to open file $filename!"; 41: exit(); 42: } 43: 44: echo "-- fgets() with file pointer pointing at EOF --\n"; 45: // seek to end of the file and try fgets() 46: var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof 47: var_dump( ftell($file_handle) ); // ensure that file pointer is at eof 48: var_dump( feof($file_handle) ); // expected false 49: 50: var_dump( fgets($file_handle) ); // try n read a line, none expected 51: var_dump( ftell($file_handle) ); // file pointer position 52: var_dump( feof($file_handle) ); // ensure thta file pointer is at eof 53: 54: //close file 55: fclose($file_handle); 56: 57: // delete file 58: delete_file($filename); 59: } // file_content_type loop 60: } // file_mode loop 61: 62: echo "Done\n"; 63: ?> 64: --EXPECTF-- 65: *** Testing fgets() : usage variations *** 66: 67: -- Testing fgets() with file opened using mode w+ -- 68: -- File content type : numeric -- 69: -- fgets() with file pointer pointing at EOF -- 70: int(0) 71: int(50) 72: bool(false) 73: bool(false) 74: int(50) 75: bool(true) 76: -- File content type : text -- 77: -- fgets() with file pointer pointing at EOF -- 78: int(0) 79: int(50) 80: bool(false) 81: bool(false) 82: int(50) 83: bool(true) 84: -- File content type : text_with_new_line -- 85: -- fgets() with file pointer pointing at EOF -- 86: int(0) 87: int(50) 88: bool(false) 89: bool(false) 90: int(50) 91: bool(true) 92: -- File content type : alphanumeric -- 93: -- fgets() with file pointer pointing at EOF -- 94: int(0) 95: int(50) 96: bool(false) 97: bool(false) 98: int(50) 99: bool(true) 100: 101: -- Testing fgets() with file opened using mode w+b -- 102: -- File content type : numeric -- 103: -- fgets() with file pointer pointing at EOF -- 104: int(0) 105: int(50) 106: bool(false) 107: bool(false) 108: int(50) 109: bool(true) 110: -- File content type : text -- 111: -- fgets() with file pointer pointing at EOF -- 112: int(0) 113: int(50) 114: bool(false) 115: bool(false) 116: int(50) 117: bool(true) 118: -- File content type : text_with_new_line -- 119: -- fgets() with file pointer pointing at EOF -- 120: int(0) 121: int(50) 122: bool(false) 123: bool(false) 124: int(50) 125: bool(true) 126: -- File content type : alphanumeric -- 127: -- fgets() with file pointer pointing at EOF -- 128: int(0) 129: int(50) 130: bool(false) 131: bool(false) 132: int(50) 133: bool(true) 134: 135: -- Testing fgets() with file opened using mode w+t -- 136: -- File content type : numeric -- 137: -- fgets() with file pointer pointing at EOF -- 138: int(0) 139: int(50) 140: bool(false) 141: bool(false) 142: int(50) 143: bool(true) 144: -- File content type : text -- 145: -- fgets() with file pointer pointing at EOF -- 146: int(0) 147: int(50) 148: bool(false) 149: bool(false) 150: int(50) 151: bool(true) 152: -- File content type : text_with_new_line -- 153: -- fgets() with file pointer pointing at EOF -- 154: int(0) 155: int(55) 156: bool(false) 157: bool(false) 158: int(55) 159: bool(true) 160: -- File content type : alphanumeric -- 161: -- fgets() with file pointer pointing at EOF -- 162: int(0) 163: int(50) 164: bool(false) 165: bool(false) 166: int(50) 167: bool(true) 168: 169: -- Testing fgets() with file opened using mode a+ -- 170: -- File content type : numeric -- 171: -- fgets() with file pointer pointing at EOF -- 172: int(0) 173: int(50) 174: bool(false) 175: bool(false) 176: int(50) 177: bool(true) 178: -- File content type : text -- 179: -- fgets() with file pointer pointing at EOF -- 180: int(0) 181: int(50) 182: bool(false) 183: bool(false) 184: int(50) 185: bool(true) 186: -- File content type : text_with_new_line -- 187: -- fgets() with file pointer pointing at EOF -- 188: int(0) 189: int(50) 190: bool(false) 191: bool(false) 192: int(50) 193: bool(true) 194: -- File content type : alphanumeric -- 195: -- fgets() with file pointer pointing at EOF -- 196: int(0) 197: int(50) 198: bool(false) 199: bool(false) 200: int(50) 201: bool(true) 202: 203: -- Testing fgets() with file opened using mode a+b -- 204: -- File content type : numeric -- 205: -- fgets() with file pointer pointing at EOF -- 206: int(0) 207: int(50) 208: bool(false) 209: bool(false) 210: int(50) 211: bool(true) 212: -- File content type : text -- 213: -- fgets() with file pointer pointing at EOF -- 214: int(0) 215: int(50) 216: bool(false) 217: bool(false) 218: int(50) 219: bool(true) 220: -- File content type : text_with_new_line -- 221: -- fgets() with file pointer pointing at EOF -- 222: int(0) 223: int(50) 224: bool(false) 225: bool(false) 226: int(50) 227: bool(true) 228: -- File content type : alphanumeric -- 229: -- fgets() with file pointer pointing at EOF -- 230: int(0) 231: int(50) 232: bool(false) 233: bool(false) 234: int(50) 235: bool(true) 236: 237: -- Testing fgets() with file opened using mode a+t -- 238: -- File content type : numeric -- 239: -- fgets() with file pointer pointing at EOF -- 240: int(0) 241: int(50) 242: bool(false) 243: bool(false) 244: int(50) 245: bool(true) 246: -- File content type : text -- 247: -- fgets() with file pointer pointing at EOF -- 248: int(0) 249: int(50) 250: bool(false) 251: bool(false) 252: int(50) 253: bool(true) 254: -- File content type : text_with_new_line -- 255: -- fgets() with file pointer pointing at EOF -- 256: int(0) 257: int(55) 258: bool(false) 259: bool(false) 260: int(55) 261: bool(true) 262: -- File content type : alphanumeric -- 263: -- fgets() with file pointer pointing at EOF -- 264: int(0) 265: int(50) 266: bool(false) 267: bool(false) 268: int(50) 269: bool(true) 270: 271: -- Testing fgets() with file opened using mode x+ -- 272: -- File content type : numeric -- 273: -- fgets() with file pointer pointing at EOF -- 274: int(0) 275: int(50) 276: bool(false) 277: bool(false) 278: int(50) 279: bool(true) 280: -- File content type : text -- 281: -- fgets() with file pointer pointing at EOF -- 282: int(0) 283: int(50) 284: bool(false) 285: bool(false) 286: int(50) 287: bool(true) 288: -- File content type : text_with_new_line -- 289: -- fgets() with file pointer pointing at EOF -- 290: int(0) 291: int(50) 292: bool(false) 293: bool(false) 294: int(50) 295: bool(true) 296: -- File content type : alphanumeric -- 297: -- fgets() with file pointer pointing at EOF -- 298: int(0) 299: int(50) 300: bool(false) 301: bool(false) 302: int(50) 303: bool(true) 304: 305: -- Testing fgets() with file opened using mode x+b -- 306: -- File content type : numeric -- 307: -- fgets() with file pointer pointing at EOF -- 308: int(0) 309: int(50) 310: bool(false) 311: bool(false) 312: int(50) 313: bool(true) 314: -- File content type : text -- 315: -- fgets() with file pointer pointing at EOF -- 316: int(0) 317: int(50) 318: bool(false) 319: bool(false) 320: int(50) 321: bool(true) 322: -- File content type : text_with_new_line -- 323: -- fgets() with file pointer pointing at EOF -- 324: int(0) 325: int(50) 326: bool(false) 327: bool(false) 328: int(50) 329: bool(true) 330: -- File content type : alphanumeric -- 331: -- fgets() with file pointer pointing at EOF -- 332: int(0) 333: int(50) 334: bool(false) 335: bool(false) 336: int(50) 337: bool(true) 338: 339: -- Testing fgets() with file opened using mode x+t -- 340: -- File content type : numeric -- 341: -- fgets() with file pointer pointing at EOF -- 342: int(0) 343: int(50) 344: bool(false) 345: bool(false) 346: int(50) 347: bool(true) 348: -- File content type : text -- 349: -- fgets() with file pointer pointing at EOF -- 350: int(0) 351: int(50) 352: bool(false) 353: bool(false) 354: int(50) 355: bool(true) 356: -- File content type : text_with_new_line -- 357: -- fgets() with file pointer pointing at EOF -- 358: int(0) 359: int(55) 360: bool(false) 361: bool(false) 362: int(55) 363: bool(true) 364: -- File content type : alphanumeric -- 365: -- fgets() with file pointer pointing at EOF -- 366: int(0) 367: int(50) 368: bool(false) 369: bool(false) 370: int(50) 371: bool(true) 372: Done