ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Algorithm-FEC/t/00_load.t
Revision: 1.5
Committed: Thu Nov 22 01:41:39 2012 UTC (13 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_1, HEAD
Changes since 1.4: +5 -1 lines
Log Message:
1.1

File Contents

# Content
1 BEGIN { $| = 1; print "1..30\n"; }
2 END {print "not ok 1\n" unless $loaded;}
3 use Algorithm::FEC;
4 $loaded = 1;
5
6 use File::Temp;
7
8 my $fec = new Algorithm::FEC 3, 5, 70;
9
10 my $test = 0;
11
12 sub ok($) {
13 $test++;
14 print $_[0] ? "ok $test\n" : "not ok $test\n";
15 }
16
17 my @files = map {
18 $fd = tmpfile ();
19 syswrite $fd, $_ x 70;
20 $_ < 2 ? $fd : [$fd, 0];
21 } 1..3;
22
23 ok 1;
24
25 $fec->set_encode_blocks (\@files);
26
27 ok 1;
28
29 my @blk;
30
31 for (0..4) {
32 ok 1;
33
34 $blk[$_] = $fec->encode ($_);
35 }
36
37 ok ($blk[0] eq "1" x 70);
38 ok ($blk[1] eq "2" x 70);
39 ok ($blk[2] eq "3" x 70);
40 ok ($blk[3] eq "%" x 70);
41 ok ($blk[4] eq "Y" x 70);
42
43 for ([[0,1,2],[0,1,2]],
44 [[0,2,1],[0,1,2]],
45 [[0,2,3],[0,3,2]],
46 [[4,3,1],[4,1,3]]) {
47 my ($idx1, $idx2) = @$_;
48
49 my @blks;
50
51 ok 1;
52 my $i;
53 for (@$idx1) {
54 $blks[$i++] = $_ < 3 ? $files[$_] : do {
55 # Create a shared hash key scalar as an extra robustness test.
56 $blk[$_] = (keys %{{$blk[$_]=>0}})[0];
57 $blk[$_];
58 };
59 }
60
61 $fec->set_decode_blocks (\@blks, $idx1);
62 $fec->decode;
63
64 ok 1;
65
66 ok ("@$idx1" eq "@$idx2");
67
68 for (0 .. $#$idx1) {
69 next if ref $blks[$_];
70 ok (($_+1) x 70 eq $blks[$_]);
71 }
72 }
73
74 ok 1;
75
76 my $a = "a" x 70;
77 my $b = "b" x 70;
78
79 $fec->copy ($b, $a);
80
81 ok ($a eq $b);
82 ok ($a eq "b" x 70);
83