Annotation of embedaddon/php/ext/standard/tests/file/fgets_variation5.phpt, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>