19
18
use Sereal::TestSet qw(:all);
21
if (not have_encoder_and_decoder()) {
22
plan skip_all => 'Did not find right version of decoder';
26
Sereal::Decoder->import(":all");
22
28
# First, test tied hashes. Expected behaviour: We don't segfault, we don't
23
29
# throw exceptions (unless the tied hash is not iterable repeatedly),
24
30
# we serialize the tied hash as if it was a normal hash - so no trace of
25
31
# tiedness in the output.
30
our @ISA = qw(Tie::StdHash);
36
our @ISA = qw(Tie::StdHash);
42
dfvgbnhmjk => "345ty6ujh",
47
tie %tied_hash => 'TiedHash';
48
%{tied(%tied_hash)} = %testhash;
49
is_deeply(\%tied_hash, \%testhash);
51
my ($out, $ok, $err, $data);
52
$ok = eval {$out = encode_sereal(\%tied_hash); 1};
53
$err = $@ || 'Zombie error';
54
ok($ok, "serializing tied hash did not die")
55
or note("Error was '$err'");
56
ok(defined $out, "serializing tied hash returns string");
58
$ok = eval {$data = decode_sereal($out); 1;};
59
$err = $@ || 'Zombie error';
60
ok($ok, "deserializing tied hash did not die")
61
or note("Error was '$err', data was:\n"), hobodecode($out);
62
ok(defined $data, "deserializing tied hash yields defined output");
63
is_deeply($data, \%testhash, "deserializing tied hash yields expected output");
36
dfvgbnhmjk => "345ty6ujh",
41
tie %tied_hash => 'TiedHash';
42
%{tied(%tied_hash)} = %testhash;
43
is_deeply(\%tied_hash, \%testhash);
45
my ($out, $ok, $err, $data);
47
$ok = eval {$out = encode_sereal(\%tied_hash); 1};
48
$err = $@ || 'Zombie error';
49
ok($ok, "serializing tied hash did not die")
50
or note("Error was '$err'");
51
ok(defined $out, "serializing tied hash returns string");
53
$ok = eval {$data = decode_sereal($out); 1;};
54
$err = $@ || 'Zombie error';
55
ok($ok, "deserializing tied hash did not die")
56
or note("Error was '$err', data was:\n"), hobodecode($out);
57
ok(defined $data, "deserializing tied hash yields defined output");
58
is_deeply($data, \%testhash, "deserializing tied hash yields expected output");
67
our @ISA = qw(Tie::StdArray);
72
our @ISA = qw(Tie::StdArray);
75
my @testarray = (1, 2, "foo", "bar", []);
77
tie @tied_array => 'TiedArray';
78
@{tied(@tied_array)} = @testarray;
79
is_deeply(\@tied_array, \@testarray);
81
my ($out, $ok, $err, $data);
82
$ok = eval {$out = encode_sereal(\@tied_array); 1};
83
$err = $@ || 'Zombie error';
84
ok($ok, "serializing tied array did not die")
85
or note("Error was '$err'");
86
ok(defined $out, "serializing tied array returns string");
88
$ok = eval {$data = decode_sereal($out); 1;};
89
$err = $@ || 'Zombie error';
90
ok($ok, "deserializing tied array did not die")
91
or note("Error was '$err', data was:\n"), hobodecode($out);
92
ok(defined $data, "deserializing tied array yields defined output");
93
is_deeply($data, \@testarray, "deserializing tied array yields expected output");
70
my @testarray = (1, 2, "foo", "bar", []);
72
tie @tied_array => 'TiedArray';
73
@{tied(@tied_array)} = @testarray;
74
is_deeply(\@tied_array, \@testarray);
76
$ok = eval {$out = encode_sereal(\@tied_array); 1};
77
$err = $@ || 'Zombie error';
78
ok($ok, "serializing tied array did not die")
79
or note("Error was '$err'");
80
ok(defined $out, "serializing tied array returns string");
82
$ok = eval {$data = decode_sereal($out); 1;};
83
$err = $@ || 'Zombie error';
84
ok($ok, "deserializing tied array did not die")
85
or note("Error was '$err', data was:\n"), hobodecode($out);
86
ok(defined $data, "deserializing tied array yields defined output");
87
is_deeply($data, \@testarray, "deserializing tied array yields expected output");
90
96
# Now tied scalars.
95
our @ISA = qw(Tie::StdScalar);
102
our @ISA = qw(Tie::StdScalar);
105
my $testscalar = [qw(foo bar baz)];
107
tie $tied_scalar => 'TiedScalar';
108
${tied($tied_scalar)} = $testscalar;
109
is_deeply($tied_scalar, $testscalar);
111
my ($out, $ok, $err, $data);
112
$ok = eval {$out = encode_sereal(\$tied_scalar); 1};
113
$err = $@ || 'Zombie error';
114
ok($ok, "serializing tied scalar did not die")
115
or note("Error was '$err'");
116
ok(defined $out, "serializing tied scalar returns string");
118
$ok = eval {$data = decode_sereal($out); 1;};
119
$err = $@ || 'Zombie error';
120
ok($ok, "deserializing tied scalar did not die")
121
or note("Error was '$err', data was:\n"), hobodecode($out);
122
ok(defined $data, "deserializing tied scalar yields defined output");
123
is_deeply($data, \$testscalar, "deserializing tied scalar yields expected output");
98
my $testscalar = [qw(foo bar baz)];
100
tie $tied_scalar => 'TiedScalar';
101
${tied($tied_scalar)} = $testscalar;
102
is_deeply($tied_scalar, $testscalar);
104
$ok = eval {$out = encode_sereal(\$tied_scalar); 1};
105
$err = $@ || 'Zombie error';
106
ok($ok, "serializing tied scalar did not die")
107
or note("Error was '$err'");
108
ok(defined $out, "serializing tied scalar returns string");
110
$ok = eval {$data = decode_sereal($out); 1;};
111
$err = $@ || 'Zombie error';
112
ok($ok, "deserializing tied scalar did not die")
113
or note("Error was '$err', data was:\n"), hobodecode($out);
114
ok(defined $data, "deserializing tied scalar yields defined output");
115
is_deeply($data, \$testscalar, "deserializing tied scalar yields expected output");
118
126
# Now test re-entrancy. DO NOT DO THIS AT HOME!
120
128
my $enc = Sereal::Encoder->new;