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