vprintf_variation12.phpt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. --TEST--
  2. Test vprintf() function : usage variations - octal formats with non-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 non-octal values are passed to
  15. * the '$format' and '$args' arguments of the function
  16. */
  17. echo "*** Testing vprintf() : octal formats and non-octal values ***\n";
  18. // defining array of octal formats
  19. $formats =
  20. '%o %+o %-o
  21. %lo %Lo %4o %-4o
  22. %10.4o %-10.4o %.4o
  23. %\'#2o %\'2o %\'$2o %\'_2o
  24. %3$o %4$o %1$o %2$o';
  25. // Arrays of non octal values for the format defined in $format.
  26. // Each sub array contains non octal values which correspond to each format in $format
  27. $args_array = array(
  28. // array of float values
  29. array(2.2, .2, 10.2,
  30. 123456.234, 123456.234, -1234.6789, +1234.6789,
  31. 2e10, +2e12, 22e+12,
  32. 12345.780, 12.000000011111, -12.00000111111, -123456.234,
  33. 3.33, +4.44, 1.11,-2.22 ),
  34. // array of int values
  35. array(2, -2, +2,
  36. 123456, 123456234, -12346789, +12346789,
  37. 123200, +20000, 22212,
  38. 12345780, 1211111, -12111111, -12345634,
  39. 3, +4, 1,-2 ),
  40. // array of strings
  41. array(" ", ' ', 'hello',
  42. '123hello', "123hello", '-123hello', '+123hello',
  43. "\12345678hello", "-\12345678hello", 'h123456ello',
  44. "1234hello", "hello\0world", "NULL", "true",
  45. "3", "4", '1', '2'),
  46. // different arrays
  47. array( array(0), array(1, 2), array(-1, -1),
  48. array("123"), array('123'), array('-123'), array("-123"),
  49. array(true), array(false), array(FALSE),
  50. array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
  51. array("3"), array("4"), array("1"), array("2") ),
  52. // array of boolean data
  53. array( true, TRUE, false,
  54. TRUE, 0, FALSE, 1,
  55. true, false, TRUE,
  56. 0, 1, 1, 0,
  57. 1, TRUE, 0, FALSE),
  58. );
  59. // looping to test vprintf() with different octal formats from the above $format array
  60. // and with non-octal values from the above $args_array array
  61. $counter = 1;
  62. foreach($args_array as $args) {
  63. echo "\n-- Iteration $counter --\n";
  64. $result = vprintf($formats, $args);
  65. echo "\n";
  66. var_dump($result);
  67. $counter++;
  68. }
  69. ?>
  70. ===DONE===
  71. --EXPECT--
  72. *** Testing vprintf() : octal formats and non-octal values ***
  73. -- Iteration 1 --
  74. 2 0 12
  75. 361100 o 37777775456 2322
  76. 30071 14 37777777764 37777416700
  77. 12 361100 2 0
  78. int(116)
  79. -- Iteration 2 --
  80. 2 37777777776 2
  81. 361100 o 37720715133 57062645
  82. 57060664 4475347 37721631371 37720717336
  83. 2 361100 2 37777777776
  84. int(146)
  85. -- Iteration 3 --
  86. 0 0 0
  87. 173 o 37777777605 173
  88. 2322 0 $0 _0
  89. 0 173 0 0
  90. int(88)
  91. -- Iteration 4 --
  92. 1 1 1
  93. 1 o 1 1
  94. #1 1 $1 _1
  95. 1 1 1 1
  96. int(75)
  97. -- Iteration 5 --
  98. 1 1 0
  99. 1 o 0 1
  100. #0 1 $1 _0
  101. 0 1 1 1
  102. int(75)
  103. ===DONE===