gzcompress_error1.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Test gzcompress() function : error conditions
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded("zlib")) {
  6. print "skip - ZLIB extension not loaded";
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Prototype : string gzcompress(string data [, int level, [int encoding]])
  12. * Description: Gzip-compress a string
  13. * Source code: ext/zlib/zlib.c
  14. * Alias to functions:
  15. */
  16. /*
  17. * add a comment here to say what the test is supposed to do
  18. */
  19. echo "*** Testing gzcompress() : error conditions ***\n";
  20. // Zero arguments
  21. echo "\n-- Testing gzcompress() function with Zero arguments --\n";
  22. var_dump( gzcompress() );
  23. //Test gzcompress with one more than the expected number of arguments
  24. echo "\n-- Testing gzcompress() function with more than expected no. of arguments --\n";
  25. $data = 'string_val';
  26. $level = 2;
  27. $encoding = ZLIB_ENCODING_RAW;
  28. $extra_arg = 10;
  29. var_dump( gzcompress($data, $level, $encoding, $extra_arg) );
  30. echo "\n-- Testing with incorrect compression level --\n";
  31. $bad_level = 99;
  32. var_dump(gzcompress($data, $bad_level));
  33. echo "\n-- Testing with invalid encoding --\n";
  34. $data = 'string_val';
  35. $encoding = 99;
  36. var_dump(gzcompress($data, $level, $encoding));
  37. echo "\n-- Testing with incorrect parameters --\n";
  38. class Tester {
  39. function Hello() {
  40. echo "Hello\n";
  41. }
  42. }
  43. $testclass = new Tester();
  44. var_dump(gzcompress($testclass));
  45. ?>
  46. ===Done===
  47. --EXPECTF--
  48. *** Testing gzcompress() : error conditions ***
  49. -- Testing gzcompress() function with Zero arguments --
  50. Warning: gzcompress() expects at least 1 parameter, 0 given in %s on line %d
  51. NULL
  52. -- Testing gzcompress() function with more than expected no. of arguments --
  53. Warning: gzcompress() expects at most 3 parameters, 4 given in %s on line %d
  54. NULL
  55. -- Testing with incorrect compression level --
  56. Warning: gzcompress(): compression level (99) must be within -1..9 in %s on line %d
  57. bool(false)
  58. -- Testing with invalid encoding --
  59. Warning: gzcompress(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
  60. bool(false)
  61. -- Testing with incorrect parameters --
  62. Warning: gzcompress() expects parameter 1 to be string, object given in %s on line %d
  63. NULL
  64. ===Done===