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.10 by williamc, Mon Aug 28 08:35:16 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
# Line 20 | Line 21
21   # expect(string) : tell the testinterface of any expected return values
22   # clearexpect()  : Reset any expect variables.
23   #cleantemp()    : delete the temporary area
24 + # cmparray(arrayref, @reqvals) : test the arrayref against expected
25 + # cmpstring(expectedstring,actualstring) :
26  
27 < package TestClass;
27 > package Utilities::TestClass;
28   require 5.004;
29   $bold  = "\033[1m";
30   $normal = "\033[0m";
# Line 55 | Line 58 | sub new {
58          $self->{class}=$module;
59          $self->{"datadir"}=$datadir;
60          $self->{filenumber}=0;
61 +        rmtree("/tmp/SCRAMtest++");
62          $self->{temparea}="/tmp/SCRAMtest++";
63          use File::Path;
64          mkpath ($self->{temparea},0, 0777);
# Line 64 | Line 68 | sub new {
68          die $@ if $@;
69          $self->{testobj}=$module->_new($self, $fullmodule);
70  
71 +        # make sure the temparea is cleaned
72 +        use File::Path;
73 +
74          return $self;
75   }
76  
# Line 76 | Line 83 | sub dotest {
83          $self->{testobj}->checktests();
84   }
85  
86 + sub cmparray {
87 +        my $self=shift;
88 +        my $array=shift;
89 +        my @vals=@_;
90 +
91 +        if ( $#{$array} ne $#vals) { $self->testfail(
92 +                 $#{$array}." items retuned, $#vals expected");
93 +        }
94 +        else {
95 +        for( my $i=0; $i<= $#{$array}; $i++) {
96 +           $self->cmpstring($vals[$i],$$array[$i]);
97 +        }
98 +        }
99 + }
100 +
101 +
102 + sub cmpstring {
103 +        my $self=shift;
104 +        my $s1=shift;
105 +        my $s2=shift;
106  
107 +        if ( ! defined $s2) {
108 +          $self->testfail("Return string is undefined expecting $s1"),
109 +        }
110 +        elsif ( $s1 ne $s2 ) {
111 +          $self->testfail("Expecting $s1 got $s2");
112 +        }
113 +        else {
114 +          $self->testpass("Got $s2 as expected");
115 +        }
116 + }
117          
118   # A virtual method to be overridden
119   sub init {
# Line 240 | Line 277 | sub testinterface {
277          $self->_testout( " (".$args.")" );
278          $num=0;
279          if ( exists $self->{expect} ) {
280 +         print "Testing Expected Values against actual returns ....\n";
281           @mylist=eval { $self->{object}->$subname(@_); };
282            die "Test Failed $@\n" if $@;
283 +         my $nrv=$#mylist+1; my $nrve=$#{$self->{expect}}+1;
284 +         print $nrv." values returned ".$nrve." expected\n";
285 +         if ( $nrv != $nrve ) {
286 +          $self->testfail("Number of returned values != that expected");
287 +         }
288           if ( defined @mylist ) {
289           # size check
290 <         if ( $#mylist < $#{$self->{expect}} ) {
291 <                $self->testfail("not enough returned values");
290 >         if ( $#mylist != $#{$self->{expect}} ) {
291 >                $self->testfail("Number of returned values inconsistent");
292           }
293           foreach $myreturn ( @mylist ) {
294            if ( ! defined $myreturn ) {
295                  print "Undefined Value Passed Back\n";
296            }
297            elsif ( $myreturn=~/HASH/ ) {
298 <             print "Hash Ref returned\n";
298 >             print "Hash Ref ".ref($myreturn)." returned\n";
299            }
300            elsif ( $myreturn=~/CODE/ ) {
301               print "Code Ref returned\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines