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