Annotation of embedaddon/php/ext/standard/tests/file/fgets_variation3.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test fgets() function : usage variations - read with/without length
! 3: --FILE--
! 4: <?php
! 5: /*
! 6: Prototype: string fgets ( resource $handle [, int $length] );
! 7: Description: Gets a line from file pointer
! 8: */
! 9:
! 10: // include the file.inc for common test funcitons
! 11: include ("file.inc");
! 12:
! 13: $file_modes = array("w+", "w+b", "w+t",
! 14: "a+", "a+b", "a+t",
! 15: "x+", "x+b", "x+t");
! 16:
! 17: $file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
! 18:
! 19: echo "*** Testing fgets() : usage variations ***\n";
! 20:
! 21: $filename = dirname(__FILE__)."/fgets_variation3.tmp";
! 22:
! 23: foreach($file_modes as $file_mode) {
! 24: echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
! 25:
! 26: foreach($file_content_types as $file_content_type) {
! 27: echo "-- File content type : $file_content_type --\n";
! 28:
! 29: /* create files with $file_content_type */
! 30: $file_handle = fopen($filename, $file_mode);
! 31: $data = fill_file($file_handle, $file_content_type, 50);
! 32:
! 33: if ( !$file_handle ) {
! 34: echo "Error: failed to open file $filename!";
! 35: exit();
! 36: }
! 37:
! 38: echo "-- fgets() with default length, file pointer at 0 --\n";
! 39: // get the file pointer to begining of the file
! 40: rewind($file_handle);
! 41:
! 42: var_dump( ftell($file_handle) );
! 43: var_dump( fgets($file_handle) ); // with default length
! 44: var_dump( ftell($file_handle) ); // ensure the file pointer position
! 45: var_dump( feof($file_handle) ); // enusre if eof set
! 46:
! 47: echo "-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --\n";
! 48: // get the file pointer to begining of the file
! 49: rewind($file_handle);
! 50:
! 51: var_dump( ftell($file_handle) );
! 52: var_dump( fgets($file_handle, 23) ); // expected: 22 chars
! 53: var_dump( ftell($file_handle) ); // ensure the file pointer position
! 54: var_dump( feof($file_handle) ); // enusre if eof set
! 55:
! 56: //close file
! 57: fclose($file_handle);
! 58:
! 59: // delete file
! 60: delete_file($filename);
! 61: } // file_content_type loop
! 62: } // file_mode loop
! 63:
! 64: echo "Done\n";
! 65: ?>
! 66: --EXPECTF--
! 67: *** Testing fgets() : usage variations ***
! 68:
! 69: -- Testing fgets() with file opened using mode w+ --
! 70: -- File content type : numeric --
! 71: -- fgets() with default length, file pointer at 0 --
! 72: int(0)
! 73: string(50) "22222222222222222222222222222222222222222222222222"
! 74: int(50)
! 75: bool(true)
! 76: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 77: int(0)
! 78: string(22) "2222222222222222222222"
! 79: int(22)
! 80: bool(false)
! 81: -- File content type : text --
! 82: -- fgets() with default length, file pointer at 0 --
! 83: int(0)
! 84: string(50) "text text text text text text text text text text "
! 85: int(50)
! 86: bool(true)
! 87: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 88: int(0)
! 89: string(22) "text text text text te"
! 90: int(22)
! 91: bool(false)
! 92: -- File content type : text_with_new_line --
! 93: -- fgets() with default length, file pointer at 0 --
! 94: int(0)
! 95: string(5) "line
! 96: "
! 97: int(5)
! 98: bool(false)
! 99: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 100: int(0)
! 101: string(5) "line
! 102: "
! 103: int(5)
! 104: bool(false)
! 105: -- File content type : alphanumeric --
! 106: -- fgets() with default length, file pointer at 0 --
! 107: int(0)
! 108: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 109: int(50)
! 110: bool(true)
! 111: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 112: int(0)
! 113: string(22) "ab12 ab12 ab12 ab12 ab"
! 114: int(22)
! 115: bool(false)
! 116:
! 117: -- Testing fgets() with file opened using mode w+b --
! 118: -- File content type : numeric --
! 119: -- fgets() with default length, file pointer at 0 --
! 120: int(0)
! 121: string(50) "22222222222222222222222222222222222222222222222222"
! 122: int(50)
! 123: bool(true)
! 124: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 125: int(0)
! 126: string(22) "2222222222222222222222"
! 127: int(22)
! 128: bool(false)
! 129: -- File content type : text --
! 130: -- fgets() with default length, file pointer at 0 --
! 131: int(0)
! 132: string(50) "text text text text text text text text text text "
! 133: int(50)
! 134: bool(true)
! 135: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 136: int(0)
! 137: string(22) "text text text text te"
! 138: int(22)
! 139: bool(false)
! 140: -- File content type : text_with_new_line --
! 141: -- fgets() with default length, file pointer at 0 --
! 142: int(0)
! 143: string(5) "line
! 144: "
! 145: int(5)
! 146: bool(false)
! 147: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 148: int(0)
! 149: string(5) "line
! 150: "
! 151: int(5)
! 152: bool(false)
! 153: -- File content type : alphanumeric --
! 154: -- fgets() with default length, file pointer at 0 --
! 155: int(0)
! 156: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 157: int(50)
! 158: bool(true)
! 159: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 160: int(0)
! 161: string(22) "ab12 ab12 ab12 ab12 ab"
! 162: int(22)
! 163: bool(false)
! 164:
! 165: -- Testing fgets() with file opened using mode w+t --
! 166: -- File content type : numeric --
! 167: -- fgets() with default length, file pointer at 0 --
! 168: int(0)
! 169: string(50) "22222222222222222222222222222222222222222222222222"
! 170: int(50)
! 171: bool(true)
! 172: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 173: int(0)
! 174: string(22) "2222222222222222222222"
! 175: int(22)
! 176: bool(false)
! 177: -- File content type : text --
! 178: -- fgets() with default length, file pointer at 0 --
! 179: int(0)
! 180: string(50) "text text text text text text text text text text "
! 181: int(50)
! 182: bool(true)
! 183: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 184: int(0)
! 185: string(22) "text text text text te"
! 186: int(22)
! 187: bool(false)
! 188: -- File content type : text_with_new_line --
! 189: -- fgets() with default length, file pointer at 0 --
! 190: int(0)
! 191: string(5) "line
! 192: "
! 193: int(5)
! 194: bool(false)
! 195: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 196: int(0)
! 197: string(5) "line
! 198: "
! 199: int(5)
! 200: bool(false)
! 201: -- File content type : alphanumeric --
! 202: -- fgets() with default length, file pointer at 0 --
! 203: int(0)
! 204: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 205: int(50)
! 206: bool(true)
! 207: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 208: int(0)
! 209: string(22) "ab12 ab12 ab12 ab12 ab"
! 210: int(22)
! 211: bool(false)
! 212:
! 213: -- Testing fgets() with file opened using mode a+ --
! 214: -- File content type : numeric --
! 215: -- fgets() with default length, file pointer at 0 --
! 216: int(0)
! 217: string(50) "22222222222222222222222222222222222222222222222222"
! 218: int(50)
! 219: bool(true)
! 220: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 221: int(0)
! 222: string(22) "2222222222222222222222"
! 223: int(22)
! 224: bool(false)
! 225: -- File content type : text --
! 226: -- fgets() with default length, file pointer at 0 --
! 227: int(0)
! 228: string(50) "text text text text text text text text text text "
! 229: int(50)
! 230: bool(true)
! 231: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 232: int(0)
! 233: string(22) "text text text text te"
! 234: int(22)
! 235: bool(false)
! 236: -- File content type : text_with_new_line --
! 237: -- fgets() with default length, file pointer at 0 --
! 238: int(0)
! 239: string(5) "line
! 240: "
! 241: int(5)
! 242: bool(false)
! 243: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 244: int(0)
! 245: string(5) "line
! 246: "
! 247: int(5)
! 248: bool(false)
! 249: -- File content type : alphanumeric --
! 250: -- fgets() with default length, file pointer at 0 --
! 251: int(0)
! 252: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 253: int(50)
! 254: bool(true)
! 255: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 256: int(0)
! 257: string(22) "ab12 ab12 ab12 ab12 ab"
! 258: int(22)
! 259: bool(false)
! 260:
! 261: -- Testing fgets() with file opened using mode a+b --
! 262: -- File content type : numeric --
! 263: -- fgets() with default length, file pointer at 0 --
! 264: int(0)
! 265: string(50) "22222222222222222222222222222222222222222222222222"
! 266: int(50)
! 267: bool(true)
! 268: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 269: int(0)
! 270: string(22) "2222222222222222222222"
! 271: int(22)
! 272: bool(false)
! 273: -- File content type : text --
! 274: -- fgets() with default length, file pointer at 0 --
! 275: int(0)
! 276: string(50) "text text text text text text text text text text "
! 277: int(50)
! 278: bool(true)
! 279: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 280: int(0)
! 281: string(22) "text text text text te"
! 282: int(22)
! 283: bool(false)
! 284: -- File content type : text_with_new_line --
! 285: -- fgets() with default length, file pointer at 0 --
! 286: int(0)
! 287: string(5) "line
! 288: "
! 289: int(5)
! 290: bool(false)
! 291: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 292: int(0)
! 293: string(5) "line
! 294: "
! 295: int(5)
! 296: bool(false)
! 297: -- File content type : alphanumeric --
! 298: -- fgets() with default length, file pointer at 0 --
! 299: int(0)
! 300: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 301: int(50)
! 302: bool(true)
! 303: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 304: int(0)
! 305: string(22) "ab12 ab12 ab12 ab12 ab"
! 306: int(22)
! 307: bool(false)
! 308:
! 309: -- Testing fgets() with file opened using mode a+t --
! 310: -- File content type : numeric --
! 311: -- fgets() with default length, file pointer at 0 --
! 312: int(0)
! 313: string(50) "22222222222222222222222222222222222222222222222222"
! 314: int(50)
! 315: bool(true)
! 316: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 317: int(0)
! 318: string(22) "2222222222222222222222"
! 319: int(22)
! 320: bool(false)
! 321: -- File content type : text --
! 322: -- fgets() with default length, file pointer at 0 --
! 323: int(0)
! 324: string(50) "text text text text text text text text text text "
! 325: int(50)
! 326: bool(true)
! 327: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 328: int(0)
! 329: string(22) "text text text text te"
! 330: int(22)
! 331: bool(false)
! 332: -- File content type : text_with_new_line --
! 333: -- fgets() with default length, file pointer at 0 --
! 334: int(0)
! 335: string(5) "line
! 336: "
! 337: int(5)
! 338: bool(false)
! 339: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 340: int(0)
! 341: string(5) "line
! 342: "
! 343: int(5)
! 344: bool(false)
! 345: -- File content type : alphanumeric --
! 346: -- fgets() with default length, file pointer at 0 --
! 347: int(0)
! 348: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 349: int(50)
! 350: bool(true)
! 351: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 352: int(0)
! 353: string(22) "ab12 ab12 ab12 ab12 ab"
! 354: int(22)
! 355: bool(false)
! 356:
! 357: -- Testing fgets() with file opened using mode x+ --
! 358: -- File content type : numeric --
! 359: -- fgets() with default length, file pointer at 0 --
! 360: int(0)
! 361: string(50) "22222222222222222222222222222222222222222222222222"
! 362: int(50)
! 363: bool(true)
! 364: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 365: int(0)
! 366: string(22) "2222222222222222222222"
! 367: int(22)
! 368: bool(false)
! 369: -- File content type : text --
! 370: -- fgets() with default length, file pointer at 0 --
! 371: int(0)
! 372: string(50) "text text text text text text text text text text "
! 373: int(50)
! 374: bool(true)
! 375: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 376: int(0)
! 377: string(22) "text text text text te"
! 378: int(22)
! 379: bool(false)
! 380: -- File content type : text_with_new_line --
! 381: -- fgets() with default length, file pointer at 0 --
! 382: int(0)
! 383: string(5) "line
! 384: "
! 385: int(5)
! 386: bool(false)
! 387: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 388: int(0)
! 389: string(5) "line
! 390: "
! 391: int(5)
! 392: bool(false)
! 393: -- File content type : alphanumeric --
! 394: -- fgets() with default length, file pointer at 0 --
! 395: int(0)
! 396: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 397: int(50)
! 398: bool(true)
! 399: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 400: int(0)
! 401: string(22) "ab12 ab12 ab12 ab12 ab"
! 402: int(22)
! 403: bool(false)
! 404:
! 405: -- Testing fgets() with file opened using mode x+b --
! 406: -- File content type : numeric --
! 407: -- fgets() with default length, file pointer at 0 --
! 408: int(0)
! 409: string(50) "22222222222222222222222222222222222222222222222222"
! 410: int(50)
! 411: bool(true)
! 412: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 413: int(0)
! 414: string(22) "2222222222222222222222"
! 415: int(22)
! 416: bool(false)
! 417: -- File content type : text --
! 418: -- fgets() with default length, file pointer at 0 --
! 419: int(0)
! 420: string(50) "text text text text text text text text text text "
! 421: int(50)
! 422: bool(true)
! 423: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 424: int(0)
! 425: string(22) "text text text text te"
! 426: int(22)
! 427: bool(false)
! 428: -- File content type : text_with_new_line --
! 429: -- fgets() with default length, file pointer at 0 --
! 430: int(0)
! 431: string(5) "line
! 432: "
! 433: int(5)
! 434: bool(false)
! 435: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 436: int(0)
! 437: string(5) "line
! 438: "
! 439: int(5)
! 440: bool(false)
! 441: -- File content type : alphanumeric --
! 442: -- fgets() with default length, file pointer at 0 --
! 443: int(0)
! 444: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 445: int(50)
! 446: bool(true)
! 447: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 448: int(0)
! 449: string(22) "ab12 ab12 ab12 ab12 ab"
! 450: int(22)
! 451: bool(false)
! 452:
! 453: -- Testing fgets() with file opened using mode x+t --
! 454: -- File content type : numeric --
! 455: -- fgets() with default length, file pointer at 0 --
! 456: int(0)
! 457: string(50) "22222222222222222222222222222222222222222222222222"
! 458: int(50)
! 459: bool(true)
! 460: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 461: int(0)
! 462: string(22) "2222222222222222222222"
! 463: int(22)
! 464: bool(false)
! 465: -- File content type : text --
! 466: -- fgets() with default length, file pointer at 0 --
! 467: int(0)
! 468: string(50) "text text text text text text text text text text "
! 469: int(50)
! 470: bool(true)
! 471: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 472: int(0)
! 473: string(22) "text text text text te"
! 474: int(22)
! 475: bool(false)
! 476: -- File content type : text_with_new_line --
! 477: -- fgets() with default length, file pointer at 0 --
! 478: int(0)
! 479: string(5) "line
! 480: "
! 481: int(5)
! 482: bool(false)
! 483: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 484: int(0)
! 485: string(5) "line
! 486: "
! 487: int(5)
! 488: bool(false)
! 489: -- File content type : alphanumeric --
! 490: -- fgets() with default length, file pointer at 0 --
! 491: int(0)
! 492: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "
! 493: int(50)
! 494: bool(true)
! 495: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --
! 496: int(0)
! 497: string(22) "ab12 ab12 ab12 ab12 ab"
! 498: int(22)
! 499: bool(false)
! 500: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>