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

1.1       misho       1: --TEST--
                      2: Test fscanf() function: usage variations - integer formats with resource 
                      3: --FILE--
                      4: <?php
                      5: 
                      6: /*
                      7:   Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
                      8:   Description: Parses input from a file according to a format
                      9: */
                     10: 
                     11: /* Test fscanf() to scan resource type using different integer format types */
                     12: 
                     13: $file_path = dirname(__FILE__);
                     14: 
                     15: echo "*** Test fscanf(): different integer format types with resource ***\n"; 
                     16: 
                     17: // create a file
                     18: $filename = "$file_path/fscanf_variation4.tmp";
                     19: $file_handle = fopen($filename, "w");
                     20: if($file_handle == false)
                     21:   exit("Error:failed to open file $filename");
                     22: 
                     23: // non-integer type of data
                     24: 
                     25: // resource type variable
                     26: $fp = fopen (__FILE__, "r");
                     27: $dfp = opendir ( dirname(__FILE__) );
                     28:   
                     29: // array of resource types
                     30: $resource_types = array (
                     31:   $fp,
                     32:   $dfp
                     33: );
                     34: 
                     35: $int_formats = array( "%d", "%hd", "%ld", "%Ld", " %d", "%d ", "% d", "\t%d", "\n%d", "%4d", "%30d", "%[0-9]", "%*d");
                     36: 
                     37: $counter = 1;
                     38: 
                     39: // writing to the file
                     40: foreach($resource_types as $value) {
                     41:   @fprintf($file_handle, $value);
                     42:   @fprintf($file_handle, "\n");
                     43: }
                     44: // closing the file
                     45: fclose($file_handle);
                     46: 
                     47: // opening the file for reading
                     48: $file_handle = fopen($filename, "r");
                     49: if($file_handle == false) {
                     50:   exit("Error:failed to open file $filename");
                     51: }
                     52: 
                     53: $counter = 1;
                     54: // reading the values from file using different integer formats
                     55: foreach($int_formats as $int_format) {
                     56:   // rewind the file so that for every foreach iteration the file pointer starts from bof
                     57:   rewind($file_handle);
                     58:   echo "\n-- iteration $counter --\n";
                     59:   while( !feof($file_handle) ) {
                     60:     var_dump( fscanf($file_handle,$int_format) );
                     61:   }
                     62:   $counter++;
                     63: }
                     64: 
                     65: // closing the resources
                     66: fclose($fp);
                     67: closedir($dfp);
                     68: 
                     69: echo "\n*** Done ***";
                     70: ?>
                     71: --CLEAN--
                     72: <?php
                     73: $file_path = dirname(__FILE__);
                     74: $filename = "$file_path/fscanf_variation4.tmp";
                     75: unlink($filename);
                     76: ?>
                     77: --EXPECTF--
                     78: *** Test fscanf(): different integer format types with resource ***
                     79: 
                     80: -- iteration 1 --
                     81: array(1) {
                     82:   [0]=>
                     83:   NULL
                     84: }
                     85: array(1) {
                     86:   [0]=>
                     87:   NULL
                     88: }
                     89: bool(false)
                     90: 
                     91: -- iteration 2 --
                     92: array(1) {
                     93:   [0]=>
                     94:   NULL
                     95: }
                     96: array(1) {
                     97:   [0]=>
                     98:   NULL
                     99: }
                    100: bool(false)
                    101: 
                    102: -- iteration 3 --
                    103: array(1) {
                    104:   [0]=>
                    105:   NULL
                    106: }
                    107: array(1) {
                    108:   [0]=>
                    109:   NULL
                    110: }
                    111: bool(false)
                    112: 
                    113: -- iteration 4 --
                    114: array(1) {
                    115:   [0]=>
                    116:   NULL
                    117: }
                    118: array(1) {
                    119:   [0]=>
                    120:   NULL
                    121: }
                    122: bool(false)
                    123: 
                    124: -- iteration 5 --
                    125: array(1) {
                    126:   [0]=>
                    127:   NULL
                    128: }
                    129: array(1) {
                    130:   [0]=>
                    131:   NULL
                    132: }
                    133: bool(false)
                    134: 
                    135: -- iteration 6 --
                    136: array(1) {
                    137:   [0]=>
                    138:   NULL
                    139: }
                    140: array(1) {
                    141:   [0]=>
                    142:   NULL
                    143: }
                    144: bool(false)
                    145: 
                    146: -- iteration 7 --
                    147: 
                    148: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
                    149: NULL
                    150: 
                    151: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
                    152: NULL
                    153: bool(false)
                    154: 
                    155: -- iteration 8 --
                    156: array(1) {
                    157:   [0]=>
                    158:   NULL
                    159: }
                    160: array(1) {
                    161:   [0]=>
                    162:   NULL
                    163: }
                    164: bool(false)
                    165: 
                    166: -- iteration 9 --
                    167: array(1) {
                    168:   [0]=>
                    169:   NULL
                    170: }
                    171: array(1) {
                    172:   [0]=>
                    173:   NULL
                    174: }
                    175: bool(false)
                    176: 
                    177: -- iteration 10 --
                    178: array(1) {
                    179:   [0]=>
                    180:   NULL
                    181: }
                    182: array(1) {
                    183:   [0]=>
                    184:   NULL
                    185: }
                    186: bool(false)
                    187: 
                    188: -- iteration 11 --
                    189: array(1) {
                    190:   [0]=>
                    191:   NULL
                    192: }
                    193: array(1) {
                    194:   [0]=>
                    195:   NULL
                    196: }
                    197: bool(false)
                    198: 
                    199: -- iteration 12 --
                    200: array(1) {
                    201:   [0]=>
                    202:   NULL
                    203: }
                    204: array(1) {
                    205:   [0]=>
                    206:   NULL
                    207: }
                    208: bool(false)
                    209: 
                    210: -- iteration 13 --
                    211: array(0) {
                    212: }
                    213: array(0) {
                    214: }
                    215: bool(false)
                    216: 
                    217: *** Done ***
                    218: 

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