FileList/t/fileList.t

filter: Statementstmt 78.0% 71 / 91 Branchbran 65.7% 25 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 75.3% 101 / 134 CC 24 SCAR 33.8
CC
24
Cov
74%
run_test
35.3
END
2.1
BEGIN
1.0
CRAP 29.3
« blib/lib/File/RsyncP/FileIO.pm ↑ Summary blib/lib/File/RsyncP/Digest.pm »
1 #!/bin/perl
2  
3 1 ▶BEGIN {print "1..21\n";}
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶END {print "not ok 1\n" unless $loaded;}
Subroutine END: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $loaded 0 1 1
5 1 ▶use File::RsyncP;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $loaded = 1;
7 1 print "ok 1\n";
8  
9 1 my @TestFiles = (
10 {
11 name => "xxx/yyy/aaa1",
12 mode => 0100755,
13 uid => 987,
14 gid => 654,
15 size => 654321,
16 mtime => time,
17 },
18 {
19 name => "xxx/yyy/aaa2",
20 mode => 0060755,
21 uid => 987,
22 gid => 654,
23 rdev_major => 0x23,
24 rdev_minor => 0x46,
25 size => 654321,
26 mtime => time,
27 },
28 {
29 name => "xxx/zzz/bbb1",
30 mode => 0060666,
31 uid => 9876,
32 gid => 6543,
33 rdev_major => 0x23,
34 rdev_minor => 0x45,
35 size => 65432,
36 mtime => time + 1,
37 },
38 {
39 name => "xxx/yyy/aaa3",
40 dev => 9123,
41 inode => 9123456,
42 mode => 0100666,
43 uid => 9876,
44 gid => 6543,
45 size => 65432,
46 mtime => time + 1,
47 },
48 {
49 name => "xxx/zzz/bbb2",
50 dev => 9123,
51 inode => 9123458,
52 mode => 0100666,
53 uid => 9876,
54 gid => 6543,
55 size => 65432,
56 mtime => time + 1,
57 },
58 {
59 name => "xxx/zzz/bbb3",
60 dev => (1 << 31) * 123 + (5432 << 18),
61 inode => (1 << 31) * 12 + (6543 << 17),
62 mode => 0100666,
63 uid => 9876,
64 gid => 6543,
65 size => (1 << 31) * 3 + (1 << 29),
66 mtime => time + 1,
67 },
68 {
69 name => "xxx/zzz/bbb4",
70 dev => (1 << 31) * 123 + (5432 << 18),
71 inode => (1 << 31) * 12 + (6543 << 17) + 1,
72 mode => 0100666,
73 uid => 9876,
74 gid => 6543,
75 size => (1 << 31) * 3 + (1 << 29),
76 mtime => time + 1,
77 },
78 {
79 name => "xxx/zzz/bbb5",
80 dev => (1 << 31) * 123 + (5432 << 18),
81 inode => (1 << 31) * 12 + (6543 << 17) + 2,
82 mode => 0100666,
83 uid => 9876,
84 gid => 6543,
85 size => (1 << 31) * 3 + (1 << 29),
86 mtime => time + 1,
87 },
88 {
89 name => "xxx/zzz/bbb6",
90 dev => (1 << 31) * 123 + (5432 << 18),
91 inode => (1 << 31) * 12 + (6543 << 17) + 3,
92 mode => 0100666,
93 uid => 9876,
94 gid => 6543,
95 size => (1 << 31) * 3 + (1 << 29),
96 mtime => time + 1,
97 },
98 {
99 name => "xxx/zzz/bbb7",
100 mode => 0100666,
101 uid => 9876,
102 gid => 6543,
103 size => (1 << 31) * 3 + (1 << 29),
104 mtime => time + 1,
105 },
106 );
107  
108 1 my $testNum = 2;
109  
110 1 for my $protocol ( qw(26 28) ) {
111 2 for my $preserve_hard_links ( qw(0 1) ) {
112 4 $testNum = run_test($testNum, $protocol, $preserve_hard_links);
113 }
114 }
115  
116 sub run_test
117 4 ▶{
Subroutine run_test: called CC=23 SCAR=35.6
118 4 my($testNum, $protocol, $preserve_hard_links) = @_;
119  
120 4 my $args = {
121 preserve_uid => 1, # --owner
122 preserve_gid => 1, # --group
123 preserve_links => 1, # --links
124 preserve_devices => 1, # --devices
125 preserve_hard_links => $preserve_hard_links, # --hard-links
126 always_checksum => 0, # --checksum
127 protocol_version => $protocol, # protocol version
128 };
129  
130 4 my @testFiles;
131 4 foreach my $f ( @TestFiles ) {
132 40 my $f2 = { %$f };
133 40 ▶ if ( !$preserve_hard_links ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($preserve_hard_links) 20 20 40
134 20 delete($f2->{dev});
135 20 delete($f2->{inode});
136 }
137 40 push(@testFiles, $f2);
138 }
139  
140 4 my $fList = File::RsyncP::FileList->new($args);
141  
142 4 ▶ for ( my $i = 0 ; $i < @testFiles ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @testFiles) 40 4 44
143 40 $fList->encode($testFiles[$i]);
144 }
145 4 ▶ if ( $fList->count == @testFiles ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fList->count == @testFiles) { } 4 0 4
146 4 print("ok $testNum\n");
147 } else {
148 0 print("not ok $testNum\n");
149 }
150 4 $testNum++;
151  
152 4 my $ok = 1;
153 4 ▶ for ( my $i = 0 ; $i < @testFiles ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @testFiles) 40 4 44
154 40 my $f = $fList->get($i);
155 40 foreach my $k ( keys(%{$testFiles[$i]}) ) {
156 280 ▶ if ( !defined($f->{$k}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $f->{$k}) 0 280 280
157 0 print(STDERR "testFiles[$i]{$k} is $testFiles[$i]{$k}, but result is undef\n");
158 0 $ok = 0;
159 0 next;
160 }
161 280 ▶ if ( $testFiles[$i]{$k} ne $f->{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($testFiles[$i]{$k} ne $f->{$k}) 0 280 280
162 0 print(STDERR "$i.$k: $testFiles[$i]{$k} vs $f->{$k}\n");
163 0 $ok = 0;
164 }
165 }
166 }
167 4 ▶ if ( $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 4 0 4
168 4 print("ok $testNum\n");
169 } else {
170 0 print("not ok $testNum\n");
171 }
172 4 $testNum++;
173  
174 4 my $data = $fList->encodeData . pack("C", 0);
175 #printf(STDERR "Protocol = $protocol, hardlinks = $preserve_hard_links, dataLen = %d\n", length($data));
176 #print(STDERR "data = ", unpack("H*", $data), "\n");
177 4 my $fList2 = File::RsyncP::FileList->new($args);
178  
179 4 my $bytesDone = $fList2->decode($data);
180  
181 4 ▶ if ( $bytesDone == length($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytesDone == length $data) { } 4 0 4
182 4 print("ok $testNum\n");
183 } else {
184 0 print("not ok $testNum\n");
185 }
186 4 $testNum++;
187  
188 4 $ok = 1;
189 4 ▶ for ( my $i = 0 ; $i < @testFiles ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @testFiles) 40 4 44
190 40 my $f = $fList2->get($i);
191 40 foreach my $k ( keys(%{$testFiles[$i]}) ) {
192 280 ▶ next if ( $k eq "rdev" );
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "rdev" 0 280 280
193 280 ▶ if ( !defined($f->{$k}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $f->{$k}) 0 280 280
194 0 print(STDERR "testFiles[$i]{$k} is $testFiles[$i]{$k}, but result is undef\n");
195 0 $ok = 0;
196 0 next;
197 }
198 280 ▶ if ( $testFiles[$i]{$k} ne $f->{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($testFiles[$i]{$k} ne $f->{$k}) 0 280 280
199 0 print(STDERR "$i.$k: $testFiles[$i]{$k} vs $f->{$k}\n");
200 0 $ok = 0;
201 }
202 }
203 }
204 4 ▶ if ( $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 4 0 4
205 4 print("ok $testNum\n");
206 } else {
207 0 print("not ok $testNum\n");
208 }
209 4 $testNum++;
210  
211 4 $fList->clean;
212 4 $fList2->clean;
213 4 $ok = 1;
214 4 ▶ for ( my $i = 0 ; $i < $fList2->count ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $fList2->count) 40 4 44
215 40 my $f2 = $fList2->get($i);
216 40 my $f = $fList->get($i);
217 40 foreach my $k ( keys(%$f2) ) {
218 372 ▶ next if ( $k eq "rdev" );
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "rdev" 8 364 372
219 364 ▶ if ( !defined($f->{$k}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $f->{$k}) 0 364 364
220 0 print(STDERR "f2{$k} is $f2->{$k}, but result is undef\n");
221 0 $ok = 0;
222 0 next;
223 }
224 364 ▶ if ( $f2->{$k} ne $f->{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f2->{$k} ne $f->{$k}) 0 364 364
225 0 print(STDERR "$i.$k: $f2->{$k} vs $f->{$k}\n");
226 0 $ok = 0;
227 }
228 }
229 }
230 4 ▶ if ( $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 4 0 4
231 4 print("ok $testNum\n");
232 } else {
233 0 print("not ok $testNum\n");
234 }
235 4 $testNum++;
236  
237 4 return $testNum;
238 }
« blib/lib/File/RsyncP/FileIO.pm ↑ Summary blib/lib/File/RsyncP/Digest.pm »