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