xref: /trunk/main/xmerge/source/palmtests/qa/bin/test_driver.pl (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1#!/usr/bin/perl
2#########################################################################
3
4 #*************************************************************************
5 #
6# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7#
8# Copyright 2000, 2010 Oracle and/or its affiliates.
9#
10# OpenOffice.org - a multi-platform office productivity suite
11#
12# This file is part of OpenOffice.org.
13#
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.
17#
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).
23#
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.
28#
29 #*************************************************************************
30
31####################################################################
32# File Name: test_driver.pl
33# Version  : 1.0
34# Project  : Xmerge
35# Author   : Brian Cameron
36# Date     : 5th Sept. 2001
37#
38# This script does the following:
39#
40# Processes the input file, and runs the tests specified in that
41# file.  This will do the following for each test:
42#
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.
49#
50# Parameter
51#   Filename to convert and change
52#
53##########################################################################
54
55# Turn on auto-flushing
56#
57$|=1;
58
59use EmRPC;
60
61# Directory where converterlib is located...
62#
63use lib "$ENV{qa-dir}/lib";
64use converterlib;
65
66#-------------------- Start of main script ------------------------------------
67
68# Environmental Settings
69
70$pose_exe = "$ENV{pose-dir}/pose/posedist/pose";
71$pose_prc = "$ENV{thirdpartyapps-dir}";
72$test_list = "";
73$infile = "";
74$merge_opt = 0;
75
76# You may need to change this from the default if your pose emulator
77# starts faster or slower than mine.
78#
79if ($ENV{'POSE_TIMEOUT'})
80{
81  $pose_timeout  = "$ENV{'POSE_TIMEOUT'}";
82}
83else
84{
85  $pose_timeout = 15;
86}
87
88$cmdline_len = @ARGV;
89if ($cmdline_len <= 0)
90{
91    print_usage();
92    exit (0);
93}
94
95&process_cmdline(@ARGV);
96&print_env();
97&verify_env_options();
98
99# Make the output directories with timestamps included in the
100# directory names.
101#
102mkdir $pdb_orig, 0777 || die "can not create directory <$pdb_new>.";
103`chmod 777 $pdb_orig`;
104mkdir $pdb_new,  0777 || die "can not create directory <$pdb_new>.";
105`chmod 777 $pdb_new`;
106mkdir $xml_new,  0777 || die "can not create directory <$pdb_new>.";
107`chmod 777 $xml_new`;
108
109&verify_prcs_exist("DBExporter.prc");
110
111if ($test_list ne "")
112{
113    open (TESTLIST, $test_list) || die "Couldn't open testcase list file $test_list";
114
115    while (<TESTLIST>)
116    {
117        &process_testcase($_);
118    }
119}
120elsif ($infile ne "")
121{
122    &process_testcase($infile);
123}
124else
125{
126    die ("You didn't supply any test cases to process");
127}
128
129print "Finished.\n";
130exit(0);
131
132#-------------------- End of main script ----------------------------------------
133
134#--------------------------------------------------------------------------------
135# Various sub routines
136#--------------------------------------------------------------------------------
137
138# process_testcase
139# infile - test case file name
140#
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.
147#
148sub process_testcase
149{
150    my $infile = $_[0];
151    my $convert_file = "";
152    my $rc;
153
154    # Process the inputfile
155    #
156    open (INFILE, $infile) || die "Failed to open test case <$infile>";
157
158    $running_testtype = "";
159
160    # Process the input file.
161    #
162    while ($c_inline = <INFILE>)
163    {
164       chomp $c_inline;
165       @entry = split('\|', $c_inline);
166
167       # Process TEST
168       #
169       if ($c_inline =~ /^ *#/ || $c_inline =~ /^[ \t]*$/)
170       {
171          # skip comments and blank lines.
172          #
173          next;
174       }
175       elsif ("$entry[0]" eq "TEST")
176       {
177          # Close the test if one is running.
178          #
179          &close_program($convert_file);
180          $running_testtype = "";
181
182          $valid_test = 0;
183
184          if ($#entry != 3)
185          {
186             print "\nERROR, $entry[0] invalid number of arguments\n\n";
187          }
188          else
189          {
190             # Start the test.
191             #
192             print "\nStarting test: $entry[1]\n";
193             $convert_file = $entry[3];
194
195             if ("$entry[2]"  =~ /[Qq][Uu][Ii][Cc][Kk][Ww][Oo][Rr][Dd]/)
196             {
197                $xml_extension = "sxw";
198                $convert_to = "doc";
199
200                # Convert XML file to pdb format.
201                #
202                $rc = &convert_to_pdb("$xml_orig", $convert_file, $xml_extension ,
203                   $convert_to,"$pdb_orig");
204                if ($rc != 0)
205                {
206                   print "\nERROR, problem converting file $convert_file\n\n";
207                }
208                else
209                {
210                   # Start pose
211                   #
212                   $rc = &start_pose("$pose_exe",
213                     "$pose_prc/Quickword.PRC,$pose_prc/DBExporter.prc,$pdb_orig/$convert_file.pdb",
214                     "Quickword", $pose_timeout);
215
216                   if ($rc == 0)
217                   {
218                      &start_quickword();
219                      $valid_test = 1;
220                      $running_testtype = "QUICKWORD";
221                      print "\npose launched, begin automated test sequence for QuickWord\n";
222                   }
223                   else
224                   {
225                      &kill_pose();
226                      $running_testtype = "";
227                   }
228                }
229             }
230             elsif ("$entry[2]"  =~ /[Mm][Ii][Nn][Ii][Cc][Aa][Ll][Cc]/)
231             {
232                $xml_extension = "sxc";
233                $convert_to = "minicalc";
234
235                # Convert XML file to pdb format.
236                #
237                $rc = &convert_to_pdb("$xml_orig", $convert_file,
238                  $xml_extension, $convert_to,"$pdb_orig");
239                if ($rc != 0)
240                {
241                   print "\nERROR, problem converting file $convert_file\n\n";
242                }
243                else
244                {
245                   # Get minicalc PDB file names, since an SXC file can
246                   # be converted to more than one.
247                   #
248                   $pdb_files="";
249                   $i = 1;
250                   while (-f "$pdb_orig/$convert_file-Sheet$i.pdb")
251                   {
252                     if ($i > 1)
253                     {
254                       $pdb_files .= ",";
255                     }
256                     $pdb_files .= "$pdb_orig/$convert_file-Sheet$i.pdb";
257                     $i++;
258                   }
259                   $number = $i-1;
260
261                   # Start pose
262                   #
263                   $rc = &start_pose("$pose_exe",
264                      "$pose_prc/MiniCalc.prc,$pose_prc/DBExporter.prc,$pdb_files",
265                      "MiniCalc", $pose_timeout);
266
267                   if ($rc == 0)
268                   {
269                      &start_minicalc();
270                      $valid_test = 1;
271                      $running_testtype = "MINICALC";
272                      print "pose launched, begin automated test sequence for MiniCalc\n";
273                   }
274                   else
275                   {
276                      &kill_pose();
277                      $running_testtype = "";
278                   }
279                }
280             }
281             else
282             {
283                print "\nERROR, invalid extension <$entry[2]>\n\n";
284             }
285          }
286       }
287
288       # Process DB_EXPORT
289       #
290       elsif ("$entry[0]" eq "DB_EXPORT")
291       {
292          if ($#entry != 1)
293          {
294            print "\nERROR, $entry[0] invalid number of arguments\n\n";
295          }
296          else
297          {
298             &db_export($entry[1]);
299          }
300       }
301
302       # Process TAP_APPLICATIONS
303       #
304       elsif ("$entry[0]" eq "TAP_APPLICATIONS")
305       {
306          if ($#entry != 0)
307          {
308            print "\nERROR, $entry[0] invalid number of arguments\n\n";
309          }
310          else
311          {
312             &tap_applications(0);
313          }
314       }
315
316       # Process ENTER_STRING_AT_LOCATION
317       #
318       elsif ("$entry[0]" eq "ENTER_STRING_AT_LOCATION")
319       {
320          if ($#entry != 3)
321          {
322             print "\nERROR, $entry[0] invalid number of arguments\n\n";
323          }
324          elsif ($valid_test == 0)
325          {
326             print "\nERROR, can not process $entry[0] for invalid test\n\n";
327          }
328          else
329          {
330             &enter_string_at_location($entry[1], $entry[2],
331               $entry[3], $running_testtype);
332          }
333       }
334
335       # Process TAP_PEN
336       #
337       elsif ("$entry[0]" eq "TAP_PEN")
338       {
339          if ($#entry != 2)
340          {
341             print "\nERROR, $entry[0] invalid number of arguments\n\n";
342          }
343          elsif ($valid_test == 0)
344          {
345             print "\nERROR, can not process $entry[0] for invalid test\n\n";
346          }
347          else
348          {
349             &pose_tap_pen($entry[1], $entry[2], 0);
350          }
351       }
352
353       # Process TAP_BUTTON
354       #
355       elsif ("$entry[0]" eq "TAP_BUTTON")
356       {
357          if ($#entry != 1)
358          {
359             print "\nERROR, $entry[0] invalid number of arguments\n\n";
360          }
361          elsif ($valid_test == 0)
362          {
363             print "\nERROR, can not process $entry[0] for invalid test\n\n";
364          }
365          else
366          {
367             &pose_tap_button($entry[1], 0);
368          }
369       }
370
371       # Process SLEEP
372       #
373       elsif ("$entry[0]" eq "SLEEP")
374       {
375          if ($#entry != 1)
376          {
377            print "\nERROR, $entry[0] invalid number of arguments\n\n";
378          }
379          else
380          {
381             &pose_sleep($entry[1]);
382          }
383       }
384
385       # Process MINICALC_ENTER_CELL
386       #
387       elsif ("$entry[0]" eq "MINICALC_ENTER_CELL")
388       {
389          if ($#entry != 3)
390          {
391             print "\nERROR, $entry[0] invalid number of arguments\n\n";
392          }
393          elsif ($valid_test == 0)
394          {
395             print "\nERROR, can not process $entry[0] for invalid test\n\n";
396          }
397          else
398          {
399             &minicalc_enter_cell($entry[1], $entry[2], $entry[3]);
400          }
401       }
402
403       # Process QUICKWORD_FIND_REPLACE
404       #
405       elsif ("$entry[0]" eq "QUICKWORD_FIND_REPLACE")
406       {
407          if ($#entry != 2)
408          {
409             print "\nERROR, $entry[0] invalid number of arguments\n\n";
410          }
411          elsif ($valid_test == 0)
412          {
413             print "\nERROR, can not process $entry[0] for invalid test\n\n";
414          }
415          else
416          {
417             &quickword_find_replace($entry[1], $entry[2]);
418          }
419       }
420       else
421       {
422          print "\nERROR, invalid line <$c_inline>\n";
423       }
424    }
425
426    &close_program($convert_file);
427}
428
429# close_program
430# convert_file - file to export
431#
432# closes the program running in pose and kills pose
433#
434sub close_program
435{
436    my $convert_file = $_[0];
437
438    if ($running_testtype eq "QUICKWORD")
439    {
440        print "QuickWord test completed.\n";
441        &close_program_quickword($convert_file);
442    }
443    elsif ($running_testtype eq "MINICALC")
444    {
445        print "MiniCalc test completed.\n";
446        &close_program_minicalc($convert_file, $number);
447    }
448}
449
450# close_program_quickword
451# convert_file - file to export
452#
453# Closes quickword and kills pose
454#
455sub close_program_quickword
456{
457      my $convert_file = $_[0];
458      my $error_file = "./error.txt";
459      my $rc;
460
461      &close_quickword();
462
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`;
467
468      &close_connection(1);
469      &kill_pose();
470      print "\nFinishing test...\n";
471
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.
475      #
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)
480      {
481        print "\nERROR, problem converting file $pdb_new/$convert_file.pdb\n\n";
482      }
483}
484
485# close_program_minicalc
486# convert_file - file to export
487#
488# Closes minicalc and kills pose
489#
490sub close_program_minicalc
491{
492      my $convert_file = $_[0];
493      my $num_files   = $_[1];
494      my $list="";
495      my $rc;
496
497      &close_minicalc();
498
499      for ($a=1; $a <= $num_files; $a++)
500      {
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`;
505      }
506
507      &close_connection(1);
508      &kill_pose();
509      print "\nFinishing test...\n";
510
511      for ($a=1; $a <= $num_files; $a++)
512      {
513        $list .="$pdb_new/$convert_file-Sheet$a.pdb "
514      }
515
516      $rc = &convert_to_xml($xml_new, $xml_orig, "$list",
517          "minicalc", "sxc", $convert_file, $merge_opt);
518      if ($rc != 0)
519      {
520        print "\nERROR, problem converting file(s) $list\n\n";
521      }
522
523      &pose_sleep(5);
524}
525
526# print_usage
527#
528# prints the usage for this program.
529#
530sub print_usage
531{
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";
544}
545
546# print_env
547#
548# Prints the current environment.
549#
550sub print_env
551{
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";
559}
560
561# process_cmdline
562#
563# command line options come in as key/value pairs.
564# read them and set the appropriate global variable
565#
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.
568#
569sub process_cmdline
570{
571    my $lu_str = &get_date_string();
572
573    foreach $i (@_)
574    {
575        my @arg= split('=', $i);
576        @arg[0] =~ tr/A-Z/a-z/;
577
578        if (@arg[0] eq "-pose-exe")
579        {
580            $pose_exe=$arg[1];
581        }
582        elsif (@arg[0] eq "-pose-prc")
583        {
584            $pose_prc=$arg[1];
585        }
586        elsif (@arg[0] eq "-pdb-orig")
587        {
588            $pdb_orig_dir=$arg[1];
589            $pdb_orig=$arg[1];
590            $pdb_orig .= "/";
591            $pdb_orig .= "$lu_str";
592        }
593        elsif (@arg[0] eq "-pdb-new")
594        {
595            $pdb_new_dir=$arg[1];
596            $pdb_new=$arg[1];
597            $pdb_new .= "/";
598            $pdb_new .= "$lu_str";
599        }
600        elsif (@arg[0] eq "-xml-orig")
601        {
602            $xml_orig=$arg[1];
603        }
604        elsif (@arg[0] eq "-xml-new")
605        {
606            $xml_new_dir=$arg[1];
607            $xml_new=$arg[1];
608            $xml_new .= "/";
609            $xml_new .= "$lu_str";
610        }
611        elsif (@arg[0] eq "-env")
612        {
613            &set_env_from_props($arg[1]);
614        }
615        elsif (@arg[0] eq "-list")
616        {
617            $test_list = $arg[1];
618        }
619        elsif (@arg[0] eq "-test")
620        {
621            $infile = $arg[1];
622        }
623        elsif (@arg[0] eq "-merge")
624        {
625             $merge_opt = 1;
626        }
627        else
628        {
629            print_usage();
630            die "Incorrect command line";
631        }
632    }
633}
634
635# set_env_from_props
636# infile - property file
637#
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.
649#
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.
652#
653sub set_env_from_props
654{
655    my $infile = $_[0];
656    my $lu_str = &get_date_string();
657
658    open(PROPSFILE, $infile) || die "Could not open properties file <$infile>";
659
660    while (<PROPSFILE>)
661    {
662        chomp $_;
663        my @arg = split('=', $_);
664        @arg[0] =~ tr/a-z/A-Z/;
665        my $len = @arg;
666        if ($len != 2)
667        {
668            die "Malformed property in $arg[0]";
669        }
670        if (@arg[0] eq "POSE_EXE")
671        {
672            $pose_exe=$arg[1];
673        }
674        elsif (@arg[0] eq "POSE_PRC")
675        {
676            $pose_prc=$arg[1];
677        }
678        elsif (@arg[0] eq "PDB_ORIG")
679        {
680            $pdb_orig_dir=$arg[1];
681            $pdb_orig=$arg[1];
682            $pdb_orig .= "/";
683            $pdb_orig .= "$lu_str";
684        }
685        elsif (@arg[0] eq "PDB_NEW")
686        {
687            $pdb_new_dir=$arg[1];
688            $pdb_new=$arg[1];
689            $pdb_new .= "/";
690            $pdb_new .= "$lu_str";
691        }
692        elsif (@arg[0] eq "XML_ORIG")
693        {
694            $xml_orig=$arg[1];
695        }
696        elsif (@arg[0] eq "XML_NEW")
697        {
698            $xml_new_dir=$arg[1];
699            $xml_new=$arg[1];
700            $xml_new .= "/";
701            $xml_new .= "$lu_str";
702        }
703
704    }
705    close PROPSFILE;
706}
707
708# verify_env_options
709#
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.
713#
714sub verify_env_options
715{
716    if (!-e "$pose_exe")
717    {
718        die "The pose executable cannot be found at $pose_exe.";
719    }
720    if (!-x $pose_exe)
721    {
722        die "$pose_exe exists but is not executable.";
723    }
724
725    if (!-e "$pose_prc")
726    {
727        die "The PRC directory specified as $pose_prc does not exist.";
728    }
729    if (!-d "$pose_prc")
730    {
731        die "The PRC location specified as $pose_prc exists, but is not a directory.";
732    }
733
734    if (!-e "$pdb_orig_dir")
735    {
736        die "The original PDB directory specified as $pdb_orig_dir does not exist.";
737    }
738    if (!-d "$pdb_orig_dir")
739    {
740        die "The original PDB directory specified as $pdb_orig_dir exists but is not a directory.";
741    }
742
743    if (!-e "$pdb_new_dir")
744    {
745        die "The new PDB directory specified as $pdb_new_dir does not exist.";
746    }
747    if (!-d "$pdb_new_dir")
748    {
749        die "The new PDB directory specified as $pdb_new_dir exists but is not a directory.";
750    }
751
752    if (!-e "$xml_orig")
753    {
754        die "The original Office document directory specified as $xml_orig does not exist.";
755    }
756    if (!-d "$xml_orig")
757    {
758        die "The original Office document location specified as $xml_orig exists but is not a directory.";
759    }
760
761    if (!-e "$xml_new_dir")
762    {
763        die "The new Office document directory specified as $xml_new_dir does not exist.";
764    }
765    if (!-d "$xml_new_dir")
766    {
767        die "The new Office document location specified as $xml_new_dir exists but is not a directory.";
768    }
769}
770
771# verify_prcs_exist
772# prcfile - the PRC file to check
773#
774# Verifies that the specified PRC file exists.
775#
776sub verify_prcs_exist
777{
778    my $prcfile = $_[0];
779
780    if (!-e "$pose_prc/$prcfile")
781    {
782        die "The pose PRC directory ($pose_prc) is correct, but I can't find $prcfile there.";
783    }
784}
785
786