vprintf_variation14.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. --TEST--
  2. Test vprintf() function : usage variations - hexa formats with non-hexa 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 hexa formats and non-hexa values are passed to
  11. * the '$format' and '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : hexa formats and non-hexa values ***\n";
  14. // defining array of different hexa formats
  15. $formats =
  16. '%x %+x %-x
  17. %lx x %4x %-4x
  18. %10.4x %-10.4x %.4x
  19. %\'#2x %\'2x %\'$2x %\'_2x
  20. %3$x %4$x %1$x %2$x';
  21. // Arrays of non hexa values for the format defined in $format.
  22. // Each sub array contains non hexa 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, +2e12, 22e+12,
  28. 12345.780, 12.000000011111, -12.00000111111, -123456.234,
  29. 3.33, +4.44, 1.11,-2.22 ),
  30. // array of int values
  31. array(2, -2, +2,
  32. 123456, -12346789, +12346789,
  33. 123200, +20000, 22212,
  34. 12345780, 1211111, -12111111, -12345634,
  35. 3, +4, 1,-2 ),
  36. // array of strings
  37. array(" ", ' ', 'hello',
  38. '123hello', '-123hello', '+123hello',
  39. "\12345678hello", "-\12345678hello", 'h123456ello',
  40. "1234hello", "hello\0world", "NULL", "true",
  41. "3", "4", '1', '2'),
  42. // different arrays
  43. array( array(0), array(1, 2), array(-1, -1),
  44. array("123"), array('-123'), array("-123"),
  45. array(true), array(TRUE), array(FALSE),
  46. array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
  47. array("3"), array("4"), array("1"), array("2") ),
  48. // array of boolean data
  49. array( true, TRUE, false,
  50. TRUE, FALSE, 1,
  51. true, TRUE, FALSE,
  52. 0, 1, 1, 0,
  53. 1, TRUE, 0, FALSE),
  54. );
  55. // looping to test vprintf() with different hexa formats from the above $format array
  56. // and with non-hexa values from the above $args_array array
  57. $counter = 1;
  58. foreach($args_array as $args) {
  59. echo "\n-- Iteration $counter --\n";
  60. $result = vprintf($formats, $args);
  61. echo "\n";
  62. var_dump($result);
  63. $counter++;
  64. }
  65. ?>
  66. --EXPECT--
  67. *** Testing vprintf() : hexa formats and non-hexa values ***
  68. -- Iteration 1 --
  69. 2 0 a
  70. 1e240 x fffffb2e 4d2
  71. 3039 c fffffff4 fffe1dc0
  72. a 1e240 2 0
  73. int(99)
  74. -- Iteration 2 --
  75. 2 fffffffe 2
  76. 1e240 x ff439a5b bc65a5
  77. bc61b4 127ae7 ff4732f9 ff439ede
  78. 2 1e240 2 fffffffe
  79. int(122)
  80. -- Iteration 3 --
  81. 0 0 0
  82. 7b x ffffff85 7b
  83. 4d2 0 $0 _0
  84. 0 7b 0 0
  85. int(80)
  86. -- Iteration 4 --
  87. 1 1 1
  88. 1 x 1 1
  89. #1 1 $1 _1
  90. 1 1 1 1
  91. int(73)
  92. -- Iteration 5 --
  93. 1 1 0
  94. 1 x 0 1
  95. #0 1 $1 _0
  96. 0 1 1 1
  97. int(73)