ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Algorithm-FEC/t/00_load.t
Revision: 1.1
Committed: Tue Sep 9 05:52:50 2003 UTC (23 years ago) by root
Content type: application/x-troff
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 BEGIN { $| = 1; print "1..27\n"; }
2     END {print "not ok 1\n" unless $loaded;}
3     use Convert::FEC;
4     $loaded = 1;
5    
6     use File::Temp;
7    
8     my $fec = new Convert::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,2,1]],
45     [[0,2,3],[0,2,1]],
46     [[4,3,1],[0,2,1]]) {
47     my ($idx1, $idx2) = @$_;
48    
49     my @blks;
50    
51     ok 1;
52     my $i;
53     for (@$idx1) {
54     $blks[$i++] = $_ < 3 ? $files[$_] : $blk[$_];
55     }
56    
57     $fec->decode (\@blks, $idx1);
58    
59     ok 1;
60    
61     ok ("@$idx1" eq "@$idx2");
62    
63     $i = 0;
64     for (@$idx1) {
65     $i++;
66     next if ref $blks[$_];
67     ok ($i x 70 eq $blks[$_]);
68     }
69     }
70