Update ooo320-m1
[ooovba.git] / xmerge / source / palmtests / qa-wrapper / bin / qa_comparator.pl
blob9b740417289181acf5ea45754674bba8def2e638
1 #!/usr/bin/perl
2 #########################################################################
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: qa_comparator.pl,v $
14 # $Revision: 1.4 $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
35 $compare_home = $ENV{'QA_COMPARATOR_HOME'};
37 if ($ENV{'CLASSPATH'})
39 $classpath_val = "$compare_home:$ENV{'CLASSPATH'}";
41 else
43 $classpath_val = "$compare_home";
46 print "classpath is $classpath_val\n";
48 $list_file="";
49 $orig_dir="";
50 $new_dir="";
51 $diff_type="";
53 ####### BEGIN MAIN ##############
54 $cmdline_len = @ARGV;
55 if ($cmdline_len <= 0)
57 print_usage();
58 exit (0);
61 process_cmdline(@ARGV);
62 print_env();
63 open (LOGFILE, ">$logfile") || die "Cannot open log file $logfile";
64 if ($test_list ne "")
66 open (TESTLIST, $test_list) || die "Couldn't open diff list file $test_list";
68 while (<TESTLIST>)
70 chomp $_;
71 process_diff(get_file_title($_));
74 close TESTLIST;
75 close LOGFILE;
77 ####### END MAIN ##############
79 sub process_diff
81 # $_[0] =~ tr/A-Z/a-z/;
83 # chdir to the output directory so the temporary files created by
84 # the java programs are put in the right place.
86 chdir ($xml_new);
88 if ($diff_type eq "xml")
90 # Ugly hack, probably a way to tell xerces directly that the dtd's
91 # are in $compare_home/dtd.
93 `cp $compare_home/dtd/* $xml_new`;
95 # $cmd = "java -classpath $classpath_val XmlWrapper $xml_orig/$_[0].sxw $xml_new/$_[0].sxw";
96 $cmd = "java -classpath $classpath_val XmlWrapper $xml_orig/$_[0] $xml_new/$_[0]";
97 print "Executing: $cmd\n";
98 $val = system($cmd)/256;
99 if ($val == 2)
101 # print LOGFILE "$_[0]|TRUE|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n";
102 print LOGFILE "$_[0]|TRUE|$xml_orig/$_[0]|$xml_new/$_[0]\n";
104 elsif($val == 3)
106 # print LOGFILE "$_[0]|FALSE|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n";
107 print LOGFILE "$_[0]|FALSE|$xml_orig/$_[0]|$xml_new/$_[0]\n";
109 else
111 # print LOGFILE "$_[0]|ERROR|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n";
112 print LOGFILE "$_[0]|ERROR|$xml_orig/$_[0]|$xml_new/$_[0]\n";
115 elsif ($diff_type eq "pdb")
117 # $cmd = "java -classpath $classpath_val SimplePdbCompare $pdb_orig/$_[0].pdb $pdb_new/$_[0].pdb\n";
118 $cmd = "java -classpath $classpath_val SimplePdbCompare $pdb_orig/$_[0] $pdb_new/$_[0]\n";
119 print "Executing: $cmd\n";
120 $val = system($cmd)/256;
121 if ($val == 2)
123 # print LOGFILE "$_[0]|TRUE|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n";
124 print LOGFILE "$_[0]|TRUE|$pdb_orig/$_[0]|$pdb_new/$_[0]\n";
126 elsif($val == 3)
128 # print LOGFILE "$_[0]|FALSE|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n";
129 print LOGFILE "$_[0]|FALSE|$pdb_orig/$_[0]|$pdb_new/$_[0]\n";
131 else
133 # print LOGFILE "$_[0]|ERROR|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n";
134 print LOGFILE "$_[0]|ERROR|$pdb_orig/$_[0]|$pdb_new/$_[0]\n";
137 else
139 die "Don't understand test type of $diff_type.";
143 sub process_cmdline
145 foreach $i (@_)
147 @arg= split('=', $i);
148 @arg[0] =~ tr/A-Z/a-z/;
150 if (@arg[0] eq "-pdb-orig")
152 $pdb_orig=$arg[1];
154 elsif (@arg[0] eq "-pdb-new")
156 $pdb_new=$arg[1];
158 elsif (@arg[0] eq "-xml-orig")
160 $xml_orig=$arg[1];
162 elsif (@arg[0] eq "-xml-new")
164 $xml_new=$arg[1];
166 elsif (@arg[0] eq "-env")
168 set_env_from_props($arg[1]);
170 elsif (@arg[0] eq "-list")
172 $test_list = $arg[1];
174 elsif (@arg[0] eq "-one")
176 $infile = $arg[1];
178 elsif (@arg[0] eq "-type")
180 $diff_type = $arg[1];
181 chomp $diff_type;
183 elsif (@arg[0] eq "-log")
185 $logfile = $arg[1];
187 else
189 print_usage();
190 die "Incorrect command line. Don't understand $i";
195 sub set_env_from_props
197 open(PROPSFILE, $_[0]) || die "Could not open properties file";
199 while (<PROPSFILE>)
201 chomp $_;
202 @arg = split('=', $_);
203 @arg[0] =~ tr/a-z/A-Z/;
204 $len = @arg;
205 if ($len != 2)
207 die "Malformed property in $ARGV[0]";
210 if (@arg[0] eq "PDB_ORIG")
212 $pdb_orig=$arg[1];
214 elsif (@arg[0] eq "PDB_NEW")
216 $pdb_new=$arg[1];
218 elsif (@arg[0] eq "XML_ORIG")
220 $xml_orig=$arg[1];
222 elsif (@arg[0] eq "XML_NEW")
224 $xml_new=$arg[1];
228 close PROPSFILE;
231 sub print_usage
233 print "Usage : compartor.pl - compare Office or pdb files\n";
234 print "\t-one=<file> :\t\t individual test case file to run\n";
235 print "\t-list=<file> :\t\t list of test case files\n";
236 print "\t-env=<file> :\t\t Properites like file defining env\n";
237 print "\t-pdb-orig=<path> :\t directory to hold original pdb files\n";
238 print "\t-pdb-new=<path> :\t directory to hold new pdb files\n";
239 print "\t-xml-orig=<path> :\t directory to hold original office documents\n";
240 print "\t-xml-new=<path> :\t directory to hold new office documents\n";
241 print "\t-type=<xml|pdb> :\t Invokes the merge option when converting\n";
242 print "\t-log=<logfile> :\t Save results to logfile.\n";
245 sub print_env
247 print "Using the following environment:\n";
248 print "\tPDB_ORIG = $pdb_orig\n";
249 print "\tPDB_NEW = $pdb_new\n";
250 print "\tXML_ORIG = $xml_orig\n";
251 print "\tXML_NEW = $xml_new\n\n";
254 sub get_file_title
256 @paths = split('\/', $_[0]);
257 $len = @paths;
258 return @paths[$len-1];
259 # @names = split('\.', @paths[$len-1]);
260 # return $names[0];