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