1 |
root |
1.3 |
BEGIN { $| = 1; print "1..141\n"; } |
2 |
root |
1.1 |
|
3 |
|
|
use CBOR::XS; |
4 |
|
|
|
5 |
|
|
print "ok 1\n"; |
6 |
root |
1.3 |
my $tst = 1; |
7 |
root |
1.1 |
|
8 |
|
|
sub tst($$) { |
9 |
|
|
my ($cbor, $correct) = @_; |
10 |
|
|
|
11 |
root |
1.2 |
# chop |
12 |
root |
1.1 |
for my $step (1 .. length $cbor) { |
13 |
|
|
my $dec = CBOR::XS->new; |
14 |
|
|
my $buf = ""; |
15 |
|
|
my @cbor; |
16 |
|
|
|
17 |
|
|
for (unpack "(a$step)*", $cbor) { |
18 |
|
|
$buf .= $_; |
19 |
root |
1.2 |
push @cbor, $dec->incr_parse ($buf); |
20 |
root |
1.1 |
} |
21 |
|
|
|
22 |
|
|
print length $buf ? "not " : "", "ok ", ++$tst, "\n"; |
23 |
|
|
|
24 |
|
|
my $enc = join " ", map +(unpack "H*", encode_cbor $_), @cbor; |
25 |
|
|
|
26 |
|
|
print $enc eq $correct ? "" : "not ", "ok ", ++$tst, " # $enc eq $correct\n"; |
27 |
|
|
} |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
sub err($$) { |
31 |
|
|
if (eval { CBOR::XS->new->max_size (1e3)->incr_parse ($_[0]); 1 }) { |
32 |
|
|
print "not ok ", ++$tst, " # unexpected success\n"; |
33 |
|
|
} elsif ($@ =~ $_[1]) { |
34 |
|
|
print "ok ", ++$tst, "\n"; |
35 |
|
|
} else { |
36 |
|
|
print "not ok ", ++$tst, " # $@\n"; |
37 |
|
|
} |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
tst "\x81\x82\x81\x80\x80\x80", "8182818080 80"; |
41 |
|
|
tst "\x01\x18\x55\x01", "01 1855 01"; |
42 |
|
|
tst "\x18\x01\x19\x02\x02\x1a\x04\x04\x04\x04\x1b\x08\x08\x08\x08\x08\x08\x08\x08\x00", "01 190202 1a04040404 1b0808080808080808 00"; |
43 |
|
|
tst "\x41A\x42CD", "4141 424344"; |
44 |
|
|
tst "\x58\x01A\x59\x00\x01B\x5a\x00\x00\x00\x01C\x5b\x00\x00\x00\x00\x00\x00\x00\x02XY\x01", "4141 4142 4143 425859 01"; |
45 |
|
|
tst "\x5f\x41A\x41B\x42CD\xff", "4441424344"; |
46 |
|
|
err "\xff", "major 7"; |
47 |
|
|
err "\x5a\xff\x00\x00\x00", "max_size"; |
48 |
|
|
|