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