1--TEST--
2Test gzdeflate() function : error conditions
3--SKIPIF--
4<?php
5if (!extension_loaded("zlib")) {
6	print "skip - ZLIB extension not loaded";
7}
8?>
9--FILE--
10<?php
11/* Prototype  : string gzdeflate(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/*
18 * add a comment here to say what the test is supposed to do
19 */
20
21echo "*** Testing gzdeflate() : error conditions ***\n";
22
23// Zero arguments
24echo "\n-- Testing gzdeflate() function with Zero arguments --\n";
25var_dump( gzdeflate() );
26
27//Test gzdeflate with one more than the expected number of arguments
28echo "\n-- Testing gzdeflate() function with more than expected no. of arguments --\n";
29$data = 'string_val';
30$level = 2;
31$encoding = ZLIB_ENCODING_RAW;
32$extra_arg = 10;
33var_dump( gzdeflate($data, $level, $encoding, $extra_arg) );
34
35echo "\n-- Testing with incorrect compression level --\n";
36$bad_level = 99;
37var_dump(gzdeflate($data, $bad_level));
38
39echo "\n-- Testing with incorrect encoding --\n";
40$bad_encoding = 99;
41var_dump(gzdeflate($data, $level, $bad_encoding));
42
43class Tester {
44    function Hello() {
45        echo "Hello\n";
46    }
47}
48
49echo "\n-- Testing with incorrect parameters --\n";
50$testclass = new Tester();
51var_dump(gzdeflate($testclass));
52var_dump(gzdeflate($data, $testclass));
53
54?>
55===Done===
56--EXPECTF--
57*** Testing gzdeflate() : error conditions ***
58
59-- Testing gzdeflate() function with Zero arguments --
60
61Warning: gzdeflate() expects at least 1 parameter, 0 given in %s on line %d
62NULL
63
64-- Testing gzdeflate() function with more than expected no. of arguments --
65
66Warning: gzdeflate() expects at most 3 parameters, 4 given in %s on line %d
67NULL
68
69-- Testing with incorrect compression level --
70
71Warning: gzdeflate(): compression level (99) must be within -1..9 in %s on line %d
72bool(false)
73
74-- Testing with incorrect encoding --
75
76Warning: gzdeflate(): encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d
77bool(false)
78
79-- Testing with incorrect parameters --
80
81Warning: gzdeflate() expects parameter 1 to be string, object given in %s on line %d
82NULL
83
84Warning: gzdeflate() expects parameter 2 to be integer, object given in %s on line %d
85NULL
86===Done===
87