DOCSIS-ConfigFile
view release on metacpan or search on metacpan
rurban@x-ray.at
0.63 2012-10-10T00:49:37Z
- Fix RT72511 Contributor velladecin@hotmail.com
0.62 2012-04-29T10:56:44Z
- Add SnmpCpeAccessControl to Syminfo Contributor: Elliot
0.61 2011-10-03T21:58:40Z
- Fix RT70882: ServiceClassName need to be zero-terminated This is
optional in input data structure and removed/not visible in decoded tree
either
0.6004 2010-09-12T21:51:02Z
- Fix #61267: Encode::int() fails on 64b systems: 1234567890 >> 8 ==
72057594033105405 != 11954685
0.6003 2010-09-05T20:38:25Z
- Fix uint() cannot return negative integers Contributor: canni
- Add int() to handle (possible) signed integers Contributor: canni
- Fix Decode::string() decodes % as %25
use warnings;
use strict;
use DOCSIS::ConfigFile;
use Test::More;
our $AUTOLOAD;
is_deeply(
snmp_object(48, 10, 6, 2, 42, 3, 2, 3, 255, 0, 1),
{oid => '1.2.3', type => 'INTEGER', value => -65535},
'snmp_object() decoded'
);
is_deeply(
snmp_object(48, 10, 6, 2, 42, 3, 2, 4, 127, 255, 255, 255),
{oid => '1.2.3', type => 'INTEGER', value => 2147483647},
'snmp_object() decoded'
);
is(bigint(1, 182, 155, 75, 172, 208, 95, 21), '123456789123456789',
'bigint() = 123456789123456789');
is(bigint(255, 0, 1), -65535, 'bigint() = -65535');
is(main::int(0, 2, 0), 512, 'int() = 512');
is(main::int(127, 255, 255, 255), 2147483647, 'int() = 2147483647');
is(main::int(0, 255, 255), 65535, 'int() = 65535');
is(main::int(255, 255), -1, 'int() = -1');
is(main::int(255, 0, 1), -65535, 'int() = -65535');
is(main::int(128, 0, 0, 0), -2147483648, 'int() = -2147483648');
is(uint(73, 150, 2, 210), 1234567890, 'uint() = 1234567890');
is(ushort(48, 57), 12345, 'ushort() = 12345');
is(uchar(123), 123, 'uchar() = 123');
is_deeply(
[vendorspec(8, 3, 0, 19, 55, 24, 1, 66)],
['0x001337' => [{type => 24, length => 1, value => '0x42'}]],
'vendorspec() decoded',
);
is_deeply(
[vendorspec(8, 3, 0, 0, 12, 4, 8, 0, 0, 255, 255, 0, 0, 0, 10)],
['0x00000c' => [{type => 4, length => 8, value => '0x0000ffff0000000a'}]],
'vendorspec() decoded',
);
is(ip(1, 2, 3, 4), '1.2.3.4', 'ip() = 1.2.3.4');
is(ether(1, 35, 69, 103, 137, 171), '0123456789ab', 'ether() = 0123456789ab');
#is(ether(1,35,69,103), 1234567, 'ether() = 1234567');
is(string(1, 35, 69, 103, 137, 171, 205, 239),
'0x0123456789abcdef', 'string() = 0x0123456789abcdef');
is(
is(hexstr(1, 35, 69, 103, 137, 171, 205, 239),
'0x0123456789abcdef', 'hexstr() = 0x0123456789abcdef');
is(
mic(102, 68, 55, 160, 241, 15, 242, 18, 129, 161, 47, 155, 128, 106, 239, 7),
'0x664437a0f10ff21281a12f9b806aef07',
'mic(102,68,55,160,241,15,242,18,129,161,47,155,128,106,239,7)',
);
is(no_value(), '', 'no value decoded as empty string');
done_testing;
# evil hack to simplify things...
sub AUTOLOAD {
my $sub = DOCSIS::ConfigFile::Decode->can($AUTOLOAD =~ /(\w+)$/);
$sub->(pack 'C*', @_);
}
t/deprecated-rt70882.t view on Meta::CPAN
use Test::More;
use File::Spec::Functions 'catfile';
use DOCSIS::ConfigFile qw(encode_docsis decode_docsis);
my $zero = decode_docsis \catfile qw(t data rt70882 encoded.cm.zero);
my $non_zero = decode_docsis \catfile qw(t data rt70882 encoded.cm.non_zero);
my $zero_bin;
@$zero{qw(CmMic CmtsMic)} = ('0xDUMMY') x 2;
@$non_zero{qw(CmMic CmtsMic)} = ('0xDUMMY') x 2;
is_deeply $zero, $non_zero, 'decoded without trailing zero';
$zero_bin = encode_docsis $zero;
like $zero_bin, qr{DataS_U_512k\0}, 'encoded with trailing zero';
done_testing;
],
'string() encoded'
) or diag "@uchar";
@uchar = hexstr({value => '0x0123456789abcdef'});
is_deeply(\@uchar, [1, 35, 69, 103, 137, 171, 205, 239], 'hexstr() encoded') or diag "@uchar";
@uchar = mic({value => 'foo'});
is_deeply(\@uchar, [], 'mic() encoded') or diag "@uchar";
is_deeply([no_value({value => 'foo'})], [], 'no value decoded as empty list');
done_testing;
# evil hack to simplify things...
sub AUTOLOAD {
my $sub = DOCSIS::ConfigFile::Encode->can($AUTOLOAD =~ /(\w+)$/);
$sub->(@_);
}
plan tests => 8;
diag '/usr/bin/hexdump is missing. Will not dump binary files as hex';
}
mkdir 't/data' unless (-d 't/data/');
my $dc = DOCSIS::ConfigFile->new(advanced_output => 0, shared_secret => '');
my ($data_bin, $data_config, $new_bin);
ok($data_bin = generate_binary(), 'DATA is read');
ok(data_to_file($data_bin, 'data.bin'), 'DATA written to data.bin');
is(docsis('data.bin'), 0, 'docsis decoded data.bin => data.c');
is(hexdump('data.bin'), 0, 'data.bin dumped as data.hex') if HEXDUMP;
ok($data_config = $dc->decode(\$data_bin), 'DC decoded DATA');
data_to_file($data_config, 'data.json');
ok($new_bin = $dc->encode($data_config), 'DC encodede DATA back');
ok(data_to_file($new_bin, 'new.bin'), 'encoded DATA stored to new.bin');
is(hexdump('new.bin'), 0, 'new.bin dumped as new.hex') if HEXDUMP;
if (is(docsis('new.bin'), 0, 'docsis decoded new.bin => new.c')) {
is(qx{diff -u t/data/data.c t/data/new.c}, '', 'no diff from docsis decoded output');
is(qx{diff -u t/data/data.hex t/data/new.hex}, '', 'no diff from hexdump output') if HEXDUMP;
}
else {
ok(0, 'cannot run diff without decoded binary');
ok(0, 'cannot run diff without decoded binary');
}
unless ($ENV{KEEP_DOCSIS_FILES}) {
unlink map {
my $n = $_;
map {"t/data/$n.$_"} qw/ bin hex c json /
} qw/data new/;
rmdir "t/data";
}
t/rt70882.t view on Meta::CPAN
plan skip_all => 'cannot find test-files' unless -e 't/data/rt70882/encoded.cm.zero';
my $zero = decode_docsis slurp('t/data/rt70882/encoded.cm.zero');
my $non_zero = decode_docsis slurp('t/data/rt70882/encoded.cm.non_zero');
my $zero_bin;
$zero->{$_} = 'MIC' for grep {/Mic/} keys %$zero;
$non_zero->{$_} = 'MIC' for grep {/Mic/} keys %$non_zero;
is_deeply $zero, $non_zero, 'decoded without trailing zero';
$zero_bin = encode_docsis $zero;
like $zero_bin, qr{DataS_U_512k\0}, 'encoded with trailing zero';
done_testing;
sub slurp {
open my $FH, '<', $_[0];
local $/;
readline $FH;
t/ushort_list-missing.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use DOCSIS::ConfigFile qw(decode_docsis encode_docsis);
plan skip_all => 'cannot find tos.bin' unless -e 't/data/ushort_list-missing.bin';
my $decoded = eval { decode_docsis \'t/data/ushort_list-missing.bin' };
ok !$@, 'ushort_list() is present in DOCSIS::ConfigFile::Decode' or diag $@;
is_deeply $decoded->{SubMgmtFilters}, [(0) x 10], 'SubMgmtFilters after decode_docsis';
my $bytes = eval { encode_docsis $decoded };
ok !$@, 'ushort_list() is present in DOCSIS::ConfigFile::Encode' or diag $@;
$decoded = eval { decode_docsis $bytes };
ok !$@, 'roundtrip decode_docsis/encode_docsis/decode_docsis';
is_deeply $decoded->{SubMgmtFilters}, [(0) x 10], 'SubMgmtFilters after roundtrip';
done_testing;
( run in 0.618 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )