line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Archive::Libarchive; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
251687
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
26
|
use 5.020; |
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
8
|
use Test2::Tools::Basic qw( diag ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
7
|
1
|
|
|
1
|
|
5
|
use Test2::Tools::Compare qw( is object call T ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
69
|
|
8
|
1
|
|
|
1
|
|
7
|
use Test2::API qw( context release ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
9
|
1
|
|
|
1
|
|
548
|
use Ref::Util qw( is_blessed_ref ); |
|
1
|
|
|
|
|
1867
|
|
|
1
|
|
|
|
|
95
|
|
10
|
1
|
|
|
1
|
|
589
|
use experimental qw( signatures ); |
|
1
|
|
|
|
|
3812
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
907
|
use parent qw( Exporter ); |
|
1
|
|
|
|
|
352
|
|
|
1
|
|
|
|
|
7
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Testing tools for Archive::Libarchive |
14
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @EXPORT = qw( la_ok la_eof la_warn la_failed la_fatal la_read_data_ok ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %code = ( |
20
|
|
|
|
|
|
|
eof => 1, |
21
|
|
|
|
|
|
|
ok => 0, |
22
|
|
|
|
|
|
|
retry => -10, |
23
|
|
|
|
|
|
|
warn => -20, |
24
|
|
|
|
|
|
|
failed => -25, |
25
|
|
|
|
|
|
|
fatal => -30, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _ok |
29
|
|
|
|
|
|
|
{ |
30
|
25
|
|
|
25
|
|
85
|
my($code, $archive, $method, $arguments, $test_name) = @_; |
31
|
|
|
|
|
|
|
|
32
|
25
|
|
33
|
|
|
116
|
$test_name //= do { |
33
|
25
|
|
|
|
|
83
|
my $name = "\$archive->$method"; |
34
|
25
|
100
|
|
|
|
91
|
if(@$arguments) |
35
|
|
|
|
|
|
|
{ |
36
|
10
|
|
|
|
|
23
|
my $first = 1; |
37
|
10
|
|
|
|
|
29
|
$name .= '('; |
38
|
10
|
|
|
|
|
33
|
foreach my $arg (@$arguments) |
39
|
|
|
|
|
|
|
{ |
40
|
30
|
100
|
|
|
|
72
|
$name .= ", " unless $first; |
41
|
30
|
|
|
|
|
45
|
$first = 0; |
42
|
|
|
|
|
|
|
|
43
|
30
|
|
|
|
|
52
|
my $ref = ref $arg; |
44
|
30
|
50
|
|
|
|
63
|
if($ref eq '') |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
45
|
|
|
|
|
|
|
{ |
46
|
30
|
50
|
|
|
|
92
|
if(length $arg > 34) |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
|
|
0
|
$name .= "'@{[ substr($arg, 0, 30) =~ s/\n/\\n/rg ]}...'"; |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else |
51
|
|
|
|
|
|
|
{ |
52
|
30
|
|
|
|
|
53
|
$name .= "'@{[ $arg =~ s/\n/\\n/rg ]}'"; |
|
30
|
|
|
|
|
149
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif($ref eq 'HASH') |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
0
|
$name .= "{...}"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif($ref eq 'ARRAY') |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
0
|
$name .= "[...]"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif($ref eq 'CODE') |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
|
|
0
|
$name .= "sub {...}"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
10
|
|
|
|
|
27
|
$name .= ')'; |
69
|
|
|
|
|
|
|
} |
70
|
25
|
|
|
|
|
66
|
$name .= " == ARCHIVE_@{[ uc $code ]}"; |
|
25
|
|
|
|
|
128
|
|
71
|
25
|
|
|
|
|
112
|
$name; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $ret = is( |
75
|
|
|
|
|
|
|
$archive, |
76
|
|
|
|
|
|
|
object { |
77
|
25
|
|
|
25
|
|
1895
|
call([ isa => 'Archive::Libarchive::Archive' ] => T()); |
78
|
25
|
100
|
|
|
|
2930
|
if(@$arguments) |
79
|
|
|
|
|
|
|
{ |
80
|
10
|
|
|
|
|
53
|
call([ $method => @$arguments ] => $code{$code}); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else |
83
|
|
|
|
|
|
|
{ |
84
|
15
|
|
|
|
|
62
|
call($method => $code{$code}); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
}, |
87
|
25
|
|
|
|
|
226
|
$test_name, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
25
|
100
|
|
|
|
108267
|
unless($ret) |
91
|
|
|
|
|
|
|
{ |
92
|
15
|
50
|
|
|
|
69
|
if(defined $archive) |
93
|
|
|
|
|
|
|
{ |
94
|
15
|
50
|
|
|
|
125
|
if($archive->can('errno')) |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
|
|
0
|
diag("error: @{[ $archive->errno ]}"); |
|
0
|
|
|
|
|
0
|
|
97
|
|
|
|
|
|
|
} |
98
|
15
|
50
|
|
|
|
88
|
if($archive->can('error_string')) |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
|
|
0
|
diag("error: @{[ $archive->error_string ]}"); |
|
0
|
|
|
|
|
0
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
0
|
diag("archive is not defined"); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
25
|
|
|
|
|
118
|
return $ret; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
foreach my $code (qw( ok eof retry warn failed fatal )) { |
114
|
|
|
|
|
|
|
|
115
|
25
|
|
|
|
|
59
|
my $sub = sub ($archive, $method, $arguments=[], $test_name=undef) |
|
25
|
|
|
|
|
57
|
|
|
25
|
|
|
|
|
71
|
|
116
|
25
|
|
|
25
|
|
110244
|
{ |
|
25
|
|
|
|
|
53
|
|
|
25
|
|
|
|
|
47
|
|
117
|
25
|
|
|
|
|
84
|
my $ctx = context(); |
118
|
25
|
|
|
|
|
2332
|
my $ret = _ok($code, $archive, $method, $arguments, $test_name=undef); |
119
|
25
|
|
|
|
|
100
|
$ctx->release; |
120
|
25
|
|
|
|
|
804
|
return $ret; |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
1
|
|
986
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
499
|
|
124
|
|
|
|
|
|
|
*{"la_$code"} = $sub; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
6
|
|
|
|
|
14
|
sub la_read_data_ok ($r, $test_name=undef) |
129
|
6
|
|
|
6
|
1
|
15738
|
{ |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
13
|
|
130
|
6
|
|
|
|
|
18
|
my $ctx = context(); |
131
|
|
|
|
|
|
|
|
132
|
6
|
|
50
|
|
|
533
|
$test_name ||= "\$archive->read_data(\\\$buffer) >= 0; # multiple calls"; |
133
|
|
|
|
|
|
|
|
134
|
6
|
|
|
|
|
12
|
my $content = ''; |
135
|
|
|
|
|
|
|
|
136
|
6
|
100
|
100
|
|
|
94
|
unless(is_blessed_ref $r && $r->isa("Archive::Libarchive::ArchiveRead")) |
137
|
|
|
|
|
|
|
{ |
138
|
2
|
|
|
|
|
12
|
$ctx->fail_and_release($test_name, "Object is not an instance of Archive::Libarchive::ArchiveRead"); |
139
|
2
|
|
|
|
|
454
|
return $content; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
4
|
50
|
|
|
|
21
|
unless($r->can('read_data')) |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
|
|
0
|
$ctx->fail_and_release($test_name, "Object does not implement read_data"); |
145
|
0
|
|
|
|
|
0
|
return $content; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
4
|
|
|
|
|
10
|
my $count = 0; |
149
|
|
|
|
|
|
|
|
150
|
4
|
|
|
|
|
7
|
while(1) |
151
|
|
|
|
|
|
|
{ |
152
|
8
|
|
|
|
|
14
|
my $buffer; |
153
|
8
|
|
|
|
|
11
|
$count++; |
154
|
8
|
|
|
|
|
21
|
my $size = $r->read_data(\$buffer); |
155
|
8
|
100
|
|
|
|
106
|
if($size > 0) |
|
|
100
|
|
|
|
|
|
156
|
|
|
|
|
|
|
{ |
157
|
4
|
|
|
|
|
8
|
$content .= $buffer; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
elsif($size == 0) |
160
|
|
|
|
|
|
|
{ |
161
|
2
|
|
|
|
|
5
|
last; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else |
164
|
|
|
|
|
|
|
{ |
165
|
2
|
|
|
|
|
12
|
my %rcode = map { $code{$_} => "ARCHIVE_" . uc($_) } keys %code; |
|
12
|
|
|
|
|
45
|
|
166
|
2
|
|
|
|
|
18
|
$ctx->fail_and_release($test_name, "Call read_data # $count returned $rcode{$size}"); |
167
|
2
|
|
|
|
|
451
|
return $content; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
2
|
|
|
|
|
10
|
$ctx->pass_and_release($test_name); |
172
|
2
|
|
|
|
|
342
|
return $content; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |