ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/URL/test/test_URLhandler.pm
Revision: 1.4
Committed: Thu Nov 4 13:51:25 1999 UTC (25 years, 6 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.3: +30 -5 lines
Log Message:
updates

File Contents

# User Rev Content
1 williamc 1.1 #
2     # urlhandler test suite
3     #
4    
5 williamc 1.4 package URL::test::test_URLhandler;
6 williamc 1.1 require 5.001;
7     use URL::URLhandler;
8     @ISA = ("TestClass"); #methods both from the test class
9    
10     sub init {
11     my $self=shift;
12     $self->{testfile}="urlfile++";
13 williamc 1.4 $self->{cache}=URL::URLcache->new($self->temparea()."/handlercache");
14 williamc 1.1 }
15    
16     sub test {
17 williamc 1.4 use URL::URLUtilities;
18 williamc 1.1 my $self=shift;
19    
20     # test 1
21 williamc 1.4 $self->newtest("Initiating URL");
22     $self->newobject($self->{cache});
23    
24     $self->newtest("Testing URL parser mechanism");
25     my $origurl="file:dir1/dir2/dir3/dir++/file?hello=++1";
26     my ($type,$rest,$cmdstring)=URLUtilities::parseURL($origurl);
27     (($type eq "file")?$self->testpass("type=".$type)
28     :$self->testfail("type=".$type));
29     (($cmdstring eq "hello=++1")?$self->testpass("cmdstring=".$cmdstring)
30     :$self->testfail("cmdstring=".$cmdstring));
31     ($handler,$base)=$self->testinterface("_typecheck", $type);
32     (($base eq "")?
33     $self->testpass("base=".$base):$self->testfail("base=".$base));
34     $urlst=$self->testinterface("_urlexpand", $origurl);
35     (($urlst eq "file:dir1/dir2/dir3/dir++/file?hello=++1")?
36     $self->testpass("urlst=".$urlst):$self->testfail("urlst=".$urlst));
37    
38 williamc 1.1 $self->newtest("Testing default cacheing mechanism with cvs test");
39     $self->test_cvs();
40     # test 2
41     $self->newtest("Testing file url mechanism");
42     $self->test_file();
43     }
44    
45     sub test_cvs {
46     my $self=shift;
47    
48     # now set a cvs base - for a pserver
49     $hashvars={
50     "base" => "cmscvs.cern.ch:/cvs_server/repositories/SCRAM" ,
51     "auth" => "pserver",
52     "user" => "anonymous",
53     "passkey" => "AA_:yZZ3e"
54     };
55     $self->testinterface("setbase", "cvs" , $hashvars );
56    
57     # now test the url mechanism
58     $self->testinterface("get", "cvs:test");
59 williamc 1.4 $self->newtest("cvs url expansion test");
60     $expectedurl="cvs:".$$hashvars{'base'}."/test";
61     ($fullurl,@junk)=$self->{object}->_urlexpand("cvs:test");
62     (($fullurl eq $expectedurl)?$self->testpass("url base expansion OK"):
63     $self->testfail("url base expansion failed \ngot $fullurl".
64     "\nexpected $expectedurl"));
65     $self->newtest("cvs checkout area test");
66     $self->verifydir($self->{cache}->file($expectedurl));
67     $self->verifydir($self->{cache}->file($expectedurl)."/CVS");
68 williamc 1.1 #clean up
69     use File::Path;
70 williamc 1.4 rmtree($self->{cache}->file($expectedurl)) or die "$!";
71 williamc 1.1 $self->testinterface("unsetbase","cvs");
72     return;
73     }
74    
75     sub test_file {
76     my $self=shift;
77     my $varhash;
78     my $varhash2;
79     my $base="$ENV{SCRAM_HOME}/src";
80     $varhash = {
81     "base" => "$base"
82     };
83     $varhash2 = {
84     "base" => "$ENV{SCRAM_HOME}/"
85     };
86     # now set a file base
87     $self->newtest("File base test");
88     $self->testinterface("setbase","file", $varhash );
89     $self->_getmethodtest("file:URL/test/testdata/".
90     $self->{testfile});
91     # different base
92     $self->newtest("Multiple file base test");
93     $self->testinterface("setbase","file", $varhash2 );
94     $self->_getmethodtest("file:src/URL/test/testdata/".
95     $self->{testfile});
96     # get rid of the last base and try again
97     $self->newtest("base restoration test");
98     $self->testinterface("unsetbase","file");
99     $self->_getmethodtest("file:URL/test/testdata/".
100     $self->{testfile});
101     # get rid of all bases and try a full path
102     $self->newtest("No Bases test");
103     $self->testinterface("unsetbase","file");
104     $self->_getmethodtest("file:$base/Utilities/test/testdata/".
105     $self->{testfile});
106     }
107    
108     # ------------ Supporting Routines -----------------------------
109    
110     sub _getmethodtest {
111     my $self=shift;
112     my $url=shift;
113 williamc 1.3 my $filename="$self->{object}->{cache}/urlfile++";
114 williamc 1.1 my $file;
115    
116 williamc 1.2 $self->testinterface("get", "$url" );
117 williamc 1.3 $self->verify("$filename",
118 williamc 1.1 $self->datadir()."/$self->{testfile}");
119     unlink $filename;
120     }
121