1#!/usr/bin/perl 2######################################################################### 3 4 #************************************************************************* 5 # 6# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7# 8# Copyright 2000, 2010 Oracle and/or its affiliates. 9# 10# OpenOffice.org - a multi-platform office productivity suite 11# 12# This file is part of OpenOffice.org. 13# 14# OpenOffice.org is free software: you can redistribute it and/or modify 15# it under the terms of the GNU Lesser General Public License version 3 16# only, as published by the Free Software Foundation. 17# 18# OpenOffice.org is distributed in the hope that it will be useful, 19# but WITHOUT ANY WARRANTY; without even the implied warranty of 20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21# GNU Lesser General Public License version 3 for more details 22# (a copy is included in the LICENSE file that accompanied this code). 23# 24# You should have received a copy of the GNU Lesser General Public License 25# version 3 along with OpenOffice.org. If not, see 26# <http://www.openoffice.org/license.html> 27# for a copy of the LGPLv3 License. 28# 29 #************************************************************************* 30 31$compare_home = $ENV{'QA_COMPARATOR_HOME'}; 32 33if ($ENV{'CLASSPATH'}) 34{ 35 $classpath_val = "$compare_home:$ENV{'CLASSPATH'}"; 36} 37else 38{ 39 $classpath_val = "$compare_home"; 40} 41 42print "classpath is $classpath_val\n"; 43 44$list_file=""; 45$orig_dir=""; 46$new_dir=""; 47$diff_type=""; 48 49####### BEGIN MAIN ############## 50$cmdline_len = @ARGV; 51if ($cmdline_len <= 0) 52{ 53 print_usage(); 54 exit (0); 55} 56 57process_cmdline(@ARGV); 58print_env(); 59open (LOGFILE, ">$logfile") || die "Cannot open log file $logfile"; 60if ($test_list ne "") 61{ 62 open (TESTLIST, $test_list) || die "Couldn't open diff list file $test_list"; 63 64 while (<TESTLIST>) 65 { 66 chomp $_; 67 process_diff(get_file_title($_)); 68 } 69} 70close TESTLIST; 71close LOGFILE; 72 73####### END MAIN ############## 74 75sub process_diff 76{ 77# $_[0] =~ tr/A-Z/a-z/; 78 79 # chdir to the output directory so the temporary files created by 80 # the java programs are put in the right place. 81 # 82 chdir ($xml_new); 83 84 if ($diff_type eq "xml") 85 { 86 # Ugly hack, probably a way to tell xerces directly that the dtd's 87 # are in $compare_home/dtd. 88 # 89 `cp $compare_home/dtd/* $xml_new`; 90 91# $cmd = "java -classpath $classpath_val XmlWrapper $xml_orig/$_[0].sxw $xml_new/$_[0].sxw"; 92 $cmd = "java -classpath $classpath_val XmlWrapper $xml_orig/$_[0] $xml_new/$_[0]"; 93 print "Executing: $cmd\n"; 94 $val = system($cmd)/256; 95 if ($val == 2) 96 { 97# print LOGFILE "$_[0]|TRUE|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n"; 98 print LOGFILE "$_[0]|TRUE|$xml_orig/$_[0]|$xml_new/$_[0]\n"; 99 } 100 elsif($val == 3) 101 { 102# print LOGFILE "$_[0]|FALSE|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n"; 103 print LOGFILE "$_[0]|FALSE|$xml_orig/$_[0]|$xml_new/$_[0]\n"; 104 } 105 else 106 { 107# print LOGFILE "$_[0]|ERROR|$xml_orig/$_[0].sxw|$xml_new/$_[0].sxw\n"; 108 print LOGFILE "$_[0]|ERROR|$xml_orig/$_[0]|$xml_new/$_[0]\n"; 109 } 110 } 111 elsif ($diff_type eq "pdb") 112 { 113# $cmd = "java -classpath $classpath_val SimplePdbCompare $pdb_orig/$_[0].pdb $pdb_new/$_[0].pdb\n"; 114 $cmd = "java -classpath $classpath_val SimplePdbCompare $pdb_orig/$_[0] $pdb_new/$_[0]\n"; 115 print "Executing: $cmd\n"; 116 $val = system($cmd)/256; 117 if ($val == 2) 118 { 119# print LOGFILE "$_[0]|TRUE|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n"; 120 print LOGFILE "$_[0]|TRUE|$pdb_orig/$_[0]|$pdb_new/$_[0]\n"; 121 } 122 elsif($val == 3) 123 { 124# print LOGFILE "$_[0]|FALSE|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n"; 125 print LOGFILE "$_[0]|FALSE|$pdb_orig/$_[0]|$pdb_new/$_[0]\n"; 126 } 127 else 128 { 129# print LOGFILE "$_[0]|ERROR|$pdb_orig/$_[0].pdb|$pdb_new/$_[0].pdb\n"; 130 print LOGFILE "$_[0]|ERROR|$pdb_orig/$_[0]|$pdb_new/$_[0]\n"; 131 } 132 } 133 else 134 { 135 die "Don't understand test type of $diff_type."; 136 } 137} 138 139sub process_cmdline 140{ 141 foreach $i (@_) 142 { 143 @arg= split('=', $i); 144 @arg[0] =~ tr/A-Z/a-z/; 145 146 if (@arg[0] eq "-pdb-orig") 147 { 148 $pdb_orig=$arg[1]; 149 } 150 elsif (@arg[0] eq "-pdb-new") 151 { 152 $pdb_new=$arg[1]; 153 } 154 elsif (@arg[0] eq "-xml-orig") 155 { 156 $xml_orig=$arg[1]; 157 } 158 elsif (@arg[0] eq "-xml-new") 159 { 160 $xml_new=$arg[1]; 161 } 162 elsif (@arg[0] eq "-env") 163 { 164 set_env_from_props($arg[1]); 165 } 166 elsif (@arg[0] eq "-list") 167 { 168 $test_list = $arg[1]; 169 } 170 elsif (@arg[0] eq "-one") 171 { 172 $infile = $arg[1]; 173 } 174 elsif (@arg[0] eq "-type") 175 { 176 $diff_type = $arg[1]; 177 chomp $diff_type; 178 } 179 elsif (@arg[0] eq "-log") 180 { 181 $logfile = $arg[1]; 182 } 183 else 184 { 185 print_usage(); 186 die "Incorrect command line. Don't understand $i"; 187 } 188 } 189} 190 191sub set_env_from_props 192{ 193 open(PROPSFILE, $_[0]) || die "Could not open properties file"; 194 195 while (<PROPSFILE>) 196 { 197 chomp $_; 198 @arg = split('=', $_); 199 @arg[0] =~ tr/a-z/A-Z/; 200 $len = @arg; 201 if ($len != 2) 202 { 203 die "Malformed property in $ARGV[0]"; 204 } 205 206 if (@arg[0] eq "PDB_ORIG") 207 { 208 $pdb_orig=$arg[1]; 209 } 210 elsif (@arg[0] eq "PDB_NEW") 211 { 212 $pdb_new=$arg[1]; 213 } 214 elsif (@arg[0] eq "XML_ORIG") 215 { 216 $xml_orig=$arg[1]; 217 } 218 elsif (@arg[0] eq "XML_NEW") 219 { 220 $xml_new=$arg[1]; 221 } 222 223 } 224 close PROPSFILE; 225} 226 227sub print_usage 228{ 229 print "Usage : compartor.pl - compare Office or pdb files\n"; 230 print "\t-one=<file> :\t\t individual test case file to run\n"; 231 print "\t-list=<file> :\t\t list of test case files\n"; 232 print "\t-env=<file> :\t\t Properites like file defining env\n"; 233 print "\t-pdb-orig=<path> :\t directory to hold original pdb files\n"; 234 print "\t-pdb-new=<path> :\t directory to hold new pdb files\n"; 235 print "\t-xml-orig=<path> :\t directory to hold original office documents\n"; 236 print "\t-xml-new=<path> :\t directory to hold new office documents\n"; 237 print "\t-type=<xml|pdb> :\t Invokes the merge option when converting\n"; 238 print "\t-log=<logfile> :\t Save results to logfile.\n"; 239} 240 241sub print_env 242{ 243 print "Using the following environment:\n"; 244 print "\tPDB_ORIG = $pdb_orig\n"; 245 print "\tPDB_NEW = $pdb_new\n"; 246 print "\tXML_ORIG = $xml_orig\n"; 247 print "\tXML_NEW = $xml_new\n\n"; 248} 249 250sub get_file_title 251{ 252 @paths = split('\/', $_[0]); 253 $len = @paths; 254 return @paths[$len-1]; 255# @names = split('\.', @paths[$len-1]); 256# return $names[0]; 257} 258