PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 61 lines | 38 code | 9 blank | 14 comment | 1 complexity | ff7e22b1436c82a4c21586db59e0833c 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 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 with octal values ***\n";
  12. // defining array of octal formats
  13. $formats = varray[
  14. "%o",
  15. "%+o %-o %O",
  16. "%lo %Lo, %4o %-4o",
  17. "%10.4o %-10.4o %04o %04.4o",
  18. "%'#2o %'2o %'$2o %'_2o",
  19. "%o %o %o %o",
  20. "%% %%o %10 o%",
  21. '%3$o %4$o %1$o %2$o'
  22. ];
  23. // Arrays of octal values for the format defined in $format.
  24. // Each sub array contains octal values which correspond to each format string in $format
  25. $args_array = varray[
  26. varray[00],
  27. varray[-01, 01, +022],
  28. varray[-020000000000, 020000000000, 017777777777, -017777777777],
  29. varray[0123456, 012345678, -01234567, 01234567],
  30. varray[0111, 02222, -0333333, -044444444],
  31. varray[0x123b, 0xfAb, 0123, 01293],
  32. varray[01234, 05678, -01234, 02345],
  33. varray[03, 04, 01, 02]
  34. ];
  35. /* creating dumping file */
  36. $data_file = dirname(__FILE__) . '/vfprintf_variation11_64bit.txt';
  37. if (!($fp = fopen($data_file, 'wt')))
  38. return;
  39. // looping to test vfprintf() with different octal formats from the above $formats array
  40. // and with octal values from the above $args_array array
  41. $counter = 1;
  42. foreach($formats as $format) {
  43. fprintf($fp, "\n-- Iteration %d --\n",$counter);
  44. vfprintf($fp, $format, $args_array[$counter-1]);
  45. $counter++;
  46. }
  47. fclose($fp);
  48. print_r(file_get_contents($data_file));
  49. echo "\n";
  50. unlink($data_file);
  51. echo "===DONE===\n";
  52. }