Return to fgets_basic.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test fgets() function : basic functionality 3: --FILE-- 4: <?php 5: /* 6: Prototype: string fgets ( resource $handle [, int $length] ); 7: Description: Gets a line from file pointer 8: */ 9: 10: // include the file.inc for common test funcitons 11: include ("file.inc"); 12: 13: $file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t"); 14: 15: $file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric"); 16: 17: echo "*** Testing fgets() : basic functionality ***\n"; 18: foreach($file_modes as $file_mode) { 19: echo "\n-- Testing fgets() with file opened using mode $file_mode --\n"; 20: foreach($file_content_types as $file_content_type) { 21: echo "-- File content type : $file_content_type --\n"; 22: /* create files with $file_content_type */ 23: create_files ( dirname(__FILE__), 1, $file_content_type, 0755, 50, "w", "fgets_basic", 1, "bytes"); //create a file 24: $filename = dirname(__FILE__)."/fgets_basic1.tmp"; // this is name of the file created by create_files() 25: $file_handle = fopen($filename, $file_mode); 26: if ( !$file_handle ) { 27: echo "Error: failed to open file $filename!"; 28: exit(); 29: } 30: 31: echo "-- fgets() with default length, file pointer at 0 --\n"; 32: var_dump( fgets($file_handle) ); // with default length 33: var_dump( ftell($file_handle) ); // ensure the file pointer position 34: var_dump( feof($file_handle) ); // enusre if eof set 35: 36: echo "-- fgets() with length = 23, Expected: 22 chars, file pointer at 0 --\n"; 37: var_dump( rewind($file_handle) ); 38: var_dump( fgets($file_handle, 23) ); // expected: 22 chars 39: var_dump( ftell($file_handle) ); // ensure the file pointer position 40: var_dump( feof($file_handle) ); // enusre if eof set 41: 42: //close file 43: fclose($file_handle); 44: 45: // delete file 46: delete_file($filename); 47: } // file_content_type loop 48: } // file_mode loop 49: 50: echo "Done\n"; 51: ?> 52: --EXPECTF-- 53: *** Testing fgets() : basic functionality *** 54: 55: -- Testing fgets() with file opened using mode r -- 56: -- File content type : numeric -- 57: -- fgets() with default length, file pointer at 0 -- 58: string(50) "22222222222222222222222222222222222222222222222222" 59: int(50) 60: bool(true) 61: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 62: bool(true) 63: string(22) "2222222222222222222222" 64: int(22) 65: bool(false) 66: -- File content type : text -- 67: -- fgets() with default length, file pointer at 0 -- 68: string(50) "text text text text text text text text text text " 69: int(50) 70: bool(true) 71: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 72: bool(true) 73: string(22) "text text text text te" 74: int(22) 75: bool(false) 76: -- File content type : text_with_new_line -- 77: -- fgets() with default length, file pointer at 0 -- 78: string(5) "line 79: " 80: int(5) 81: bool(false) 82: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 83: bool(true) 84: string(5) "line 85: " 86: int(5) 87: bool(false) 88: -- File content type : alphanumeric -- 89: -- fgets() with default length, file pointer at 0 -- 90: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 " 91: int(50) 92: bool(true) 93: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 94: bool(true) 95: string(22) "ab12 ab12 ab12 ab12 ab" 96: int(22) 97: bool(false) 98: 99: -- Testing fgets() with file opened using mode rb -- 100: -- File content type : numeric -- 101: -- fgets() with default length, file pointer at 0 -- 102: string(50) "22222222222222222222222222222222222222222222222222" 103: int(50) 104: bool(true) 105: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 106: bool(true) 107: string(22) "2222222222222222222222" 108: int(22) 109: bool(false) 110: -- File content type : text -- 111: -- fgets() with default length, file pointer at 0 -- 112: string(50) "text text text text text text text text text text " 113: int(50) 114: bool(true) 115: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 116: bool(true) 117: string(22) "text text text text te" 118: int(22) 119: bool(false) 120: -- File content type : text_with_new_line -- 121: -- fgets() with default length, file pointer at 0 -- 122: string(5) "line 123: " 124: int(5) 125: bool(false) 126: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 127: bool(true) 128: string(5) "line 129: " 130: int(5) 131: bool(false) 132: -- File content type : alphanumeric -- 133: -- fgets() with default length, file pointer at 0 -- 134: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 " 135: int(50) 136: bool(true) 137: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 138: bool(true) 139: string(22) "ab12 ab12 ab12 ab12 ab" 140: int(22) 141: bool(false) 142: 143: -- Testing fgets() with file opened using mode rt -- 144: -- File content type : numeric -- 145: -- fgets() with default length, file pointer at 0 -- 146: string(50) "22222222222222222222222222222222222222222222222222" 147: int(50) 148: bool(true) 149: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 150: bool(true) 151: string(22) "2222222222222222222222" 152: int(22) 153: bool(false) 154: -- File content type : text -- 155: -- fgets() with default length, file pointer at 0 -- 156: string(50) "text text text text text text text text text text " 157: int(50) 158: bool(true) 159: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 160: bool(true) 161: string(22) "text text text text te" 162: int(22) 163: bool(false) 164: -- File content type : text_with_new_line -- 165: -- fgets() with default length, file pointer at 0 -- 166: string(5) "line 167: " 168: int(5) 169: bool(false) 170: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 171: bool(true) 172: string(5) "line 173: " 174: int(5) 175: bool(false) 176: -- File content type : alphanumeric -- 177: -- fgets() with default length, file pointer at 0 -- 178: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 " 179: int(50) 180: bool(true) 181: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 182: bool(true) 183: string(22) "ab12 ab12 ab12 ab12 ab" 184: int(22) 185: bool(false) 186: 187: -- Testing fgets() with file opened using mode r+ -- 188: -- File content type : numeric -- 189: -- fgets() with default length, file pointer at 0 -- 190: string(50) "22222222222222222222222222222222222222222222222222" 191: int(50) 192: bool(true) 193: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 194: bool(true) 195: string(22) "2222222222222222222222" 196: int(22) 197: bool(false) 198: -- File content type : text -- 199: -- fgets() with default length, file pointer at 0 -- 200: string(50) "text text text text text text text text text text " 201: int(50) 202: bool(true) 203: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 204: bool(true) 205: string(22) "text text text text te" 206: int(22) 207: bool(false) 208: -- File content type : text_with_new_line -- 209: -- fgets() with default length, file pointer at 0 -- 210: string(5) "line 211: " 212: int(5) 213: bool(false) 214: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 215: bool(true) 216: string(5) "line 217: " 218: int(5) 219: bool(false) 220: -- File content type : alphanumeric -- 221: -- fgets() with default length, file pointer at 0 -- 222: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 " 223: int(50) 224: bool(true) 225: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 226: bool(true) 227: string(22) "ab12 ab12 ab12 ab12 ab" 228: int(22) 229: bool(false) 230: 231: -- Testing fgets() with file opened using mode r+b -- 232: -- File content type : numeric -- 233: -- fgets() with default length, file pointer at 0 -- 234: string(50) "22222222222222222222222222222222222222222222222222" 235: int(50) 236: bool(true) 237: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 238: bool(true) 239: string(22) "2222222222222222222222" 240: int(22) 241: bool(false) 242: -- File content type : text -- 243: -- fgets() with default length, file pointer at 0 -- 244: string(50) "text text text text text text text text text text " 245: int(50) 246: bool(true) 247: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 248: bool(true) 249: string(22) "text text text text te" 250: int(22) 251: bool(false) 252: -- File content type : text_with_new_line -- 253: -- fgets() with default length, file pointer at 0 -- 254: string(5) "line 255: " 256: int(5) 257: bool(false) 258: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 259: bool(true) 260: string(5) "line 261: " 262: int(5) 263: bool(false) 264: -- File content type : alphanumeric -- 265: -- fgets() with default length, file pointer at 0 -- 266: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 " 267: int(50) 268: bool(true) 269: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 270: bool(true) 271: string(22) "ab12 ab12 ab12 ab12 ab" 272: int(22) 273: bool(false) 274: 275: -- Testing fgets() with file opened using mode r+t -- 276: -- File content type : numeric -- 277: -- fgets() with default length, file pointer at 0 -- 278: string(50) "22222222222222222222222222222222222222222222222222" 279: int(50) 280: bool(true) 281: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 282: bool(true) 283: string(22) "2222222222222222222222" 284: int(22) 285: bool(false) 286: -- File content type : text -- 287: -- fgets() with default length, file pointer at 0 -- 288: string(50) "text text text text text text text text text text " 289: int(50) 290: bool(true) 291: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 292: bool(true) 293: string(22) "text text text text te" 294: int(22) 295: bool(false) 296: -- File content type : text_with_new_line -- 297: -- fgets() with default length, file pointer at 0 -- 298: string(5) "line 299: " 300: int(5) 301: bool(false) 302: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 303: bool(true) 304: string(5) "line 305: " 306: int(5) 307: bool(false) 308: -- File content type : alphanumeric -- 309: -- fgets() with default length, file pointer at 0 -- 310: string(50) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 " 311: int(50) 312: bool(true) 313: -- fgets() with length = 23, Expected: 22 chars, file pointer at 0 -- 314: bool(true) 315: string(22) "ab12 ab12 ab12 ab12 ab" 316: int(22) 317: bool(false) 318: Done