File: 02seq.t

package info (click to toggle)
libconvert-ber-perl 1.3200-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 2,237; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,073 bytes parent folder | download | duplicates (9)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/local/bin/perl

#
# Test the use of sequences
#

use Convert::BER;

print "1..5\n";

$test = 1;

$ber = Convert::BER->new->encode(
    SEQUENCE => [
	INTEGER => 1,
	BOOLEAN => 0,
	STRING => "A string"
    ]
);

if($ber) {
    my $data = $ber->buffer;

    print "ok ",$test++,"\n";

    my $result = pack("C*", 0x30, 0x10, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00,
			    0x04, 0x08, 0x41, 0x20, 0x73, 0x74, 0x72, 0x69,
			    0x6E, 0x67
    );

    print "not "
	unless $ber->buffer eq $result;
    print "ok ",$test++,"\n";

    my $seq = undef;

    print "not "
	unless $ber->decode(SEQUENCE => \$seq) && $seq;

    print "ok ",$test++,"\n";

    print "not "
	unless substr($result,2) eq $seq->buffer;

    print "ok ",$test++,"\n";

    $ber = new Convert::BER($data);

    my($int,$bool,$str);

    $ber->decode(
	SEQUENCE => [
	    INTEGER => \$int,
	    BOOLEAN => \$bool,
	    STRING  => \$str,
	]
    ) && ($int == 1) && !$bool && ($str eq "A string")
	or print "not ";

    print "ok ",$test++,"\n";

    
}

print "not ok ",$test++,"\n"
	while($test <= 5);