1cdf0e10cSrcweir#!/usr/bin/perl
2cdf0e10cSrcweir#########################################################################
3cdf0e10cSrcweir
4*7e90fac2SAndrew Rist #**************************************************************
5*7e90fac2SAndrew Rist#
6*7e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
7*7e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
8*7e90fac2SAndrew Rist#  distributed with this work for additional information
9*7e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
10*7e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
11*7e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
12*7e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
13*7e90fac2SAndrew Rist#
14*7e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
15*7e90fac2SAndrew Rist#
16*7e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
17*7e90fac2SAndrew Rist#  software distributed under the License is distributed on an
18*7e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*7e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
20*7e90fac2SAndrew Rist#  specific language governing permissions and limitations
21*7e90fac2SAndrew Rist#  under the License.
22*7e90fac2SAndrew Rist#
23*7e90fac2SAndrew Rist#**************************************************************
24*7e90fac2SAndrew Rist
25*7e90fac2SAndrew Rist
26cdf0e10cSrcweir
27cdf0e10cSrcweir####################################################################
28cdf0e10cSrcweir# File Name: test_driver.pl
29cdf0e10cSrcweir# Version  : 1.0
30cdf0e10cSrcweir# Project  : Xmerge
31cdf0e10cSrcweir# Author   : Brian Cameron
32cdf0e10cSrcweir# Date	   : 5th Sept. 2001
33cdf0e10cSrcweir#
34cdf0e10cSrcweir#
35cdf0e10cSrcweir# This script does the following:
36cdf0e10cSrcweir#
37cdf0e10cSrcweir# Processes the input file, and runs the tests specified in that
38cdf0e10cSrcweir# file.  This will do the following for each test:
39cdf0e10cSrcweir#
40cdf0e10cSrcweir# 1. Convert a file from XML to PDB format
41cdf0e10cSrcweir# 2. Starts up the Palm OS emulator with the appropriate program
42cdf0e10cSrcweir#    running and the converted file loaded the program.
43cdf0e10cSrcweir# 3. Makes automated changes as specified in the inputfile to
44cdf0e10cSrcweir#    this script..
45cdf0e10cSrcweir# 4. Returns to the main applications window.
46cdf0e10cSrcweir#
47cdf0e10cSrcweir# Parameter
48cdf0e10cSrcweir#   Filename to convert and change
49cdf0e10cSrcweir#
50cdf0e10cSrcweir##########################################################################
51cdf0e10cSrcweir
52cdf0e10cSrcweir# Turn on auto-flushing
53cdf0e10cSrcweir#
54cdf0e10cSrcweir$|=1;
55cdf0e10cSrcweir
56cdf0e10cSrcweiruse EmRPC;
57cdf0e10cSrcweir
58cdf0e10cSrcweir# Directory where converterlib is located...
59cdf0e10cSrcweir#
60cdf0e10cSrcweir#use lib "/export/home/test/qadir/qa/lib";
61cdf0e10cSrcweiruse lib $ENV{'QA_LIB_HOME'};
62cdf0e10cSrcweiruse converterlib;
63cdf0e10cSrcweir
64cdf0e10cSrcweir#-------------------- Start of main script ------------------------------------
65cdf0e10cSrcweir
66cdf0e10cSrcweir# Environmental Settings
67cdf0e10cSrcweir
68cdf0e10cSrcweir$pose_exe = "";
69cdf0e10cSrcweir$pose_prc = "";
70cdf0e10cSrcweir$test_list = "";
71cdf0e10cSrcweir$infile = "";
72cdf0e10cSrcweir$merge_opt = 0;
73cdf0e10cSrcweir# if testcase hasn't completed in 10 mins, then kill it off
74cdf0e10cSrcweir$testcase_timeout=600;
75cdf0e10cSrcweir
76cdf0e10cSrcweir# You may need to change this from the default if your pose emulator
77cdf0e10cSrcweir# starts faster or slower than mine.
78cdf0e10cSrcweir#
79cdf0e10cSrcweirif ($ENV{'POSE_TIMEOUT'})
80cdf0e10cSrcweir{
81cdf0e10cSrcweir  $pose_timeout  = "$ENV{'POSE_TIMEOUT'}";
82cdf0e10cSrcweir}
83cdf0e10cSrcweirelse
84cdf0e10cSrcweir{
85cdf0e10cSrcweir  $pose_timeout = 15;
86cdf0e10cSrcweir}
87cdf0e10cSrcweir
88cdf0e10cSrcweir$cmdline_len = @ARGV;
89cdf0e10cSrcweirif ($cmdline_len <= 0)
90cdf0e10cSrcweir{
91cdf0e10cSrcweir	print_usage();
92cdf0e10cSrcweir	exit (0);
93cdf0e10cSrcweir}
94cdf0e10cSrcweir
95cdf0e10cSrcweir&process_cmdline(@ARGV);
96cdf0e10cSrcweir&print_env();
97cdf0e10cSrcweir&verify_env_options();
98cdf0e10cSrcweir
99cdf0e10cSrcweir# Make the output directories with timestamps included in the
100cdf0e10cSrcweir# directory names.
101cdf0e10cSrcweir#
102cdf0e10cSrcweirmkdir $pdb_orig, 0777 || die "can not create directory <$pdb_orig>.";
103cdf0e10cSrcweir`chmod 777 $pdb_orig`;
104cdf0e10cSrcweirmkdir $pdb_new,  0777 || die "can not create directory <$pdb_new>.";
105cdf0e10cSrcweir`chmod 777 $pdb_new`;
106cdf0e10cSrcweirmkdir $xml_new,  0777 || die "can not create directory <$xml_new>.";
107cdf0e10cSrcweir`chmod 777 $xml_new`;
108cdf0e10cSrcweir
109cdf0e10cSrcweir&verify_prcs_exist("DBExporter.prc");
110cdf0e10cSrcweir
111cdf0e10cSrcweirif ($test_list ne "")
112cdf0e10cSrcweir{
113cdf0e10cSrcweir	open (TESTLIST, $test_list) || die "Couldn't open testcase list file $test_list";
114cdf0e10cSrcweir
115cdf0e10cSrcweir	while (<TESTLIST>)
116cdf0e10cSrcweir	{
117cdf0e10cSrcweir		&process_testcase($_);
118cdf0e10cSrcweir	}
119cdf0e10cSrcweir}
120cdf0e10cSrcweirelsif ($infile ne "")
121cdf0e10cSrcweir{
122cdf0e10cSrcweir	if (!defined($child_pid = fork()))
123cdf0e10cSrcweir	{
124cdf0e10cSrcweir		# there was an error forking a process
125cdf0e10cSrcweir		print "ERROR: Unable to fork process\n";
126cdf0e10cSrcweir		die "ERROR: Unable to fork process\n";
127cdf0e10cSrcweir	}
128cdf0e10cSrcweir	elsif ($child_pid)
129cdf0e10cSrcweir	{
130cdf0e10cSrcweir		# this is the parent process
131cdf0e10cSrcweir		# run the actual test here
132cdf0e10cSrcweirprint "********\tPARENT (pid = $$): process_testcase...\n";
133cdf0e10cSrcweir		&process_testcase($infile);
134cdf0e10cSrcweirprint "********\tPARENT (pid = $$): ...process_testcase finished normally\n";
135cdf0e10cSrcweir
136cdf0e10cSrcweir		# test finished normally, so kill the monitor
137cdf0e10cSrcweir		# that is running in the child process
138cdf0e10cSrcweirprint "********\tPARENT (pid = $$): kill child process ($child_pid)\n";
139cdf0e10cSrcweirprint "********\tPARENT Before:\n";
140cdf0e10cSrcweirsystem( "/usr/bin/ptree" );
141cdf0e10cSrcweir		kill( $child_pid );
142cdf0e10cSrcweir		kill( 9, $child_pid );
143cdf0e10cSrcweirprint "********\tPARENT After:\n";
144cdf0e10cSrcweirsystem( "/usr/bin/ptree" );
145cdf0e10cSrcweir	}
146cdf0e10cSrcweir	else
147cdf0e10cSrcweir	{
148cdf0e10cSrcweirprint "********\tCHILD (pid = $$): sleep for $testcase_timeout seconds\n";
149cdf0e10cSrcweir		# this is the child process
150cdf0e10cSrcweir		# wait on the test running in the parent, and
151cdf0e10cSrcweir		# kill it if it hasn't finished on time
152cdf0e10cSrcweir		sleep( $testcase_timeout );
153cdf0e10cSrcweir
154cdf0e10cSrcweir		# if the parent hasn't killed this process before it
155cdf0e10cSrcweir		# gets here, then it's probably hung, so we need to
156cdf0e10cSrcweir		# kill it.
157cdf0e10cSrcweir		print "********\tCHILD (pid = $$): TEST HUNG? still "
158cdf0e10cSrcweir			."running after [$testcase_timeout] seconds - "
159cdf0e10cSrcweir			."need to kill test process\n";
160cdf0e10cSrcweir		$parent = getppid;
161cdf0e10cSrcweir
162cdf0e10cSrcweir		if ( $parent != 1 ) {
163cdf0e10cSrcweir			print "********\nCHILD (pid = $$): Killing process ($parent)\n";
164cdf0e10cSrcweir			kill( $parent );
165cdf0e10cSrcweir			kill( 9, $parent );
166cdf0e10cSrcweir		} else {
167cdf0e10cSrcweir			# If we cannot get the ppid, then the parent might
168cdf0e10cSrcweir			# have died abnormally, before it got a chance to
169cdf0e10cSrcweir			# kill this (child) process.
170cdf0e10cSrcweir			print "********\nCHILD (pid = $$): cannot determine ppid - "
171cdf0e10cSrcweir				."terminating\n";
172cdf0e10cSrcweirsystem( "/usr/bin/ptree" );
173cdf0e10cSrcweir			exit(2);
174cdf0e10cSrcweir		}
175cdf0e10cSrcweir
176cdf0e10cSrcweir		exit(1);
177cdf0e10cSrcweir	}
178cdf0e10cSrcweir}
179cdf0e10cSrcweirelse
180cdf0e10cSrcweir{
181cdf0e10cSrcweir	die ("You didn't supply any test cases to process");
182cdf0e10cSrcweir}
183cdf0e10cSrcweir
184cdf0e10cSrcweirprint "Finished.\n";
185cdf0e10cSrcweirexit(0);
186cdf0e10cSrcweir
187cdf0e10cSrcweir#-------------------- End of main script ----------------------------------------
188cdf0e10cSrcweir
189cdf0e10cSrcweir#--------------------------------------------------------------------------------
190cdf0e10cSrcweir# Various sub routines
191cdf0e10cSrcweir#--------------------------------------------------------------------------------
192cdf0e10cSrcweir
193cdf0e10cSrcweir# process_testcase
194cdf0e10cSrcweir# infile - test case file name
195cdf0e10cSrcweir#
196cdf0e10cSrcweir# This is the main driver function
197cdf0e10cSrcweir# Opens the infile, reads it in parses it, runs the appropriate conversion
198cdf0e10cSrcweir# starts pose and load the file into the emulator. It launches the
199cdf0e10cSrcweir# appropriate editor and then runs the commands specified in the test case.
200cdf0e10cSrcweir# It then exports the file and saves it locally. Finally it is converted
201cdf0e10cSrcweir# back to the original office format.
202cdf0e10cSrcweir#
203cdf0e10cSrcweirsub process_testcase
204cdf0e10cSrcweir{
205cdf0e10cSrcweir    my $infile = $_[0];
206cdf0e10cSrcweir    my $convert_file = "";
207cdf0e10cSrcweir    my $rc;
208cdf0e10cSrcweir
209cdf0e10cSrcweir	# Process the inputfile
210cdf0e10cSrcweir	#
211cdf0e10cSrcweir	open (INFILE, $infile) || die "Failed to open test case <$infile>";
212cdf0e10cSrcweir
213cdf0e10cSrcweir	$running_testtype = "";
214cdf0e10cSrcweir
215cdf0e10cSrcweir	# Process the input file.
216cdf0e10cSrcweir	#
217cdf0e10cSrcweir	while ($c_inline = <INFILE>)
218cdf0e10cSrcweir	{
219cdf0e10cSrcweir	   chomp $c_inline;
220cdf0e10cSrcweir	   @entry = split('\|', $c_inline);
221cdf0e10cSrcweir
222cdf0e10cSrcweir	   # Process TEST
223cdf0e10cSrcweir	   #
224cdf0e10cSrcweir	   if ($c_inline =~ /^ *#/ || $c_inline =~ /^[ \t]*$/)
225cdf0e10cSrcweir	   {
226cdf0e10cSrcweir	      # skip comments and blank lines.
227cdf0e10cSrcweir	      #
228cdf0e10cSrcweir	      next;
229cdf0e10cSrcweir	   }
230cdf0e10cSrcweir	   elsif ("$entry[0]" eq "TEST")
231cdf0e10cSrcweir	   {
232cdf0e10cSrcweir	      # Close the test if one is running.
233cdf0e10cSrcweir	      #
234cdf0e10cSrcweir	      &close_program($convert_file);
235cdf0e10cSrcweir	      $running_testtype = "";
236cdf0e10cSrcweir
237cdf0e10cSrcweir	      $valid_test = 0;
238cdf0e10cSrcweir
239cdf0e10cSrcweir	      if ($#entry != 3)
240cdf0e10cSrcweir	      {
241cdf0e10cSrcweir	         print "\nERROR, $entry[0] invalid number of arguments\n\n";
242cdf0e10cSrcweir	      }
243cdf0e10cSrcweir	      else
244cdf0e10cSrcweir	      {
245cdf0e10cSrcweir	         # Start the test.
246cdf0e10cSrcweir	         #
247cdf0e10cSrcweir	         print "\nStarting test: $entry[1]\n";
248cdf0e10cSrcweir	         $convert_file = $entry[3];
249cdf0e10cSrcweir
250cdf0e10cSrcweir	         if ("$entry[2]"  =~ /[Qq][Uu][Ii][Cc][Kk][Ww][Oo][Rr][Dd]/)
251cdf0e10cSrcweir	         {
252cdf0e10cSrcweir	            $xml_extension = "sxw";
253cdf0e10cSrcweir	            $convert_to = "application/x-aportisdoc";
254cdf0e10cSrcweir
255cdf0e10cSrcweir	            # Convert XML file to pdb format.
256cdf0e10cSrcweir	            #
257cdf0e10cSrcweir	            $rc = &convert_to_pdb("$xml_orig", $convert_file, $xml_extension ,
258cdf0e10cSrcweir	               $convert_to,"$pdb_orig");
259cdf0e10cSrcweir	            if ($rc != 0)
260cdf0e10cSrcweir	            {
261cdf0e10cSrcweir	               print "\nERROR, problem converting file $convert_file\n\n";
262cdf0e10cSrcweir	            }
263cdf0e10cSrcweir	            else
264cdf0e10cSrcweir	            {
265cdf0e10cSrcweir	               # Start pose
266cdf0e10cSrcweir	               #
267cdf0e10cSrcweir	               $rc = &start_pose("$pose_exe",
268cdf0e10cSrcweir                     "$pose_prc/Quickword.PRC,$pose_prc/DBExporter.prc,$pdb_orig/$convert_file.pdb",
269cdf0e10cSrcweir	                 "Quickword", $pose_timeout);
270cdf0e10cSrcweir
271cdf0e10cSrcweir	               if ($rc == 0)
272cdf0e10cSrcweir	               {
273cdf0e10cSrcweir	                  &start_quickword();
274cdf0e10cSrcweir	                  $valid_test = 1;
275cdf0e10cSrcweir	                  $running_testtype = "QUICKWORD";
276cdf0e10cSrcweir                      print "\npose launched, begin automated test sequence for QuickWord\n";
277cdf0e10cSrcweir	               }
278cdf0e10cSrcweir                   else
279cdf0e10cSrcweir                   {
280cdf0e10cSrcweir                      &kill_pose();
281cdf0e10cSrcweir	                  $running_testtype = "";
282cdf0e10cSrcweir                   }
283cdf0e10cSrcweir	            }
284cdf0e10cSrcweir	         }
285cdf0e10cSrcweir	         elsif ("$entry[2]"  =~ /[Mm][Ii][Nn][Ii][Cc][Aa][Ll][Cc]/)
286cdf0e10cSrcweir	         {
287cdf0e10cSrcweir	            $xml_extension = "sxc";
288cdf0e10cSrcweir	            $convert_to = "application/x-minicalc";
289cdf0e10cSrcweir
290cdf0e10cSrcweir	            # Convert XML file to pdb format.
291cdf0e10cSrcweir	            #
292cdf0e10cSrcweir	            $rc = &convert_to_pdb("$xml_orig", $convert_file,
293cdf0e10cSrcweir                  $xml_extension, $convert_to,"$pdb_orig");
294cdf0e10cSrcweir	            if ($rc != 0)
295cdf0e10cSrcweir	            {
296cdf0e10cSrcweir	               print "\nERROR, problem converting file $convert_file\n\n";
297cdf0e10cSrcweir	            }
298cdf0e10cSrcweir	            else
299cdf0e10cSrcweir	            {
300cdf0e10cSrcweir	               # Get minicalc PDB file names, since an SXC file can
301cdf0e10cSrcweir	               # be converted to more than one.
302cdf0e10cSrcweir	               #
303cdf0e10cSrcweir	               $pdb_files="";
304cdf0e10cSrcweir	               $i = 1;
305cdf0e10cSrcweir	               while (-f "$pdb_orig/$convert_file-Sheet$i.pdb")
306cdf0e10cSrcweir	               {
307cdf0e10cSrcweir	                 if ($i > 1)
308cdf0e10cSrcweir	                 {
309cdf0e10cSrcweir	                   $pdb_files .= ",";
310cdf0e10cSrcweir	                 }
311cdf0e10cSrcweir	                 $pdb_files .= "$pdb_orig/$convert_file-Sheet$i.pdb";
312cdf0e10cSrcweir	                 $i++;
313cdf0e10cSrcweir	               }
314cdf0e10cSrcweir	               $number = $i-1;
315cdf0e10cSrcweir
316cdf0e10cSrcweir	               # Start pose
317cdf0e10cSrcweir	               #
318cdf0e10cSrcweir	               $rc = &start_pose("$pose_exe",
319cdf0e10cSrcweir	                  "$pose_prc/MiniCalc.prc,$pose_prc/DBExporter.prc,$pdb_files",
320cdf0e10cSrcweir	                  "MiniCalc", $pose_timeout);
321cdf0e10cSrcweir
322cdf0e10cSrcweir	               if ($rc == 0)
323cdf0e10cSrcweir	               {
324cdf0e10cSrcweir	                  &start_minicalc();
325cdf0e10cSrcweir	                  $valid_test = 1;
326cdf0e10cSrcweir	                  $running_testtype = "MINICALC";
327cdf0e10cSrcweir                      print "pose launched, begin automated test sequence for MiniCalc\n";
328cdf0e10cSrcweir	               }
329cdf0e10cSrcweir                   else
330cdf0e10cSrcweir                   {
331cdf0e10cSrcweir                      &kill_pose();
332cdf0e10cSrcweir	                  $running_testtype = "";
333cdf0e10cSrcweir                   }
334cdf0e10cSrcweir	            }
335cdf0e10cSrcweir	         }
336cdf0e10cSrcweir	         else
337cdf0e10cSrcweir	         {
338cdf0e10cSrcweir	            print "\nERROR, invalid extension <$entry[2]>\n\n";
339cdf0e10cSrcweir	         }
340cdf0e10cSrcweir	      }
341cdf0e10cSrcweir	   }
342cdf0e10cSrcweir
343cdf0e10cSrcweir	   # Process DB_EXPORT
344cdf0e10cSrcweir	   #
345cdf0e10cSrcweir	   elsif ("$entry[0]" eq "DB_EXPORT")
346cdf0e10cSrcweir	   {
347cdf0e10cSrcweir	      if ($#entry != 1)
348cdf0e10cSrcweir	      {
349cdf0e10cSrcweir         	print "\nERROR, $entry[0] invalid number of arguments\n\n";
350cdf0e10cSrcweir	      }
351cdf0e10cSrcweir	      else
352cdf0e10cSrcweir	      {
353cdf0e10cSrcweir	         &db_export($entry[1]);
354cdf0e10cSrcweir	      }
355cdf0e10cSrcweir	   }
356cdf0e10cSrcweir
357cdf0e10cSrcweir	   # Process TAP_APPLICATIONS
358cdf0e10cSrcweir	   #
359cdf0e10cSrcweir	   elsif ("$entry[0]" eq "TAP_APPLICATIONS")
360cdf0e10cSrcweir	   {
361cdf0e10cSrcweir	      if ($#entry != 0)
362cdf0e10cSrcweir	      {
363cdf0e10cSrcweir         	print "\nERROR, $entry[0] invalid number of arguments\n\n";
364cdf0e10cSrcweir	      }
365cdf0e10cSrcweir	      else
366cdf0e10cSrcweir	      {
367cdf0e10cSrcweir	         &tap_applications(0);
368cdf0e10cSrcweir	      }
369cdf0e10cSrcweir	   }
370cdf0e10cSrcweir
371cdf0e10cSrcweir	   # Process ENTER_STRING_AT_LOCATION
372cdf0e10cSrcweir	   #
373cdf0e10cSrcweir	   elsif ("$entry[0]" eq "ENTER_STRING_AT_LOCATION")
374cdf0e10cSrcweir	   {
375cdf0e10cSrcweir	      if ($#entry != 3)
376cdf0e10cSrcweir	      {
377cdf0e10cSrcweir	         print "\nERROR, $entry[0] invalid number of arguments\n\n";
378cdf0e10cSrcweir	      }
379cdf0e10cSrcweir	      elsif ($valid_test == 0)
380cdf0e10cSrcweir	      {
381cdf0e10cSrcweir	         print "\nERROR, can not process $entry[0] for invalid test\n\n";
382cdf0e10cSrcweir	      }
383cdf0e10cSrcweir	      else
384cdf0e10cSrcweir	      {
385cdf0e10cSrcweir	         &enter_string_at_location($entry[1], $entry[2],
386cdf0e10cSrcweir               $entry[3], $running_testtype);
387cdf0e10cSrcweir	      }
388cdf0e10cSrcweir	   }
389cdf0e10cSrcweir
390cdf0e10cSrcweir	   # Process TAP_PEN
391cdf0e10cSrcweir	   #
392cdf0e10cSrcweir	   elsif ("$entry[0]" eq "TAP_PEN")
393cdf0e10cSrcweir	   {
394cdf0e10cSrcweir	      if ($#entry != 2)
395cdf0e10cSrcweir	      {
396cdf0e10cSrcweir	         print "\nERROR, $entry[0] invalid number of arguments\n\n";
397cdf0e10cSrcweir	      }
398cdf0e10cSrcweir	      elsif ($valid_test == 0)
399cdf0e10cSrcweir	      {
400cdf0e10cSrcweir	         print "\nERROR, can not process $entry[0] for invalid test\n\n";
401cdf0e10cSrcweir	      }
402cdf0e10cSrcweir	      else
403cdf0e10cSrcweir	      {
404cdf0e10cSrcweir	         &pose_tap_pen($entry[1], $entry[2], 0);
405cdf0e10cSrcweir	      }
406cdf0e10cSrcweir	   }
407cdf0e10cSrcweir
408cdf0e10cSrcweir	   # Process TAP_BUTTON
409cdf0e10cSrcweir	   #
410cdf0e10cSrcweir	   elsif ("$entry[0]" eq "TAP_BUTTON")
411cdf0e10cSrcweir	   {
412cdf0e10cSrcweir	      if ($#entry != 1)
413cdf0e10cSrcweir	      {
414cdf0e10cSrcweir	         print "\nERROR, $entry[0] invalid number of arguments\n\n";
415cdf0e10cSrcweir	      }
416cdf0e10cSrcweir	      elsif ($valid_test == 0)
417cdf0e10cSrcweir	      {
418cdf0e10cSrcweir	         print "\nERROR, can not process $entry[0] for invalid test\n\n";
419cdf0e10cSrcweir	      }
420cdf0e10cSrcweir	      else
421cdf0e10cSrcweir	      {
422cdf0e10cSrcweir	         &pose_tap_button($entry[1], 0);
423cdf0e10cSrcweir	      }
424cdf0e10cSrcweir	   }
425cdf0e10cSrcweir
426cdf0e10cSrcweir           # Process TAP_PEN_HARD
427cdf0e10cSrcweir           #
428cdf0e10cSrcweir           elsif ("$entry[0]" eq "TAP_PEN_HARD")
429cdf0e10cSrcweir           {
430cdf0e10cSrcweir              if ($#entry != 2)
431cdf0e10cSrcweir              {
432cdf0e10cSrcweir                 print "\nERROR, $entry[0] invalid number of arguments\n\n";
433cdf0e10cSrcweir              }
434cdf0e10cSrcweir              elsif ($valid_test == 0)
435cdf0e10cSrcweir              {
436cdf0e10cSrcweir                 print "\nERROR, can not process $entry[0] for invalid test\n\n";
437cdf0e10cSrcweir              }
438cdf0e10cSrcweir              else
439cdf0e10cSrcweir              {
440cdf0e10cSrcweir                 &pose_tap_pen_hard($entry[1],$entry[2], 0);
441cdf0e10cSrcweir              }
442cdf0e10cSrcweir           }
443cdf0e10cSrcweir
444cdf0e10cSrcweir
445cdf0e10cSrcweir	   # Process SLEEP
446cdf0e10cSrcweir	   #
447cdf0e10cSrcweir	   elsif ("$entry[0]" eq "SLEEP")
448cdf0e10cSrcweir	   {
449cdf0e10cSrcweir	      if ($#entry != 1)
450cdf0e10cSrcweir	      {
451cdf0e10cSrcweir         	print "\nERROR, $entry[0] invalid number of arguments\n\n";
452cdf0e10cSrcweir	      }
453cdf0e10cSrcweir	      else
454cdf0e10cSrcweir	      {
455cdf0e10cSrcweir	         &pose_sleep($entry[1]);
456cdf0e10cSrcweir	      }
457cdf0e10cSrcweir	   }
458cdf0e10cSrcweir
459cdf0e10cSrcweir	   # Process MINICALC_ENTER_CELL
460cdf0e10cSrcweir	   #
461cdf0e10cSrcweir	   elsif ("$entry[0]" eq "MINICALC_ENTER_CELL")
462cdf0e10cSrcweir	   {
463cdf0e10cSrcweir	      if ($#entry != 3)
464cdf0e10cSrcweir	      {
465cdf0e10cSrcweir	         print "\nERROR, $entry[0] invalid number of arguments\n\n";
466cdf0e10cSrcweir	      }
467cdf0e10cSrcweir	      elsif ($valid_test == 0)
468cdf0e10cSrcweir	      {
469cdf0e10cSrcweir	         print "\nERROR, can not process $entry[0] for invalid test\n\n";
470cdf0e10cSrcweir	      }
471cdf0e10cSrcweir	      else
472cdf0e10cSrcweir	      {
473cdf0e10cSrcweir	         &minicalc_enter_cell($entry[1], $entry[2], $entry[3]);
474cdf0e10cSrcweir	      }
475cdf0e10cSrcweir	   }
476cdf0e10cSrcweir
477cdf0e10cSrcweir	   # Process QUICKWORD_FIND_REPLACE
478cdf0e10cSrcweir	   #
479cdf0e10cSrcweir	   elsif ("$entry[0]" eq "QUICKWORD_FIND_REPLACE")
480cdf0e10cSrcweir	   {
481cdf0e10cSrcweir	      if ($#entry != 2)
482cdf0e10cSrcweir	      {
483cdf0e10cSrcweir	         print "\nERROR, $entry[0] invalid number of arguments\n\n";
484cdf0e10cSrcweir	      }
485cdf0e10cSrcweir	      elsif ($valid_test == 0)
486cdf0e10cSrcweir	      {
487cdf0e10cSrcweir	         print "\nERROR, can not process $entry[0] for invalid test\n\n";
488cdf0e10cSrcweir	      }
489cdf0e10cSrcweir	      else
490cdf0e10cSrcweir	      {
491cdf0e10cSrcweir	         &quickword_find_replace($entry[1], $entry[2]);
492cdf0e10cSrcweir	      }
493cdf0e10cSrcweir	   }
494cdf0e10cSrcweir	   else
495cdf0e10cSrcweir	   {
496cdf0e10cSrcweir	      print "\nERROR, invalid line <$c_inline>\n";
497cdf0e10cSrcweir	   }
498cdf0e10cSrcweir	}
499cdf0e10cSrcweir
500cdf0e10cSrcweir	&close_program($convert_file);
501cdf0e10cSrcweir}
502cdf0e10cSrcweir
503cdf0e10cSrcweir# close_program
504cdf0e10cSrcweir# convert_file - file to export
505cdf0e10cSrcweir#
506cdf0e10cSrcweir# closes the program running in pose and kills pose
507cdf0e10cSrcweir#
508cdf0e10cSrcweirsub close_program
509cdf0e10cSrcweir{
510cdf0e10cSrcweir    my $convert_file = $_[0];
511cdf0e10cSrcweir
512cdf0e10cSrcweir	if ($running_testtype eq "QUICKWORD")
513cdf0e10cSrcweir    {
514cdf0e10cSrcweir        print "QuickWord test completed.\n";
515cdf0e10cSrcweir		&close_program_quickword($convert_file);
516cdf0e10cSrcweir    }
517cdf0e10cSrcweir	elsif ($running_testtype eq "MINICALC")
518cdf0e10cSrcweir    {
519cdf0e10cSrcweir        print "MiniCalc test completed.\n";
520cdf0e10cSrcweir		&close_program_minicalc($convert_file, $number);
521cdf0e10cSrcweir    }
522cdf0e10cSrcweir}
523cdf0e10cSrcweir
524cdf0e10cSrcweir# close_program_quickword
525cdf0e10cSrcweir# convert_file - file to export
526cdf0e10cSrcweir#
527cdf0e10cSrcweir# Closes quickword and kills pose
528cdf0e10cSrcweir#
529cdf0e10cSrcweirsub close_program_quickword
530cdf0e10cSrcweir{
531cdf0e10cSrcweir      my $convert_file = $_[0];
532cdf0e10cSrcweir      my $error_file = "./error.txt";
533cdf0e10cSrcweir      my $rc;
534cdf0e10cSrcweir
535cdf0e10cSrcweir      &close_quickword();
536cdf0e10cSrcweir
537cdf0e10cSrcweir      &db_export($convert_file);
538cdf0e10cSrcweir      print "Moving /tmp/$convert_file.pdb to $pdb_new\n";
539cdf0e10cSrcweir      `mv /tmp/$convert_file.pdb $pdb_new`;
540cdf0e10cSrcweir      `chmod 666 $pdb_new/$convert_file.pdb`;
541cdf0e10cSrcweir
542cdf0e10cSrcweir      &close_connection(1);
543cdf0e10cSrcweir      &kill_pose();
544cdf0e10cSrcweir      print "\nFinishing test...\n";
545cdf0e10cSrcweir
546cdf0e10cSrcweir      # The path of where to put the error file should be specified
547cdf0e10cSrcweir      # in the properties file.  Not sure if it is really necessary
548cdf0e10cSrcweir      # to put this out to a separate file.  STDOUT should be fine.
549cdf0e10cSrcweir      #
550cdf0e10cSrcweir      $rc = &convert_to_xml($xml_new, $xml_orig,
551cdf0e10cSrcweir        "$pdb_new/$convert_file.pdb", "application/x-aportisdoc" ,
552cdf0e10cSrcweir          "sxw", $convert_file, $merge_opt);
553cdf0e10cSrcweir      if ($rc != 0)
554cdf0e10cSrcweir      {
555cdf0e10cSrcweir        print "\nERROR, problem converting file $pdb_new/$convert_file.pdb\n\n";
556cdf0e10cSrcweir      }
557cdf0e10cSrcweir}
558cdf0e10cSrcweir
559cdf0e10cSrcweir# close_program_minicalc
560cdf0e10cSrcweir# convert_file - file to export
561cdf0e10cSrcweir#
562cdf0e10cSrcweir# Closes minicalc and kills pose
563cdf0e10cSrcweir#
564cdf0e10cSrcweirsub close_program_minicalc
565cdf0e10cSrcweir{
566cdf0e10cSrcweir	  my $convert_file = $_[0];
567cdf0e10cSrcweir	  my $num_files   = $_[1];
568cdf0e10cSrcweir	  my $list="";
569cdf0e10cSrcweir	  my $rc;
570cdf0e10cSrcweir
571cdf0e10cSrcweir	  &close_minicalc();
572cdf0e10cSrcweir
573cdf0e10cSrcweir	  for ($a=1; $a <= $num_files; $a++)
574cdf0e10cSrcweir	  {
575cdf0e10cSrcweir	    &db_export("$convert_file-Sheet$a");
576cdf0e10cSrcweir	    print "Moving /tmp/$convert_file-Sheet$a.pdb to $pdb_new/\n";
577cdf0e10cSrcweir	    `mv /tmp/$convert_file-Sheet$a.pdb $pdb_new/`;
578cdf0e10cSrcweir	    `chmod 666 $pdb_new/$convert_file-Sheet$a.pdb`;
579cdf0e10cSrcweir	  }
580cdf0e10cSrcweir
581cdf0e10cSrcweir	  &close_connection(1);
582cdf0e10cSrcweir	  &kill_pose();
583cdf0e10cSrcweir	  print "\nFinishing test...\n";
584cdf0e10cSrcweir
585cdf0e10cSrcweir	  for ($a=1; $a <= $num_files; $a++)
586cdf0e10cSrcweir	  {
587cdf0e10cSrcweir	    $list .="$pdb_new/$convert_file-Sheet$a.pdb "
588cdf0e10cSrcweir	  }
589cdf0e10cSrcweir
590cdf0e10cSrcweir	  $rc = &convert_to_xml($xml_new, $xml_orig, "$list",
591cdf0e10cSrcweir		  "application/x-minicalc", "sxc", $convert_file, $merge_opt);
592cdf0e10cSrcweir	  if ($rc != 0)
593cdf0e10cSrcweir	  {
594cdf0e10cSrcweir	    print "\nERROR, problem converting file(s) $list\n\n";
595cdf0e10cSrcweir	  }
596cdf0e10cSrcweir
597cdf0e10cSrcweir      &pose_sleep(5);
598cdf0e10cSrcweir}
599cdf0e10cSrcweir
600cdf0e10cSrcweir# print_usage
601cdf0e10cSrcweir#
602cdf0e10cSrcweir# prints the usage for this program.
603cdf0e10cSrcweir#
604cdf0e10cSrcweirsub print_usage
605cdf0e10cSrcweir{
606cdf0e10cSrcweir	print "Usage : test_driver.pl\n";
607cdf0e10cSrcweir	print "\t-test=<file> \t\t: individual test case file to run\n";
608cdf0e10cSrcweir	print "\t-list=<file> \t\t: list of test case files\n";
609cdf0e10cSrcweir	print "\t-env=<file> \t\t: Properites like file defining env\n";
610cdf0e10cSrcweir	print "\t-pose-exe=<fullpath> \t: path to pose executable\n";
611cdf0e10cSrcweir	print "\t-pose-prc=<path> \t: path to directory holding prc files\n";
612cdf0e10cSrcweir	print "\t-pdb-orig=<path> \t: directory to hold original pdb files\n";
613cdf0e10cSrcweir	print "\t-pdb-new=<path> \t: directory to hold new pdb files\n";
614cdf0e10cSrcweir	print "\t-xml-orig=<path> \t: directory to hold original office documents\n";
615cdf0e10cSrcweir	print "\t-xml-new=<path> \t: directory to hold new office documents\n";
616cdf0e10cSrcweir	print "\t-merge          \t: Invokes the merge option when converting\n";
617cdf0e10cSrcweir	print "\t                \t  from PDB back to XML.\n";
618cdf0e10cSrcweir}
619cdf0e10cSrcweir
620cdf0e10cSrcweir# print_env
621cdf0e10cSrcweir#
622cdf0e10cSrcweir# Prints the current environment.
623cdf0e10cSrcweir#
624cdf0e10cSrcweirsub print_env
625cdf0e10cSrcweir{
626cdf0e10cSrcweir	print "\nUsing the following environment:\n";
627cdf0e10cSrcweir	print "\tPOSE_EXE  = $pose_exe\n";
628cdf0e10cSrcweir	print "\tPOSE_PRC  = $pose_prc\n";
629cdf0e10cSrcweir	print "\tPDB_ORIG  = $pdb_orig\n";
630cdf0e10cSrcweir	print "\tPDB_NEW   = $pdb_new\n";
631cdf0e10cSrcweir	print "\tXML_ORIG  = $xml_orig\n";
632cdf0e10cSrcweir	print "\tXML_NEW   = $xml_new\n";
633cdf0e10cSrcweir}
634cdf0e10cSrcweir
635cdf0e10cSrcweir# process_cmdline
636cdf0e10cSrcweir#
637cdf0e10cSrcweir# command line options come in as key/value pairs.
638cdf0e10cSrcweir# read them and set the appropriate global variable
639cdf0e10cSrcweir#
640cdf0e10cSrcweir# Sets these globals: pose_exe, pose_prc, xml_orig, xml_new_dir,
641cdf0e10cSrcweir# xml_new, pdb_orig_dir, pdb_orig, pdb_new_dir, pdb_new.
642cdf0e10cSrcweir#
643cdf0e10cSrcweirsub process_cmdline
644cdf0e10cSrcweir{
645cdf0e10cSrcweir	foreach $i (@_)
646cdf0e10cSrcweir	{
647cdf0e10cSrcweir		my @arg= split('=', $i);
648cdf0e10cSrcweir		@arg[0] =~ tr/A-Z/a-z/;
649cdf0e10cSrcweir
650cdf0e10cSrcweir		if (@arg[0] eq "-pose-exe")
651cdf0e10cSrcweir		{
652cdf0e10cSrcweir			$pose_exe=$arg[1];
653cdf0e10cSrcweir		}
654cdf0e10cSrcweir		elsif (@arg[0] eq "-pose-prc")
655cdf0e10cSrcweir		{
656cdf0e10cSrcweir			$pose_prc=$arg[1];
657cdf0e10cSrcweir		}
658cdf0e10cSrcweir		elsif (@arg[0] eq "-pdb-orig")
659cdf0e10cSrcweir		{
660cdf0e10cSrcweir			$pdb_orig_dir=$arg[1];
661cdf0e10cSrcweir			$pdb_orig=$arg[1];
662cdf0e10cSrcweir		}
663cdf0e10cSrcweir		elsif (@arg[0] eq "-pdb-new")
664cdf0e10cSrcweir		{
665cdf0e10cSrcweir			$pdb_new_dir=$arg[1];
666cdf0e10cSrcweir			$pdb_new=$arg[1];
667cdf0e10cSrcweir		}
668cdf0e10cSrcweir		elsif (@arg[0] eq "-xml-orig")
669cdf0e10cSrcweir		{
670cdf0e10cSrcweir			$xml_orig=$arg[1];
671cdf0e10cSrcweir		}
672cdf0e10cSrcweir		elsif (@arg[0] eq "-xml-new")
673cdf0e10cSrcweir		{
674cdf0e10cSrcweir			$xml_new_dir=$arg[1];
675cdf0e10cSrcweir			$xml_new=$arg[1];
676cdf0e10cSrcweir		}
677cdf0e10cSrcweir		elsif (@arg[0] eq "-env")
678cdf0e10cSrcweir		{
679cdf0e10cSrcweir			&set_env_from_props($arg[1]);
680cdf0e10cSrcweir		}
681cdf0e10cSrcweir		elsif (@arg[0] eq "-list")
682cdf0e10cSrcweir		{
683cdf0e10cSrcweir			$test_list = $arg[1];
684cdf0e10cSrcweir		}
685cdf0e10cSrcweir		elsif (@arg[0] eq "-test")
686cdf0e10cSrcweir		{
687cdf0e10cSrcweir			$infile = $arg[1];
688cdf0e10cSrcweir		}
689cdf0e10cSrcweir		elsif (@arg[0] eq "-merge")
690cdf0e10cSrcweir		{
691cdf0e10cSrcweir		     $merge_opt = 1;
692cdf0e10cSrcweir		}
693cdf0e10cSrcweir		else
694cdf0e10cSrcweir		{
695cdf0e10cSrcweir			print_usage();
696cdf0e10cSrcweir			die "Incorrect command line";
697cdf0e10cSrcweir		}
698cdf0e10cSrcweir	}
699cdf0e10cSrcweir}
700cdf0e10cSrcweir
701cdf0e10cSrcweir# set_env_from_props
702cdf0e10cSrcweir# infile - property file
703cdf0e10cSrcweir#
704cdf0e10cSrcweir# Read the properties file, of the form key=value
705cdf0e10cSrcweir# Valid key values are :
706cdf0e10cSrcweir#	POSE_EXE
707cdf0e10cSrcweir#	POSE_PRC
708cdf0e10cSrcweir#	PDB_ORIG
709cdf0e10cSrcweir#	PDB_NEW
710cdf0e10cSrcweir#	XML_ORIG
711cdf0e10cSrcweir#	XML_NEW
712cdf0e10cSrcweir# If a value is found the appropriate global variable is set.
713cdf0e10cSrcweir#
714cdf0e10cSrcweir# Sets these globals: pose_exe, pose_prc, xml_orig, xml_new_dir,
715cdf0e10cSrcweir# xml_new, pdb_orig_dir, pdb_orig, pdb_new_dir, pdb_new.
716cdf0e10cSrcweir#
717cdf0e10cSrcweirsub set_env_from_props
718cdf0e10cSrcweir{
719cdf0e10cSrcweir    my $infile = $_[0];
720cdf0e10cSrcweir
721cdf0e10cSrcweir	open(PROPSFILE, $infile) || die "Could not open properties file <$infile>";
722cdf0e10cSrcweir
723cdf0e10cSrcweir	while (<PROPSFILE>)
724cdf0e10cSrcweir	{
725cdf0e10cSrcweir		chomp $_;
726cdf0e10cSrcweir		my @arg = split('=', $_);
727cdf0e10cSrcweir		@arg[0] =~ tr/a-z/A-Z/;
728cdf0e10cSrcweir		my $len = @arg;
729cdf0e10cSrcweir		if ($len != 2)
730cdf0e10cSrcweir		{
731cdf0e10cSrcweir			die "Malformed property in $arg[0]";
732cdf0e10cSrcweir		}
733cdf0e10cSrcweir		if (@arg[0] eq "POSE_EXE")
734cdf0e10cSrcweir		{
735cdf0e10cSrcweir			$pose_exe=$arg[1];
736cdf0e10cSrcweir		}
737cdf0e10cSrcweir		elsif (@arg[0] eq "POSE_PRC")
738cdf0e10cSrcweir		{
739cdf0e10cSrcweir			$pose_prc=$arg[1];
740cdf0e10cSrcweir		}
741cdf0e10cSrcweir		elsif (@arg[0] eq "PDB_ORIG")
742cdf0e10cSrcweir		{
743cdf0e10cSrcweir			$pdb_orig_dir=$arg[1];
744cdf0e10cSrcweir			$pdb_orig=$arg[1];
745cdf0e10cSrcweir		}
746cdf0e10cSrcweir		elsif (@arg[0] eq "PDB_NEW")
747cdf0e10cSrcweir		{
748cdf0e10cSrcweir			$pdb_new_dir=$arg[1];
749cdf0e10cSrcweir			$pdb_new=$arg[1];
750cdf0e10cSrcweir		}
751cdf0e10cSrcweir		elsif (@arg[0] eq "XML_ORIG")
752cdf0e10cSrcweir		{
753cdf0e10cSrcweir			$xml_orig=$arg[1];
754cdf0e10cSrcweir		}
755cdf0e10cSrcweir		elsif (@arg[0] eq "XML_NEW")
756cdf0e10cSrcweir		{
757cdf0e10cSrcweir			$xml_new_dir=$arg[1];
758cdf0e10cSrcweir			$xml_new=$arg[1];
759cdf0e10cSrcweir		}
760cdf0e10cSrcweir
761cdf0e10cSrcweir	}
762cdf0e10cSrcweir	close PROPSFILE;
763cdf0e10cSrcweir}
764cdf0e10cSrcweir
765cdf0e10cSrcweir# verify_env_options
766cdf0e10cSrcweir#
767cdf0e10cSrcweir# Verify that input options are correctly set.
768cdf0e10cSrcweir# Assumes pose_exe, pose_prc, xml_orig, xml_new_dir,
769cdf0e10cSrcweir# pdb_orig_dir, and pdb_new_dir are already set.
770cdf0e10cSrcweir#
771cdf0e10cSrcweirsub verify_env_options
772cdf0e10cSrcweir{
773cdf0e10cSrcweir	if (!-e "$pose_exe")
774cdf0e10cSrcweir	{
775cdf0e10cSrcweir		die "The pose executable cannot be found at $pose_exe.";
776cdf0e10cSrcweir	}
777cdf0e10cSrcweir	if (!-x $pose_exe)
778cdf0e10cSrcweir	{
779cdf0e10cSrcweir		die "$pose_exe exists but is not executable.";
780cdf0e10cSrcweir	}
781cdf0e10cSrcweir
782cdf0e10cSrcweir	if (!-e "$pose_prc")
783cdf0e10cSrcweir	{
784cdf0e10cSrcweir		die "The PRC directory specified as $pose_prc does not exist.";
785cdf0e10cSrcweir	}
786cdf0e10cSrcweir	if (!-d "$pose_prc")
787cdf0e10cSrcweir	{
788cdf0e10cSrcweir		die "The PRC location specified as $pose_prc exists, but is not a directory.";
789cdf0e10cSrcweir	}
790cdf0e10cSrcweir
791cdf0e10cSrcweir	if (!-e "$pdb_orig_dir")
792cdf0e10cSrcweir	{
793cdf0e10cSrcweir		die "The original PDB directory specified as $pdb_orig_dir does not exist.";
794cdf0e10cSrcweir	}
795cdf0e10cSrcweir	if (!-d "$pdb_orig_dir")
796cdf0e10cSrcweir	{
797cdf0e10cSrcweir		die "The original PDB directory specified as $pdb_orig_dir exists but is not a directory.";
798cdf0e10cSrcweir	}
799cdf0e10cSrcweir
800cdf0e10cSrcweir	if (!-e "$pdb_new_dir")
801cdf0e10cSrcweir	{
802cdf0e10cSrcweir		die "The new PDB directory specified as $pdb_new_dir does not exist.";
803cdf0e10cSrcweir	}
804cdf0e10cSrcweir	if (!-d "$pdb_new_dir")
805cdf0e10cSrcweir	{
806cdf0e10cSrcweir		die "The new PDB directory specified as $pdb_new_dir exists but is not a directory.";
807cdf0e10cSrcweir	}
808cdf0e10cSrcweir
809cdf0e10cSrcweir	if (!-e "$xml_orig")
810cdf0e10cSrcweir	{
811cdf0e10cSrcweir		die "The original Office document directory specified as $xml_orig does not exist.";
812cdf0e10cSrcweir	}
813cdf0e10cSrcweir	if (!-d "$xml_orig")
814cdf0e10cSrcweir	{
815cdf0e10cSrcweir		die "The original Office document location specified as $xml_orig exists but is not a directory.";
816cdf0e10cSrcweir	}
817cdf0e10cSrcweir
818cdf0e10cSrcweir	if (!-e "$xml_new_dir")
819cdf0e10cSrcweir	{
820cdf0e10cSrcweir		die "The new Office document directory specified as $xml_new_dir does not exist.";
821cdf0e10cSrcweir	}
822cdf0e10cSrcweir	if (!-d "$xml_new_dir")
823cdf0e10cSrcweir	{
824cdf0e10cSrcweir		die "The new Office document location specified as $xml_new_dir exists but is not a directory.";
825cdf0e10cSrcweir	}
826cdf0e10cSrcweir}
827cdf0e10cSrcweir
828cdf0e10cSrcweir# verify_prcs_exist
829cdf0e10cSrcweir# prcfile - the PRC file to check
830cdf0e10cSrcweir#
831cdf0e10cSrcweir# Verifies that the specified PRC file exists.
832cdf0e10cSrcweir#
833cdf0e10cSrcweirsub verify_prcs_exist
834cdf0e10cSrcweir{
835cdf0e10cSrcweir    my $prcfile = $_[0];
836cdf0e10cSrcweir
837cdf0e10cSrcweir	if (!-e "$pose_prc/$prcfile")
838cdf0e10cSrcweir	{
839cdf0e10cSrcweir		die "The pose PRC directory ($pose_prc) is correct, but I can't find $prcfile there.";
840cdf0e10cSrcweir	}
841cdf0e10cSrcweir}
842cdf0e10cSrcweir
843