vprintf_variation12.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /*
  10. * Test vprintf() when different octal formats and non-octal values are passed to
  11. * the '$format' and '$args' arguments of the function
  12. */
  13. echo "*** Testing vprintf() : octal formats and non-octal values ***\n";
  14. // defining array of octal formats
  15. $formats =
  16. '%o %+o %-o
  17. %lo %4o %-4o
  18. %10.4o %-10.4o %.4o
  19. %\'#2o %\'2o %\'$2o %\'_2o
  20. %3$o %4$o %1$o %2$o';
  21. // Arrays of non octal values for the format defined in $format.
  22. // Each sub array contains non octal 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(false), 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, false, TRUE,
  52. 0, 1, 1, 0,
  53. 1, TRUE, 0, FALSE),
  54. );
  55. // looping to test vprintf() with different octal formats from the above $format array
  56. // and with non-octal 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() : octal formats and non-octal values ***
  68. -- Iteration 1 --
  69. 2 0 12
  70. 361100 37777775456 2322
  71. 30071 14 37777777764 37777416700
  72. 12 361100 2 0
  73. int(112)
  74. -- Iteration 2 --
  75. 2 37777777776 2
  76. 361100 37720715133 57062645
  77. 57060664 4475347 37721631371 37720717336
  78. 2 361100 2 37777777776
  79. int(142)
  80. -- Iteration 3 --
  81. 0 0 0
  82. 173 37777777605 173
  83. 2322 0 $0 _0
  84. 0 173 0 0
  85. int(84)
  86. -- Iteration 4 --
  87. 1 1 1
  88. 1 1 1
  89. #1 1 $1 _1
  90. 1 1 1 1
  91. int(71)
  92. -- Iteration 5 --
  93. 1 1 0
  94. 1 0 1
  95. #0 1 $1 _0
  96. 0 1 1 1
  97. int(71)