File: 137.phpt

package info (click to toggle)
php-msgpack 1%3A3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,224 kB
  • sloc: ansic: 3,925; xml: 458; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (3)
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
--TEST--
unpack/pack str8
--INI--
msgpack.use_str8_serialization = 1
--SKIPIF--
<?php
    if (version_compare(PHP_VERSION, '5.2.0') < 0) {
        echo "skip tests in PHP 5.2 or newer";
    }
--FILE--
<?php
    if(!extension_loaded('msgpack')) {
        dl('msgpack.' . PHP_SHLIB_SUFFIX);
    }

    $str = "Simple test for short string - type str8";
    $str8 = chr(0xD9) . chr(strlen($str)) . $str;
    echo msgpack_unpack($str8) . "\n";

    //assert str8 serialization works, and default for use use_str8_serialization is 1
    $data = msgpack_pack($str);
    var_dump(bin2hex($data));
    echo ($data[0] == chr(0xD9) && $data[1] == chr(strlen($str)) ?  "OK" : "FAILED"), PHP_EOL;

    ini_set('msgpack.use_str8_serialization', 0);
    $data = msgpack_pack($str);
    var_dump(bin2hex($data));
    echo ($data[0] == chr(0xDA) && $data[2] == chr(strlen($str)) ?  "OK" : "FAILED"), PHP_EOL;

?>
--EXPECTF--
Simple test for short string - type str8
string(84) "d92853696d706c65207465737420666f722073686f727420737472696e67202d20747970652073747238"
OK
string(86) "da002853696d706c65207465737420666f722073686f727420737472696e67202d20747970652073747238"
OK