xref: /aoo4110/main/sc/source/ui/vba/testvba/testResult.pl (revision b1cdbd2c)
1#!/usr/bin/perl -w
2# *************************************************************
3#
4#  Licensed to the Apache Software Foundation (ASF) under one
5#  or more contributor license agreements.  See the NOTICE file
6#  distributed with this work for additional information
7#  regarding copyright ownership.  The ASF licenses this file
8#  to you under the Apache License, Version 2.0 (the
9#  "License"); you may not use this file except in compliance
10#  with the License.  You may obtain a copy of the License at
11#
12#    http://www.apache.org/licenses/LICENSE-2.0
13#
14#  Unless required by applicable law or agreed to in writing,
15#  software distributed under the License is distributed on an
16#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17#  KIND, either express or implied.  See the License for the
18#  specific language governing permissions and limitations
19#  under the License.
20#
21# *************************************************************
22use File::Temp qw/ tempfile tempdir /;
23use File::Basename;
24use File::stat;
25use File::Copy;
26
27my $binDir = dirname($0);
28my $timestampclean= "perl $binDir/timestampsClean.pl";
29#sub gen_diff($)
30
31sub testLog
32{
33   # 2 No Log to compare against
34   # 1 Log passed
35   # 0 Log failed
36   my $result = 0;
37   my $testfile = shift;
38   my $dirtocheck = shift;
39   my $filename = basename($testfile);
40   $filename = "$logdir/$filename";
41   print "processing $testfile $filename\n";
42   if ( -f $filename )  {
43      my $tmpFile;
44      $dir = tempdir( CLEANUP => 1 );
45      ($fh, $tmpFile) = tempfile( DIR => $dir );
46      close($fh);
47      #
48      my $status = system("diff -U 0 -p $testfile $filename |  $timestampclean > $tmpFile");
49      my $info = stat($tmpFile) or die "no $tmpFile: $!";
50      if ( ($status >>=8) == 0 &&  ( $info->size == 0)  ) {
51         #print "diff worked size is 0\n";
52         $result = 1;
53      }
54      elsif ( ($status >>=8) == 0 &&  ( $info->size > 0)  )
55      {
56         #print "diff worked size > 0\n";
57         $result = 0;
58      }
59      else
60      {
61         #print "diff failed size > 0\n";
62         $result = 0;
63      }
64   }
65   else
66   {
67      #print "not file > 0\n";
68      $result = 2;
69   }
70   #print "diff result = $result\n";
71   return $result;
72}
73
74if ( ! ( $logdir = shift @ARGV ) ) {
75    print STDERR "No logdir specified!\n";
76    usage();
77    exit 1;
78}
79
80if ( ! ( $testlogdir = shift @ARGV ) ) {
81    print STDERR "No testdocuments dir to compare against specified!\n";
82    usage();
83    exit 1;
84}
85
86if ( !(-d $logdir ) ) {
87   print STDERR "No output directory $logdir exists, please create it!!!!\n";
88   exit 1;
89}
90if ( !(-d $testlogdir ) ) {
91   print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n";
92    usage();
93    exit 1;
94}
95print "logdir $logdir\n";
96print "testlogdir $testlogdir\n";
97sub filter_crud($)
98{
99    my $a = shift;
100
101    $a =~ /~$/ && return;
102    $a =~ /\#$/ && return;
103    $a =~ /\.orig$/ && return;
104    $a =~ /unxlng.*\.pro$/ && return;
105    $a =~ /wntmsc.*\.pro$/ && return;
106    $a =~ /.swp$/ && return;
107    $a =~ /POSITION/ && return;
108    $a =~ /ReadMe/ && return;
109    $a =~ /.tmp$/ && return;
110    $a =~ /\.svn/ && return;
111    $a eq 'CVS' && return;
112    $a eq '.' && return;
113    $a eq '..' && return;
114
115    return $a;
116}
117sub slurp_dir($);
118
119sub slurp_dir($)
120{
121    my $dir = shift;
122    my ($dirhandle, $fname);
123    my @files = ();
124
125    opendir ($dirhandle, $dir) || die "Can't open $dir";
126    while ($fname = readdir ($dirhandle)) {
127	$fname = filter_crud($fname);
128	defined $fname || next;
129#	if (-d "$dir/$fname") {
130#	    push @files, slurp_dir("$dir/$fname");
131#	} else
132        {
133	    push @files, "$dir/$fname";
134	}
135    }
136    closedir ($dirhandle);
137
138    return @files;
139}
140
141if (-d $testlogdir) {
142    push @files, slurp_dir($testlogdir);
143}
144
145my $processed = 0;
146my $passed = 0;
147my @passedTests=();
148my @skippedTests=();
149my @failedTests=();
150
151my $failureCmd="";
152my $testfile = shift @ARGV;
153my $testfilepath = "$testlogdir/$testfile";
154$testfilepath =~ s/\.xls/\.log/;
155print "$testfilepath\n";
156for $a (@files) {
157   $filename = $a;
158   if ( "$testfilepath" eq "$filename" )
159   {
160   $processed++;
161   my $testcase = $a;
162   $testcase =~ s/\.log/\.xls/;
163   my $result = testLog( $a, $logdir );
164   if ( $result == 0 ) {
165      push @failedTests, basename($testcase);
166      if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; }
167   }
168   elsif ( $result == 2 ) {
169      #print "skipped $a\n";
170      push @skippedTests, $testcase;
171   }
172   else {
173      $passed++;
174      push @passedTests, $testcase;
175      #print "Test document for $a \t \t passed. \n";
176   }
177   }
178}
179my $compared=@passedTests+@failedTests;
180my $skip = @skippedTests;
181print "skipped $skip test-cases(s)\n";
182print "compared $compared test-case documents\n";
183print "\t \t $passed tests $@passedTests\n";
184if ( @failedTests > 0 ) {
185   print "the following test-case documents failed, please examine the logs manually\n";
186
187   for $a (@failedTests) {
188      print "\t$a\n";
189   }
190   print "e.g. $failureCmd\n"
191}
192