mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-18 20:38:00 +01:00
Fix tests
This commit is contained in:
parent
599964ea5f
commit
5e602fb575
@ -2,8 +2,16 @@ use strict;
|
||||
use warnings;
|
||||
use Data::MessagePack;
|
||||
use Test::More tests => 9;
|
||||
use t::Util;
|
||||
|
||||
my $input = [
|
||||
false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,
|
||||
127,127,255,65535,4294967295,-32,-32,-128,-32768,
|
||||
-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","",
|
||||
[0],[0],[0],[],[],[],{},{},{},
|
||||
{"a" => 97},{"a" => 97},{"a" => 97},[[]],[["a"]]
|
||||
];
|
||||
|
||||
my $input = [ 42, "foo", { x => [ (1) x 16 ] }, undef, 1 ];
|
||||
my $packed = Data::MessagePack->pack($input);
|
||||
is_deeply(Data::MessagePack->unpack($packed), $input);
|
||||
|
||||
@ -16,30 +24,20 @@ is_deeply(Data::MessagePack->unpack($packed), $input);
|
||||
|
||||
{
|
||||
my $up = Data::MessagePack::Unpacker->new();
|
||||
is $up->execute(substr($packed, 0, 3), 0), 3;
|
||||
ok !$up->is_finished;
|
||||
$up->execute($packed, 3);
|
||||
ok $up->is_finished;
|
||||
is_deeply $up->data, $input;
|
||||
}
|
||||
$packed x= 3;
|
||||
|
||||
my $offset = 0;
|
||||
for my $i(1 .. 3) {
|
||||
note "block $i (offset: $offset/".length($packed).")";
|
||||
note "starting 3 bytes: ", join " ", map { unpack 'H2', $_ }
|
||||
split //, substr($packed, $offset, 3);
|
||||
|
||||
{
|
||||
my $up = Data::MessagePack::Unpacker->new();
|
||||
my $size = 8;
|
||||
|
||||
note "packed size: ", length($packed);
|
||||
open my $stream, '<:bytes :scalar', \$packed;
|
||||
binmode $stream;
|
||||
my $buff;
|
||||
while( read($stream, $buff, $size) ) {
|
||||
note "buff: ", join " ", map { unpack 'H2', $_ } split //, $buff;
|
||||
|
||||
$up->execute($buff);
|
||||
$offset = $up->execute($packed, $offset);
|
||||
ok $up->is_finished, 'finished';
|
||||
my $data = $up->data;
|
||||
is_deeply $data, $input;
|
||||
$up->reset();
|
||||
}
|
||||
ok $up->is_finished, 'is_finished';
|
||||
my $data = $up->data;
|
||||
note explain($data);
|
||||
is_deeply $data, $input;
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ for my $mpac($mpac1, $mpac2) {
|
||||
my $offset = 0;
|
||||
my $i = 0;
|
||||
while($offset < length($mpac)) {
|
||||
$offset += $mps->execute($mpac, $offset);
|
||||
$offset = $mps->execute($mpac, $offset);
|
||||
is_deeply $mps->data, $data[$i], "data[$i]";
|
||||
$mps->reset;
|
||||
$i++;
|
||||
|
40
perl/t/10_splitted_bytes.t
Executable file
40
perl/t/10_splitted_bytes.t
Executable file
@ -0,0 +1,40 @@
|
||||
#!perl
|
||||
|
||||
# This feature is not yet supported, but 0.23 (or former) caused SEGV in this code,
|
||||
# so we put it here.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::MessagePack;
|
||||
use Test::More;
|
||||
use t::Util;
|
||||
|
||||
my $input = [
|
||||
false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,
|
||||
127,127,255,65535,4294967295,-32,-32,-128,-32768,
|
||||
-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","",
|
||||
[0],[0],[0],[],[],[],{},{},{},
|
||||
{"a" => 97},{"a" => 97},{"a" => 97},[[]],[["a"]]
|
||||
];
|
||||
|
||||
my $packed = Data::MessagePack->pack($input);
|
||||
|
||||
foreach my $size(1 .. 16) {
|
||||
local $TODO = "Splitted byte streaming is not yet supported (bufer size: $size)";
|
||||
|
||||
my $up = Data::MessagePack::Unpacker->new();
|
||||
|
||||
open my $stream, '<:bytes :scalar', \$packed;
|
||||
binmode $stream;
|
||||
my $buff;
|
||||
while( read($stream, $buff, $size) ) {
|
||||
#note "buff: ", join " ", map { unpack 'H2', $_ } split //, $buff;
|
||||
|
||||
$up->execute($buff);
|
||||
}
|
||||
ok $up->is_finished, 'is_finished';
|
||||
my $data = $up->data;
|
||||
is_deeply $data, $input;
|
||||
}
|
||||
|
||||
done_testing;
|
@ -1,6 +1,7 @@
|
||||
package t::Util;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::MessagePack;
|
||||
|
||||
sub import {
|
||||
my $pkg = caller(0);
|
||||
@ -15,6 +16,7 @@ sub import {
|
||||
*{"$pkg\::false"} = sub () {
|
||||
Data::MessagePack::false()
|
||||
};
|
||||
*{"$pkg\::null"} = sub() { undef };
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user