vprintf_variation11.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /* 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 octal formats and octal values are passed to
  15. * the '$format' and '$args' arguments of the function
  16. */
  17. echo "*** Testing vprintf() : octal formats with octal values ***\n";
  18. // defining array of octal formats
  19. $formats = array(
  20. "%o",
  21. "%+o %-o %O",
  22. "%lo %Lo, %4o %-4o",
  23. "%10.4o %-10.4o %04o %04.4o",
  24. "%'#2o %'2o %'$2o %'_2o",
  25. "%o %o %o %o",
  26. "%% %%o %10 o%",
  27. '%3$o %4$o %1$o %2$o'
  28. );
  29. // Arrays of octal values for the format defined in $format.
  30. // Each sub array contains octal values which correspond to each format string in $format
  31. $args_array = array(
  32. array(00),
  33. array(-01, 01, +022),
  34. array(-020000000000, 020000000000, 017777777777, -017777777777),
  35. array(0123456, 012345678, -01234567, 01234567),
  36. array(0111, 02222, -0333333, -044444444),
  37. array(0x123b, 0xfAb, 0123, 01293),
  38. array(01234, 05678, -01234, 02345),
  39. array(03, 04, 01, 02)
  40. );
  41. // looping to test vprintf() with different octal formats from the above $formats array
  42. // and with octal values from the above $args_array array
  43. $counter = 1;
  44. foreach($formats as $format) {
  45. echo "\n-- Iteration $counter --\n";
  46. $result = vprintf($format, $args_array[$counter-1]);
  47. echo "\n";
  48. var_dump($result);
  49. $counter++;
  50. }
  51. ?>
  52. ===DONE===
  53. --EXPECT--
  54. *** Testing vprintf() : octal formats with octal values ***
  55. -- Iteration 1 --
  56. 0
  57. int(1)
  58. -- Iteration 2 --
  59. 37777777777 1
  60. int(14)
  61. -- Iteration 3 --
  62. 20000000000 o, 17777777777 20000000001
  63. int(38)
  64. -- Iteration 4 --
  65. 37776543211 0000
  66. int(38)
  67. -- Iteration 5 --
  68. 111 2222 37777444445 37733333334
  69. int(32)
  70. -- Iteration 6 --
  71. 11073 7653 123 12
  72. int(17)
  73. -- Iteration 7 --
  74. % %o o
  75. int(6)
  76. -- Iteration 8 --
  77. 1 2 3 4
  78. int(7)
  79. ===DONE===