summaryrefslogtreecommitdiff
path: root/php/tests/066.phpt
diff options
context:
space:
mode:
authoradvect <advect@gmail.com>2010-10-30 16:06:50 +0900
committeradvect <advect@gmail.com>2010-10-30 16:06:50 +0900
commitbad69fd3977fca94d643a88d819badaca4839fd5 (patch)
tree87ca7d41a9d66fdef51e5b035d39ba44d62380c7 /php/tests/066.phpt
parentb4ae6bf82c8bcd6012c805a2206fcb81ad39dd0b (diff)
downloadmsgpack-python-bad69fd3977fca94d643a88d819badaca4839fd5.tar.gz
php: fiexed unpacker
Diffstat (limited to 'php/tests/066.phpt')
-rw-r--r--php/tests/066.phpt70
1 files changed, 70 insertions, 0 deletions
diff --git a/php/tests/066.phpt b/php/tests/066.phpt
new file mode 100644
index 0000000..d2e430d
--- /dev/null
+++ b/php/tests/066.phpt
@@ -0,0 +1,70 @@
+--TEST--
+Extra bytes buffered streaming unserialization (single)
+--SKIPIF--
+--FILE--
+<?php
+if(!extension_loaded('msgpack')) {
+ dl('msgpack.' . PHP_SHLIB_SUFFIX);
+}
+
+$unpacker = new MessagePackUnpacker();
+
+function test($type, $variable, $test = null) {
+ global $unpacker;
+
+ foreach ($variable as $var)
+ {
+ $serialized = pack('H*', $var);
+
+ $length = strlen($serialized);
+
+ for ($i = 0; $i < $length;) {
+ $len = rand(1, 10);
+ $str = substr($serialized, $i, $len);
+
+ $unpacker->feed($str);
+
+ while (true) {
+ if ($unpacker->execute()) {
+ $unserialized = $unpacker->data();
+ var_dump($unserialized);
+ $unpacker->reset();
+ } else {
+ break;
+ }
+ }
+ $i += $len;
+ }
+ }
+}
+
+test('array(1, 2, 3)', array('9301020392'));
+test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904'));
+--EXPECTF--
+array(3) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ }
+ [1]=>
+ array(2) {
+ [0]=>
+ int(3)
+ [1]=>
+ int(9)
+ }
+}
+int(4)