| 1 | package Music::Tag::Test; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; use warnings; use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | our $VERSION = '.4101'; | |||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use base 'Exporter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use vars '@EXPORT'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Test::More; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Digest::SHA1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use File::Copy; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | @EXPORT = qw(create_tag read_tag random_write random_read random_write_num random_read_num random_write_date random_read_date filetest); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | my %values = (); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub create_tag { | ||||||||||||||||||
|
Subroutine
create_tag: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 17 | 0 | my $filetest = shift; | |||||||||||||||||||
| 18 | 0 | my $tagoptions = shift; | |||||||||||||||||||
| 19 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 20 | 0 | ▶ | return 0 unless (-f $filetest); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | ▶ | my $tag = Music::Tag->new($filetest, $tagoptions, $testoptions->{plugin} || 'Auto'); | ||||||||||||||||||
|
Condition0%0/2
$testoptions->{'plugin'} || 'Auto'
MC/DC0%0/1
$testoptions->{'plugin'} || 'Auto'
$testoptions->{'plugin'}
Truth table0%0/2
A
A= $testoptions->{'plugin'}
| |||||||||||||||||||||
| 22 | 0 | ok($tag, 'Object created: ' . $filetest); | |||||||||||||||||||
| 23 | 0 | ▶ | die unless $tag; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 0 | ok($tag->get_tag, 'get_tag called: ' . $filetest); | |||||||||||||||||||
| 25 | 0 | ok($tag->isa('Music::Tag'), 'Correct Class: ' . $filetest); | |||||||||||||||||||
| 26 | 0 | return $tag; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | sub read_tag { | ||||||||||||||||||
|
Subroutine
read_tag: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 30 | 0 | my $tag = shift; | |||||||||||||||||||
| 31 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 32 | 0 | ▶ | return 0 if (! exists $testoptions->{values_in}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | my $c=0; | |||||||||||||||||||
| 34 | 0 | foreach my $meth (keys %{$testoptions->{values_in}}) { | |||||||||||||||||||
| 35 | SKIP: { | ||||||||||||||||||||
| 36 | 0 | ▶ | skip "$meth test skipped", 1 if (! $testoptions->{values_in}->{$meth}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 0 | $c++; | |||||||||||||||||||
| 38 | 0 | cmp_ok($tag->$meth, 'eq', $testoptions->{values_in}->{$meth}); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | 0 | return $c; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub random_write { | ||||||||||||||||||
|
Subroutine
random_write: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 45 | 0 | my $tag = shift; | |||||||||||||||||||
| 46 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 47 | 0 | ▶ | return 0 if (! exists $testoptions->{random_write}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 0 | my $c = 0; | |||||||||||||||||||
| 49 | 0 | foreach my $meth (@{$testoptions->{random_write}}) { | |||||||||||||||||||
| 50 | 0 | my $val = "test" . $meth . int(rand(1000)); | |||||||||||||||||||
| 51 | 0 | $values{$meth} = $val; | |||||||||||||||||||
| 52 | 0 | ok($tag->$meth($val), 'auto write to ' . $meth); | |||||||||||||||||||
| 53 | 0 | $c++; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 0 | return $c; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub random_write_num { | ||||||||||||||||||
|
Subroutine
random_write_num: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 59 | 0 | my $tag = shift; | |||||||||||||||||||
| 60 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 61 | 0 | ▶ | return 0 if (! exists $testoptions->{random_write_num}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | my $c = 0; | |||||||||||||||||||
| 63 | 0 | foreach my $meth (@{$testoptions->{random_write_num}}) { | |||||||||||||||||||
| 64 | 0 | my $val = int(rand(10))+1; | |||||||||||||||||||
| 65 | 0 | $values{$meth} = $val; | |||||||||||||||||||
| 66 | 0 | ok($tag->$meth($val), 'auto write to ' . $meth); | |||||||||||||||||||
| 67 | 0 | $c++; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 0 | return $c; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | sub random_write_date { | ||||||||||||||||||
|
Subroutine
random_write_date: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 73 | 0 | my $tag = shift; | |||||||||||||||||||
| 74 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 75 | 0 | ▶ | return 0 if (! exists $testoptions->{random_write_date}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | my $c = 0; | |||||||||||||||||||
| 77 | 0 | foreach my $meth (@{$testoptions->{random_write_date}}) { | |||||||||||||||||||
| 78 | 0 | my $val = int(rand(1_400_000_000)) + 399_999_999; | |||||||||||||||||||
| 79 | 0 | $values{$meth} = $val; | |||||||||||||||||||
| 80 | 0 | ok($tag->$meth($val), 'auto write to '. $meth); | |||||||||||||||||||
| 81 | 0 | $c++; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | 0 | return $c; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | sub random_read { | ||||||||||||||||||
|
Subroutine
random_read: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | my $tag = shift; | |||||||||||||||||||
| 88 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 89 | 0 | ▶ | return 0 if (! exists $testoptions->{random_write}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | my $c = 0; | |||||||||||||||||||
| 91 | 0 | foreach my $meth (@{$testoptions->{random_write}}) { | |||||||||||||||||||
| 92 | 0 | cmp_ok($tag->$meth, 'eq', $values{$meth}, 'auto read of ' . $meth); | |||||||||||||||||||
| 93 | 0 | $c++; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | 0 | return $c; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | sub random_read_num { | ||||||||||||||||||
|
Subroutine
random_read_num: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 99 | 0 | my $tag = shift; | |||||||||||||||||||
| 100 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 101 | 0 | ▶ | return 0 if (! exists $testoptions->{random_write_num}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 0 | my $c = 0; | |||||||||||||||||||
| 103 | 0 | foreach my $meth (@{$testoptions->{random_write_num}}) { | |||||||||||||||||||
| 104 | 0 | cmp_ok($tag->$meth, '==', $values{$meth}, 'auto read of ' . $meth); | |||||||||||||||||||
| 105 | 0 | $c++; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | 0 | return $c; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub random_read_date { | ||||||||||||||||||
|
Subroutine
random_read_date: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 111 | 0 | my $tag = shift; | |||||||||||||||||||
| 112 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 113 | 0 | ▶ | return 0 if (! exists $testoptions->{random_write_date}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 0 | my $c = 0; | |||||||||||||||||||
| 115 | 0 | foreach my $meth (@{$testoptions->{random_write_date}}) { | |||||||||||||||||||
| 116 | 0 | my $meth_t = $meth; | |||||||||||||||||||
| 117 | 0 | $meth_t =~ s/epoch/time/; | |||||||||||||||||||
| 118 | 0 | my $meth_d = $meth; | |||||||||||||||||||
| 119 | 0 | $meth_d =~ s/epoch/date/; | |||||||||||||||||||
| 120 | 0 | $meth_d =~ s/_date//; | |||||||||||||||||||
| 121 | 0 | my @tm = gmtime($values{$meth}); | |||||||||||||||||||
| 122 | 0 | cmp_ok(substr($tag->$meth_t,0,16), 'eq', substr(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $tm[5]+1900, $tm[4]+1, $tm[3], $tm[2], $tm[1], $tm[0]),0,16), 'auto read from '. $meth_t); | |||||||||||||||||||
| 123 | 0 | cmp_ok($tag->$meth_d, 'eq', sprintf('%04d-%02d-%02d', $tm[5]+1900, $tm[4]+1, $tm[3]), 'auto read from '. $meth_d); | |||||||||||||||||||
| 124 | 0 | $c+=2; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | 0 | return $c; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 0 | ▶ | sub read_picture { | ||||||||||||||||||
|
Subroutine
read_picture: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 130 | 0 | my $tag = shift; | |||||||||||||||||||
| 131 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 132 | 0 | my $c = 0; | |||||||||||||||||||
| 133 | 0 | ▶ | return 0 if (! $testoptions->{picture_read}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | 0 | ok($tag->picture_exists, 'Picture Exists'); | |||||||||||||||||||
| 135 | 0 | $c+=2; | |||||||||||||||||||
| 136 | 0 | ▶ | if ($testoptions->{picture_sha1}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | 0 | my $sha1 = Digest::SHA1->new(); | |||||||||||||||||||
| 138 | 0 | $sha1->add($tag->picture->{_Data}); | |||||||||||||||||||
| 139 | 0 | cmp_ok($sha1->hexdigest, 'eq', $testoptions->{picture_sha1}, 'digest of picture matches during read'); | |||||||||||||||||||
| 140 | 0 | $c++; | |||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | ▶ | sub write_picture { | ||||||||||||||||||
|
Subroutine
write_picture: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 145 | 0 | my $tag = shift; | |||||||||||||||||||
| 146 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 147 | 0 | my $c = 0; | |||||||||||||||||||
| 148 | 0 | ▶ | return 0 if (! $testoptions->{picture_file}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 149 | 0 | ok($tag->picture_filename($testoptions->{picture_file}), 'add picture'); | |||||||||||||||||||
| 150 | 0 | ok($tag->picture_exists, 'Picture Exists after write'); | |||||||||||||||||||
| 151 | 0 | $c+=2; | |||||||||||||||||||
| 152 | 0 | ▶ | if ($testoptions->{picture_sha1}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 153 | 0 | my $sha1 = Digest::SHA1->new(); | |||||||||||||||||||
| 154 | 0 | $sha1->add($tag->picture->{_Data}); | |||||||||||||||||||
| 155 | 0 | cmp_ok($sha1->hexdigest, 'eq', $testoptions->{picture_sha1}, 'digest of picture matches after write'); | |||||||||||||||||||
| 156 | 0 | $c++; | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | 0 | return $c; | |||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 0 | ▶ | sub filetest { | ||||||||||||||||||
|
Subroutine
filetest: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||
| 162 | 0 | my $file = shift; | |||||||||||||||||||
| 163 | 0 | my $filetest = shift; | |||||||||||||||||||
| 164 | 0 | my $tagoptions = shift; | |||||||||||||||||||
| 165 | 0 | my $testoptions = shift; | |||||||||||||||||||
| 166 | 0 | my $c = 0; | |||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | SKIP: { | ||||||||||||||||||||
| 169 | 0 | ▶ | skip ("File: $file does not exists", $testoptions->{count} || 1) if (! -f $file); | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$testoptions->{'count'} || 1
MC/DC0%0/1
$testoptions->{'count'} || 1
$testoptions->{'count'}
Truth table0%0/2
A
A= $testoptions->{'count'}
| |||||||||||||||||||||
| 170 | 0 | ▶ | return unless (-f $file); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | 0 | copy($file, $filetest); | |||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 0 | my $tag = create_tag($filetest,$tagoptions,$testoptions); | |||||||||||||||||||
| 174 | 0 | $c+=3; | |||||||||||||||||||
| 175 | 0 | ▶ | die unless $tag; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 0 | read_tag($tag,$testoptions); | |||||||||||||||||||
| 179 | 0 | ▶ | if ($testoptions->{picture_in}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 180 | 0 | ok($tag->picture_exists, 'Picture should exists'); | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | else { | ||||||||||||||||||||
| 183 | 0 | ok(! $tag->picture_exists, 'Picture should not exist'); | |||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | 0 | $c++; | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 0 | ▶ | if ($testoptions->{skip_write_tests}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 188 | 0 | $tag->close(); | |||||||||||||||||||
| 189 | 0 | $tag = undef; | |||||||||||||||||||
| 190 | } | ||||||||||||||||||||
| 191 | else { | ||||||||||||||||||||
| 192 | 0 | $c+= random_write($tag,$testoptions); | |||||||||||||||||||
| 193 | 0 | $c+= random_write_num($tag,$testoptions); | |||||||||||||||||||
| 194 | 0 | $c+= random_write_date($tag,$testoptions); | |||||||||||||||||||
| 195 | 0 | $c+= write_picture($tag,$testoptions); | |||||||||||||||||||
| 196 | 0 | ok($tag->set_tag, 'set_tag: ' . $filetest); | |||||||||||||||||||
| 197 | 0 | $c++; | |||||||||||||||||||
| 198 | 0 | $tag->close(); | |||||||||||||||||||
| 199 | 0 | $tag = undef; | |||||||||||||||||||
| 200 | 0 | my $tag2 = create_tag($filetest,$tagoptions,$testoptions); | |||||||||||||||||||
| 201 | 0 | $c+=3; | |||||||||||||||||||
| 202 | 0 | $c+= random_read($tag2,$testoptions); | |||||||||||||||||||
| 203 | 0 | $c+= random_read_num($tag2,$testoptions); | |||||||||||||||||||
| 204 | 0 | $c+= random_read_date($tag2,$testoptions); | |||||||||||||||||||
| 205 | 0 | $c+= read_picture($tag2,$testoptions); | |||||||||||||||||||
| 206 | 0 | $tag2->close(); | |||||||||||||||||||
| 207 | } | ||||||||||||||||||||
| 208 | 0 | unlink($filetest); | |||||||||||||||||||
| 209 | 0 | return $c; | |||||||||||||||||||
| 210 | } | ||||||||||||||||||||
| 211 | } | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 1 | 1; | |||||||||||||||||||
| 215 | __END__ | ||||||||||||||||||||