Annotation of embedaddon/php/ext/standard/tests/file/fread_variation2.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test fread() function : usage variations - read some/all chars, write only mode (Bug #42036)
! 3: --FILE--
! 4: <?php
! 5: /*
! 6: Prototype: string fread ( resource $handle [, int $length] );
! 7: Description: reads up to length bytes from the file pointer referenced by handle.
! 8: Reading stops when up to length bytes have been read, EOF (end of file) is
! 9: reached, (for network streams) when a packet becomes available, or (after
! 10: opening userspace stream) when 8192 bytes have been read whichever comes first.
! 11: */
! 12:
! 13: /* Try reading some or all content of the file opened in write only mode */
! 14:
! 15: // include the file.inc for common functions for test
! 16: include ("file.inc");
! 17:
! 18: /* Function : function check_read(resource $file_handle, int $read_size, int $expect_size)
! 19: Description : Read data from file of size $read_size and verifies that $expected_size no. of
! 20: bytes are read.
! 21: $file_handle : File Handle
! 22: $read_size : No. of bytes to be read.
! 23: $expect_size : Expected data length
! 24: Returns: returns the data read
! 25: */
! 26: function check_read($file_handle, $read_size, $expect_size) {
! 27: // print file pointer position before read
! 28: var_dump( ftell($file_handle) );
! 29: var_dump( feof($file_handle) );
! 30:
! 31: // read the data of size $read_size
! 32: echo "Reading $read_size bytes from file, expecting $expect_size bytes ... ";
! 33: $data_from_file = fread($file_handle, $read_size);
! 34:
! 35: // check if data read is of expected size
! 36: if ( strlen($data_from_file) == $expect_size)
! 37: echo "OK\n";
! 38: else
! 39: echo "Error reading file, total number of bytes read = ".strlen($data_from_file)."\n";
! 40:
! 41: // file pointer position after read
! 42: var_dump( ftell($file_handle) );
! 43: // check if file pointer at eof()
! 44: var_dump( feof($file_handle) );
! 45: echo "\n";
! 46:
! 47: return $data_from_file;
! 48: }
! 49:
! 50: echo "*** Testing fread() : usage variations ***\n";
! 51:
! 52: $file_modes = array("a","ab","at",
! 53: "w","wb","wt",
! 54: "x","xb","xt" );
! 55:
! 56: $file_content_types = array("numeric","text","text_with_new_line", "alphanumeric");
! 57:
! 58: foreach($file_content_types as $file_content_type) {
! 59: echo "\n-- Testing fread() with file having content of type ". $file_content_type ." --\n";
! 60:
! 61: /* open the file using $files_modes and perform fread() on it */
! 62: foreach($file_modes as $file_mode) {
! 63: if(!strstr($file_mode,"x")){
! 64: /* create files with $file_content_type */
! 65: create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 1, "w", "fread_variation", 2);
! 66: }
! 67:
! 68: $filename = dirname(__FILE__)."/fread_variation2.tmp"; // this is name of the file created by create_files()
! 69: echo "-- File opened in mode ".$file_mode." --\n";
! 70: $file_handle = fopen($filename, $file_mode);
! 71: if (!$file_handle) {
! 72: echo "Error: failed to fopen() file: $filename!";
! 73: exit();
! 74: }
! 75:
! 76: if(strstr($file_mode,"w") || strstr($file_mode,"x") ) {
! 77: fill_file($file_handle, $file_content_type, 1024);
! 78: }
! 79:
! 80: rewind($file_handle);
! 81: echo "-- Reading entire file content, expeceted : 0 bytes --\n";
! 82: // read from file, by giving the file actual size,
! 83: $data_from_file = check_read($file_handle, 1024, (strstr($file_mode, "+") ? 1024 : 0 ) );
! 84: // calculate the hash and dump it, if data read, expecting here no data was read
! 85: if ( $data_from_file != false)
! 86: var_dump( md5($data_from_file) );
! 87:
! 88: // reading file by giving less than its size
! 89: echo "-- Reading file content less than max. file size, expeceted : 0 bytes --\n";
! 90: rewind($file_handle);
! 91: $data_from_file = check_read($file_handle, 1000, (strstr($file_mode, "+") ? 1000 : 0 ) );
! 92: // calculate the hash and dump it, if data read, expecting here no data was read
! 93: if ( $data_from_file != false)
! 94: var_dump( md5($data_from_file) );
! 95:
! 96: // now close the file
! 97: fclose($file_handle);
! 98:
! 99: // delete the file created
! 100: delete_file($filename); // delete file
! 101: } // end of inner foreach loop
! 102: }// end of outer foreach loop
! 103:
! 104: echo "Done\n";
! 105: ?>
! 106: --EXPECTF--
! 107: *** Testing fread() : usage variations ***
! 108:
! 109: -- Testing fread() with file having content of type numeric --
! 110: -- File opened in mode a --
! 111: -- Reading entire file content, expeceted : 0 bytes --
! 112: int(0)
! 113: bool(false)
! 114: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 115: int(0)
! 116: bool(false)
! 117:
! 118: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 119: int(0)
! 120: bool(false)
! 121: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 122: int(0)
! 123: bool(false)
! 124:
! 125: -- File opened in mode ab --
! 126: -- Reading entire file content, expeceted : 0 bytes --
! 127: int(0)
! 128: bool(false)
! 129: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 130: int(0)
! 131: bool(false)
! 132:
! 133: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 134: int(0)
! 135: bool(false)
! 136: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 137: int(0)
! 138: bool(false)
! 139:
! 140: -- File opened in mode at --
! 141: -- Reading entire file content, expeceted : 0 bytes --
! 142: int(0)
! 143: bool(false)
! 144: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 145: int(0)
! 146: bool(false)
! 147:
! 148: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 149: int(0)
! 150: bool(false)
! 151: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 152: int(0)
! 153: bool(false)
! 154:
! 155: -- File opened in mode w --
! 156: -- Reading entire file content, expeceted : 0 bytes --
! 157: int(0)
! 158: bool(false)
! 159: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 160: int(0)
! 161: bool(false)
! 162:
! 163: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 164: int(0)
! 165: bool(false)
! 166: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 167: int(0)
! 168: bool(false)
! 169:
! 170: -- File opened in mode wb --
! 171: -- Reading entire file content, expeceted : 0 bytes --
! 172: int(0)
! 173: bool(false)
! 174: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 175: int(0)
! 176: bool(false)
! 177:
! 178: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 179: int(0)
! 180: bool(false)
! 181: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 182: int(0)
! 183: bool(false)
! 184:
! 185: -- File opened in mode wt --
! 186: -- Reading entire file content, expeceted : 0 bytes --
! 187: int(0)
! 188: bool(false)
! 189: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 190: int(0)
! 191: bool(false)
! 192:
! 193: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 194: int(0)
! 195: bool(false)
! 196: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 197: int(0)
! 198: bool(false)
! 199:
! 200: -- File opened in mode x --
! 201: -- Reading entire file content, expeceted : 0 bytes --
! 202: int(0)
! 203: bool(false)
! 204: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 205: int(0)
! 206: bool(false)
! 207:
! 208: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 209: int(0)
! 210: bool(false)
! 211: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 212: int(0)
! 213: bool(false)
! 214:
! 215: -- File opened in mode xb --
! 216: -- Reading entire file content, expeceted : 0 bytes --
! 217: int(0)
! 218: bool(false)
! 219: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 220: int(0)
! 221: bool(false)
! 222:
! 223: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 224: int(0)
! 225: bool(false)
! 226: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 227: int(0)
! 228: bool(false)
! 229:
! 230: -- File opened in mode xt --
! 231: -- Reading entire file content, expeceted : 0 bytes --
! 232: int(0)
! 233: bool(false)
! 234: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 235: int(0)
! 236: bool(false)
! 237:
! 238: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 239: int(0)
! 240: bool(false)
! 241: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 242: int(0)
! 243: bool(false)
! 244:
! 245:
! 246: -- Testing fread() with file having content of type text --
! 247: -- File opened in mode a --
! 248: -- Reading entire file content, expeceted : 0 bytes --
! 249: int(0)
! 250: bool(false)
! 251: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 252: int(0)
! 253: bool(false)
! 254:
! 255: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 256: int(0)
! 257: bool(false)
! 258: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 259: int(0)
! 260: bool(false)
! 261:
! 262: -- File opened in mode ab --
! 263: -- Reading entire file content, expeceted : 0 bytes --
! 264: int(0)
! 265: bool(false)
! 266: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 267: int(0)
! 268: bool(false)
! 269:
! 270: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 271: int(0)
! 272: bool(false)
! 273: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 274: int(0)
! 275: bool(false)
! 276:
! 277: -- File opened in mode at --
! 278: -- Reading entire file content, expeceted : 0 bytes --
! 279: int(0)
! 280: bool(false)
! 281: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 282: int(0)
! 283: bool(false)
! 284:
! 285: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 286: int(0)
! 287: bool(false)
! 288: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 289: int(0)
! 290: bool(false)
! 291:
! 292: -- File opened in mode w --
! 293: -- Reading entire file content, expeceted : 0 bytes --
! 294: int(0)
! 295: bool(false)
! 296: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 297: int(0)
! 298: bool(false)
! 299:
! 300: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 301: int(0)
! 302: bool(false)
! 303: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 304: int(0)
! 305: bool(false)
! 306:
! 307: -- File opened in mode wb --
! 308: -- Reading entire file content, expeceted : 0 bytes --
! 309: int(0)
! 310: bool(false)
! 311: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 312: int(0)
! 313: bool(false)
! 314:
! 315: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 316: int(0)
! 317: bool(false)
! 318: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 319: int(0)
! 320: bool(false)
! 321:
! 322: -- File opened in mode wt --
! 323: -- Reading entire file content, expeceted : 0 bytes --
! 324: int(0)
! 325: bool(false)
! 326: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 327: int(0)
! 328: bool(false)
! 329:
! 330: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 331: int(0)
! 332: bool(false)
! 333: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 334: int(0)
! 335: bool(false)
! 336:
! 337: -- File opened in mode x --
! 338: -- Reading entire file content, expeceted : 0 bytes --
! 339: int(0)
! 340: bool(false)
! 341: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 342: int(0)
! 343: bool(false)
! 344:
! 345: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 346: int(0)
! 347: bool(false)
! 348: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 349: int(0)
! 350: bool(false)
! 351:
! 352: -- File opened in mode xb --
! 353: -- Reading entire file content, expeceted : 0 bytes --
! 354: int(0)
! 355: bool(false)
! 356: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 357: int(0)
! 358: bool(false)
! 359:
! 360: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 361: int(0)
! 362: bool(false)
! 363: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 364: int(0)
! 365: bool(false)
! 366:
! 367: -- File opened in mode xt --
! 368: -- Reading entire file content, expeceted : 0 bytes --
! 369: int(0)
! 370: bool(false)
! 371: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 372: int(0)
! 373: bool(false)
! 374:
! 375: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 376: int(0)
! 377: bool(false)
! 378: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 379: int(0)
! 380: bool(false)
! 381:
! 382:
! 383: -- Testing fread() with file having content of type text_with_new_line --
! 384: -- File opened in mode a --
! 385: -- Reading entire file content, expeceted : 0 bytes --
! 386: int(0)
! 387: bool(false)
! 388: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 389: int(0)
! 390: bool(false)
! 391:
! 392: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 393: int(0)
! 394: bool(false)
! 395: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 396: int(0)
! 397: bool(false)
! 398:
! 399: -- File opened in mode ab --
! 400: -- Reading entire file content, expeceted : 0 bytes --
! 401: int(0)
! 402: bool(false)
! 403: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 404: int(0)
! 405: bool(false)
! 406:
! 407: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 408: int(0)
! 409: bool(false)
! 410: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 411: int(0)
! 412: bool(false)
! 413:
! 414: -- File opened in mode at --
! 415: -- Reading entire file content, expeceted : 0 bytes --
! 416: int(0)
! 417: bool(false)
! 418: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 419: int(0)
! 420: bool(false)
! 421:
! 422: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 423: int(0)
! 424: bool(false)
! 425: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 426: int(0)
! 427: bool(false)
! 428:
! 429: -- File opened in mode w --
! 430: -- Reading entire file content, expeceted : 0 bytes --
! 431: int(0)
! 432: bool(false)
! 433: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 434: int(0)
! 435: bool(false)
! 436:
! 437: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 438: int(0)
! 439: bool(false)
! 440: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 441: int(0)
! 442: bool(false)
! 443:
! 444: -- File opened in mode wb --
! 445: -- Reading entire file content, expeceted : 0 bytes --
! 446: int(0)
! 447: bool(false)
! 448: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 449: int(0)
! 450: bool(false)
! 451:
! 452: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 453: int(0)
! 454: bool(false)
! 455: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 456: int(0)
! 457: bool(false)
! 458:
! 459: -- File opened in mode wt --
! 460: -- Reading entire file content, expeceted : 0 bytes --
! 461: int(0)
! 462: bool(false)
! 463: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 464: int(0)
! 465: bool(false)
! 466:
! 467: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 468: int(0)
! 469: bool(false)
! 470: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 471: int(0)
! 472: bool(false)
! 473:
! 474: -- File opened in mode x --
! 475: -- Reading entire file content, expeceted : 0 bytes --
! 476: int(0)
! 477: bool(false)
! 478: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 479: int(0)
! 480: bool(false)
! 481:
! 482: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 483: int(0)
! 484: bool(false)
! 485: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 486: int(0)
! 487: bool(false)
! 488:
! 489: -- File opened in mode xb --
! 490: -- Reading entire file content, expeceted : 0 bytes --
! 491: int(0)
! 492: bool(false)
! 493: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 494: int(0)
! 495: bool(false)
! 496:
! 497: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 498: int(0)
! 499: bool(false)
! 500: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 501: int(0)
! 502: bool(false)
! 503:
! 504: -- File opened in mode xt --
! 505: -- Reading entire file content, expeceted : 0 bytes --
! 506: int(0)
! 507: bool(false)
! 508: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 509: int(0)
! 510: bool(false)
! 511:
! 512: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 513: int(0)
! 514: bool(false)
! 515: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 516: int(0)
! 517: bool(false)
! 518:
! 519:
! 520: -- Testing fread() with file having content of type alphanumeric --
! 521: -- File opened in mode a --
! 522: -- Reading entire file content, expeceted : 0 bytes --
! 523: int(0)
! 524: bool(false)
! 525: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 526: int(0)
! 527: bool(false)
! 528:
! 529: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 530: int(0)
! 531: bool(false)
! 532: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 533: int(0)
! 534: bool(false)
! 535:
! 536: -- File opened in mode ab --
! 537: -- Reading entire file content, expeceted : 0 bytes --
! 538: int(0)
! 539: bool(false)
! 540: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 541: int(0)
! 542: bool(false)
! 543:
! 544: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 545: int(0)
! 546: bool(false)
! 547: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 548: int(0)
! 549: bool(false)
! 550:
! 551: -- File opened in mode at --
! 552: -- Reading entire file content, expeceted : 0 bytes --
! 553: int(0)
! 554: bool(false)
! 555: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 556: int(0)
! 557: bool(false)
! 558:
! 559: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 560: int(0)
! 561: bool(false)
! 562: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 563: int(0)
! 564: bool(false)
! 565:
! 566: -- File opened in mode w --
! 567: -- Reading entire file content, expeceted : 0 bytes --
! 568: int(0)
! 569: bool(false)
! 570: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 571: int(0)
! 572: bool(false)
! 573:
! 574: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 575: int(0)
! 576: bool(false)
! 577: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 578: int(0)
! 579: bool(false)
! 580:
! 581: -- File opened in mode wb --
! 582: -- Reading entire file content, expeceted : 0 bytes --
! 583: int(0)
! 584: bool(false)
! 585: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 586: int(0)
! 587: bool(false)
! 588:
! 589: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 590: int(0)
! 591: bool(false)
! 592: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 593: int(0)
! 594: bool(false)
! 595:
! 596: -- File opened in mode wt --
! 597: -- Reading entire file content, expeceted : 0 bytes --
! 598: int(0)
! 599: bool(false)
! 600: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 601: int(0)
! 602: bool(false)
! 603:
! 604: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 605: int(0)
! 606: bool(false)
! 607: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 608: int(0)
! 609: bool(false)
! 610:
! 611: -- File opened in mode x --
! 612: -- Reading entire file content, expeceted : 0 bytes --
! 613: int(0)
! 614: bool(false)
! 615: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 616: int(0)
! 617: bool(false)
! 618:
! 619: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 620: int(0)
! 621: bool(false)
! 622: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 623: int(0)
! 624: bool(false)
! 625:
! 626: -- File opened in mode xb --
! 627: -- Reading entire file content, expeceted : 0 bytes --
! 628: int(0)
! 629: bool(false)
! 630: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 631: int(0)
! 632: bool(false)
! 633:
! 634: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 635: int(0)
! 636: bool(false)
! 637: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 638: int(0)
! 639: bool(false)
! 640:
! 641: -- File opened in mode xt --
! 642: -- Reading entire file content, expeceted : 0 bytes --
! 643: int(0)
! 644: bool(false)
! 645: Reading 1024 bytes from file, expecting 0 bytes ... OK
! 646: int(0)
! 647: bool(false)
! 648:
! 649: -- Reading file content less than max. file size, expeceted : 0 bytes --
! 650: int(0)
! 651: bool(false)
! 652: Reading 1000 bytes from file, expecting 0 bytes ... OK
! 653: int(0)
! 654: bool(false)
! 655:
! 656: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>