2 #########################################################################
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
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.
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).
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.
29 #*************************************************************************
31 ####################################################################
32 # File Name: test_driver.pl
35 # Author : Brian Cameron
36 # Date : 5th Sept. 2001
38 # This script does the following:
40 # Processes the input file, and runs the tests specified in that
41 # file. This will do the following for each test:
43 # 1. Convert a file from XML to PDB format
44 # 2. Starts up the Palm OS emulator with the appropriate program
45 # running and the converted file loaded the program.
46 # 3. Makes automated changes as specified in the inputfile to
48 # 4. Returns to the main applications window.
51 # Filename to convert and change
53 ##########################################################################
55 # Turn on auto-flushing
61 # Directory where converterlib is located...
63 use lib
"$ENV{qa-dir}/lib";
66 #-------------------- Start of main script ------------------------------------
68 # Environmental Settings
70 $pose_exe = "$ENV{pose-dir}/pose/posedist/pose";
71 $pose_prc = "$ENV{thirdpartyapps-dir}";
76 # You may need to change this from the default if your pose emulator
77 # starts faster or slower than mine.
79 if ($ENV{'POSE_TIMEOUT'})
81 $pose_timeout = "$ENV{'POSE_TIMEOUT'}";
89 if ($cmdline_len <= 0)
95 &process_cmdline
(@ARGV);
97 &verify_env_options
();
99 # Make the output directories with timestamps included in the
102 mkdir $pdb_orig, 0777 || die "can not create directory <$pdb_new>.";
103 `chmod 777 $pdb_orig`;
104 mkdir $pdb_new, 0777 || die "can not create directory <$pdb_new>.";
105 `chmod 777 $pdb_new`;
106 mkdir $xml_new, 0777 || die "can not create directory <$pdb_new>.";
107 `chmod 777 $xml_new`;
109 &verify_prcs_exist
("DBExporter.prc");
111 if ($test_list ne "")
113 open (TESTLIST
, $test_list) || die "Couldn't open testcase list file $test_list";
117 &process_testcase
($_);
120 elsif ($infile ne "")
122 &process_testcase
($infile);
126 die ("You didn't supply any test cases to process");
132 #-------------------- End of main script ----------------------------------------
134 #--------------------------------------------------------------------------------
135 # Various sub routines
136 #--------------------------------------------------------------------------------
139 # infile - test case file name
141 # This is the main driver function
142 # Opens the infile, reads it in parses it, runs the appropriate conversion
143 # starts pose and load the file into the emulator. It launches the
144 # appropriate editor and then runs the commands specified in the test case.
145 # It then exports the file and saves it locally. Finally it is converted
146 # back to the original office format.
151 my $convert_file = "";
154 # Process the inputfile
156 open (INFILE
, $infile) || die "Failed to open test case <$infile>";
158 $running_testtype = "";
160 # Process the input file.
162 while ($c_inline = <INFILE
>)
165 @entry = split('\|', $c_inline);
169 if ($c_inline =~ /^ *#/ || $c_inline =~ /^[ \t]*$/)
171 # skip comments and blank lines.
175 elsif ("$entry[0]" eq "TEST")
177 # Close the test if one is running.
179 &close_program
($convert_file);
180 $running_testtype = "";
186 print "\nERROR, $entry[0] invalid number of arguments\n\n";
192 print "\nStarting test: $entry[1]\n";
193 $convert_file = $entry[3];
195 if ("$entry[2]" =~ /[Qq][Uu][Ii][Cc][Kk][Ww][Oo][Rr][Dd]/)
197 $xml_extension = "sxw";
200 # Convert XML file to pdb format.
202 $rc = &convert_to_pdb
("$xml_orig", $convert_file, $xml_extension ,
203 $convert_to,"$pdb_orig");
206 print "\nERROR, problem converting file $convert_file\n\n";
212 $rc = &start_pose
("$pose_exe",
213 "$pose_prc/Quickword.PRC,$pose_prc/DBExporter.prc,$pdb_orig/$convert_file.pdb",
214 "Quickword", $pose_timeout);
220 $running_testtype = "QUICKWORD";
221 print "\npose launched, begin automated test sequence for QuickWord\n";
226 $running_testtype = "";
230 elsif ("$entry[2]" =~ /[Mm][Ii][Nn][Ii][Cc][Aa][Ll][Cc]/)
232 $xml_extension = "sxc";
233 $convert_to = "minicalc";
235 # Convert XML file to pdb format.
237 $rc = &convert_to_pdb
("$xml_orig", $convert_file,
238 $xml_extension, $convert_to,"$pdb_orig");
241 print "\nERROR, problem converting file $convert_file\n\n";
245 # Get minicalc PDB file names, since an SXC file can
246 # be converted to more than one.
250 while (-f
"$pdb_orig/$convert_file-Sheet$i.pdb")
256 $pdb_files .= "$pdb_orig/$convert_file-Sheet$i.pdb";
263 $rc = &start_pose
("$pose_exe",
264 "$pose_prc/MiniCalc.prc,$pose_prc/DBExporter.prc,$pdb_files",
265 "MiniCalc", $pose_timeout);
271 $running_testtype = "MINICALC";
272 print "pose launched, begin automated test sequence for MiniCalc\n";
277 $running_testtype = "";
283 print "\nERROR, invalid extension <$entry[2]>\n\n";
290 elsif ("$entry[0]" eq "DB_EXPORT")
294 print "\nERROR, $entry[0] invalid number of arguments\n\n";
298 &db_export
($entry[1]);
302 # Process TAP_APPLICATIONS
304 elsif ("$entry[0]" eq "TAP_APPLICATIONS")
308 print "\nERROR, $entry[0] invalid number of arguments\n\n";
312 &tap_applications
(0);
316 # Process ENTER_STRING_AT_LOCATION
318 elsif ("$entry[0]" eq "ENTER_STRING_AT_LOCATION")
322 print "\nERROR, $entry[0] invalid number of arguments\n\n";
324 elsif ($valid_test == 0)
326 print "\nERROR, can not process $entry[0] for invalid test\n\n";
330 &enter_string_at_location
($entry[1], $entry[2],
331 $entry[3], $running_testtype);
337 elsif ("$entry[0]" eq "TAP_PEN")
341 print "\nERROR, $entry[0] invalid number of arguments\n\n";
343 elsif ($valid_test == 0)
345 print "\nERROR, can not process $entry[0] for invalid test\n\n";
349 &pose_tap_pen
($entry[1], $entry[2], 0);
355 elsif ("$entry[0]" eq "TAP_BUTTON")
359 print "\nERROR, $entry[0] invalid number of arguments\n\n";
361 elsif ($valid_test == 0)
363 print "\nERROR, can not process $entry[0] for invalid test\n\n";
367 &pose_tap_button
($entry[1], 0);
373 elsif ("$entry[0]" eq "SLEEP")
377 print "\nERROR, $entry[0] invalid number of arguments\n\n";
381 &pose_sleep
($entry[1]);
385 # Process MINICALC_ENTER_CELL
387 elsif ("$entry[0]" eq "MINICALC_ENTER_CELL")
391 print "\nERROR, $entry[0] invalid number of arguments\n\n";
393 elsif ($valid_test == 0)
395 print "\nERROR, can not process $entry[0] for invalid test\n\n";
399 &minicalc_enter_cell
($entry[1], $entry[2], $entry[3]);
403 # Process QUICKWORD_FIND_REPLACE
405 elsif ("$entry[0]" eq "QUICKWORD_FIND_REPLACE")
409 print "\nERROR, $entry[0] invalid number of arguments\n\n";
411 elsif ($valid_test == 0)
413 print "\nERROR, can not process $entry[0] for invalid test\n\n";
417 &quickword_find_replace
($entry[1], $entry[2]);
422 print "\nERROR, invalid line <$c_inline>\n";
426 &close_program
($convert_file);
430 # convert_file - file to export
432 # closes the program running in pose and kills pose
436 my $convert_file = $_[0];
438 if ($running_testtype eq "QUICKWORD")
440 print "QuickWord test completed.\n";
441 &close_program_quickword
($convert_file);
443 elsif ($running_testtype eq "MINICALC")
445 print "MiniCalc test completed.\n";
446 &close_program_minicalc
($convert_file, $number);
450 # close_program_quickword
451 # convert_file - file to export
453 # Closes quickword and kills pose
455 sub close_program_quickword
457 my $convert_file = $_[0];
458 my $error_file = "./error.txt";
463 &db_export
($convert_file);
464 print "Moving /tmp/$convert_file.pdb to $pdb_new\n";
465 `mv /tmp/$convert_file.pdb $pdb_new`;
466 `chmod 666 $pdb_new/$convert_file.pdb`;
468 &close_connection
(1);
470 print "\nFinishing test...\n";
472 # The path of where to put the error file should be specified
473 # in the properties file. Not sure if it is really necessary
474 # to put this out to a separate file. STDOUT should be fine.
476 $rc = &convert_to_xml
($xml_new, $xml_orig,
477 "$pdb_new/$convert_file.pdb", "doc" ,
478 "sxw", $convert_file, $merge_opt);
481 print "\nERROR, problem converting file $pdb_new/$convert_file.pdb\n\n";
485 # close_program_minicalc
486 # convert_file - file to export
488 # Closes minicalc and kills pose
490 sub close_program_minicalc
492 my $convert_file = $_[0];
493 my $num_files = $_[1];
499 for ($a=1; $a <= $num_files; $a++)
501 &db_export
("$convert_file-Sheet$a");
502 print "Moving /tmp/$convert_file-Sheet$a.pdb to $pdb_new/\n";
503 `mv /tmp/$convert_file-Sheet$a.pdb $pdb_new/`;
504 `chmod 666 $pdb_new/$convert_file-Sheet$a.pdb`;
507 &close_connection
(1);
509 print "\nFinishing test...\n";
511 for ($a=1; $a <= $num_files; $a++)
513 $list .="$pdb_new/$convert_file-Sheet$a.pdb "
516 $rc = &convert_to_xml
($xml_new, $xml_orig, "$list",
517 "minicalc", "sxc", $convert_file, $merge_opt);
520 print "\nERROR, problem converting file(s) $list\n\n";
528 # prints the usage for this program.
532 print "Usage : test_driver.pl\n";
533 print "\t-test=<file> \t\t: individual test case file to run\n";
534 print "\t-list=<file> \t\t: list of test case files\n";
535 print "\t-env=<file> \t\t: Properites like file defining env\n";
536 print "\t-pose-exe=<fullpath> \t: path to pose executable\n";
537 print "\t-pose-prc=<path> \t: path to directory holding prc files\n";
538 print "\t-pdb-orig=<path> \t: directory to hold original pdb files\n";
539 print "\t-pdb-new=<path> \t: directory to hold new pdb files\n";
540 print "\t-xml-orig=<path> \t: directory to hold original office documents\n";
541 print "\t-xml-new=<path> \t: directory to hold new office documents\n";
542 print "\t-merge \t: Invokes the merge option when converting\n";
543 print "\t \t from PDB back to XML.\n";
548 # Prints the current environment.
552 print "\nUsing the following environment:\n";
553 print "\tPOSE_EXE = $pose_exe\n";
554 print "\tPOSE_PRC = $pose_prc\n";
555 print "\tPDB_ORIG = $pdb_orig\n";
556 print "\tPDB_NEW = $pdb_new\n";
557 print "\tXML_ORIG = $xml_orig\n";
558 print "\tXML_NEW = $xml_new\n";
563 # command line options come in as key/value pairs.
564 # read them and set the appropriate global variable
566 # Sets these globals: pose_exe, pose_prc, xml_orig, xml_new_dir,
567 # xml_new, pdb_orig_dir, pdb_orig, pdb_new_dir, pdb_new.
571 my $lu_str = &get_date_string
();
575 my @arg= split('=', $i);
576 @arg[0] =~ tr/A-Z/a-z/;
578 if (@arg[0] eq "-pose-exe")
582 elsif (@arg[0] eq "-pose-prc")
586 elsif (@arg[0] eq "-pdb-orig")
588 $pdb_orig_dir=$arg[1];
591 $pdb_orig .= "$lu_str";
593 elsif (@arg[0] eq "-pdb-new")
595 $pdb_new_dir=$arg[1];
598 $pdb_new .= "$lu_str";
600 elsif (@arg[0] eq "-xml-orig")
604 elsif (@arg[0] eq "-xml-new")
606 $xml_new_dir=$arg[1];
609 $xml_new .= "$lu_str";
611 elsif (@arg[0] eq "-env")
613 &set_env_from_props
($arg[1]);
615 elsif (@arg[0] eq "-list")
617 $test_list = $arg[1];
619 elsif (@arg[0] eq "-test")
623 elsif (@arg[0] eq "-merge")
630 die "Incorrect command line";
636 # infile - property file
638 # Read the properties file, of the form key=value
639 # Valid key values are :
648 # If a value is found the appropriate global variable is set.
650 # Sets these globals: pose_exe, pose_prc, xml_orig, xml_new_dir,
651 # xml_new, pdb_orig_dir, pdb_orig, pdb_new_dir, pdb_new.
653 sub set_env_from_props
656 my $lu_str = &get_date_string
();
658 open(PROPSFILE
, $infile) || die "Could not open properties file <$infile>";
663 my @arg = split('=', $_);
664 @arg[0] =~ tr/a-z/A-Z/;
668 die "Malformed property in $arg[0]";
670 if (@arg[0] eq "POSE_EXE")
674 elsif (@arg[0] eq "POSE_PRC")
678 elsif (@arg[0] eq "PDB_ORIG")
680 $pdb_orig_dir=$arg[1];
683 $pdb_orig .= "$lu_str";
685 elsif (@arg[0] eq "PDB_NEW")
687 $pdb_new_dir=$arg[1];
690 $pdb_new .= "$lu_str";
692 elsif (@arg[0] eq "XML_ORIG")
696 elsif (@arg[0] eq "XML_NEW")
698 $xml_new_dir=$arg[1];
701 $xml_new .= "$lu_str";
710 # Verify that input options are correctly set.
711 # Assumes pose_exe, pose_prc, xml_orig, xml_new_dir,
712 # pdb_orig_dir, and pdb_new_dir are already set.
714 sub verify_env_options
718 die "The pose executable cannot be found at $pose_exe.";
722 die "$pose_exe exists but is not executable.";
727 die "The PRC directory specified as $pose_prc does not exist.";
731 die "The PRC location specified as $pose_prc exists, but is not a directory.";
734 if (!-e
"$pdb_orig_dir")
736 die "The original PDB directory specified as $pdb_orig_dir does not exist.";
738 if (!-d
"$pdb_orig_dir")
740 die "The original PDB directory specified as $pdb_orig_dir exists but is not a directory.";
743 if (!-e
"$pdb_new_dir")
745 die "The new PDB directory specified as $pdb_new_dir does not exist.";
747 if (!-d
"$pdb_new_dir")
749 die "The new PDB directory specified as $pdb_new_dir exists but is not a directory.";
754 die "The original Office document directory specified as $xml_orig does not exist.";
758 die "The original Office document location specified as $xml_orig exists but is not a directory.";
761 if (!-e
"$xml_new_dir")
763 die "The new Office document directory specified as $xml_new_dir does not exist.";
765 if (!-d
"$xml_new_dir")
767 die "The new Office document location specified as $xml_new_dir exists but is not a directory.";
772 # prcfile - the PRC file to check
774 # Verifies that the specified PRC file exists.
776 sub verify_prcs_exist
780 if (!-e
"$pose_prc/$prcfile")
782 die "The pose PRC directory ($pose_prc) is correct, but I can't find $prcfile there.";