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.1 by williamc, Tue Apr 11 08:57:03 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 21 | Line 22
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 55 | Line 56 | sub new {
56          $self->{class}=$module;
57          $self->{"datadir"}=$datadir;
58          $self->{filenumber}=0;
59 +        rmtree("/tmp/SCRAMtest++");
60          $self->{temparea}="/tmp/SCRAMtest++";
61          use File::Path;
62          mkpath ($self->{temparea},0, 0777);
# Line 64 | 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 77 | 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 240 | 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("not enough returned values");
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 Ref returned\n";
281 >             print "Hash Ref ".ref($myreturn)." returned\n";
282            }
283            elsif ( $myreturn=~/CODE/ ) {
284               print "Code Ref returned\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines