File: 550_decode_into.t

package info (click to toggle)
libsereal-decoder-perl 4.005%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,952 kB
  • sloc: ansic: 8,105; perl: 5,782; sh: 25; makefile: 5
file content (41 lines) | stat: -rw-r--r-- 1,312 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use strict;
use warnings;
use Test::More tests => 8;
use File::Spec;
use lib File::Spec->catdir(qw(t lib));
BEGIN {
    lib->import('lib')
        if !-d 't';
}
use Sereal::TestSet qw(have_encoder_and_decoder);

use Sereal::Decoder;
my $decoder= Sereal::Decoder->new();
my $enc_ref= "=\363rl\3\0Qcfoo\1";
my $enc_str= "=\363rl\3\0}blah blah blah blah blah blah";

# Repeatedly decode "into" the $into variable.
# Overwrting/reusing the data it contains.
# We alternate between ref and scalar to see if we can trigger a segfault.

my $into;
$decoder->decode($enc_ref, $into);
ok(ref $into, "first decode was a reference");
$decoder->decode($enc_str, $into);
ok(!ref $into, "second decode was a string");

$decoder->decode($enc_ref, $into);
ok(ref $into, "third decode was a reference");
$decoder->decode($enc_str, $into);
ok(!ref $into, "fourth decode was a string (and did not segfault)");

$decoder->decode($enc_ref, $into);
ok(ref $into, "fifth decode was a reference - and did not segault");
$decoder->decode($enc_str, $into);
ok(!ref $into, "sixth decode was a string  - and did not segfault, probably ok");

$decoder->decode($enc_ref, $into);
ok(ref $into, "seventh decode was a reference - maybe overkill");
$decoder->decode($enc_str, $into);
ok(!ref $into, "eight decode was a string - maybe overkill");