vprintf_variation16.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. --TEST--
  2. Test vprintf() function : usage variations - unsigned formats with signed and other types of values
  3. --SKIPIF--
  4. <?php
  5. if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
  6. ?>
  7. --FILE--
  8. <?php
  9. /* Prototype : string vprintf(string format, array args)
  10. * Description: Output a formatted string
  11. * Source code: ext/standard/formatted_print.c
  12. */
  13. /*
  14. * Test vprintf() when different unsigned formats and signed values and other types of values
  15. * are passed to the '$format' and '$args' arguments of the function
  16. */
  17. echo "*** Testing vprintf() : unsigned formats and signed & other types of values ***\n";
  18. // defining array of unsigned formats
  19. $formats =
  20. '%u %+u %-u
  21. %lu %Lu %4u %-4u
  22. %10.4u %-10.4u %.4u
  23. %\'#2u %\'2u %\'$2u %\'_2u
  24. %3$u %4$u %1$u %2$u';
  25. // Arrays of signed and other type of values for the format defined in $format.
  26. // Each sub array contains signed values which correspond to each format in $format
  27. $args_array = array(
  28. // array of float values
  29. array(+2.2, +.2, +10.2,
  30. +123456.234, +123456.234, +1234.6789,
  31. +2e10, +2e12, +22e+12,
  32. +12345.780, +12.000000011111, -12.00000111111, -123456.234,
  33. +3.33, +4.44, +1.11,-2.22 ),
  34. // array of strings
  35. array(" ", ' ', 'hello',
  36. '123hello', "123hello", '-123hello', '+123hello',
  37. "\12345678hello", "-\12345678hello", 'h123456ello',
  38. "1234hello", "hello\0world", "NULL", "true",
  39. "3", "4", '1', '2'),
  40. // different arrays
  41. array( array(0), array(1, 2), array(-1, -1),
  42. array("123"), array('123'), array('-123'), array("-123"),
  43. array(true), array(TRUE), array(FALSE),
  44. array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
  45. array("3"), array("4"), array("1"), array("2") ),
  46. // array of boolean data
  47. array( true, TRUE, false,
  48. TRUE, 0, FALSE, 1,
  49. true, TRUE, FALSE,
  50. 0, 1, 1, 0,
  51. 1, TRUE, 0, FALSE),
  52. );
  53. // looping to test vprintf() with different unsigned formats from the above $format array
  54. // and with signed and other types of values from the above $args_array array
  55. $counter = 1;
  56. foreach($args_array as $args) {
  57. echo "\n-- Iteration $counter --\n";
  58. $result = vprintf($formats, $args);
  59. echo "\n";
  60. var_dump($result);
  61. $counter++;
  62. }
  63. ?>
  64. ===DONE===
  65. --EXPECT--
  66. *** Testing vprintf() : unsigned formats and signed & other types of values ***
  67. -- Iteration 1 --
  68. 2 0 10
  69. 123456 u 1234 2820130816
  70. 2840207360 1177509888 12345
  71. 12 4294967284 4294843840 _3
  72. 10 123456 2 0
  73. int(115)
  74. -- Iteration 2 --
  75. 0 0 0
  76. 123 u 4294967173 123
  77. 0 0 0
  78. 1234 0 $0 _0
  79. 0 123 0 0
  80. int(88)
  81. -- Iteration 3 --
  82. 1 1 1
  83. 1 u 1 1
  84. 1 1 1
  85. #1 1 $1 _1
  86. 1 1 1 1
  87. int(76)
  88. -- Iteration 4 --
  89. 1 1 0
  90. 1 u 0 1
  91. 1 1 0
  92. #0 1 $1 _0
  93. 0 1 1 1
  94. int(76)
  95. ===DONE===