Firemen/Analyze.pm

filter: Statementstmt 80.2% 285 / 355 Branchbran 71.5% 123 / 172 Conditioncond 53.3% 24 / 45 MC/DCmcdc 28.5% 8 / 28 Subroutinesub 100% 14 / 14 Podpod 100% 5 / 5 totaltotal 74.1% 459 / 619 CC 119 SCAR 55.2
CC
119
Cov
76%
checkConfig
360.2
compare
17.2
checkTreeConfig
14.7
CRAP 249.4
« Firemen/ParseHelp/Creo3.pm ↑ Summary Firemen/Common.pm »
1 #!/usr/bin/perl
2 ######################
3 #
4 # Copyright (C) 2011 TU Clausthal, Institut fuer Maschinenwesen, Joachim Langenbach
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 ######################
20  
21 # Pod::Weaver infos
22 # ABSTRACT: Module provides functions to compare to lists with options (and values)
23  
24 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 package CAD::Firemen::Analyze;
28 {
29 9 $CAD::Firemen::Analyze::VERSION = '0.7.2';
30 }
31 9 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 9 our @EXPORT_OK = qw(compare checkConfig checkTreeConfig optionsToIngoreAtPathCheckings);
33 9 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 9 ▶use CAD::Firemen::Change;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 9 ▶use CAD::Firemen::Common qw(print2ColsRightAligned printBlock maxLength testPassed testFailed printColored strip);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 9 ▶use CAD::Firemen::Load qw(loadCDB loadConfig loadDatabase);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use CAD::Firemen::Option::Check;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 3 ▶sub compare {
Subroutine compare: called CC=17 SCAR=28.5
Pod documented
42 3 my %options1 = ();
43 3 my %options2 = ();
44 3 my $refOptions1 = shift;
45 3 my $refOptions2 = shift;
46  
47 # result variables
48 3 my %added = ();
49 3 my %changed = ();
50 3 my %removed = ();
51 3 my %duplicates = ();
52  
53 3 ▶ if(!defined($refOptions1)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $refOptions1) 0 3 3
54 0 return (\%added, \%changed, \%removed, \%duplicates);
55 }
56 3 ▶ if(!defined($refOptions2)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $refOptions2) 0 3 3
57 0 return (\%added, \%changed, \%removed, \%duplicates);
58 }
59 3 %options1 = %{$refOptions1};
60 3 %options2= %{$refOptions2};
61  
62 # Compare the options
63 # get the options, which are set in config 2 and not in config 1 (added)
64 # also determine changed options
65 3 foreach my $opt (sort(keys(%options2))){
66 56 ▶ if(scalar(keys(%{$options2{$opt}})) > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$options2{$opt};} > 1) 1 55 56
67 1 $duplicates{$opt} = "Duplicated in second config at lines ". join(", ", keys(%{$options2{$opt}})) .".";
68 }
69 56 ▶ if(!exists($options1{$opt})){
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $options1{$opt}) { } 12 44 56
70 12 my @keys = keys(%{$options2{$opt}});
71 12 $added{$opt} = $keys[0];
72 }
73 else{
74 44 ▶ if(scalar(keys(%{$options1{$opt}})) > 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$options1{$opt};} > 1) 1 43 44
75 1 ▶ if(exists($duplicates{$opt})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $duplicates{$opt}) { } 1 0 1
76 1 $duplicates{$opt} .= " ";
77 }
78 else{
79 0 $duplicates{$opt} = "";
80 }
81 1 $duplicates{$opt} .= "Duplicated in first config at lines ". join(", ", keys(%{$options1{$opt}})) .".";
82 }
83 # evalute changes and assume, that the order is not changed
84 # @TODO Get those combination of changes, with less changes
85 # e.g. a change with Case only is smaller change than NoSpecial and so on
86 44 my $max = $options1{$opt};
87 44 my $min = $options2{$opt};
88 44 my @keys1 = sort(keys(%{$options1{$opt}}));
89 44 my @keys2 = sort(keys(%{$options2{$opt}}));
90 44 ▶ if(ref($options1{$opt}->{$keys1[0]}) eq "HASH"){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $options1{$opt}{$keys1[0]} eq "HASH") 5 39 44
91 # it's the format of the cdb files, do not try to detect changes
92 5 next;
93 }
94 39 ▶ if(scalar(@keys1) < scalar(@keys2)){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys1 < scalar @keys2) 1 38 39
95 1 $max = $options2{$opt};
96 1 $min = $options1{$opt};
97 }
98 39 ▶ for(my $i = 0; $i < scalar(keys(%{$max})); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar keys %{$max;}) 41 39 80
99 41 my $change = new CAD::Firemen::Change("name" => $opt);
100 41 ▶ if($i < scalar(keys(%{$min}))){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar keys %{$min;}) { } 40 1 41
101 40 $change->setValueOld($options1{$opt}->{$keys1[$i]});
102 40 $change->setValueNew($options2{$opt}->{$keys2[$i]});
103 }
104 else{
105 1 ▶ if(scalar(@keys1) < scalar(@keys2)){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys1 < scalar @keys2) { } 1 0 1
106 1 $change->setValueOld("NOT AVAILABLE");
107 1 $change->setValueNew($options2{$opt}->{$keys2[$i]});
108 }
109 else{
110 0 $change->setValueOld($options1{$opt}->{$keys1[$i]});
111 0 $change->setValueNew("NOT AVAILABLE");
112 }
113 }
114 41 $change->evalChange();
115 41 ▶ if(!$change->changeType(CAD::Firemen::Change::Type->NoChange)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($change->changeType("CAD::Firemen::Change::Type"->NoChange)) 12 29 41
116 12 ▶ if(!exists($changed{$opt})){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $changed{$opt}) 10 2 12
117 10 $changed{$opt} = [];
118 }
119 12 push(@{$changed{$opt}}, $change);
120 }
121 }
122 }
123 }
124  
125 3 foreach my $opt (sort(keys(%options1))){
126 51 ▶ if(!exists($options2{$opt})){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options2{$opt}) 7 44 51
127 7 my @keys = keys(%{$options1{$opt}});
128 7 $removed{$opt} = $keys[0];
129 }
130 }
131  
132 3 return (\%added, \%changed, \%removed, \%duplicates);
133 }
134  
135 23 ▶sub optionsToIngoreAtPathCheckings {
Subroutine optionsToIngoreAtPathCheckings: called CC=1 SCAR=0.0
Pod documented
136 # allowed options with relative paths
137 # (it is only checked, whether the key exists, the value is ignored)
138 23 my %allowedRelativePaths = ();
139 23 $allowedRelativePaths{"TRAIL_DIR"} = 1;
140 23 $allowedRelativePaths{"PROTKDAT"} = 1;
141 23 return %allowedRelativePaths;
142 }
143  
144 23 ▶sub optionsToIngoreAtDuplicatesCheckings {
Subroutine optionsToIngoreAtDuplicatesCheckings: called CC=1 SCAR=0.0
Pod documented
145 # allowed options with relative paths
146 # (it is only checked, whether the key exists, the value is ignored)
147 23 my %allowedDuplicates = ();
148 23 $allowedDuplicates{"PROTKDAT"} = 1;
149 23 return %allowedDuplicates;
150 }
151  
152 23 ▶sub checkConfig {
Subroutine checkConfig: called CC=90 SCAR=58.9
Pod documented
153 23 my (%params) = @_;
154 23 my $dbh = $params{"databaseHandle"};
155 23 my $cdbUrl = $params{"cdbUrl"};
156 23 my $cfgUrl = $params{"cfgUrl"};
157 23 my $caseInsensitive = $params{"caseInsensitive"};
158 23 my $verbose = $params{"verbose"};
159 23 my $description = $params{"description"};
160  
161 # allowed options with relative paths
162 # (it is only checked, whether the key exists, the value is ignored)
163 23 my %allowedRelativePaths = optionsToIngoreAtPathCheckings();
164  
165 # allowed options with occurence greater one
166 23 my %allowedDuplicates = optionsToIngoreAtDuplicatesCheckings();
167  
168 23 my %options = ();
169 23 my %descriptions = ();
170 23 my %resultsCompare = ();
171 23 my %resultsDuplicates = ();
172 23 my %resultsWrongValues = ();
173 23 my %resultsAbsolutePaths = ();
174 23 my %resultsDefaultValues= ();
175 23 my $checkResult = 1;
176  
177 23 ▶ if(!defined($verbose)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $verbose) 13 10 23
178 13 $verbose = 0;
179 }
180 23 ▶ if(!defined($caseInsensitive)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $caseInsensitive) 21 2 23
181 21 $caseInsensitive = 0;
182 }
183 23 ▶ if(!defined($description)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $description) 23 0 23
184 23 $description = 0;
185 }
186  
187 23 ▶ if(!defined($dbh) && (!defined($cdbUrl) || $cdbUrl eq "")){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dbh and !defined($cdbUrl) || $cdbUrl eq "") 2 21 23
Condition83%5/6
not defined $dbh and !defined($cdbUrl) || $cdbUrl eq ""
!ll&&!rl&&r
0212
not defined $cdbUrl or $cdbUrl eq ""
l!l&&r!l&&!r
1121
MC/DC66%2/3
not defined $dbh and !defined($cdbUrl) || $cdbUrl eq ""
not defined $dbh not defined $cdbUrl $cdbUrl eq ""
Truth table75%3/4
not(A) and not(B) or C
A= not defined $dbhB= not defined $cdbUrlC= $cdbUrl eq ""
ABCresult
0XX0
1000
11X1
1011
188 2 return 0;
189 }
190  
191 21 ▶ if(!defined($cfgUrl) || $cfgUrl eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cfgUrl or $cfgUrl eq "") 4 17 21
Condition100%3/3
not defined $cfgUrl or $cfgUrl eq ""
l!l&&r!l&&!r
1317
MC/DC100%2/2
not defined $cfgUrl or $cfgUrl eq ""
not defined $cfgUrl $cfgUrl eq ""
Truth table100%3/3
not(A) or B
A= not defined $cfgUrlB= $cfgUrl eq ""
ABresult
1X1
011
000
192 4 return 0;
193 }
194  
195 17 ▶ if($verbose > 2){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 2) 8 9 17
196 8 ▶ if($dbh){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh) 0 8 8
197 0 print "Database: ". $dbh->{Name} ."\n";
198 }
199 8 print "CDB URL: ". $cdbUrl ."\n";
200 8 print "Config URL: ". $cfgUrl ."\n";
201 }
202  
203 17 ▶ if(!defined($dbh)){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dbh) { } 17 0 17
204 17 my ($ref1, $ref2) = loadCDB($cdbUrl, $verbose);
205 17 %options = %{$ref1};
206 17 my %errorsCDB = %{$ref2};
207 17 ▶ if(scalar(keys(%errorsCDB))){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %errorsCDB) 3 14 17
208 3 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 1 2 3
209 1 testFailed("Load CDB");
210 }
211 3 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 1 2 3
212 1 print "Errors while parsing ". $cdbUrl .":\n";
213 0 my @lines = sort { $a <=> $b } keys(%errorsCDB);
214 1 my $max = length($lines[scalar(@lines) - 1]);
215 1 foreach my $line (@lines){
216 1 printColored(sprintf("%". $max ."s", $line) .": ". $errorsCDB{$line} ."\n", "red");
217 }
218 }
219 3 return 0;
220 }
221 }
222 else{
223 0 my ($ref1, $ref2, $ref3) = loadDatabase($dbh, "SELECT * FROM options", $verbose);
224 0 %options = %{$ref1};
225 0 my %errors = %{$ref2};
226 0 %descriptions = %{$ref3};
227 0 ▶ if(scalar(keys(%errors))){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %errors) 0 0 0
228 0 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 0 0 0
229 0 testFailed("Query Database");
230 }
231 0 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
232 0 print "Errors whilequerying the database ". $dbh->{Name} .":\n";
233 0 my @lines = sort { $a <=> $b } keys(%errors);
234 0 my $max = length($lines[scalar(@lines) - 1]);
235 0 foreach my $line (@lines){
236 0 printColored(sprintf("%". $max ."s", $line) .": ". $errors{$line} ."\n", "red");
237 }
238 }
239 0 return 0;
240 }
241 }
242  
243 14 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 7 7 14
244 7 my $name = $cdbUrl;
245 7 ▶ if($dbh){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh) 0 7 7
246 0 $name = $dbh->{Name};
247 }
248 7 print2ColsRightAligned("Load Options from ". $name, scalar(keys(%options)), "green");
249 }
250 14 ▶ if($verbose > 2){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 2) 7 7 14
251 7 foreach my $key (sort(keys(%options))){
252 7428 print $key ."\n";
253 7428 foreach my $param (sort(keys(%{$options{$key}}))){
254 7428 print " ". $param;
255 7428 ▶ if($options{$param}){
Branch: 1 branch
BranchTrueFalseTotal
if ($options{$param}) 0 7428 7428
256 0 print " (Default)";
257 }
258 7428 print "\n";
259 }
260 }
261 }
262  
263 # Load the config.pro file and check, if there are not supported options
264 14 my ($resultRef, $errorRef, $parsedLines) = loadConfig($cfgUrl);
265 14 my %cfgOptions = %{$resultRef};
266 14 my %errors = %{$errorRef};
267 14 ▶ if(scalar(keys(%errors)) < 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %errors < 1) { } 10 4 14
268 10 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 5 5 10
269 5 testPassed("Load Config (Lines: ". $parsedLines .", Options: ". scalar(keys(%cfgOptions)) .")");
270 }
271 }
272 else{
273 4 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 2 2 4
274 2 testFailed("Load Config");
275 }
276 4 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 2 2 4
277 0 my @lines = sort { $a <=> $b } keys(%errors);
278 2 my $length = length($lines[scalar(@lines) - 1]);
279 2 foreach my $line (@lines){
280 2 print sprintf("%". $length ."s", $line) .": ". $errors{$line} ."\n";
281 }
282 }
283 4 return 0;
284 }
285  
286 10 foreach my $opt (keys(%cfgOptions)){
287 # check of existence
288 320 ▶ if(!exists($options{$opt})){
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $options{$opt}) { } 2 318 320
289 2 my @lines = keys(%{$cfgOptions{$opt}});
290 2 $resultsCompare{$lines[0]} = new CAD::Firemen::Option::Check(
291 "name" => $opt,
292 "errorString" => "The option ". $opt ." is not listed in given cdb"
293 2 ); "The option ". $opt ." is not listed in given cdb";
294 }
295 else{
296 318 foreach my $line (keys(%{$cfgOptions{$opt}})){
297 # checks whether the given value is supported
298 318 ▶ if(scalar(keys(%{$options{$opt}})) > 0){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$options{$opt};} > 0) 318 0 318
299 318 my $found = 0;
300 318 my $case = 0;
301 318 my @cdbKeys = keys(%{$options{$opt}});
302 318 my $cdbKey = $cdbKeys[0];
303 318 foreach my $value (keys(%{$options{$opt}->{$cdbKey}})){
304 # handle special case ( -FS )
305 # I think ( -Fs ) means something like Free String
306 # Therefore all values which have the possible Value ( -Fs )
307 # are set to found, if they are not empty
308 498 ▶ if($value eq "( -Fs )"){
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "( -Fs )") 130 368 498
309 130 ▶ if($cfgOptions{$opt}->{$line} ne ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($cfgOptions{$opt}{$line} ne "") 130 0 130
310 130 $found = 1;
311 130 last;
312 }
313 }
314 # it's equal to default value
315 368 ▶ if((uc($value) eq uc($cfgOptions{$opt}->{$line})) && $options{$opt}->{$cdbKey}->{$value}){
Branch: 1 branch
BranchTrueFalseTotal
if (uc $value eq uc $cfgOptions{$opt}{$line} and $options{$opt}{$cdbKey}{$value}) 0 368 368
Condition66%2/3
uc $value eq uc $cfgOptions{$opt}{$line} and $options{$opt}{$cdbKey}{$value}
!ll&&!rl&&r
1801880
MC/DC0%0/2
uc $value eq uc $cfgOptions{$opt}{$line} and $options{$opt}{$cdbKey}{$value}
uc $value eq uc $cfgOptions{$opt}{$line} $options{$opt}{$cdbKey}{$value}
Truth table66%2/3
A and B
A= uc $value eq uc $cfgOptions{$opt}{$line}B= $options{$opt}{$cdbKey}{$value}
ABresult
0X0
100
111
316 0 $resultsDefaultValues{$line} = new CAD::Firemen::Option::Check(
317 "name" => $opt,
318 "errorString" => "The option ". $opt ." is equal to default value (". $value .")"
319 );
320 }
321 368 ▶ if($value eq $cfgOptions{$opt}->{$line}){
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq $cfgOptions{$opt}{$line}) 184 184 368
322 184 $found = 1;
323 184 last;
324 }
325 184 ▶ if(uc($value) eq uc($cfgOptions{$opt}->{$line})){
Branch: 1 branch
BranchTrueFalseTotal
if (uc $value eq uc $cfgOptions{$opt}{$line}) 4 180 184
326 4 $case = 1;
327 4 last;
328 }
329 }
330 318 ▶ if(!$found){
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 4 314 318
331 $resultsWrongValues{$line} = new CAD::Firemen::Option::Check(
332 "name" => $opt,
333 4 "errorString" => "The option ". $opt ." has not supported value ". $cfgOptions{$opt}->{$line} ." (Possible: ". join("|", keys(%{$options{$opt}->{$cdbKey}})) .")",
334 "case" => $case
335 );
336 }
337 }
338 # check that only relative paths are used,
339 # if this option is not listed in %allowedRelativePaths
340 318 ▶ if(!exists($allowedRelativePaths{$opt}) && File::Spec->file_name_is_absolute($cfgOptions{$opt}->{$line})){
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $allowedRelativePaths{$opt} and "File::Spec"->file_name_is_absolute($cfgOptions{$opt}{$line})) 0 318 318
Condition66%2/3
not exists $allowedRelativePaths{$opt} and "File::Spec"->file_name_is_absolute($cfgOptions{$opt}{$line})
!ll&&!rl&&r
103080
MC/DC0%0/2
not exists $allowedRelativePaths{$opt} and "File::Spec"->file_name_is_absolute($cfgOptions{$opt}{$line})
not exists $allowedRelativePaths{$opt} "File::Spec"->file_name_is_absolute($cfgOptions{$opt}{$line})
Truth table66%2/3
not(A) and B
A= not exists $allowedRelativePaths{$opt}B= "File::Spec"->file_name_is_absolute($cfgOptions{$opt}{$line})
ABresult
0X0
100
111
341 $resultsAbsolutePaths{$line} = new CAD::Firemen::Option::Check(
342 "name" => $opt,
343 0 "errorString" => "The Option ". $opt ." contains an absolute path: ". $cfgOptions{$opt}->{$line}
344 );
345 }
346 }
347 }
348  
349 # check for duplicates
350 320 ▶ if(!exists($allowedDuplicates{$opt}) && (scalar(keys(%{$cfgOptions{$opt}})) > 1)){
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $allowedDuplicates{$opt} and scalar keys %{$cfgOptions{$opt};} > 1) 0 320 320
Condition33%1/3
not exists $allowedDuplicates{$opt} and scalar keys %{$cfgOptions{$opt};} > 1
!ll&&!rl&&r
03200
MC/DC0%0/2
not exists $allowedDuplicates{$opt} and scalar keys %{$cfgOptions{$opt};} > 1
not exists $allowedDuplicates{$opt} scalar keys %{$cfgOptions{$opt};} > 1
Truth table33%1/3
not(A) and B
A= not exists $allowedDuplicates{$opt}B= scalar keys %{$cfgOptions{$opt};} > 1
ABresult
0X0
100
111
351 $resultsDuplicates{$opt} = new CAD::Firemen::Option::Check(
352 "name" => $opt,
353 0 "errorString" => "The Option ". $opt ." is set at lines ". join(", ", keys(%{$cfgOptions{$opt}}))
354 );
355 }
356 }
357  
358 # print the result of the compare check (if option exists)
359 0 my @keys = sort { $a <=> $b } keys(%resultsCompare);
360 10 ▶ if(scalar(@keys) < 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys < 1) { } 8 2 10
361 8 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 4 4 8
362 4 testPassed("COMPARE");
363 }
364 }
365 else{
366 2 $checkResult = 0;
367 2 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 1 1 2
368 1 testFailed("COMPARE");
369 }
370 2 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 1 1 2
371 1 my $length = length($keys[scalar(@keys) - 1]);
372 1 foreach my $key (@keys){
373 1 print sprintf("%". $length ."s", $key) .": ". $resultsCompare{$key}->errorString() ."\n";
374 1 ▶ if($description && exists($descriptions{$resultsCompare{$key}->option()})){
Branch: 1 branch
BranchTrueFalseTotal
if ($description and exists $descriptions{$resultsCompare{$key}->option}) 0 1 1
Condition33%1/3
$description and exists $descriptions{$resultsCompare{$key}->option}
!ll&&!rl&&r
100
MC/DC0%0/2
$description and exists $descriptions{$resultsCompare{$key}->option}
$description exists $descriptions{$resultsCompare{$key}->option}
Truth table33%1/3
A and B
A= $descriptionB= exists $descriptions{$resultsCompare{$key}->option}
ABresult
0X0
100
111
375 0 printBlock($descriptions{$resultsCompare{$key}->option()}, $length + 4);
376 }
377 }
378 }
379 }
380  
381 # print the result of the value check
382 # handle ignored cases
383 0 @keys = sort { $a <=> $b } keys(%resultsWrongValues);
384 10 my $ignored = 0;
385 10 foreach my $key (@keys){
386 4 ▶ if($resultsWrongValues{$key}->case()){
Branch: 1 branch
BranchTrueFalseTotal
if ($resultsWrongValues{$key}->case) 4 0 4
387 4 $ignored++;
388 }
389 }
390 10 ▶ if(!$caseInsensitive){
Branch: 1 branch
BranchTrueFalseTotal
unless ($caseInsensitive) 8 2 10
391 8 $ignored = 0;
392 }
393 10 ▶ if((scalar(@keys) < 1) || ($caseInsensitive && (scalar(@keys) == $ignored))){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys < 1 or $caseInsensitive and scalar @keys == $ignored) { } 8 2 10
Condition83%5/6
scalar @keys < 1 or $caseInsensitive and scalar @keys == $ignored
l!l&&r!l&&!r
622
$caseInsensitive and scalar @keys == $ignored
!ll&&!rl&&r
202
MC/DC66%2/3
scalar @keys < 1 or $caseInsensitive and scalar @keys == $ignored
scalar @keys < 1 $caseInsensitive scalar @keys == $ignored
Truth table75%3/4
A or B and C
A= scalar @keys < 1B= $caseInsensitiveC= scalar @keys == $ignored
ABCresult
1XX1
0111
00X0
0100
394 8 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 4 4 8
395 4 testPassed("VALUES (Ignored: ". $ignored .")");
396 }
397 }
398 else{
399 2 $checkResult = 0;
400 2 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 1 1 2
401 1 testFailed("VALUES (Ignored: ". $ignored .")");
402 }
403 2 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 1 1 2
404 1 my $length = length($keys[scalar(@keys) - 1]);
405 1 foreach my $key (@keys){
406 1 my $color = "reset";
407 1 ▶ if($resultsWrongValues{$key}->case()){
Branch: 1 branch
BranchTrueFalseTotal
if ($resultsWrongValues{$key}->case) 1 0 1
408 1 $color = "cyan";
409 }
410 1 ▶ if(!$resultsWrongValues{$key}->case() || !$caseInsensitive){
Branch: 1 branch
BranchTrueFalseTotal
unless ($resultsWrongValues{$key}->case and $caseInsensitive) 1 0 1
Condition33%1/3
$resultsWrongValues{$key}->case and $caseInsensitive
!ll&&!rl&&r
010
MC/DC0%0/2
$resultsWrongValues{$key}->case and $caseInsensitive
$resultsWrongValues{$key}->case $caseInsensitive
Truth table33%1/3
A and B
A= $resultsWrongValues{$key}->caseB= $caseInsensitive
ABresult
0X0
100
111
411 1 printColored(sprintf("%". $length ."s", $key) .": ". $resultsWrongValues{$key}->errorString() ."\n", $color);
412 1 ▶ if($description && exists($descriptions{$resultsWrongValues{$key}->option()})){
Branch: 1 branch
BranchTrueFalseTotal
if ($description and exists $descriptions{$resultsWrongValues{$key}->option}) 0 1 1
Condition33%1/3
$description and exists $descriptions{$resultsWrongValues{$key}->option}
!ll&&!rl&&r
100
MC/DC0%0/2
$description and exists $descriptions{$resultsWrongValues{$key}->option}
$description exists $descriptions{$resultsWrongValues{$key}->option}
Truth table33%1/3
A and B
A= $descriptionB= exists $descriptions{$resultsWrongValues{$key}->option}
ABresult
0X0
100
111
413 0 printBlock($descriptions{$resultsWrongValues{$key}->option()}, $length + 4);
414 }
415 }
416 }
417 }
418 }
419  
420 # print the result of the default values here (they are not treated as errors)
421 0 @keys = sort { $a <=> $b } keys(%resultsDefaultValues);
422 10 ▶ if(scalar(@keys) < 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys < 1) { } 10 0 10
423 10 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 5 5 10
424 5 testPassed("Default values");
425 }
426 }
427 else{
428 0 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 0 0 0
429 0 print2ColsRightAligned("Default values", scalar(@keys), "yellow");
430 }
431 0 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
432 0 my $length = length($keys[scalar(@keys) - 1]);
433 0 foreach my $key (@keys){
434 0 print sprintf("%". $length ."s", $key) .": ". $resultsDefaultValues{$key}->errorString() ."\n";
435 0 ▶ if($description && exists($descriptions{$resultsDefaultValues{$key}->option()})){
Branch: 1 branch
BranchTrueFalseTotal
if ($description and exists $descriptions{$resultsDefaultValues{$key}->option}) 0 0 0
Condition0%0/3
$description and exists $descriptions{$resultsDefaultValues{$key}->option}
!ll&&!rl&&r
000
MC/DC0%0/2
$description and exists $descriptions{$resultsDefaultValues{$key}->option}
$description exists $descriptions{$resultsDefaultValues{$key}->option}
Truth table0%0/3
A and B
A= $descriptionB= exists $descriptions{$resultsDefaultValues{$key}->option}
ABresult
0X0
100
111
436 0 printBlock($descriptions{$resultsDefaultValues{$key}->option()}, $length + 4);
437 }
438 }
439 }
440 }
441  
442 # print the result of the duplicate check
443 10 @keys = sort(keys(%resultsDuplicates));
444 10 ▶ if(scalar(@keys) < 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys < 1) { } 10 0 10
445 10 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 5 5 10
446 5 testPassed("DUPLICATES");
447 }
448 }
449 else{
450 0 $checkResult = 0;
451 0 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 0 0 0
452 0 testFailed("DUPLICATES");
453 }
454 0 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
455 0 my $length = maxLength(@keys);
456 0 foreach my $key (@keys){
457 0 printColored(sprintf("%". $length ."s", $key) .": ". $resultsDuplicates{$key}->errorString() ."\n", "red");
458 0 ▶ if($description && exists($descriptions{$resultsDuplicates{$key}->option()})){
Branch: 1 branch
BranchTrueFalseTotal
if ($description and exists $descriptions{$resultsDuplicates{$key}->option}) 0 0 0
Condition0%0/3
$description and exists $descriptions{$resultsDuplicates{$key}->option}
!ll&&!rl&&r
000
MC/DC0%0/2
$description and exists $descriptions{$resultsDuplicates{$key}->option}
$description exists $descriptions{$resultsDuplicates{$key}->option}
Truth table0%0/3
A and B
A= $descriptionB= exists $descriptions{$resultsDuplicates{$key}->option}
ABresult
0X0
100
111
459 0 printBlock($descriptions{$resultsDuplicates{$key}->option()}, $length + 4);
460 }
461 }
462 }
463 }
464  
465 # print the result of the no absolute path check
466 0 @keys = sort { $a <=> $b } keys(%resultsAbsolutePaths);
467 10 ▶ if(scalar(@keys) < 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys < 1) { } 10 0 10
468 10 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 5 5 10
469 5 testPassed("NO ABSOLUTE PATHS");
470 }
471 }
472 else{
473 0 $checkResult = 0;
474 0 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 0 0 0
475 0 testFailed("NO ABSOLUTE PATHS");
476 }
477 0 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
478 0 my $length = length($keys[scalar(@keys) - 1]);
479 0 foreach my $key (@keys){
480 0 printColored(sprintf("%". $length ."s", $key) .": ". $resultsAbsolutePaths{$key}->errorString() ."\n", "red");
481 0 ▶ if($description && exists($descriptions{$resultsAbsolutePaths{$key}->option()})){
Branch: 1 branch
BranchTrueFalseTotal
if ($description and exists $descriptions{$resultsAbsolutePaths{$key}->option}) 0 0 0
Condition0%0/3
$description and exists $descriptions{$resultsAbsolutePaths{$key}->option}
!ll&&!rl&&r
000
MC/DC0%0/2
$description and exists $descriptions{$resultsAbsolutePaths{$key}->option}
$description exists $descriptions{$resultsAbsolutePaths{$key}->option}
Truth table0%0/3
A and B
A= $descriptionB= exists $descriptions{$resultsAbsolutePaths{$key}->option}
ABresult
0X0
100
111
482 0 printBlock($descriptions{$resultsAbsolutePaths{$key}->option()}, $length + 4);
483 }
484 }
485 }
486 }
487  
488 10 return $checkResult;
489 }
490  
491 7 ▶sub checkTreeConfig {
Subroutine checkTreeConfig: called CC=14 SCAR=26.9
Pod documented
492 7 my $cfgUrl = shift;
493 7 my $verbose = shift;
494  
495 7 my $CFG;
496 7 my %resultsEmptyLines = ();
497  
498 7 ▶ if(!defined($verbose)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $verbose) 5 2 7
499 5 $verbose = 0;
500 }
501  
502 7 ▶ if(!defined($cfgUrl) || $cfgUrl eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cfgUrl or $cfgUrl eq "") 2 5 7
Condition100%3/3
not defined $cfgUrl or $cfgUrl eq ""
l!l&&r!l&&!r
115
MC/DC100%2/2
not defined $cfgUrl or $cfgUrl eq ""
not defined $cfgUrl $cfgUrl eq ""
Truth table100%3/3
not(A) or B
A= not defined $cfgUrlB= $cfgUrl eq ""
ABresult
1X1
011
000
503 2 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 0 2 2
504 0 print "No URL given\n";
505 }
506 2 return 0;
507 }
508  
509 # Get all possible options listed within the cdb file
510 5 ▶ if(!open($CFG, "<", $cfgUrl)){
Branch: 1 branch
BranchTrueFalseTotal
unless (open $CFG, "<", $cfgUrl) 1 4 5
511 1 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 0 1 1
512 0 print "Could not open file! (". $cfgUrl .")\n";
513 }
514 1 return 0;
515 }
516  
517 4 my $i = 0;
518 4 ▶ while(<$CFG>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $CFG)) 94 4 98
519 94 my $line = strip($_);
520 94 $i++;
521 94 ▶ if($line eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "") 2 92 94
522 2 $resultsEmptyLines{$i} = "Empty line";
523 }
524 }
525  
526 4 close($CFG);
527  
528 4 my $result = 1;
529 # print the result of the no blank lines
530 0 my @keys = sort { $a <=> $b } keys(%resultsEmptyLines);
531 4 ▶ if(scalar(@keys) < 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keys < 1) { } 2 2 4
532 2 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 1 1 2
533 1 testPassed("NO EMPTY LINES");
534 }
535 }
536 else{
537 2 $result = 0;
538 2 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 1 1 2
539 1 testFailed("NO EMPTY LINES");
540 }
541 2 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 2 2
542 0 my $length = length($keys[scalar(@keys) - 1]);
543 0 foreach my $key (@keys){
544 0 printColored(sprintf("%". $length ."s", $key) .": ". $resultsEmptyLines{$key} ."\n", "red");
545 }
546 }
547 }
548  
549 4 return $result;
550 }
551  
552 9 1;
553  
554 __END__
« Firemen/ParseHelp/Creo3.pm ↑ Summary Firemen/Common.pm »