merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / xmerge / source / palmtests / qa / bin / test_driver.pl
blob55d1d44f45d9cc19a7ac6dadb35aab7938031035
1 #!/usr/bin/perl
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
33 # Version : 1.0
34 # Project : Xmerge
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
47 # this script..
48 # 4. Returns to the main applications window.
50 # Parameter
51 # Filename to convert and change
53 ##########################################################################
55 # Turn on auto-flushing
57 $|=1;
59 use EmRPC;
61 # Directory where converterlib is located...
63 use lib "$ENV{qa-dir}/lib";
64 use converterlib;
66 #-------------------- Start of main script ------------------------------------
68 # Environmental Settings
70 $pose_exe = "$ENV{pose-dir}/pose/posedist/pose";
71 $pose_prc = "$ENV{thirdpartyapps-dir}";
72 $test_list = "";
73 $infile = "";
74 $merge_opt = 0;
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'}";
83 else
85 $pose_timeout = 15;
88 $cmdline_len = @ARGV;
89 if ($cmdline_len <= 0)
91 print_usage();
92 exit (0);
95 &process_cmdline(@ARGV);
96 &print_env();
97 &verify_env_options();
99 # Make the output directories with timestamps included in the
100 # directory names.
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";
115 while (<TESTLIST>)
117 &process_testcase($_);
120 elsif ($infile ne "")
122 &process_testcase($infile);
124 else
126 die ("You didn't supply any test cases to process");
129 print "Finished.\n";
130 exit(0);
132 #-------------------- End of main script ----------------------------------------
134 #--------------------------------------------------------------------------------
135 # Various sub routines
136 #--------------------------------------------------------------------------------
138 # process_testcase
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.
148 sub process_testcase
150 my $infile = $_[0];
151 my $convert_file = "";
152 my $rc;
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>)
164 chomp $c_inline;
165 @entry = split('\|', $c_inline);
167 # Process TEST
169 if ($c_inline =~ /^ *#/ || $c_inline =~ /^[ \t]*$/)
171 # skip comments and blank lines.
173 next;
175 elsif ("$entry[0]" eq "TEST")
177 # Close the test if one is running.
179 &close_program($convert_file);
180 $running_testtype = "";
182 $valid_test = 0;
184 if ($#entry != 3)
186 print "\nERROR, $entry[0] invalid number of arguments\n\n";
188 else
190 # Start the test.
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";
198 $convert_to = "doc";
200 # Convert XML file to pdb format.
202 $rc = &convert_to_pdb("$xml_orig", $convert_file, $xml_extension ,
203 $convert_to,"$pdb_orig");
204 if ($rc != 0)
206 print "\nERROR, problem converting file $convert_file\n\n";
208 else
210 # Start pose
212 $rc = &start_pose("$pose_exe",
213 "$pose_prc/Quickword.PRC,$pose_prc/DBExporter.prc,$pdb_orig/$convert_file.pdb",
214 "Quickword", $pose_timeout);
216 if ($rc == 0)
218 &start_quickword();
219 $valid_test = 1;
220 $running_testtype = "QUICKWORD";
221 print "\npose launched, begin automated test sequence for QuickWord\n";
223 else
225 &kill_pose();
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");
239 if ($rc != 0)
241 print "\nERROR, problem converting file $convert_file\n\n";
243 else
245 # Get minicalc PDB file names, since an SXC file can
246 # be converted to more than one.
248 $pdb_files="";
249 $i = 1;
250 while (-f "$pdb_orig/$convert_file-Sheet$i.pdb")
252 if ($i > 1)
254 $pdb_files .= ",";
256 $pdb_files .= "$pdb_orig/$convert_file-Sheet$i.pdb";
257 $i++;
259 $number = $i-1;
261 # Start pose
263 $rc = &start_pose("$pose_exe",
264 "$pose_prc/MiniCalc.prc,$pose_prc/DBExporter.prc,$pdb_files",
265 "MiniCalc", $pose_timeout);
267 if ($rc == 0)
269 &start_minicalc();
270 $valid_test = 1;
271 $running_testtype = "MINICALC";
272 print "pose launched, begin automated test sequence for MiniCalc\n";
274 else
276 &kill_pose();
277 $running_testtype = "";
281 else
283 print "\nERROR, invalid extension <$entry[2]>\n\n";
288 # Process DB_EXPORT
290 elsif ("$entry[0]" eq "DB_EXPORT")
292 if ($#entry != 1)
294 print "\nERROR, $entry[0] invalid number of arguments\n\n";
296 else
298 &db_export($entry[1]);
302 # Process TAP_APPLICATIONS
304 elsif ("$entry[0]" eq "TAP_APPLICATIONS")
306 if ($#entry != 0)
308 print "\nERROR, $entry[0] invalid number of arguments\n\n";
310 else
312 &tap_applications(0);
316 # Process ENTER_STRING_AT_LOCATION
318 elsif ("$entry[0]" eq "ENTER_STRING_AT_LOCATION")
320 if ($#entry != 3)
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";
328 else
330 &enter_string_at_location($entry[1], $entry[2],
331 $entry[3], $running_testtype);
335 # Process TAP_PEN
337 elsif ("$entry[0]" eq "TAP_PEN")
339 if ($#entry != 2)
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";
347 else
349 &pose_tap_pen($entry[1], $entry[2], 0);
353 # Process TAP_BUTTON
355 elsif ("$entry[0]" eq "TAP_BUTTON")
357 if ($#entry != 1)
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";
365 else
367 &pose_tap_button($entry[1], 0);
371 # Process SLEEP
373 elsif ("$entry[0]" eq "SLEEP")
375 if ($#entry != 1)
377 print "\nERROR, $entry[0] invalid number of arguments\n\n";
379 else
381 &pose_sleep($entry[1]);
385 # Process MINICALC_ENTER_CELL
387 elsif ("$entry[0]" eq "MINICALC_ENTER_CELL")
389 if ($#entry != 3)
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";
397 else
399 &minicalc_enter_cell($entry[1], $entry[2], $entry[3]);
403 # Process QUICKWORD_FIND_REPLACE
405 elsif ("$entry[0]" eq "QUICKWORD_FIND_REPLACE")
407 if ($#entry != 2)
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";
415 else
417 &quickword_find_replace($entry[1], $entry[2]);
420 else
422 print "\nERROR, invalid line <$c_inline>\n";
426 &close_program($convert_file);
429 # close_program
430 # convert_file - file to export
432 # closes the program running in pose and kills pose
434 sub close_program
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";
459 my $rc;
461 &close_quickword();
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);
469 &kill_pose();
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);
479 if ($rc != 0)
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];
494 my $list="";
495 my $rc;
497 &close_minicalc();
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);
508 &kill_pose();
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);
518 if ($rc != 0)
520 print "\nERROR, problem converting file(s) $list\n\n";
523 &pose_sleep(5);
526 # print_usage
528 # prints the usage for this program.
530 sub print_usage
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";
546 # print_env
548 # Prints the current environment.
550 sub print_env
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";
561 # process_cmdline
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.
569 sub process_cmdline
571 my $lu_str = &get_date_string();
573 foreach $i (@_)
575 my @arg= split('=', $i);
576 @arg[0] =~ tr/A-Z/a-z/;
578 if (@arg[0] eq "-pose-exe")
580 $pose_exe=$arg[1];
582 elsif (@arg[0] eq "-pose-prc")
584 $pose_prc=$arg[1];
586 elsif (@arg[0] eq "-pdb-orig")
588 $pdb_orig_dir=$arg[1];
589 $pdb_orig=$arg[1];
590 $pdb_orig .= "/";
591 $pdb_orig .= "$lu_str";
593 elsif (@arg[0] eq "-pdb-new")
595 $pdb_new_dir=$arg[1];
596 $pdb_new=$arg[1];
597 $pdb_new .= "/";
598 $pdb_new .= "$lu_str";
600 elsif (@arg[0] eq "-xml-orig")
602 $xml_orig=$arg[1];
604 elsif (@arg[0] eq "-xml-new")
606 $xml_new_dir=$arg[1];
607 $xml_new=$arg[1];
608 $xml_new .= "/";
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")
621 $infile = $arg[1];
623 elsif (@arg[0] eq "-merge")
625 $merge_opt = 1;
627 else
629 print_usage();
630 die "Incorrect command line";
635 # set_env_from_props
636 # infile - property file
638 # Read the properties file, of the form key=value
639 # Valid key values are :
640 # POSE_EXE
641 # POSE_PRC
642 # POSE_PERL
643 # TEST_HOME
644 # PDB_ORIG
645 # PDB_NEW
646 # XML_ORIG
647 # XML_NEW
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
655 my $infile = $_[0];
656 my $lu_str = &get_date_string();
658 open(PROPSFILE, $infile) || die "Could not open properties file <$infile>";
660 while (<PROPSFILE>)
662 chomp $_;
663 my @arg = split('=', $_);
664 @arg[0] =~ tr/a-z/A-Z/;
665 my $len = @arg;
666 if ($len != 2)
668 die "Malformed property in $arg[0]";
670 if (@arg[0] eq "POSE_EXE")
672 $pose_exe=$arg[1];
674 elsif (@arg[0] eq "POSE_PRC")
676 $pose_prc=$arg[1];
678 elsif (@arg[0] eq "PDB_ORIG")
680 $pdb_orig_dir=$arg[1];
681 $pdb_orig=$arg[1];
682 $pdb_orig .= "/";
683 $pdb_orig .= "$lu_str";
685 elsif (@arg[0] eq "PDB_NEW")
687 $pdb_new_dir=$arg[1];
688 $pdb_new=$arg[1];
689 $pdb_new .= "/";
690 $pdb_new .= "$lu_str";
692 elsif (@arg[0] eq "XML_ORIG")
694 $xml_orig=$arg[1];
696 elsif (@arg[0] eq "XML_NEW")
698 $xml_new_dir=$arg[1];
699 $xml_new=$arg[1];
700 $xml_new .= "/";
701 $xml_new .= "$lu_str";
705 close PROPSFILE;
708 # verify_env_options
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
716 if (!-e "$pose_exe")
718 die "The pose executable cannot be found at $pose_exe.";
720 if (!-x $pose_exe)
722 die "$pose_exe exists but is not executable.";
725 if (!-e "$pose_prc")
727 die "The PRC directory specified as $pose_prc does not exist.";
729 if (!-d "$pose_prc")
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.";
752 if (!-e "$xml_orig")
754 die "The original Office document directory specified as $xml_orig does not exist.";
756 if (!-d "$xml_orig")
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.";
771 # verify_prcs_exist
772 # prcfile - the PRC file to check
774 # Verifies that the specified PRC file exists.
776 sub verify_prcs_exist
778 my $prcfile = $_[0];
780 if (!-e "$pose_prc/$prcfile")
782 die "The pose PRC directory ($pose_prc) is correct, but I can't find $prcfile there.";