Annotation of embedaddon/php/ext/standard/tests/file/ftruncate_variation4-win32.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test ftruncate() function : usage variations - truncate file to negative 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_variation4.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", 4);
! 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 a negative size --\n";
! 54: /* try to truncate it to a negative size, size should not change*/
! 55:
! 56: $new_size = -1000;
! 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: }//end of outer foreach loop
! 70: echo "Done\n";
! 71: ?>
! 72: --EXPECTF--
! 73: *** Testing ftruncate() : usage variations ***
! 74:
! 75: -- Testing ftruncate() with file having data of type numeric --
! 76: -- Testing ftruncate() with file opening using r mode --
! 77: -- Testing ftruncate(): try truncating file to a negative size --
! 78: int(1024)
! 79: int(0)
! 80: bool(false)
! 81: int(0)
! 82: bool(false)
! 83: int(1024)
! 84: -- Testing ftruncate() with file opening using rb mode --
! 85: -- Testing ftruncate(): try truncating file to a negative size --
! 86: int(1024)
! 87: int(0)
! 88: bool(false)
! 89: int(0)
! 90: bool(false)
! 91: int(1024)
! 92: -- Testing ftruncate() with file opening using rt mode --
! 93: -- Testing ftruncate(): try truncating file to a negative size --
! 94: int(1024)
! 95: int(0)
! 96: bool(false)
! 97: int(0)
! 98: bool(false)
! 99: int(1024)
! 100: -- Testing ftruncate() with file opening using r+ mode --
! 101: -- Testing ftruncate(): try truncating file to a negative size --
! 102: int(1024)
! 103: int(0)
! 104: bool(false)
! 105: int(0)
! 106: bool(false)
! 107: int(1024)
! 108: -- Testing ftruncate() with file opening using r+b mode --
! 109: -- Testing ftruncate(): try truncating file to a negative size --
! 110: int(1024)
! 111: int(0)
! 112: bool(false)
! 113: int(0)
! 114: bool(false)
! 115: int(1024)
! 116: -- Testing ftruncate() with file opening using r+t mode --
! 117: -- Testing ftruncate(): try truncating file to a negative size --
! 118: int(1024)
! 119: int(0)
! 120: bool(false)
! 121: int(0)
! 122: bool(false)
! 123: int(1024)
! 124: -- Testing ftruncate() with file opening using w mode --
! 125: -- Testing ftruncate(): try truncating file to a negative size --
! 126: int(1024)
! 127: int(0)
! 128: bool(false)
! 129: int(0)
! 130: bool(false)
! 131: int(1024)
! 132: -- Testing ftruncate() with file opening using wb mode --
! 133: -- Testing ftruncate(): try truncating file to a negative size --
! 134: int(1024)
! 135: int(0)
! 136: bool(false)
! 137: int(0)
! 138: bool(false)
! 139: int(1024)
! 140: -- Testing ftruncate() with file opening using wt mode --
! 141: -- Testing ftruncate(): try truncating file to a negative size --
! 142: int(1024)
! 143: int(0)
! 144: bool(false)
! 145: int(0)
! 146: bool(false)
! 147: int(1024)
! 148: -- Testing ftruncate() with file opening using w+ mode --
! 149: -- Testing ftruncate(): try truncating file to a negative size --
! 150: int(1024)
! 151: int(0)
! 152: bool(false)
! 153: int(0)
! 154: bool(false)
! 155: int(1024)
! 156: -- Testing ftruncate() with file opening using w+b mode --
! 157: -- Testing ftruncate(): try truncating file to a negative size --
! 158: int(1024)
! 159: int(0)
! 160: bool(false)
! 161: int(0)
! 162: bool(false)
! 163: int(1024)
! 164: -- Testing ftruncate() with file opening using w+t mode --
! 165: -- Testing ftruncate(): try truncating file to a negative size --
! 166: int(1024)
! 167: int(0)
! 168: bool(false)
! 169: int(0)
! 170: bool(false)
! 171: int(1024)
! 172: -- Testing ftruncate() with file opening using x mode --
! 173: -- Testing ftruncate(): try truncating file to a negative size --
! 174: int(1024)
! 175: int(0)
! 176: bool(false)
! 177: int(0)
! 178: bool(false)
! 179: int(1024)
! 180: -- Testing ftruncate() with file opening using xb mode --
! 181: -- Testing ftruncate(): try truncating file to a negative size --
! 182: int(1024)
! 183: int(0)
! 184: bool(false)
! 185: int(0)
! 186: bool(false)
! 187: int(1024)
! 188: -- Testing ftruncate() with file opening using xt mode --
! 189: -- Testing ftruncate(): try truncating file to a negative size --
! 190: int(1024)
! 191: int(0)
! 192: bool(false)
! 193: int(0)
! 194: bool(false)
! 195: int(1024)
! 196: -- Testing ftruncate() with file opening using x+ mode --
! 197: -- Testing ftruncate(): try truncating file to a negative size --
! 198: int(1024)
! 199: int(0)
! 200: bool(false)
! 201: int(0)
! 202: bool(false)
! 203: int(1024)
! 204: -- Testing ftruncate() with file opening using x+b mode --
! 205: -- Testing ftruncate(): try truncating file to a negative size --
! 206: int(1024)
! 207: int(0)
! 208: bool(false)
! 209: int(0)
! 210: bool(false)
! 211: int(1024)
! 212: -- Testing ftruncate() with file opening using x+t mode --
! 213: -- Testing ftruncate(): try truncating file to a negative size --
! 214: int(1024)
! 215: int(0)
! 216: bool(false)
! 217: int(0)
! 218: bool(false)
! 219: int(1024)
! 220: -- Testing ftruncate() with file opening using a mode --
! 221: -- Testing ftruncate(): try truncating file to a negative size --
! 222: int(1024)
! 223: int(0)
! 224: bool(false)
! 225: int(0)
! 226: bool(false)
! 227: int(1024)
! 228: -- Testing ftruncate() with file opening using ab mode --
! 229: -- Testing ftruncate(): try truncating file to a negative size --
! 230: int(1024)
! 231: int(0)
! 232: bool(false)
! 233: int(0)
! 234: bool(false)
! 235: int(1024)
! 236: -- Testing ftruncate() with file opening using at mode --
! 237: -- Testing ftruncate(): try truncating file to a negative size --
! 238: int(1024)
! 239: int(0)
! 240: bool(false)
! 241: int(0)
! 242: bool(false)
! 243: int(1024)
! 244: -- Testing ftruncate() with file opening using a+ mode --
! 245: -- Testing ftruncate(): try truncating file to a negative size --
! 246: int(1024)
! 247: int(0)
! 248: bool(false)
! 249: int(0)
! 250: bool(false)
! 251: int(1024)
! 252: -- Testing ftruncate() with file opening using a+b mode --
! 253: -- Testing ftruncate(): try truncating file to a negative size --
! 254: int(1024)
! 255: int(0)
! 256: bool(false)
! 257: int(0)
! 258: bool(false)
! 259: int(1024)
! 260: -- Testing ftruncate() with file opening using a+t mode --
! 261: -- Testing ftruncate(): try truncating file to a negative size --
! 262: int(1024)
! 263: int(0)
! 264: bool(false)
! 265: int(0)
! 266: bool(false)
! 267: int(1024)
! 268:
! 269: -- Testing ftruncate() with file having data of type text_with_new_line --
! 270: -- Testing ftruncate() with file opening using r mode --
! 271: -- Testing ftruncate(): try truncating file to a negative size --
! 272: int(1024)
! 273: int(0)
! 274: bool(false)
! 275: int(0)
! 276: bool(false)
! 277: int(1024)
! 278: -- Testing ftruncate() with file opening using rb mode --
! 279: -- Testing ftruncate(): try truncating file to a negative size --
! 280: int(1024)
! 281: int(0)
! 282: bool(false)
! 283: int(0)
! 284: bool(false)
! 285: int(1024)
! 286: -- Testing ftruncate() with file opening using rt mode --
! 287: -- Testing ftruncate(): try truncating file to a negative size --
! 288: int(1024)
! 289: int(0)
! 290: bool(false)
! 291: int(0)
! 292: bool(false)
! 293: int(1024)
! 294: -- Testing ftruncate() with file opening using r+ mode --
! 295: -- Testing ftruncate(): try truncating file to a negative size --
! 296: int(1024)
! 297: int(0)
! 298: bool(false)
! 299: int(0)
! 300: bool(false)
! 301: int(1024)
! 302: -- Testing ftruncate() with file opening using r+b mode --
! 303: -- Testing ftruncate(): try truncating file to a negative size --
! 304: int(1024)
! 305: int(0)
! 306: bool(false)
! 307: int(0)
! 308: bool(false)
! 309: int(1024)
! 310: -- Testing ftruncate() with file opening using r+t mode --
! 311: -- Testing ftruncate(): try truncating file to a negative size --
! 312: int(1024)
! 313: int(0)
! 314: bool(false)
! 315: int(0)
! 316: bool(false)
! 317: int(1024)
! 318: -- Testing ftruncate() with file opening using w mode --
! 319: -- Testing ftruncate(): try truncating file to a negative size --
! 320: int(1024)
! 321: int(0)
! 322: bool(false)
! 323: int(0)
! 324: bool(false)
! 325: int(1024)
! 326: -- Testing ftruncate() with file opening using wb mode --
! 327: -- Testing ftruncate(): try truncating file to a negative size --
! 328: int(1024)
! 329: int(0)
! 330: bool(false)
! 331: int(0)
! 332: bool(false)
! 333: int(1024)
! 334: -- Testing ftruncate() with file opening using wt mode --
! 335: -- Testing ftruncate(): try truncating file to a negative size --
! 336: int(1137)
! 337: int(0)
! 338: bool(false)
! 339: int(0)
! 340: bool(false)
! 341: int(1137)
! 342: -- Testing ftruncate() with file opening using w+ mode --
! 343: -- Testing ftruncate(): try truncating file to a negative size --
! 344: int(1024)
! 345: int(0)
! 346: bool(false)
! 347: int(0)
! 348: bool(false)
! 349: int(1024)
! 350: -- Testing ftruncate() with file opening using w+b mode --
! 351: -- Testing ftruncate(): try truncating file to a negative size --
! 352: int(1024)
! 353: int(0)
! 354: bool(false)
! 355: int(0)
! 356: bool(false)
! 357: int(1024)
! 358: -- Testing ftruncate() with file opening using w+t mode --
! 359: -- Testing ftruncate(): try truncating file to a negative size --
! 360: int(1137)
! 361: int(0)
! 362: bool(false)
! 363: int(0)
! 364: bool(false)
! 365: int(1137)
! 366: -- Testing ftruncate() with file opening using x mode --
! 367: -- Testing ftruncate(): try truncating file to a negative size --
! 368: int(1024)
! 369: int(0)
! 370: bool(false)
! 371: int(0)
! 372: bool(false)
! 373: int(1024)
! 374: -- Testing ftruncate() with file opening using xb mode --
! 375: -- Testing ftruncate(): try truncating file to a negative size --
! 376: int(1024)
! 377: int(0)
! 378: bool(false)
! 379: int(0)
! 380: bool(false)
! 381: int(1024)
! 382: -- Testing ftruncate() with file opening using xt mode --
! 383: -- Testing ftruncate(): try truncating file to a negative size --
! 384: int(1137)
! 385: int(0)
! 386: bool(false)
! 387: int(0)
! 388: bool(false)
! 389: int(1137)
! 390: -- Testing ftruncate() with file opening using x+ mode --
! 391: -- Testing ftruncate(): try truncating file to a negative size --
! 392: int(1024)
! 393: int(0)
! 394: bool(false)
! 395: int(0)
! 396: bool(false)
! 397: int(1024)
! 398: -- Testing ftruncate() with file opening using x+b mode --
! 399: -- Testing ftruncate(): try truncating file to a negative size --
! 400: int(1024)
! 401: int(0)
! 402: bool(false)
! 403: int(0)
! 404: bool(false)
! 405: int(1024)
! 406: -- Testing ftruncate() with file opening using x+t mode --
! 407: -- Testing ftruncate(): try truncating file to a negative size --
! 408: int(1137)
! 409: int(0)
! 410: bool(false)
! 411: int(0)
! 412: bool(false)
! 413: int(1137)
! 414: -- Testing ftruncate() with file opening using a mode --
! 415: -- Testing ftruncate(): try truncating file to a negative size --
! 416: int(1024)
! 417: int(0)
! 418: bool(false)
! 419: int(0)
! 420: bool(false)
! 421: int(1024)
! 422: -- Testing ftruncate() with file opening using ab mode --
! 423: -- Testing ftruncate(): try truncating file to a negative size --
! 424: int(1024)
! 425: int(0)
! 426: bool(false)
! 427: int(0)
! 428: bool(false)
! 429: int(1024)
! 430: -- Testing ftruncate() with file opening using at mode --
! 431: -- Testing ftruncate(): try truncating file to a negative size --
! 432: int(1024)
! 433: int(0)
! 434: bool(false)
! 435: int(0)
! 436: bool(false)
! 437: int(1024)
! 438: -- Testing ftruncate() with file opening using a+ mode --
! 439: -- Testing ftruncate(): try truncating file to a negative size --
! 440: int(1024)
! 441: int(0)
! 442: bool(false)
! 443: int(0)
! 444: bool(false)
! 445: int(1024)
! 446: -- Testing ftruncate() with file opening using a+b mode --
! 447: -- Testing ftruncate(): try truncating file to a negative size --
! 448: int(1024)
! 449: int(0)
! 450: bool(false)
! 451: int(0)
! 452: bool(false)
! 453: int(1024)
! 454: -- Testing ftruncate() with file opening using a+t mode --
! 455: -- Testing ftruncate(): try truncating file to a negative size --
! 456: int(1024)
! 457: int(0)
! 458: bool(false)
! 459: int(0)
! 460: bool(false)
! 461: int(1024)
! 462: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>