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