xref: /AOO41X/main/xmerge/source/palmtests/qa-wrapper/bin/qa_comparator.pl (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
1#!/usr/bin/perl
2#########################################################################
3
4 #**************************************************************
5#
6#  Licensed to the Apache Software Foundation (ASF) under one
7#  or more contributor license agreements.  See the NOTICE file
8#  distributed with this work for additional information
9#  regarding copyright ownership.  The ASF licenses this file
10#  to you under the Apache License, Version 2.0 (the
11#  "License"); you may not use this file except in compliance
12#  with the License.  You may obtain a copy of the License at
13#
14#    http://www.apache.org/licenses/LICENSE-2.0
15#
16#  Unless required by applicable law or agreed to in writing,
17#  software distributed under the License is distributed on an
18#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19#  KIND, either express or implied.  See the License for the
20#  specific language governing permissions and limitations
21#  under the License.
22#
23#**************************************************************
24
25
26
27$compare_home = $ENV{'QA_COMPARATOR_HOME'};
28
29if ($ENV{'CLASSPATH'})
30{
31   $classpath_val = "$compare_home:$ENV{'CLASSPATH'}";
32}
33else
34{
35   $classpath_val = "$compare_home";
36}
37
38print "classpath is $classpath_val\n";
39
40$list_file="";
41$orig_dir="";
42$new_dir="";
43$diff_type="";
44
45####### BEGIN MAIN ##############
46$cmdline_len = @ARGV;
47if ($cmdline_len <= 0)
48{
49    print_usage();
50    exit (0);
51}
52
53process_cmdline(@ARGV);
54print_env();
55open (LOGFILE, ">$logfile") || die "Cannot open log file $logfile";
56if ($test_list ne "")
57{
58    open (TESTLIST, $test_list) || die "Couldn't open diff list file $test_list";
59
60    while (<TESTLIST>)
61    {
62        chomp $_;
63        process_diff(get_file_title($_));
64    }
65}
66close TESTLIST;
67close LOGFILE;
68
69####### END MAIN ##############
70
71sub process_diff
72{
73#   $_[0] =~ tr/A-Z/a-z/;
74
75    # chdir to the output directory so the temporary files created by
76    # the java programs are put in the right place.
77    #
78    chdir ($xml_new);
79
80    if ($diff_type eq "xml")
81    {
82        # Ugly hack, probably a way to tell xerces directly that the dtd's
83        # are in $compare_home/dtd.
84        #
85        `cp $compare_home/dtd/* $xml_new`;
86
87#       $cmd = "java -classpath $classpath_val XmlWrapper $xml_orig/$_[0].sxw $xml_new/$_[0].sxw";
88        $cmd = "java -classpath $classpath_val XmlWrapper $xml_orig/$_[0] $xml_new/$_[0]";
89        print "Executing: $cmd\n";
90        $val = system($cmd)/256;
91        if ($val == 2)
92        {
93#           print LOGFILE "$_[0]|TRUE|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n";
94            print LOGFILE "$_[0]|TRUE|$xml_orig/$_[0]|$xml_new/$_[0]\n";
95        }
96        elsif($val == 3)
97        {
98#           print LOGFILE "$_[0]|FALSE|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n";
99            print LOGFILE "$_[0]|FALSE|$xml_orig/$_[0]|$xml_new/$_[0]\n";
100        }
101        else
102        {
103#           print LOGFILE "$_[0]|ERROR|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n";
104            print LOGFILE "$_[0]|ERROR|$xml_orig/$_[0]|$xml_new/$_[0]\n";
105        }
106    }
107    elsif ($diff_type eq "pdb")
108    {
109#       $cmd = "java -classpath $classpath_val SimplePdbCompare $pdb_orig/$_[0].pdb $pdb_new/$_[0].pdb\n";
110        $cmd = "java -classpath $classpath_val SimplePdbCompare $pdb_orig/$_[0] $pdb_new/$_[0]\n";
111        print "Executing: $cmd\n";
112        $val = system($cmd)/256;
113        if ($val == 2)
114        {
115#           print LOGFILE "$_[0]|TRUE|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n";
116            print LOGFILE "$_[0]|TRUE|$pdb_orig/$_[0]|$pdb_new/$_[0]\n";
117        }
118        elsif($val == 3)
119        {
120#           print LOGFILE "$_[0]|FALSE|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n";
121            print LOGFILE "$_[0]|FALSE|$pdb_orig/$_[0]|$pdb_new/$_[0]\n";
122        }
123        else
124        {
125#           print LOGFILE "$_[0]|ERROR|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n";
126            print LOGFILE "$_[0]|ERROR|$pdb_orig/$_[0]|$pdb_new/$_[0]\n";
127        }
128    }
129    else
130    {
131        die "Don't understand test type of $diff_type.";
132    }
133}
134
135sub process_cmdline
136{
137    foreach $i (@_)
138    {
139        @arg= split('=', $i);
140        @arg[0] =~ tr/A-Z/a-z/;
141
142        if (@arg[0] eq "-pdb-orig")
143        {
144            $pdb_orig=$arg[1];
145        }
146        elsif (@arg[0] eq "-pdb-new")
147        {
148            $pdb_new=$arg[1];
149        }
150        elsif (@arg[0] eq "-xml-orig")
151        {
152            $xml_orig=$arg[1];
153        }
154        elsif (@arg[0] eq "-xml-new")
155        {
156            $xml_new=$arg[1];
157        }
158        elsif (@arg[0] eq "-env")
159        {
160            set_env_from_props($arg[1]);
161        }
162        elsif (@arg[0] eq "-list")
163        {
164            $test_list = $arg[1];
165        }
166        elsif (@arg[0] eq "-one")
167        {
168            $infile = $arg[1];
169        }
170        elsif (@arg[0] eq "-type")
171        {
172            $diff_type = $arg[1];
173            chomp $diff_type;
174        }
175        elsif (@arg[0] eq "-log")
176        {
177            $logfile = $arg[1];
178        }
179        else
180        {
181            print_usage();
182            die "Incorrect command line. Don't understand $i";
183        }
184    }
185}
186
187sub set_env_from_props
188{
189    open(PROPSFILE, $_[0]) || die "Could not open properties file";
190
191    while (<PROPSFILE>)
192    {
193        chomp $_;
194        @arg = split('=', $_);
195        @arg[0] =~ tr/a-z/A-Z/;
196        $len = @arg;
197        if ($len != 2)
198        {
199            die "Malformed property in $ARGV[0]";
200        }
201
202        if (@arg[0] eq "PDB_ORIG")
203        {
204            $pdb_orig=$arg[1];
205        }
206        elsif (@arg[0] eq "PDB_NEW")
207        {
208            $pdb_new=$arg[1];
209        }
210        elsif (@arg[0] eq "XML_ORIG")
211        {
212            $xml_orig=$arg[1];
213        }
214        elsif (@arg[0] eq "XML_NEW")
215        {
216            $xml_new=$arg[1];
217        }
218
219    }
220    close PROPSFILE;
221}
222
223sub print_usage
224{
225    print "Usage : compartor.pl - compare Office or pdb files\n";
226    print "\t-one=<file> :\t\t individual test case file to run\n";
227    print "\t-list=<file> :\t\t list of test case files\n";
228    print "\t-env=<file> :\t\t Properites like file defining env\n";
229    print "\t-pdb-orig=<path> :\t directory to hold original pdb files\n";
230    print "\t-pdb-new=<path> :\t directory to hold new pdb files\n";
231    print "\t-xml-orig=<path> :\t directory to hold original office documents\n";
232    print "\t-xml-new=<path> :\t directory to hold new office documents\n";
233    print "\t-type=<xml|pdb> :\t Invokes the merge option when converting\n";
234    print "\t-log=<logfile> :\t Save results to logfile.\n";
235}
236
237sub print_env
238{
239    print "Using the following environment:\n";
240    print "\tPDB_ORIG  = $pdb_orig\n";
241    print "\tPDB_NEW   = $pdb_new\n";
242    print "\tXML_ORIG  = $xml_orig\n";
243    print "\tXML_NEW   = $xml_new\n\n";
244}
245
246sub get_file_title
247{
248    @paths = split('\/', $_[0]);
249    $len = @paths;
250    return @paths[$len-1];
251#   @names = split('\.', @paths[$len-1]);
252#   return $names[0];
253}
254