5 $url1 = new URI::URL 'http://www/foo/test.gif?search+x#frag';
6 $url2 = new URI::URL 'http:test';
8 my $pwd if $^O eq "MacOS";
10 unless ($^O eq "MacOS") {
11 $file = "/etc/passwd";
12 -r $file or $file = "./README";
18 my $dir = Mac::Files::FindFolder(Mac::Files::kOnSystemDisk(),
19 Mac::Files::kDesktopFolderType());
22 open(README,">$file") or die "Unable to open $file";
23 print README "This is a dummy file for LWP testing purposes\n";
25 open(README,">/dev/null") or die "Unable to open /dev/null";
26 print README "This is a dummy file for LWP testing purposes\n";
32 ["/this.dir/file.html" => "text/html",],
33 ["test.gif.htm" => "text/html",],
34 ["test.txt.gz" => "text/plain", "gzip"],
35 ["gif.foo" => "application/octet-stream",],
36 ["lwp-0.03.tar.Z" => "application/x-tar", "compress"],
37 [$file => "text/plain",],
38 ["/random/file" => "application/octet-stream",],
39 [($^O eq 'VMS'? "nl:" : "/dev/null") => "text/plain",],
40 [$url1 => "image/gif",],
41 [$url2 => "application/octet-stream",],
42 ["x.ppm.Z.UU" => "image/x-portable-pixmap","compress","x-uuencode",],
45 $notests = @tests + 3;
46 print "1..$notests\n";
48 if ($ENV{HOME} and -f "$ENV{HOME}/.mime.types") {
50 The MediaTypes test might fail because you have a private ~/.mime.types file
51 If you get a failed test, try to move it away while testing.
58 ($file, $expectedtype, @expectedEnc) = @$_;
59 $type1 = guess_media_type($file);
60 ($type, @enc) = guess_media_type($file);
61 if ($type1 ne $type) {
62 print "guess_media_type does not return same content-type in scalar and array conext.\n";
65 $type = "undef" unless defined $type;
66 if ($type eq $expectedtype and "@enc" eq "@expectedEnc") {
70 print "expected '$expectedtype' for '$file', got '$type'\n";
71 print "encoding: expected: '@expectedEnc', got '@enc'\n"
72 if @expectedEnc || @enc;
73 print "nok ok $testno\n";
78 @imgSuffix = media_suffix('image/*');
79 print "Image suffixes: @imgSuffix\n";
82 require HTTP::Response;
83 $r = new HTTP::Response 200, "Document follows";
84 $r->title("file.tar.gz.uu");
85 guess_media_type($r->title, $r);
88 print "not " unless $r->content_type eq "application/x-tar";
89 print "ok $testno\n"; $testno++;
91 @enc = $r->header("Content-Encoding");
92 print "not " unless "@enc" eq "gzip x-uuencode";
93 print "ok $testno\n"; $testno++;
96 use LWP::MediaTypes qw(add_type add_encoding);
97 add_type("x-world/x-vrml", qw(wrl vrml));
98 add_encoding("x-gzip" => "gz");
99 add_encoding(rot13 => "r13");
101 @x = guess_media_type("foo.vrml.r13.gz");
103 print "not " unless "@x" eq "x-world/x-vrml rot13 x-gzip";
104 print "ok $testno\n"; $testno++;
106 #print LWP::MediaTypes::_dump();