ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/TestClass.pm
(Generate patch)

Comparing COMP/SCRAM/src/Utilities/TestClass.pm (file contents):
Revision 1.4 by williamc, Wed Sep 1 09:15:58 1999 UTC vs.
Revision 1.9 by williamc, Thu Mar 2 16:40:24 2000 UTC

# Line 6 | Line 6
6   # new($module,testdatadir) : module example - Utilities/urlhandler
7   # dotest(@args) : Start testing - arguments dependent on inheriting class
8   #
9 + # cmpstring(expectedstring,returnedstring) : cmp a string and fail if not equal
10   # newtest() : Initiate a testing sequence
11   # verify(actual_result_file, expected_result_file) : compare two files
12   # verifydir(dir) : Check existence of the directory
13 + # verifyexists(file) : Verify the existence of file
14   # datadir([dir]) : return the current data directory (set it to dir if supplied)
15 < # ------------------- Private Methods ----------------------------------
15 > # testfail(string) : report that current test has failed
16 > # testpass(string) : report that current test has passed
17   # newfilename() : return a new filename that can be opened etc.
18   # temparea() : return a directory for building temporary stuff
19   # newobject(@args) : Set up a new object to be tested
20   # testinterface($name,@args) : perform interface tests for $name with @args
21   # expect(string) : tell the testinterface of any expected return values
22   # clearexpect()  : Reset any expect variables.
23 + #cleantemp()    : delete the temporary area
24  
25 < package TestClass;
25 > package Utilities::TestClass;
26   require 5.004;
27   $bold  = "\033[1m";
28   $normal = "\033[0m";
# Line 52 | Line 56 | sub new {
56          $self->{class}=$module;
57          $self->{"datadir"}=$datadir;
58          $self->{filenumber}=0;
59 <        $self->{temparea}="/tmp/SCRAMtest";
59 >        rmtree("/tmp/SCRAMtest++");
60 >        $self->{temparea}="/tmp/SCRAMtest++";
61          use File::Path;
62          mkpath ($self->{temparea},0, 0777);
63  
# Line 61 | Line 66 | sub new {
66          die $@ if $@;
67          $self->{testobj}=$module->_new($self, $fullmodule);
68  
69 +        # make sure the temparea is cleaned
70 +        use File::Path;
71 +
72          return $self;
73   }
74  
# Line 74 | Line 82 | sub dotest {
82   }
83  
84  
85 + sub cmpstring {
86 +        my $self=shift;
87 +        my $s1=shift;
88 +        my $s2=shift;
89 +
90 +        if ( ! defined $s2) {
91 +          $self->testfail("Return string is undefined expecting $s1"),
92 +        }
93 +        elsif ( $s1 ne $s2 ) {
94 +          $self->testfail("Expecting $s1 got $s2");
95 +        }
96 +        else {
97 +          $self->testpass("Got $s2 as expected");
98 +        }
99 + }
100          
101   # A virtual method to be overridden
102   sub init {
# Line 108 | Line 131 | sub verify {
131          open ( FILE1, "<$file1" ) or die "Cannot Read Test Output $file1 $!\n";
132          open ( FILE2, "<$file2" ) or die "Cannot Read Benchmark file ".
133                                                          "$file2 $!\n";
134 <        while ( $f1=<FILE1> ) {
135 <         $f2=<FILE2>;
136 <         if ( $f2 ne $f1 ) {
137 <           print "T:\n$f1\nB:$f2\n";
134 >        while ( $f1=<FILE2> ) {
135 >         $f2=<FILE1>;
136 >         if ( (!defined $f2 ) || ( ! defined $f1) || ($f2 ne $f1 )) {
137 >           #print "T:\n$f1\nB:$f2\n";
138             $same=0;
139           }
140          }
# Line 127 | Line 150 | sub verifydir {
150          my $name=shift;
151  
152          if ( -d "$name" ) {
153 <           $self->testpass("");
153 >           $self->testpass("Directory $name exists - test passed");
154          }
155          else {
156             $self->testfail("Directory $name does not exist");
157          }
158   }
159  
160 + sub verifyexists {
161 +        my $self=shift;
162 +        my $name=shift;
163 +
164 +        if ( -e "$name" ) {
165 +           $self->testpass("$name exists - test passed");
166 +        }
167 +        else {
168 +           $self->testfail("$name does not exist");
169 +        }
170 + }
171 +
172   sub testfail {
173          my $self=shift;
174          my $string=shift;
# Line 225 | Line 260 | sub testinterface {
260          $self->_testout( " (".$args.")" );
261          $num=0;
262          if ( exists $self->{expect} ) {
263 +         print "Testing Expected Values against actual returns ....\n";
264           @mylist=eval { $self->{object}->$subname(@_); };
265            die "Test Failed $@\n" if $@;
266 +         my $nrv=$#mylist+1; my $nrve=$#{$self->{expect}}+1;
267 +         print $nrv." values returned ".$nrve." expected\n";
268 +         if ( $nrv != $nrve ) {
269 +          $self->testfail("Number of returned values != that expected");
270 +         }
271           if ( defined @mylist ) {
272 +         # size check
273 +         if ( $#mylist != $#{$self->{expect}} ) {
274 +                $self->testfail("Number of returned values inconsistent");
275 +         }
276           foreach $myreturn ( @mylist ) {
277            if ( ! defined $myreturn ) {
278                  print "Undefined Value Passed Back\n";
279            }
280 <          elsif ( \$myreturn=~/HASH/ ) {
281 <             print "Hash Refreturned\n";
280 >          elsif ( $myreturn=~/HASH/ ) {
281 >             print "Hash Ref ".ref($myreturn)." returned\n";
282            }
283 <          elsif ( \$myreturn=~/CODE/ ) {
283 >          elsif ( $myreturn=~/CODE/ ) {
284               print "Code Ref returned\n";
285            }
286 <          elsif ( \$myreturn=~/ARRAY/ ) {
286 >          elsif ( $myreturn=~/ARRAY/ ) {
287              print "Array Ref returned\n";
288            }
289            else {
# Line 265 | Line 310 | sub testinterface {
310   #
311   sub expect {
312          my $self=shift;
268        my $string=shift;
313  
314 <        push @{$self->{expect}}, $string;
314 >        push @{$self->{expect}}, @_;
315   }
316  
317   sub clearexpect {
# Line 365 | Line 409 | sub analyseInterface {
409          }
410          close SRCIN;
411   }
412 +
413 + sub cleantemp {
414 +        my $self=shift;
415 +        use File::Path;
416 +        rmtree($self->temparea());
417 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines