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