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