Annotation of embedaddon/php/ext/standard/tests/strings/vfprintf_variation3.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test vfprintf() function : usage variations - int formats with int values
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : int vfprintf  ( resource $handle  , string $format , array $args  )
                      6:  * Description: Write a formatted string to a stream
                      7:  * Source code: ext/standard/formatted_print.c
                      8: */
                      9: 
                     10: /*
                     11:  * Test vfprintf() when different int formats and int values are passed to
                     12:  * the '$format' and '$args' arguments of the function
                     13: */
                     14: 
                     15: echo "*** Testing vfprintf() : int formats with int values ***\n";
                     16: 
                     17: 
                     18: // defining array of int formats
                     19: $formats = array(
                     20:   "%d",
                     21:   "%+d %-d %D",
                     22:   "%ld %Ld, %4d %-4d",
                     23:   "%10.4d %-10.4d %04d %04.4d",
                     24:   "%'#2d %'2d %'$2d %'_2d",
                     25:   "%d %d %d %d",
                     26:   "% %%d d%",
                     27:   '%3$d %4$d %1$d %2$d'
                     28: );
                     29: 
                     30: // Arrays of int values for the format defined in $format.
                     31: // Each sub array contains int values which correspond to each format string in $format
                     32: $args_array = array(
                     33:   array(0),
                     34:   array(-1, 1, +22),
                     35:   array(2147483647, -2147483648, +2147483640, -2147483640),
                     36:   array(123456, 12345678, -1234567, 1234567),
                     37:   array(111, 2222, 333333, 44444444),
                     38:   array(0x123b, 0xfAb, 0123, 01293),
                     39:   array(1234, -5678, 2345),
                     40:   array(3, 4, 1, 2)
                     41: 
                     42: );
                     43: 
                     44: // looping to test vfprintf() with different int formats from the above $format array
                     45: // and with int values from the above $args_array array
                     46: 
                     47: /* creating dumping file */
1.1.1.2 ! misho      48: $data_file = dirname(__FILE__) . '/vfprintf_variation3.txt';
1.1       misho      49: if (!($fp = fopen($data_file, 'wt')))
                     50:    return;
                     51: 
                     52: $counter = 1;
                     53: foreach($formats as $format) {
                     54:   fprintf($fp, "\n-- Iteration %d --\n",$counter);
                     55:   vfprintf($fp, $format, $args_array[$counter-1]);
                     56:   $counter++;
                     57: }
                     58: 
                     59: fclose($fp);
                     60: print_r(file_get_contents($data_file));
                     61: echo "\n";
                     62: 
                     63: unlink($data_file);
                     64: 
                     65: ?>
                     66: ===DONE===
                     67: --EXPECT--
                     68: *** Testing vfprintf() : int formats with int values ***
                     69: 
                     70: -- Iteration 1 --
                     71: 0
                     72: -- Iteration 2 --
                     73: -1 1 
                     74: -- Iteration 3 --
                     75: 2147483647 d, 2147483640 -2147483640
                     76: -- Iteration 4 --
                     77:     123456 12345678   -1234567 1234567
                     78: -- Iteration 5 --
                     79: 111 2222 333333 44444444
                     80: -- Iteration 6 --
                     81: 4667 4011 83 10
                     82: -- Iteration 7 --
                     83: %-5678 d
                     84: -- Iteration 8 --
                     85: 1 2 3 4
                     86: ===DONE===
                     87: 

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