vprintf_variation11.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --TEST--
  2. Test vprintf() function : usage variations - octal formats with octal 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 octal formats and octal values are passed to
  11. * the '$format' and '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : octal formats with octal values ***\n";
  14. // defining array of octal formats
  15. $formats = array(
  16. "%o",
  17. "%+o %-o",
  18. "%lo %4o %-4o",
  19. "%10.4o %-10.4o %04o %04.4o",
  20. "%'#2o %'2o %'$2o %'_2o",
  21. "%o %o %o %o",
  22. "%% %%o",
  23. '%3$o %4$o %1$o %2$o'
  24. );
  25. // Arrays of octal values for the format defined in $format.
  26. // Each sub array contains octal values which correspond to each format string in $format
  27. $args_array = array(
  28. array(00),
  29. array(-01, 01),
  30. array(-020000000000, 017777777777, -017777777777),
  31. array(0123456, 01234567, -01234567, 01234567),
  32. array(0111, 02222, -0333333, -044444444),
  33. array(0x123b, 0xfAb, 0123, 012),
  34. array(01234, 0567),
  35. array(03, 04, 01, 02)
  36. );
  37. // looping to test vprintf() with different octal formats from the above $formats 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() : octal formats with octal values ***
  50. -- Iteration 1 --
  51. 0
  52. int(1)
  53. -- Iteration 2 --
  54. 37777777777 1
  55. int(13)
  56. -- Iteration 3 --
  57. 20000000000 17777777777 20000000001
  58. int(35)
  59. -- Iteration 4 --
  60. 37776543211 0000
  61. int(38)
  62. -- Iteration 5 --
  63. 111 2222 37777444445 37733333334
  64. int(32)
  65. -- Iteration 6 --
  66. 11073 7653 123 12
  67. int(17)
  68. -- Iteration 7 --
  69. % %o
  70. int(4)
  71. -- Iteration 8 --
  72. 1 2 3 4
  73. int(7)