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
|
#!/usr/local/bin/perl
#
# Test that the primitive operators are working
#
use Convert::BER;
print "1..6\n"; # This testcase needs more tests
$tcount = $test = 1;
sub test (&) {
my $sub = shift;
eval { $sub->() };
print "not ok ",$test++,"\n"
while($test < $tcount);
warn "count mismatch test=$test tcount=$tcount"
unless $test == $tcount;
$tcount = $test;
}
##
## Test building optional
##
$tcount += 4;
test {
my $ber = Convert::BER->new->encode( OPTIONAL => [ INTEGER => 0x35 ] ) or die;
print "ok ",$test++,"\n";
my $result = pack("C*", 0x02, 0x01, 0x35);
die $ber->hexdump unless $ber->buffer eq $result;
print "ok ",$test++,"\n";
my $int;
$ber->decode( OPTIONAL => [ INTEGER => \$int ]) or die;
print "ok ",$test++,"\n";
die unless $int == 0x35;
print "ok ",$test++,"\n";
};
$tcount += 2;
test {
my $ber = Convert::BER->new->encode( OPTIONAL => [ INTEGER => undef ] ) or die;
print "ok ",$test++,"\n";
my $result = "";
die $ber->dump unless $ber->buffer eq $result;
print "ok ",$test++,"\n";
};
|