1--TEST--
2disabled php only for class methods (ini_set)
3--SKIPIF--
4--FILE--
5<?php
6if(!extension_loaded('msgpack')) {
7    dl('msgpack.' . PHP_SHLIB_SUFFIX);
8}
9
10ini_set('msgpack.php_only', 0);
11
12function test($type, $variable, $test = null) {
13    $msgpack = new MessagePack();
14
15    $serialized = $msgpack->pack($variable);
16    $unserialized = $msgpack->unpack($serialized);
17
18    var_dump($unserialized);
19
20    if (!is_bool($test))
21    {
22        echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
23    }
24    else
25    {
26        echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
27    }
28}
29
30test('null', null);
31
32test('bool: true', true);
33test('bool: false', false);
34
35test('zero: 0', 0);
36test('small: 1', 1);
37test('small: -1', -1);
38test('medium: 1000', 1000);
39test('medium: -1000', -1000);
40test('large: 100000', 100000);
41test('large: -100000', -100000);
42
43test('double: 123.456', 123.456);
44
45test('empty: ""', "");
46test('string: "foobar"', "foobar");
47
48test('array: empty', array(), false);
49test('array(1, 2, 3)', array(1, 2, 3), false);
50test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false);
51
52test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false);
53test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false);
54test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false);
55test('array("" => "empty")', array("" => "empty"), false);
56
57$a = array('foo');
58test('array($a, $a)', array($a, $a), false);
59test('array(&$a, &$a)', array(&$a, &$a), false);
60
61$a = array(null);
62$b = array(&$a);
63$a[0] = &$b;
64
65test('cyclic', $a, true);
66
67$a = array(
68    'a' => array(
69        'b' => 'c',
70        'd' => 'e'
71        ),
72    'f' => array(
73        'g' => 'h'
74        )
75    );
76
77test('array', $a, false);
78
79class Obj {
80    public $a;
81    protected $b;
82    private $c;
83
84    function __construct($a, $b, $c) {
85        $this->a = $a;
86        $this->b = $b;
87        $this->c = $c;
88    }
89}
90
91test('object', new Obj(1, 2, 3), true);
92
93test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true);
94
95$o = new Obj(1, 2, 3);
96
97test('object', array(&$o, &$o), true);
98--EXPECTF--
99NULL
100OK
101bool(true)
102OK
103bool(false)
104OK
105int(0)
106OK
107int(1)
108OK
109int(-1)
110OK
111int(1000)
112OK
113int(-1000)
114OK
115int(100000)
116OK
117int(-100000)
118OK
119float(123.456)
120OK
121string(0) ""
122OK
123string(6) "foobar"
124OK
125array(0) {
126}
127OK
128array(3) {
129  [0]=>
130  int(1)
131  [1]=>
132  int(2)
133  [2]=>
134  int(3)
135}
136OK
137array(3) {
138  [0]=>
139  array(3) {
140    [0]=>
141    int(1)
142    [1]=>
143    int(2)
144    [2]=>
145    int(3)
146  }
147  [1]=>
148  array(3) {
149    [0]=>
150    int(4)
151    [1]=>
152    int(5)
153    [2]=>
154    int(6)
155  }
156  [2]=>
157  array(3) {
158    [0]=>
159    int(7)
160    [1]=>
161    int(8)
162    [2]=>
163    int(9)
164  }
165}
166OK
167array(3) {
168  [0]=>
169  string(3) "foo"
170  [1]=>
171  string(3) "foo"
172  [2]=>
173  string(3) "foo"
174}
175OK
176array(2) {
177  ["one"]=>
178  int(1)
179  ["two"]=>
180  int(2)
181}
182OK
183array(2) {
184  ["kek"]=>
185  string(3) "lol"
186  ["lol"]=>
187  string(3) "kek"
188}
189OK
190array(1) {
191  [""]=>
192  string(5) "empty"
193}
194OK
195array(2) {
196  [0]=>
197  array(1) {
198    [0]=>
199    string(3) "foo"
200  }
201  [1]=>
202  array(1) {
203    [0]=>
204    string(3) "foo"
205  }
206}
207OK
208array(2) {
209  [0]=>
210  array(1) {
211    [0]=>
212    string(3) "foo"
213  }
214  [1]=>
215  array(1) {
216    [0]=>
217    string(3) "foo"
218  }
219}
220OK
221array(1) {
222  [0]=>
223  array(1) {
224    [0]=>
225    array(1) {
226      [0]=>
227      NULL
228    }
229  }
230}
231OK
232array(2) {
233  ["a"]=>
234  array(2) {
235    ["b"]=>
236    string(1) "c"
237    ["d"]=>
238    string(1) "e"
239  }
240  ["f"]=>
241  array(1) {
242    ["g"]=>
243    string(1) "h"
244  }
245}
246OK
247array(3) {
248  [0]=>
249  int(1)
250  [1]=>
251  int(2)
252  [2]=>
253  int(3)
254}
255OK
256array(2) {
257  [0]=>
258  array(3) {
259    [0]=>
260    int(1)
261    [1]=>
262    int(2)
263    [2]=>
264    int(3)
265  }
266  [1]=>
267  array(3) {
268    [0]=>
269    int(4)
270    [1]=>
271    int(5)
272    [2]=>
273    int(6)
274  }
275}
276OK
277array(2) {
278  [0]=>
279  array(3) {
280    [0]=>
281    int(1)
282    [1]=>
283    int(2)
284    [2]=>
285    int(3)
286  }
287  [1]=>
288  array(3) {
289    [0]=>
290    int(1)
291    [1]=>
292    int(2)
293    [2]=>
294    int(3)
295  }
296}
297OK
298