vprintf_variation13.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --TEST--
  2. Test vprintf() function : usage variations - hexa formats with 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 hexa values are passed to
  11. * the '$format' and '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : hexa formats with hexa values ***\n";
  14. // defining array of different hexa formats
  15. $formats = array(
  16. "%x",
  17. "%+x %-x %X",
  18. "%lx %4x %-4x",
  19. "%10.4x %-10.4x %04x %04.4x",
  20. "%'#2x %'2x %'$2x %'_2x",
  21. "%x %x %x %x",
  22. "% %%x",
  23. '%3$x %4$x %1$x %2$x'
  24. );
  25. // Arrays of hexa values for the format defined in $format.
  26. // Each sub array contains hexa values which correspond to each format string in $format
  27. $args_array = array(
  28. array(0x0),
  29. array(-0x1, 0x1, +0x22),
  30. array(0x7FFFFFFF, +0x7000000, -0x80000000),
  31. array(123456, 12345678, -1234567, 1234567),
  32. array(1, 0x2222, 0333333, -0x44444444),
  33. array(0x123b, 0xfAb, "0xaxz", 012),
  34. array(0x1234, 0x34, 0x2ff),
  35. array(0x3, 0x4, 0x1, 0x2)
  36. );
  37. // looping to test vprintf() with different char octal from the above $format array
  38. // and with octal values from the above $args_array array
  39. $counter = 1;
  40. foreach($formats as $format) {
  41. echo "\n-- Iteration $counter --\n";
  42. $result = vprintf($format, $args_array[$counter-1]);
  43. echo "\n";
  44. var_dump($result);
  45. $counter++;
  46. }
  47. ?>
  48. --EXPECT--
  49. *** Testing vprintf() : hexa formats with hexa values ***
  50. -- Iteration 1 --
  51. 0
  52. int(1)
  53. -- Iteration 2 --
  54. ffffffff 1 22
  55. int(13)
  56. -- Iteration 3 --
  57. 7fffffff 7000000 80000000
  58. int(25)
  59. -- Iteration 4 --
  60. ffed2979 0000
  61. int(35)
  62. -- Iteration 5 --
  63. #1 2222 1b6db bbbbbbbc
  64. int(22)
  65. -- Iteration 6 --
  66. 123b fab 0 a
  67. int(12)
  68. -- Iteration 7 --
  69. %34
  70. int(3)
  71. -- Iteration 8 --
  72. 1 2 3 4
  73. int(7)