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