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.9.2.2.6.1 by williamc, Thu Nov 2 15:53:57 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(int,"0 text"," non 0 text") : 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 +          if ( ( ! defined $s1 ) || ( $s1==undef )) {
110 +            $self->testpass("Got undefined as expected");
111 +          }
112 +          else {
113 +            $self->testfail("Return string is undefined expecting $s1"),
114 +          }
115 +        }
116 +        elsif ( $s1 ne $s2 ) {
117 +          $self->testfail("Expecting $s1 got $s2");
118 +        }
119 +        else {
120 +          $self->testpass("Got $s2 as expected");
121 +        }
122 + }
123          
124   # A virtual method to be overridden
125   sub init {
# Line 149 | Line 192 | sub verifyexists {
192          }
193   }
194  
195 + sub testswitch {
196 +        my $self=shift;
197 +        my $bool=shift;
198 +        my $string1=shift;
199 +        my $string2=shift;
200 +
201 +        if ( ! $bool ) {
202 +           $self->testpass($string1);
203 +        }
204 +        else {
205 +           $self->testfail($string2);
206 +        }
207 + }
208 +
209   sub testfail {
210          my $self=shift;
211          my $string=shift;
# Line 240 | Line 297 | sub testinterface {
297          $self->_testout( " (".$args.")" );
298          $num=0;
299          if ( exists $self->{expect} ) {
300 +         print "Testing Expected Values against actual returns ....\n";
301           @mylist=eval { $self->{object}->$subname(@_); };
302            die "Test Failed $@\n" if $@;
303 +         my $nrv=$#mylist+1; my $nrve=$#{$self->{expect}}+1;
304 +         print $nrv." values returned ".$nrve." expected\n";
305 +         if ( $nrv != $nrve ) {
306 +          $self->testfail("Number of returned values != that expected");
307 +         }
308           if ( defined @mylist ) {
309           # size check
310 <         if ( $#mylist < $#{$self->{expect}} ) {
311 <                $self->testfail("not enough returned values");
310 >         if ( $#mylist != $#{$self->{expect}} ) {
311 >                $self->testfail("Number of returned values inconsistent");
312           }
313           foreach $myreturn ( @mylist ) {
314            if ( ! defined $myreturn ) {
315                  print "Undefined Value Passed Back\n";
316            }
317            elsif ( $myreturn=~/HASH/ ) {
318 <             print "Hash Ref returned\n";
318 >             print "Hash Ref ".ref($myreturn)." returned\n";
319            }
320            elsif ( $myreturn=~/CODE/ ) {
321               print "Code Ref returned\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines