vfprintf_basic.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Test vfprintf() function : basic functionality
  3. --CREDITS--
  4. Felix De Vliegher <felix.devliegher@gmail.com>
  5. --INI--
  6. precision=14
  7. --FILE--
  8. <?php
  9. function writeAndDump($fp, $format, $args)
  10. {
  11. ftruncate( $fp, 0 );
  12. $length = vfprintf( $fp, $format, $args );
  13. rewind( $fp );
  14. $content = stream_get_contents( $fp );
  15. var_dump( $content );
  16. var_dump( $length );
  17. }
  18. echo "*** Testing vfprintf() : basic functionality ***\n";
  19. // Open handle
  20. $file = 'vfprintf_basic.txt';
  21. $fp = fopen( $file, "a+" );
  22. // Test vfprintf()
  23. writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) );
  24. writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) );
  25. writeAndDump( $fp, "%d digit", array( '54' ) );
  26. writeAndDump( $fp, "%b %b", array( true, false ) );
  27. writeAndDump( $fp, "%c %c %c", array( 65, 66, 67 ) );
  28. writeAndDump( $fp, "%e %E %e", array( 1000, 2e4, +2e2 ) );
  29. writeAndDump( $fp, "%02d", array( 50 ) );
  30. writeAndDump( $fp, "Testing %b %d %f %s %x %X", array( 9, 6, 2.5502, "foobar", 15, 65 ) );
  31. // Close handle
  32. fclose( $fp );
  33. ?>
  34. --CLEAN--
  35. <?php
  36. $file = 'vfprintf_basic.txt';
  37. unlink( $file );
  38. ?>
  39. --EXPECT--
  40. *** Testing vfprintf() : basic functionality ***
  41. string(17) "Foo is 30 and bar"
  42. int(17)
  43. string(11) "bar bar bar"
  44. int(11)
  45. string(8) "54 digit"
  46. int(8)
  47. string(3) "1 0"
  48. int(3)
  49. string(5) "A B C"
  50. int(5)
  51. string(35) "1.000000e+3 2.000000E+4 2.000000e+2"
  52. int(35)
  53. string(2) "50"
  54. int(2)
  55. string(35) "Testing 1001 6 2.550200 foobar f 41"
  56. int(35)