summaryrefslogtreecommitdiff
path: root/php/tests/test_pack.phpt
blob: 595e4d03eeb164d2d57ef4ab12ed9e0f12878851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
--TEST--
Test msgpack_pack() function : basic functionality
--SKIPIF--
<?php if (!extension_loaded("msgpack")) print "skip"; ?>
--FILE--
<?php 
echo "*** Testing msgpack_pack() : basic functionality ***\n";


function create_map($num)
{
    $data = array();
    for($i=0; $i<=$num; $i++)
        $data[$i+1] = $i;
    return $data;
}

$inputs =  array (
        // null
/*1*/   null,
        NULL,

        // boolean
/*3*/   false,
        FALSE,
        true,
        TRUE,

        // zero
/*7*/   0,

        // positive fixnum
/*8*/   1,
        (1<<6),
        (1<<7)-1,

        // positive int 8
/*11*/  (1<<7),
        (1<<8)-1,

        // positive int 16
/*13*/  (1<<8),
        (1<<16)-1,

        // positive int 32
/*15*/  (1<<16),
        (1<<32)-1,

        // positive int 64
/*17*/  (1<<32),
        (1<<64)-1,

        // negative fixnum
/*19*/  -1,
        -((1<<5)-1),
        -(1<<5),

        // negative int 8
/*22*/  -((1<<5)+1),
        -(1<<7),

        // negative int 16
/*24*/  -((1<<7)+1),
        -(1<<15),

        //negative int 32
/*26*/  -((1<<15)+1),
        -(1<<31),

        // negative int 64
/*28*/  -((1<<31)+1),
        -(1<<63),

        // double
/*30*/  1.0,
        0.1,
        -0.1,
        -1.0,

        // fixraw
/*34*/  "",
        str_repeat(" ", (1<<5)-1),

        // raw 16
/*36*/  str_repeat(" ", (1<<5)),
        //str_repeat(" ", (1<<16)-1),

        // raw 32
/*38*/  //str_repeat(" ", (1<<16)),
        //str_repeat(" ", (1<<32)-1),  // memory error

        // fixarraw
/*39*/  array(), 
        range(0, (1<<4)-1),

        // array 16
/*41*/  range(0, (1<<4)),
        //range(0, (1<<16)-1),

        // array 32
/*43*/  //range(0, (1<<16)),
        //range(0, (1<<32)-1),  // memory error

        // fixmap
        //array(),
/*44*/  //create_map((1<<4)-1),

        // map 16
/*45*/  //create_map((1<<4)),
        //create_map((1<<16)-1),

        // map 32
/*47*/  //create_map((1<<16))
        //create_map((1<<32)-1)  // memory error
);

$count = 1;
foreach($inputs as $input) {
  echo "-- Iteration $count --\n";	
  $str = unpack('H*', msgpack_pack($input)); 
  var_dump("0x".$str[1]);
  $count ++;
}

?>
===DONE===
--EXPECT--
*** Testing msgpack_pack() : basic functionality ***
-- Iteration 1 --
string(4) "0xc0"
-- Iteration 2 --
string(4) "0xc0"
-- Iteration 3 --
string(4) "0xc2"
-- Iteration 4 --
string(4) "0xc2"
-- Iteration 5 --
string(4) "0xc3"
-- Iteration 6 --
string(4) "0xc3"
-- Iteration 7 --
string(4) "0x00"
-- Iteration 8 --
string(4) "0x7f"
-- Iteration 9 --
string(6) "0xcc80"
-- Iteration 10 --
string(8) "0xcd0100"
-- Iteration 11 --
string(4) "0xff"
-- Iteration 12 --
string(6) "0xd0df"
-- Iteration 13 --
string(8) "0xd1ff7f"
-- Iteration 14 --
string(8) "0x810101"
-- Iteration 15 --
string(20) "0xcb3ff0000000000000"
-- Iteration 16 --
string(4) "0x90"
-- Iteration 17 --
string(34) "0x9f000102030405060708090a0b0c0d0e"
-- Iteration 18 --
string(40) "0xdc0010000102030405060708090a0b0c0d0e0f"
-- Iteration 19 --
string(64) "0x8f0100020103020403050406050706080709080a090b0a0c0b0d0c0e0d0f0e"
-- Iteration 20 --
string(72) "0xde00100100020103020403050406050706080709080a090b0a0c0b0d0c0e0d0f0e100f"
===DONE===