1 | BEGIN { $| = 1; print "1..21\n"; } |
1 | BEGIN { $| = 1; print "1..123\n"; } |
2 | |
2 | |
3 | use CBOR::XS; |
3 | use CBOR::XS; |
4 | |
4 | |
5 | print "ok 1\n"; |
5 | print "ok 1\n"; |
6 | my $tst = 0; |
6 | my $tst = 1; |
7 | |
7 | |
8 | sub tst($$) { |
8 | sub tst($$) { |
9 | my ($cbor, $correct) = @_; |
9 | my ($cbor, $correct) = @_; |
10 | |
10 | |
|
|
11 | my $dec = CBOR::XS->new; |
|
|
12 | |
|
|
13 | # chop |
11 | for my $step (1 .. length $cbor) { |
14 | for my $step (1 .. length $cbor) { |
12 | my $dec = CBOR::XS->new; |
|
|
13 | my $buf = ""; |
15 | my $buf = ""; |
14 | my @cbor; |
16 | my @cbor; |
15 | |
17 | |
|
|
18 | $dec->incr_reset; |
|
|
19 | |
16 | for (unpack "(a$step)*", $cbor) { |
20 | for (unpack "(a$step)*", $cbor) { |
17 | $buf .= $_; |
21 | $buf .= $_; |
18 | push @cbor, $dec->incr_parse ($buf, 1); |
22 | push @cbor, $dec->incr_parse_multiple ($buf); |
19 | } |
23 | } |
20 | |
24 | |
21 | print length $buf ? "not " : "", "ok ", ++$tst, "\n"; |
25 | print length $buf ? "not " : "", "ok ", ++$tst, "\n"; |
22 | |
26 | |
23 | my $enc = join " ", map +(unpack "H*", encode_cbor $_), @cbor; |
27 | my $enc = join " ", map +(unpack "H*", encode_cbor $_), @cbor; |
24 | |
28 | |
25 | print $enc eq $correct ? "" : "not ", "ok ", ++$tst, " # $enc eq $correct\n"; |
29 | print $enc eq $correct ? "" : "not ", "ok ", ++$tst, " # ($step) $enc eq $correct\n"; |
26 | } |
30 | } |
27 | } |
31 | } |
28 | |
32 | |
29 | sub err($$) { |
33 | sub err($$) { |
30 | if (eval { CBOR::XS->new->max_size (1e3)->incr_parse ($_[0]); 1 }) { |
34 | if (eval { CBOR::XS->new->max_size (1e3)->incr_parse ($_[0]); 1 }) { |
… | |
… | |
36 | } |
40 | } |
37 | } |
41 | } |
38 | |
42 | |
39 | tst "\x81\x82\x81\x80\x80\x80", "8182818080 80"; |
43 | tst "\x81\x82\x81\x80\x80\x80", "8182818080 80"; |
40 | tst "\x01\x18\x55\x01", "01 1855 01"; |
44 | tst "\x01\x18\x55\x01", "01 1855 01"; |
41 | 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"; |
45 | #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"; |
|
|
46 | tst "\x18\x01\x19\x02\x02\x1a\x04\x04\x04\x04\x00", "01 190202 1a04040404 00"; |
42 | tst "\x41A\x42CD", "4141 424344"; |
47 | tst "\x41A\x42CD", "4141 424344"; |
43 | 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"; |
48 | 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"; |
44 | tst "\x5f\x41A\x41B\x42CD\xff", "4441424344"; |
49 | tst "\x5f\x41A\x41B\x42CD\xff", "4441424344"; |
45 | err "\xff", "major 7"; |
50 | err "\xff", "major 7"; |
46 | err "\x5a\xff\x00\x00\x00", "max_size"; |
51 | err "\x5a\xff\x00\x00\x00", "max_size"; |