vprintf_variation4.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --TEST--
  2. Test vprintf() function : usage variations - int formats with non-integer 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. /*
  10. * Test vprintf() when different int formats and non-int values are passed to
  11. * the '$format' and '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : int formats and non-integer values ***\n";
  14. // defining array of int formats
  15. $formats =
  16. '%d %+d %-d
  17. %ld %4d %-4d
  18. %10.4d %-10.4d %.4d %04.4d
  19. %\'#2d %\'2d %\'$2d %\'_2d
  20. %3$d %4$d %1$d %2$d';
  21. // Arrays of non int values for the format defined in $format.
  22. // Each sub array contains non int values which correspond to each format in $format
  23. $args_array = array(
  24. // array of float values
  25. array(2.2, .2, 10.2,
  26. 123456.234, -1234.6789, +1234.6789,
  27. 2e10, +2e5, 4e3, 22e+6,
  28. 12345.780, 12.000000011111, -12.00000111111, -123456.234,
  29. 3.33, +4.44, 1.11,-2.22 ),
  30. // array of strings
  31. array(" ", ' ', 'hello',
  32. '123hello', '-123hello', '+123hello',
  33. "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
  34. "1234hello", "hello\0world", "NULL", "true",
  35. "3", "4", '1', '2'),
  36. // different arrays
  37. array( array(0), array(1, 2), array(-1, -1),
  38. array("123"), array('-123'), array("-123"),
  39. array(true), array(false), array(TRUE), array(FALSE),
  40. array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
  41. array("3"), array("4"), array("1"), array("2") ),
  42. // array of boolean data
  43. array( true, TRUE, false,
  44. TRUE, FALSE, 1,
  45. true, false, TRUE, FALSE,
  46. 0, 1, 1, 0,
  47. 1, TRUE, 0, FALSE),
  48. );
  49. // looping to test vprintf() with different int formats from the above $format array
  50. // and with non-int values from the above $args_array array
  51. $counter = 1;
  52. foreach($args_array as $args) {
  53. echo "\n-- Iteration $counter --\n";
  54. $result = vprintf($formats, $args);
  55. echo "\n";
  56. var_dump($result);
  57. $counter++;
  58. }
  59. ?>
  60. --EXPECT--
  61. *** Testing vprintf() : int formats and non-integer values ***
  62. -- Iteration 1 --
  63. 2 +0 10
  64. 123456 -1234 1234
  65. -1474836480 200000 4000 22000000
  66. 12345 12 -12 -123456
  67. 10 123456 2 0
  68. int(109)
  69. -- Iteration 2 --
  70. 0 +0 0
  71. 123 -123 123
  72. 0 0 123456 0000
  73. 1234 0 $0 _0
  74. 0 123 0 0
  75. int(89)
  76. -- Iteration 3 --
  77. 1 +1 1
  78. 1 1 1
  79. 1 1 1 0001
  80. #1 1 $1 _1
  81. 1 1 1 1
  82. int(78)
  83. -- Iteration 4 --
  84. 1 +1 0
  85. 1 0 1
  86. 1 0 1 0000
  87. #0 1 $1 _0
  88. 0 1 1 1
  89. int(78)