PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/vfprintf_variation12_64bit.php

http://github.com/facebook/hiphop-php
PHP | 84 lines | 51 code | 14 blank | 19 comment | 1 complexity | 418948eb1f06c97991533d8be79d2c1f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : int vfprintf ( resource $handle , string $format , array $args )
  3. * Description: Write a formatted string to a stream
  4. * Source code: ext/standard/formatted_print.c
  5. */
  6. /*
  7. * Test vfprintf() when different octal formats and non-octal values are passed to
  8. * the '$format' and '$args' arguments of the function
  9. */
  10. <<__EntryPoint>> function main(): void {
  11. echo "*** Testing vfprintf() : octal formats and non-octal values ***\n";
  12. // defining array of octal formats
  13. $formats =
  14. '%o %+o %-o
  15. %lo %Lo %4o %-4o
  16. %10.4o %-10.4o %.4o
  17. %\'#2o %\'2o %\'$2o %\'_2o
  18. %3$o %4$o %1$o %2$o';
  19. // Arrays of non octal values for the format defined in $format.
  20. // Each sub array contains non octal values which correspond to each format in $format
  21. $args_array = varray[
  22. // array of float values
  23. varray[2.2, .2, 10.2,
  24. 123456.234, 123456.234, -1234.6789, +1234.6789,
  25. 2e10, +2e12, 22e+12,
  26. 12345.780, 12.000000011111, -12.00000111111, -123456.234,
  27. 3.33, +4.44, 1.11,-2.22 ],
  28. // array of int values
  29. varray[2, -2, +2,
  30. 123456, 123456234, -12346789, +12346789,
  31. 123200, +20000, 22212,
  32. 12345780, 1211111, -12111111, -12345634,
  33. 3, +4, 1,-2 ],
  34. // array of strings
  35. varray[" ", ' ', 'hello',
  36. '123hello', "123hello", '-123hello', '+123hello',
  37. "\12345678hello", "-\12345678hello", 'h123456ello',
  38. "1234hello", "hello\0world", "NULL", "true",
  39. "3", "4", '1', '2'],
  40. // different arrays
  41. varray[ varray[0], varray[1, 2], varray[-1, -1],
  42. varray["123"], varray['123'], varray['-123'], varray["-123"],
  43. varray[true], varray[false], varray[FALSE],
  44. varray["123hello"], varray["1", "2"], varray['123hello'], darray[12=>"12twelve"],
  45. varray["3"], varray["4"], varray["1"], varray["2"] ],
  46. // array of boolean data
  47. varray[ true, TRUE, false,
  48. TRUE, 0, FALSE, 1,
  49. true, false, TRUE,
  50. 0, 1, 1, 0,
  51. 1, TRUE, 0, FALSE],
  52. ];
  53. /* creating dumping file */
  54. $data_file = dirname(__FILE__) . '/vfprintf_variation12_64bit.txt';
  55. if (!($fp = fopen($data_file, 'wt')))
  56. return;
  57. // looping to test vfprintf() with different octal formats from the above $format array
  58. // and with non-octal values from the above $args_array array
  59. $counter = 1;
  60. foreach($args_array as $args) {
  61. fprintf($fp, "\n-- Iteration %d --\n",$counter);
  62. vfprintf($fp, $formats, $args);
  63. $counter++;
  64. }
  65. fclose($fp);
  66. print_r(file_get_contents($data_file));
  67. echo "\n";
  68. unlink($data_file);
  69. echo "===DONE===\n";
  70. }