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

1.1       misho       1: --TEST--
                      2: Test fscanf() function: usage variations - string formats with boolean 
                      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 boolean data using different string format types */
                     12: 
                     13: $file_path = dirname(__FILE__);
                     14: 
                     15: echo "*** Test fscanf(): different string format types with boolean data ***\n"; 
                     16: 
                     17: // create a file
                     18: $filename = "$file_path/fscanf_variation19.tmp";
                     19: $file_handle = fopen($filename, "w");
                     20: if($file_handle == false)
                     21:   exit("Error:failed to open file $filename");
                     22: 
                     23: // array of boolean types
                     24: $bool_types = array (
                     25:   true,
                     26:   false,
                     27:   TRUE,
                     28:   FALSE,
                     29: );
                     30: 
                     31: $string_formats = array( "%s",
                     32:                          "%hs", "%ls", "%Ls",
                     33:                          " %s", "%s ", "% s",
                     34:                         "\t%s", "\n%s", "%4s",
                     35:                         "%30s", "%[a-zA-Z0-9]", "%*s");
                     36: 
                     37: $counter = 1;
                     38: 
                     39: // writing to the file
                     40: foreach($bool_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 string formats
                     55: foreach($string_formats as $string_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,$string_format) );
                     61:   }
                     62:   $counter++;
                     63: }
                     64: 
                     65: echo "\n*** Done ***";
                     66: ?>
                     67: --CLEAN--
                     68: <?php
                     69: $file_path = dirname(__FILE__);
                     70: $filename = "$file_path/fscanf_variation19.tmp";
                     71: unlink($filename);
                     72: ?>
                     73: --EXPECTF--
                     74: *** Test fscanf(): different string format types with boolean data ***
                     75: 
                     76: -- iteration 1 --
                     77: array(1) {
                     78:   [0]=>
                     79:   string(1) "1"
                     80: }
                     81: NULL
                     82: array(1) {
                     83:   [0]=>
                     84:   string(1) "1"
                     85: }
                     86: NULL
                     87: bool(false)
                     88: 
                     89: -- iteration 2 --
                     90: array(1) {
                     91:   [0]=>
                     92:   string(1) "1"
                     93: }
                     94: NULL
                     95: array(1) {
                     96:   [0]=>
                     97:   string(1) "1"
                     98: }
                     99: NULL
                    100: bool(false)
                    101: 
                    102: -- iteration 3 --
                    103: array(1) {
                    104:   [0]=>
                    105:   string(1) "1"
                    106: }
                    107: NULL
                    108: array(1) {
                    109:   [0]=>
                    110:   string(1) "1"
                    111: }
                    112: NULL
                    113: bool(false)
                    114: 
                    115: -- iteration 4 --
                    116: array(1) {
                    117:   [0]=>
                    118:   string(1) "1"
                    119: }
                    120: NULL
                    121: array(1) {
                    122:   [0]=>
                    123:   string(1) "1"
                    124: }
                    125: NULL
                    126: bool(false)
                    127: 
                    128: -- iteration 5 --
                    129: array(1) {
                    130:   [0]=>
                    131:   string(1) "1"
                    132: }
                    133: NULL
                    134: array(1) {
                    135:   [0]=>
                    136:   string(1) "1"
                    137: }
                    138: NULL
                    139: bool(false)
                    140: 
                    141: -- iteration 6 --
                    142: array(1) {
                    143:   [0]=>
                    144:   string(1) "1"
                    145: }
                    146: NULL
                    147: array(1) {
                    148:   [0]=>
                    149:   string(1) "1"
                    150: }
                    151: NULL
                    152: bool(false)
                    153: 
                    154: -- iteration 7 --
                    155: 
                    156: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
                    157: NULL
                    158: 
                    159: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
                    160: NULL
                    161: 
                    162: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
                    163: NULL
                    164: 
                    165: Warning: fscanf(): Bad scan conversion character " " in %s on line %d
                    166: NULL
                    167: bool(false)
                    168: 
                    169: -- iteration 8 --
                    170: array(1) {
                    171:   [0]=>
                    172:   string(1) "1"
                    173: }
                    174: NULL
                    175: array(1) {
                    176:   [0]=>
                    177:   string(1) "1"
                    178: }
                    179: NULL
                    180: bool(false)
                    181: 
                    182: -- iteration 9 --
                    183: array(1) {
                    184:   [0]=>
                    185:   string(1) "1"
                    186: }
                    187: NULL
                    188: array(1) {
                    189:   [0]=>
                    190:   string(1) "1"
                    191: }
                    192: NULL
                    193: bool(false)
                    194: 
                    195: -- iteration 10 --
                    196: array(1) {
                    197:   [0]=>
                    198:   string(1) "1"
                    199: }
                    200: NULL
                    201: array(1) {
                    202:   [0]=>
                    203:   string(1) "1"
                    204: }
                    205: NULL
                    206: bool(false)
                    207: 
                    208: -- iteration 11 --
                    209: array(1) {
                    210:   [0]=>
                    211:   string(1) "1"
                    212: }
                    213: NULL
                    214: array(1) {
                    215:   [0]=>
                    216:   string(1) "1"
                    217: }
                    218: NULL
                    219: bool(false)
                    220: 
                    221: -- iteration 12 --
                    222: array(1) {
                    223:   [0]=>
                    224:   string(1) "1"
                    225: }
                    226: array(1) {
                    227:   [0]=>
                    228:   NULL
                    229: }
                    230: array(1) {
                    231:   [0]=>
                    232:   string(1) "1"
                    233: }
                    234: array(1) {
                    235:   [0]=>
                    236:   NULL
                    237: }
                    238: bool(false)
                    239: 
                    240: -- iteration 13 --
                    241: array(0) {
                    242: }
                    243: NULL
                    244: array(0) {
                    245: }
                    246: NULL
                    247: bool(false)
                    248: 
                    249: *** Done ***
                    250: 

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