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.6 by williamc, Fri Dec 17 10:10:36 1999 UTC vs.
Revision 1.11 by williamc, Mon Sep 11 11:31:49 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 + # testswitch(bool,"true text","falsetext") : testpass or fail according to bool
16   # testfail(string) : report that current test has failed
17   # testpass(string) : report that current test has passed
18   # newfilename() : return a new filename that can be opened etc.
# Line 20 | Line 22
22   # expect(string) : tell the testinterface of any expected return values
23   # clearexpect()  : Reset any expect variables.
24   #cleantemp()    : delete the temporary area
25 + # cmparray(arrayref, @reqvals) : test the arrayref against expected
26 + # cmpstring(expectedstring,actualstring) :
27  
28 < package TestClass;
28 > package Utilities::TestClass;
29   require 5.004;
30   $bold  = "\033[1m";
31   $normal = "\033[0m";
# Line 55 | Line 59 | sub new {
59          $self->{class}=$module;
60          $self->{"datadir"}=$datadir;
61          $self->{filenumber}=0;
62 +        rmtree("/tmp/SCRAMtest++");
63          $self->{temparea}="/tmp/SCRAMtest++";
64          use File::Path;
65          mkpath ($self->{temparea},0, 0777);
# Line 64 | Line 69 | sub new {
69          die $@ if $@;
70          $self->{testobj}=$module->_new($self, $fullmodule);
71  
72 +        # make sure the temparea is cleaned
73 +        use File::Path;
74 +
75          return $self;
76   }
77  
# Line 76 | Line 84 | sub dotest {
84          $self->{testobj}->checktests();
85   }
86  
87 + sub cmparray {
88 +        my $self=shift;
89 +        my $array=shift;
90 +        my @vals=@_;
91 +
92 +        if ( $#{$array} ne $#vals) { $self->testfail(
93 +                 $#{$array}." items retuned, $#vals expected");
94 +        }
95 +        else {
96 +        for( my $i=0; $i<= $#{$array}; $i++) {
97 +           $self->cmpstring($vals[$i],$$array[$i]);
98 +        }
99 +        }
100 + }
101 +
102 +
103 + sub cmpstring {
104 +        my $self=shift;
105 +        my $s1=shift;
106 +        my $s2=shift;
107  
108 +        if ( ! defined $s2) {
109 +          $self->testfail("Return string is undefined expecting $s1"),
110 +        }
111 +        elsif ( $s1 ne $s2 ) {
112 +          $self->testfail("Expecting $s1 got $s2");
113 +        }
114 +        else {
115 +          $self->testpass("Got $s2 as expected");
116 +        }
117 + }
118          
119   # A virtual method to be overridden
120   sub init {
# Line 149 | Line 187 | sub verifyexists {
187          }
188   }
189  
190 + sub testswitch {
191 +        my $self=shift;
192 +        my $bool=shift;
193 +        my $string1=shift;
194 +        my $string2=shift;
195 +
196 +        if ( $bool ) {
197 +           $self->testpass($string1);
198 +        }
199 +        else {
200 +           $self->testfail($string2);
201 +        }
202 + }
203 +
204   sub testfail {
205          my $self=shift;
206          my $string=shift;
# Line 240 | Line 292 | sub testinterface {
292          $self->_testout( " (".$args.")" );
293          $num=0;
294          if ( exists $self->{expect} ) {
295 +         print "Testing Expected Values against actual returns ....\n";
296           @mylist=eval { $self->{object}->$subname(@_); };
297            die "Test Failed $@\n" if $@;
298 +         my $nrv=$#mylist+1; my $nrve=$#{$self->{expect}}+1;
299 +         print $nrv." values returned ".$nrve." expected\n";
300 +         if ( $nrv != $nrve ) {
301 +          $self->testfail("Number of returned values != that expected");
302 +         }
303           if ( defined @mylist ) {
304           # size check
305 <         if ( $#mylist < $#{$self->{expect}} ) {
306 <                $self->testfail("not enough returned values");
305 >         if ( $#mylist != $#{$self->{expect}} ) {
306 >                $self->testfail("Number of returned values inconsistent");
307           }
308           foreach $myreturn ( @mylist ) {
309            if ( ! defined $myreturn ) {
310                  print "Undefined Value Passed Back\n";
311            }
312            elsif ( $myreturn=~/HASH/ ) {
313 <             print "Hash Ref returned\n";
313 >             print "Hash Ref ".ref($myreturn)." returned\n";
314            }
315            elsif ( $myreturn=~/CODE/ ) {
316               print "Code Ref returned\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines