Annotation of embedaddon/php/ext/standard/tests/file/007_basic.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test fopen(), fclose() & feof() functions: basic functionality
! 3: --FILE--
! 4: <?php
! 5: /*
! 6: Prototype: resource fopen(string $filename, string $mode
! 7: [, bool $use_include_path [, resource $context]] );
! 8: Description: Opens file or URL.
! 9:
! 10: Prototype: bool fclose ( resource $handle );
! 11: Description: Closes an open file pointer
! 12:
! 13: Prototype: bool feof ( resource $handle );
! 14: Description: Tests for end-of-file on a file pointer
! 15: */
! 16:
! 17: echo "*** Testing basic operations of fopen() and fclose() functions ***\n";
! 18: $modes = array(
! 19: "w",
! 20: "wb",
! 21: "wt",
! 22: "w+",
! 23: "w+b",
! 24: "w+t",
! 25:
! 26: "r",
! 27: "rb",
! 28: "rt",
! 29: "r+",
! 30: "r+b",
! 31: "r+t",
! 32:
! 33: "a",
! 34: "ab",
! 35: "at",
! 36: "a+",
! 37: "a+t",
! 38: "a+b"
! 39: );
! 40:
! 41: for( $i=0; $i<count($modes); $i++ ) {
! 42: echo "\n-- Iteration with mode '$modes[$i]' --\n";
! 43:
! 44: $filename = dirname(__FILE__)."/007_basic.tmp";
! 45: // check fopen()
! 46: $handle = fopen($filename, $modes[$i]);
! 47: var_dump($handle );
! 48: var_dump( ftell($handle) );
! 49: var_dump( feof($handle) );
! 50:
! 51: // check fclose()
! 52: var_dump( fclose($handle) );
! 53: var_dump( $handle );
! 54: // confirm the closure, using ftell() and feof(), expect, false
! 55: var_dump( ftell($handle) );
! 56: var_dump( feof($handle) );
! 57: }
! 58:
! 59: // remove the temp file
! 60: unlink($filename);
! 61:
! 62: $x_modes = array(
! 63: "x",
! 64: "xb",
! 65: "xt",
! 66: "x+",
! 67: "x+b",
! 68: "x+t"
! 69: );
! 70:
! 71: for( $i=0; $i<count($x_modes); $i++ ) {
! 72: echo "\n-- Iteration with mode '$x_modes[$i]' --\n";
! 73: $handle = fopen($filename, $x_modes[$i]);
! 74: var_dump($handle );
! 75: var_dump( ftell($handle) );
! 76: var_dump( feof($handle) );
! 77:
! 78: // check fclose()
! 79: var_dump( fclose($handle) );
! 80: var_dump( $handle );
! 81: // confirm the closure, using ftell() and feof(), expect, false
! 82: var_dump( ftell($handle) );
! 83: var_dump( feof($handle) );
! 84: var_dump( $handle );
! 85:
! 86: // remove the file
! 87: unlink( $filename );
! 88: }
! 89:
! 90: echo "\n*** Done ***\n";
! 91: --EXPECTF--
! 92: *** Testing basic operations of fopen() and fclose() functions ***
! 93:
! 94: -- Iteration with mode 'w' --
! 95: resource(%d) of type (stream)
! 96: int(0)
! 97: bool(false)
! 98: bool(true)
! 99: resource(%d) of type (Unknown)
! 100:
! 101: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 102: bool(false)
! 103:
! 104: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 105: bool(false)
! 106:
! 107: -- Iteration with mode 'wb' --
! 108: resource(%d) of type (stream)
! 109: int(0)
! 110: bool(false)
! 111: bool(true)
! 112: resource(%d) of type (Unknown)
! 113:
! 114: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 115: bool(false)
! 116:
! 117: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 118: bool(false)
! 119:
! 120: -- Iteration with mode 'wt' --
! 121: resource(%d) of type (stream)
! 122: int(0)
! 123: bool(false)
! 124: bool(true)
! 125: resource(%d) of type (Unknown)
! 126:
! 127: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 128: bool(false)
! 129:
! 130: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 131: bool(false)
! 132:
! 133: -- Iteration with mode 'w+' --
! 134: resource(%d) of type (stream)
! 135: int(0)
! 136: bool(false)
! 137: bool(true)
! 138: resource(%d) of type (Unknown)
! 139:
! 140: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 141: bool(false)
! 142:
! 143: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 144: bool(false)
! 145:
! 146: -- Iteration with mode 'w+b' --
! 147: resource(%d) of type (stream)
! 148: int(0)
! 149: bool(false)
! 150: bool(true)
! 151: resource(%d) of type (Unknown)
! 152:
! 153: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 154: bool(false)
! 155:
! 156: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 157: bool(false)
! 158:
! 159: -- Iteration with mode 'w+t' --
! 160: resource(%d) of type (stream)
! 161: int(0)
! 162: bool(false)
! 163: bool(true)
! 164: resource(%d) of type (Unknown)
! 165:
! 166: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 167: bool(false)
! 168:
! 169: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 170: bool(false)
! 171:
! 172: -- Iteration with mode 'r' --
! 173: resource(%d) of type (stream)
! 174: int(0)
! 175: bool(false)
! 176: bool(true)
! 177: resource(%d) of type (Unknown)
! 178:
! 179: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 180: bool(false)
! 181:
! 182: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 183: bool(false)
! 184:
! 185: -- Iteration with mode 'rb' --
! 186: resource(%d) of type (stream)
! 187: int(0)
! 188: bool(false)
! 189: bool(true)
! 190: resource(%d) of type (Unknown)
! 191:
! 192: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 193: bool(false)
! 194:
! 195: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 196: bool(false)
! 197:
! 198: -- Iteration with mode 'rt' --
! 199: resource(%d) of type (stream)
! 200: int(0)
! 201: bool(false)
! 202: bool(true)
! 203: resource(%d) of type (Unknown)
! 204:
! 205: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 206: bool(false)
! 207:
! 208: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 209: bool(false)
! 210:
! 211: -- Iteration with mode 'r+' --
! 212: resource(%d) of type (stream)
! 213: int(0)
! 214: bool(false)
! 215: bool(true)
! 216: resource(%d) of type (Unknown)
! 217:
! 218: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 219: bool(false)
! 220:
! 221: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 222: bool(false)
! 223:
! 224: -- Iteration with mode 'r+b' --
! 225: resource(%d) of type (stream)
! 226: int(0)
! 227: bool(false)
! 228: bool(true)
! 229: resource(%d) of type (Unknown)
! 230:
! 231: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 232: bool(false)
! 233:
! 234: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 235: bool(false)
! 236:
! 237: -- Iteration with mode 'r+t' --
! 238: resource(%d) of type (stream)
! 239: int(0)
! 240: bool(false)
! 241: bool(true)
! 242: resource(%d) of type (Unknown)
! 243:
! 244: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 245: bool(false)
! 246:
! 247: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 248: bool(false)
! 249:
! 250: -- Iteration with mode 'a' --
! 251: resource(%d) of type (stream)
! 252: int(0)
! 253: bool(false)
! 254: bool(true)
! 255: resource(%d) of type (Unknown)
! 256:
! 257: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 258: bool(false)
! 259:
! 260: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 261: bool(false)
! 262:
! 263: -- Iteration with mode 'ab' --
! 264: resource(%d) of type (stream)
! 265: int(0)
! 266: bool(false)
! 267: bool(true)
! 268: resource(%d) of type (Unknown)
! 269:
! 270: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 271: bool(false)
! 272:
! 273: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 274: bool(false)
! 275:
! 276: -- Iteration with mode 'at' --
! 277: resource(%d) of type (stream)
! 278: int(0)
! 279: bool(false)
! 280: bool(true)
! 281: resource(%d) of type (Unknown)
! 282:
! 283: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 284: bool(false)
! 285:
! 286: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 287: bool(false)
! 288:
! 289: -- Iteration with mode 'a+' --
! 290: resource(%d) of type (stream)
! 291: int(0)
! 292: bool(false)
! 293: bool(true)
! 294: resource(%d) of type (Unknown)
! 295:
! 296: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 297: bool(false)
! 298:
! 299: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 300: bool(false)
! 301:
! 302: -- Iteration with mode 'a+t' --
! 303: resource(%d) of type (stream)
! 304: int(0)
! 305: bool(false)
! 306: bool(true)
! 307: resource(%d) of type (Unknown)
! 308:
! 309: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 310: bool(false)
! 311:
! 312: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 313: bool(false)
! 314:
! 315: -- Iteration with mode 'a+b' --
! 316: resource(%d) of type (stream)
! 317: int(0)
! 318: bool(false)
! 319: bool(true)
! 320: resource(%d) of type (Unknown)
! 321:
! 322: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 323: bool(false)
! 324:
! 325: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 326: bool(false)
! 327:
! 328: -- Iteration with mode 'x' --
! 329: resource(%d) of type (stream)
! 330: int(0)
! 331: bool(false)
! 332: bool(true)
! 333: resource(%d) of type (Unknown)
! 334:
! 335: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 336: bool(false)
! 337:
! 338: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 339: bool(false)
! 340: resource(%d) of type (Unknown)
! 341:
! 342: -- Iteration with mode 'xb' --
! 343: resource(%d) of type (stream)
! 344: int(0)
! 345: bool(false)
! 346: bool(true)
! 347: resource(%d) of type (Unknown)
! 348:
! 349: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 350: bool(false)
! 351:
! 352: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 353: bool(false)
! 354: resource(%d) of type (Unknown)
! 355:
! 356: -- Iteration with mode 'xt' --
! 357: resource(%d) of type (stream)
! 358: int(0)
! 359: bool(false)
! 360: bool(true)
! 361: resource(%d) of type (Unknown)
! 362:
! 363: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 364: bool(false)
! 365:
! 366: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 367: bool(false)
! 368: resource(%d) of type (Unknown)
! 369:
! 370: -- Iteration with mode 'x+' --
! 371: resource(%d) of type (stream)
! 372: int(0)
! 373: bool(false)
! 374: bool(true)
! 375: resource(%d) of type (Unknown)
! 376:
! 377: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 378: bool(false)
! 379:
! 380: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 381: bool(false)
! 382: resource(%d) of type (Unknown)
! 383:
! 384: -- Iteration with mode 'x+b' --
! 385: resource(%d) of type (stream)
! 386: int(0)
! 387: bool(false)
! 388: bool(true)
! 389: resource(%d) of type (Unknown)
! 390:
! 391: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 392: bool(false)
! 393:
! 394: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 395: bool(false)
! 396: resource(%d) of type (Unknown)
! 397:
! 398: -- Iteration with mode 'x+t' --
! 399: resource(%d) of type (stream)
! 400: int(0)
! 401: bool(false)
! 402: bool(true)
! 403: resource(%d) of type (Unknown)
! 404:
! 405: Warning: ftell(): %d is not a valid stream resource in %s on line %d
! 406: bool(false)
! 407:
! 408: Warning: feof(): %d is not a valid stream resource in %s on line %d
! 409: bool(false)
! 410: resource(%d) of type (Unknown)
! 411:
! 412: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>