Annotation of embedaddon/php/ext/zlib/tests/gzopen_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test gzopen() function : usage variation
3: --SKIPIF--
4: <?php
5: if (!extension_loaded("zlib")) {
6: print "skip - zlib extension not loaded";
7: }
8: ?>
9: --FILE--
10: <?php
11: /* Prototype : resource gzopen(string filename, string mode [, int use_include_path])
12: * Description: Open a .gz-file and return a .gz-file pointer
13: * Source code: ext/zlib/zlib.c
14: * Alias to functions:
15: */
16:
17: echo "*** Testing gzopen() : usage variation ***\n";
18:
19: // Define error handler
20: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
21: if (error_reporting() != 0) {
22: // report non-silenced errors
23: echo "Error: $err_no - $err_msg, $filename($linenum)\n";
24: }
25: }
26: set_error_handler('test_error_handler');
27:
28: // Initialise function arguments not being substituted (if any)
29: $filename = dirname(__FILE__)."/004.txt.gz";
30: $mode = 'r';
31:
32: //get an unset variable
33: $unset_var = 10;
34: unset ($unset_var);
35:
36: // define some classes
37: class classWithToString
38: {
39: public function __toString() {
40: return "Class A object";
41: }
42: }
43:
44: class classWithoutToString
45: {
46: }
47:
48: // heredoc string
49: $heredoc = <<<EOT
50: hello world
51: EOT;
52:
53: // get a resource variable
54: $fp = fopen(__FILE__, "r");
55:
56: // add arrays
57: $index_array = array (1, 2, 3);
58: $assoc_array = array ('one' => 1, 'two' => 2);
59:
60: //array of values to iterate over
61: $inputs = array(
62:
63: // float data
64: 'float 10.5' => 10.5,
65: 'float -10.5' => -10.5,
66: 'float 12.3456789000e10' => 12.3456789000e10,
67: 'float -12.3456789000e10' => -12.3456789000e10,
68: 'float .5' => .5,
69:
70: // array data
71: 'empty array' => array(),
72: 'int indexed array' => $index_array,
73: 'associative array' => $assoc_array,
74: 'nested arrays' => array('foo', $index_array, $assoc_array),
75:
76: // null data
77: 'uppercase NULL' => NULL,
78: 'lowercase null' => null,
79:
80: // boolean data
81: 'lowercase true' => true,
82: 'lowercase false' =>false,
83: 'uppercase TRUE' =>TRUE,
84: 'uppercase FALSE' =>FALSE,
85:
86: // empty data
87: 'empty string DQ' => "",
88: 'empty string SQ' => '',
89:
90: // string data
91: 'string DQ' => "string",
92: 'string SQ' => 'string',
93: 'mixed case string' => "sTrInG",
94: 'heredoc' => $heredoc,
95:
96: // object data
97: 'instance of classWithToString' => new classWithToString(),
98: 'instance of classWithoutToString' => new classWithoutToString(),
99:
100: // undefined data
101: 'undefined var' => @$undefined_var,
102:
103: // unset data
104: 'unset var' => @$unset_var,
105:
106: // resource variable
107: 'resource' => $fp
108: );
109:
110: // loop through each element of the array for use_include_path
111:
112: foreach($inputs as $key =>$value) {
113: echo "\n--$key--\n";
114: $res = gzopen($filename, $mode, $value);
115: var_dump($res);
116: if ($res === true) {
117: gzclose($res);
118: }
119: };
120:
121: fclose($fp);
122:
123: ?>
124: ===DONE===
125: --EXPECTF--
126: *** Testing gzopen() : usage variation ***
127:
128: --float 10.5--
129: resource(%d) of type (stream)
130:
131: --float -10.5--
132: resource(%d) of type (stream)
133:
134: --float 12.3456789000e10--
135: resource(%d) of type (stream)
136:
137: --float -12.3456789000e10--
138: resource(%d) of type (stream)
139:
140: --float .5--
141: resource(%d) of type (stream)
142:
143: --empty array--
144: Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
145: NULL
146:
147: --int indexed array--
148: Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
149: NULL
150:
151: --associative array--
152: Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
153: NULL
154:
155: --nested arrays--
156: Error: 2 - gzopen() expects parameter 3 to be long, array given, %s(%d)
157: NULL
158:
159: --uppercase NULL--
160: resource(%d) of type (stream)
161:
162: --lowercase null--
163: resource(%d) of type (stream)
164:
165: --lowercase true--
166: resource(%d) of type (stream)
167:
168: --lowercase false--
169: resource(%d) of type (stream)
170:
171: --uppercase TRUE--
172: resource(%d) of type (stream)
173:
174: --uppercase FALSE--
175: resource(%d) of type (stream)
176:
177: --empty string DQ--
178: Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
179: NULL
180:
181: --empty string SQ--
182: Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
183: NULL
184:
185: --string DQ--
186: Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
187: NULL
188:
189: --string SQ--
190: Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
191: NULL
192:
193: --mixed case string--
194: Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
195: NULL
196:
197: --heredoc--
198: Error: 2 - gzopen() expects parameter 3 to be long, string given, %s(%d)
199: NULL
200:
201: --instance of classWithToString--
202: Error: 2 - gzopen() expects parameter 3 to be long, object given, %s(%d)
203: NULL
204:
205: --instance of classWithoutToString--
206: Error: 2 - gzopen() expects parameter 3 to be long, object given, %s(%d)
207: NULL
208:
209: --undefined var--
210: resource(%d) of type (stream)
211:
212: --unset var--
213: resource(%d) of type (stream)
214:
215: --resource--
216: Error: 2 - gzopen() expects parameter 3 to be long, resource given, %s(%d)
217: NULL
218: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>