File: comp2bin.t

package info (click to toggle)
libconvert-binhex-perl 1.119%2Bpristine-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 312 kB
  • ctags: 137
  • sloc: perl: 838; makefile: 45
file content (85 lines) | stat: -rw-r--r-- 1,820 bytes parent folder | download | duplicates (3)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use lib "./blib/lib", "./lib", "./t";

use Checker;
use Convert::BinHex;

%TEST = (
	 PIVOT_3 => {
	     COMP => ["90 00 01 02 03 04 00", 
		      "90 00 03"],
	     BIN  => "90 01 02 03 04 00 90 03",
	 },
	 PIVOT_2 => {
	     COMP => ["90 00 01 02 03 04 00 90", 
		      "00 03"],
	     BIN  => "90 01 02 03 04 00 90 03",
	 },
	 PIVOT_1 => {
	     COMP => ["90 00 01 02 03 04 00 90 00", 
		      "03"],
	     BIN  => "90 01 02 03 04 00 90 03",
	 },
	 CHOPPY => {
	     COMP => ["90",
		      "00",
		      "01 02 03 04",
		      "00", 
		      "90",
		      "00",
		      "03"],
	     BIN  => "90 01 02 03 04 00 90 03",
	 },
	 FOUR_FIVES => {
	     COMP => ["01 02 03 04 05 90 04"],
	     BIN  => "01 02 03 04 05 05 05 05",
	 },
	 FOUR_FIVES_AND_A_SIX => {
	     COMP => ["01 02 03 04 05 90 04 06"],
	     BIN  => "01 02 03 04 05 05 05 05 06",
	 },
	 FOUR_MARKS => {
	     COMP => ["01 02 03 04 90 00 90 04"],
	     BIN  => "01 02 03 04 90 90 90 90",
	 },
	 FOUR_MARKS_AND_A_SIX => {
	     COMP => ["01 02 03 04 90 00 90 04 06"],
	     BIN  => "01 02 03 04 90 90 90 90 06",
	 },
	 FIVE_ONES_AND_TWOS => {
	     COMP => ["01 90 05 02 90 05"],
	     BIN  => "01 01 01 01 01 02 02 02 02 02",
	 },
	 );	
	
sub str2hex {
	my $str = shift;
	eval '"\x' . join('\x', split(/\s+/,$str)) . '"';
}

#------------------------------------------------------------
# BEGIN
#------------------------------------------------------------
print "1..9\n";
my $TESTKEY;
foreach $TESTKEY (sort keys %TEST) {
    my $test = $TEST{$TESTKEY};
    my @comps = map { str2hex($_) } @{$test->{COMP}};
    my $bin  = str2hex($test->{BIN});
    
    my $comp;
    my $rbin = '';
    my $H2B = Convert::BinHex->hex2bin;
    foreach $comp (@comps) {
	$rbin .= $H2B->comp2bin_next($comp);
    }
    check(($rbin eq $bin), "test $TESTKEY");
}
1;