ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/t/52_object.t
Revision: 1.7
Committed: Sat Nov 30 17:19:34 2013 UTC (10 years, 6 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.6: +9 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.7 BEGIN { $| = 1; print "1..21\n"; }
2 root 1.4 BEGIN { $^W = 0 } # hate
3 root 1.1
4     use CBOR::XS;
5    
6     print "ok 1\n";
7    
8     sub CBOR::XS::tocbor::TO_CBOR {
9     print @_ == 1 ? "" : "not ", "ok 3\n";
10     print CBOR::XS::tocbor:: eq ref $_[0] ? "" : "not ", "ok 4\n";
11     print $_[0]{k} == 1 ? "" : "not ", "ok 5\n";
12     7
13     }
14    
15     $obj = bless { k => 1 }, CBOR::XS::tocbor::;
16    
17     print "ok 2\n";
18    
19     $enc = encode_cbor $obj;
20     print $enc eq "\x07" ? "" : "not ", "ok 6\n";
21    
22     print "ok 7\n";
23    
24     sub CBOR::XS::freeze::FREEZE {
25     print @_ == 2 ? "" : "not ", "ok 8\n";
26     print $_[1] eq "CBOR" ? "" : "not ", "ok 9\n";
27     print CBOR::XS::freeze:: eq ref $_[0] ? "" : "not ", "ok 10\n";
28     print $_[0]{k} == 1 ? "" : "not ", "ok 11\n";
29     (3, 1, 2)
30     }
31    
32     sub CBOR::XS::freeze::THAW {
33     print @_ == 5 ? "" : "not ", "ok 13\n";
34     print CBOR::XS::freeze:: eq $_[0] ? "" : "not ", "ok 14\n";
35     print $_[1] eq "CBOR" ? "" : "not ", "ok 15\n";
36     print $_[2] == 3 ? "" : "not ", "ok 16\n";
37     print $_[3] == 1 ? "" : "not ", "ok 17\n";
38     print $_[4] == 2 ? "" : "not ", "ok 18\n";
39     777
40     }
41    
42     $obj = bless { k => 1 }, CBOR::XS::freeze::;
43     $enc = encode_cbor $obj;
44 root 1.6 print $enc eq (pack "H*", "d81a845043424f523a3a58533a3a667265657a65030102") ? "" : "not ", "ok 12 ", (unpack "H*", $enc), "\n";
45 root 1.1
46     $dec = decode_cbor $enc;
47     print $dec eq 777 ? "" : "not ", "ok 19\n";
48    
49 root 1.7 sub CBOR::XS::freeze2::FREEZE {
50     77
51     }
52    
53     my $enc = CBOR::XS->new->allow_sharing->encode ([(bless [], CBOR::XS::freeze2::) x 3]);
54     print $enc eq (pack "H*", "83d81cd81a825143424f523a3a58533a3a667265657a6532184dd81d00d81d00") ? "" : "not ", "ok 20 ", (unpack "H*", $enc), "\n";
55    
56     print "ok 21\n";
57 root 1.1