tests/libjava-mauve/src/gnu/testlet/java/net/URL/URLTest.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.0
       
     2 // Uses: MyURLStreamHandler
       
     3 
       
     4 /*
       
     5    Copyright (C) 1999 Hewlett-Packard Company
       
     6 
       
     7    This file is part of Mauve.
       
     8 
       
     9    Mauve is free software; you can redistribute it and/or modify
       
    10    it under the terms of the GNU General Public License as published by
       
    11    the Free Software Foundation; either version 2, or (at your option)
       
    12    any later version.
       
    13 
       
    14    Mauve is distributed in the hope that it will be useful,
       
    15    but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    17    GNU General Public License for more details.
       
    18 
       
    19    You should have received a copy of the GNU General Public License
       
    20    along with Mauve; see the file COPYING.  If not, write to
       
    21    the Free Software Foundation, 59 Temple Place - Suite 330,
       
    22    Boston, MA 02111-1307, USA.
       
    23 */
       
    24 
       
    25 package gnu.testlet.java.net.URL;
       
    26 import gnu.testlet.Testlet;
       
    27 import gnu.testlet.TestHarness;
       
    28 
       
    29 import java.io.IOException;
       
    30 import java.net.*;
       
    31 
       
    32 
       
    33 public class URLTest implements Testlet
       
    34 {
       
    35   protected static TestHarness harness;
       
    36 	public void test_Basics()
       
    37 	{
       
    38 		boolean ok;
       
    39 		
       
    40 		// see whether malformed exception is thrown or not.
       
    41 
       
    42 		harness.checkPoint("Constructors");
       
    43 
       
    44 		ok = false;
       
    45 		try {
       
    46 			URL url = new URL("hithleksjf" );
       
    47 		}
       
    48 		catch ( MalformedURLException e ){
       
    49 			ok = true;
       
    50 			harness.check(true);
       
    51 		}
       
    52 		harness.check(ok, "Error in test_Basics - 1 " + 
       
    53 			" should have raised malformed URL exception here");
       
    54 
       
    55 		ok = false;
       
    56 		try {
       
    57 			URL url = new URL("http://////://" );
       
    58 			ok = true;
       
    59 		}
       
    60 		catch ( MalformedURLException e ){
       
    61 		}
       
    62 		harness.check(ok, "Error in test_Basics  - 2 " + 
       
    63 			" should not have raised malformed URL exception here");
       
    64 
       
    65 
       
    66 		ok = false;
       
    67 		try {
       
    68 			URL url = new URL("http://sources.redhat.com/index.html" );
       
    69 			ok = true;
       
    70 		}
       
    71 		catch ( MalformedURLException e ){
       
    72 		}
       
    73 		harness.check(ok, "Error in test_Basics  - 3 " +
       
    74 			" should not have raised malformed URL exception here");
       
    75 
       
    76 		ok = false;
       
    77 		try {
       
    78 			URL url = new URL((String) null);
       
    79 		}
       
    80 		catch (MalformedURLException e) {
       
    81 			ok = true;
       
    82 		}
       
    83 		harness.check(ok, "Error in test_Basics  - 4 " +
       
    84 			" should have raised malformed URL exception here");
       
    85 
       
    86 		// URL with individual arguments.
       
    87 		harness.checkPoint("get Methods");
       
    88 		try {
       
    89 			URL baseurl = new URL("http://sources.redhat.com/");
       
    90 			URL url = new URL ( baseurl, "index.html");
       
    91 			url.hashCode();
       
    92 			baseurl.hashCode();
       
    93 			URL.setURLStreamHandlerFactory( null );
       
    94 			URL.setURLStreamHandlerFactory( null );
       
    95 			harness.check (url.getProtocol(), "http");
       
    96 			harness.check (url.getPort(), -1);
       
    97 			harness.check (url.getHost(), "sources.redhat.com");
       
    98 			harness.check (url.getFile(), "/index.html");
       
    99 			harness.check (url.equals(new URL("http://sources.redhat.com/index.html")));
       
   100 			harness.check (url.hashCode() != 0);
       
   101 		}
       
   102 		catch ( MalformedURLException e ){
       
   103 				harness.fail(" Error in test_Basics  - 9 " + 
       
   104 					" exception should not be thrown here");
       
   105 		}
       
   106 
       
   107 
       
   108 		try {
       
   109 			URL url = new URL ( "http", "sources.redhat.com", "/index.html");
       
   110 
       
   111 			harness.check (url.getProtocol(), "http");
       
   112 			harness.check (url.getPort(), -1);
       
   113 			harness.check (url.getHost(), "sources.redhat.com");
       
   114 			harness.check (url.getFile(), "/index.html");
       
   115 			harness.check (url.equals(new URL("http://sources.redhat.com/index.html")));
       
   116 
       
   117 			URL url1 = new URL ( "http", "sources.redhat.com", 80,  "/index.html");
       
   118 			harness.check (url1.getPort(), 80);
       
   119 			harness.check(url.equals(url1));
       
   120 			harness.check(url1.toExternalForm(),
       
   121 					"http://sources.redhat.com:80/index.html");
       
   122 		}
       
   123 		catch ( MalformedURLException e ){
       
   124 				harness.fail(" Error in test_Basics  - 16 " + 
       
   125 					" exception should not be thrown here");
       
   126 		}
       
   127 
       
   128 
       
   129 		try {
       
   130 			URL url = new URL ( "http://sources.redhat.com:80/mauve/testarea/index.html");
       
   131 
       
   132 			harness.check (url.getProtocol(), "http");
       
   133 			harness.check (url.getPort(), 80);
       
   134 			harness.check (url.getHost(), "sources.redhat.com");
       
   135 			harness.check (url.getFile(), "/mauve/testarea/index.html");
       
   136 		}
       
   137 		catch ( MalformedURLException e ){
       
   138 				harness.fail(" Error in test_Basics  - 21 " + 
       
   139 					" exception should not be thrown here");
       
   140 		}
       
   141 
       
   142                 try {
       
   143                         URL u1 = new URL("http://foo@some.nice.place/bar/");
       
   144                         URL u2 = new URL("http://some.nice.place/bar/");
       
   145                         URL u3 = new URL(u1, "more/path", null);
       
   146 
       
   147                         harness.check (u1.getUserInfo(), "foo");
       
   148                         harness.check (u2.getUserInfo(), null);
       
   149                         harness.check (u3.getUserInfo(), "foo");
       
   150                         harness.check (u3.getProtocol(), "http");
       
   151                         harness.check (u3.getHost(), "some.nice.place");
       
   152                 }
       
   153                 catch ( MalformedURLException e ){
       
   154 				harness.fail(" Error in test_Basics  - 27 " + 
       
   155                                              " exception should not be thrown here");
       
   156                 }
       
   157                 
       
   158 		try {
       
   159 			URL u1 = new URL("http://domain.com");
       
   160 			URL u2 = new URL(u1, "/redir?http://domain2.com/index.html");
       
   161 
       
   162 			harness.check (u2.getProtocol(), "http");
       
   163 			harness.check (u2.getHost(), "domain.com");
       
   164 			harness.check (u2.getPath(), "/redir");
       
   165 			harness.check (u2.getQuery(), "http://domain2.com/index.html");
       
   166                 }
       
   167                 catch ( MalformedURLException e ){
       
   168 				harness.fail(" Error in test_Basics  - 35 " + 
       
   169                                              " exception should not be thrown here");
       
   170                 }
       
   171 
       
   172 		harness.checkPoint("Null context handler");
       
   173 		try
       
   174 		{
       
   175 			URL u = new URL(null, "http://sources.redhat.com/");
       
   176 
       
   177 			harness.check(true);
       
   178 		}
       
   179                 catch ( MalformedURLException e ){
       
   180 			harness.fail(" Error in test_Basics - null context");
       
   181 		}
       
   182 		catch (NullPointerException e) {
       
   183 			harness.fail(" Error in test_Basics - null context");
       
   184 		}
       
   185                 harness.checkPoint("Colon in spec");
       
   186                 try {
       
   187                     URL cxt = new URL("http://www.foo.bar.com");
       
   188                     URL url = new URL(cxt, "_urn:testing/");
       
   189                     harness.check("http://www.foo.bar.com/_urn:testing/".equals(url.toString()));
       
   190                 }
       
   191                 catch (Exception e) {
       
   192                     harness.fail(" Error in test_Basics - Colon in spec");
       
   193                 }
       
   194 	}
       
   195 
       
   196 	public void test_openConnection()
       
   197 	{
       
   198 		harness.checkPoint("openConnection");
       
   199 		try {
       
   200 			URL url = new URL ( "http://sources.redhat.com/mauve/testarea/index.html");
       
   201 
       
   202 			URLConnection conn = url.openConnection();
       
   203 
       
   204 			if (conn == null) {
       
   205 				harness.fail("openConnection returned null");
       
   206 				return;
       
   207 			}
       
   208 
       
   209 			String headerField = conn.getHeaderField(2);
       
   210 			harness.check (headerField != null
       
   211 					&& headerField.indexOf("Apache") != -1,
       
   212 							"I want my Apache server!");
       
   213 			String conttype	= conn.getContentType();
       
   214 			harness.check (conttype != null
       
   215 					&& conttype.indexOf("text/html") != -1,
       
   216 							"Content must be text/html");
       
   217 
       
   218 			try {
       
   219 				Object obj = url.getContent();
       
   220 			} catch (Throwable t) {
       
   221 				harness.fail("getContent() threw Exception");
       
   222 				harness.debug(t);
       
   223 			}
       
   224 			harness.check (url.toExternalForm(),
       
   225 				"http://sources.redhat.com/mauve/testarea/index.html");
       
   226 			harness.check (url.getRef(), null);
       
   227 
       
   228 			URL url2 = new URL("http://www.hhp.com/index.html#help");
       
   229 			harness.check (url2.getRef(), "help");
       
   230 		}catch ( Exception e ){
       
   231 				harness.fail(" Error in test_openConnection  - 3 " + 
       
   232 					" exception should not be thrown here");
       
   233 				harness.debug(e);
       
   234 		}		
       
   235 
       
   236 	}
       
   237 
       
   238 
       
   239 
       
   240 	public void test_openStream()
       
   241 	{
       
   242 		harness.checkPoint("openStream");
       
   243 		try {
       
   244 			harness.debug("creating URL");
       
   245 			URL url = new URL ( "http://sources.redhat.com/mauve/testarea/index.html");
       
   246 			harness.debug("opening stream");
       
   247 			java.io.InputStream conn = url.openStream();
       
   248 
       
   249 			byte b [] = new byte[256];
       
   250 			harness.debug("reding from stream");
       
   251 			conn.read(b , 0 , 256 );
       
   252 
       
   253 			String str = new String( b ) ;
       
   254 			harness.check (str.indexOf("HTML") != -1,
       
   255 							"Need some HTML");
       
   256 
       
   257 		}catch ( Exception e ){
       
   258 			harness.fail(" Error in test_openStream  - 2 " + 
       
   259 					" exception should not be thrown here");
       
   260 			harness.debug(e);
       
   261 		}		
       
   262 
       
   263 	}
       
   264 
       
   265 
       
   266 	public void test_sameFile()
       
   267 	{
       
   268 		harness.checkPoint("sameFile");
       
   269 		try {
       
   270 			URL url = new URL ( "http://sources.redhat.com/mauve/testarea/index.html");
       
   271 			URL url1 = new URL ( "http://sources.redhat.com/mauve/testarea/index.html");
       
   272 			harness.check (url.sameFile(url1));
       
   273 
       
   274 			URL url2 = new URL ( "http://sources.redhat.com:80/mauve/testarea/index.html");
       
   275 			harness.check (url.sameFile(url2));
       
   276 
       
   277 		}catch ( Exception e ){
       
   278 			harness.fail(" Error in test_sameFile  - 3 " + 
       
   279 					" exception should not be thrown here");
       
   280 		}
       
   281 
       
   282 	}
       
   283 	
       
   284 
       
   285 	public void test_toString()
       
   286 	{
       
   287 		harness.checkPoint("toString");
       
   288 		try {
       
   289 			URL url = new URL ( "http://sources.redhat.com/index.html");
       
   290 			String str = url.toString();
       
   291 
       
   292 			URL url1 = new URL ( "http://sources.redhat.com:80/mauve/testarea/index.html");
       
   293 			String str1 = url1.toString();
       
   294 
       
   295 			URL url2 = new URL ( "http://205.180.83.71/");
       
   296 			String str2 = url2.toString();
       
   297 
       
   298 			harness.check (str, "http://sources.redhat.com/index.html");
       
   299 			harness.check (str1, "http://sources.redhat.com:80/mauve/testarea/index.html");
       
   300 			harness.check (str2, "http://205.180.83.71/");
       
   301 
       
   302 			URL url3 = new URL( "ftp" , "sources.redhat.com" , 21 , "/dir/dir1.lst");
       
   303 			String str3 = url3.toString( );
       
   304 
       
   305 			harness.check (str3, "ftp://sources.redhat.com:21/dir/dir1.lst");
       
   306 		}catch ( Exception e ){
       
   307 			harness.debug(e);
       
   308 			harness.fail(" Error in test_toString  - 5 " + 
       
   309 					" exception should not be thrown here");
       
   310 		}		
       
   311 	}
       
   312 
       
   313 	public void test_URLStreamHandler()
       
   314 	{
       
   315 		harness.checkPoint("URLStreamHandler");
       
   316 		try {
       
   317 		  URL url = new URL ( "http://sources.redhat.com/index.html");
       
   318 		// test URLStreamHandler
       
   319  		MyURLStreamHandler sh = new MyURLStreamHandler();
       
   320  		sh.invoke_setURL(url, "http", "sources.redhat.com", 80, "/index.html", "#ref");
       
   321 		harness.check(true);
       
   322  		sh.invoke_parseURL(url, "http://sources.redhat.com/index.html", 0, 20);
       
   323 		harness.check(true);
       
   324 		}catch ( MalformedURLException e ){
       
   325 			harness.fail(" Error in test_URLStreamHandler  - 1 " + 
       
   326 					" exception should not be thrown here");
       
   327 		}
       
   328 		
       
   329 		harness.checkPoint("inherit URLStreamHandler");
       
   330 		try {
       
   331 		    URL base = new URL("acme",
       
   332 				       "www.redhat.com",
       
   333 				       80,
       
   334 				       "/docs/",
       
   335 				       new MyURLStreamHandler());
       
   336 		    URL other = new URL(base, "manuals/enterprise/");
       
   337 		    harness.check(other.toString(),
       
   338 		    		"acme://www.redhat.com:80/docs/manuals/enterprise/");
       
   339 		} catch (IOException _) {
       
   340 			harness.check(false);
       
   341 			harness.debug(_);
       
   342 		}
       
   343 
       
   344 		harness.checkPoint("jar base with full http spec");
       
   345 		try {
       
   346 		    URL base = new URL("jar:file:///test.jar!/foo/bar.txt");
       
   347 		    URL other = new URL(base, "http://planet.classpath.org/");
       
   348 		    harness.check(other.toString(),
       
   349 		    		"http://planet.classpath.org/");
       
   350 		} catch (IOException _) {
       
   351 			harness.check(false);
       
   352 			harness.debug(_);
       
   353 		}
       
   354 	}
       
   355 
       
   356 
       
   357         public void test_cr601a() {
       
   358             String[][] s = {
       
   359 
       
   360                 // tests 0..3
       
   361                 {"file:////c:/pub/files/foobar.txt",
       
   362                  "file:////c:/pub/files/foobar.txt",
       
   363                  "",
       
   364                  "//c:/pub/files/foobar.txt"},
       
   365 
       
   366                 // tests 4..7
       
   367                 {"file:///c:/pub/files/foobar.txt",
       
   368                  "file:/c:/pub/files/foobar.txt",
       
   369                  "",
       
   370                  "/c:/pub/files/foobar.txt"},
       
   371 
       
   372                 // tests 8..11
       
   373                 {"file://hpjavaux/c:/pub/files/foobar.txt",
       
   374                  "file://hpjavaux/c:/pub/files/foobar.txt",
       
   375                  "hpjavaux",
       
   376                  "/c:/pub/files/foobar.txt"},
       
   377 
       
   378                 // tests 12..15
       
   379                 {"file://c:/pub/files/foobar.txt",
       
   380                  "file://c:/pub/files/foobar.txt",
       
   381                  "c",
       
   382                  "/pub/files/foobar.txt"},
       
   383 
       
   384                 // tests 16..19
       
   385                 {"file:/c:/pub/files/foobar.txt",
       
   386                  "file:/c:/pub/files/foobar.txt",
       
   387                  "",
       
   388                  "/c:/pub/files/foobar.txt"},
       
   389 
       
   390                 // tests 20..23
       
   391                 {"file:c:/pub/files/foobar.txt",
       
   392                  "file:c:/pub/files/foobar.txt",
       
   393                  "",
       
   394                  "c:/pub/files/foobar.txt"},
       
   395 
       
   396                 // tests 24..27
       
   397                 {"file:////hpjavant/bgee/foobar.txt",
       
   398                  "file:////hpjavant/bgee/foobar.txt",
       
   399                  "",
       
   400                  "//hpjavant/bgee/foobar.txt"},
       
   401 
       
   402                 // tests 28..31
       
   403                 {"file:///hpjavant/bgee/foobar.txt",
       
   404                  "file:/hpjavant/bgee/foobar.txt",
       
   405                  "",
       
   406                  "/hpjavant/bgee/foobar.txt"},
       
   407 
       
   408                 // tests 32..35
       
   409                 {"file://hpjavant/bgee/foobar.txt",
       
   410                  "file://hpjavant/bgee/foobar.txt",
       
   411                  "hpjavant",
       
   412                  "/bgee/foobar.txt"},
       
   413 
       
   414                 // tests 36..39
       
   415                 {"file:/hpjavant/bgee/foobar.txt",
       
   416                  "file:/hpjavant/bgee/foobar.txt",
       
   417                  "",
       
   418                  "/hpjavant/bgee/foobar.txt"},
       
   419 
       
   420                 // tests 40..43
       
   421                 {"file://hpjavaux//hpjavant/bgee/foobar.txt",
       
   422                  "file://hpjavaux//hpjavant/bgee/foobar.txt",
       
   423                  "hpjavaux",
       
   424                  "//hpjavant/bgee/foobar.txt"},
       
   425 
       
   426                 // tests 44..47
       
   427                 {"file://hpjavaux/bgee/foobar.txt",
       
   428                  "file://hpjavaux/bgee/foobar.txt",
       
   429                  "hpjavaux",
       
   430                  "/bgee/foobar.txt"},
       
   431 
       
   432                 // tests 48..51
       
   433                 {"file://hpjavaux/c:/pubs/files/foobar.txt",
       
   434                  "file://hpjavaux/c:/pubs/files/foobar.txt",
       
   435                  "hpjavaux",
       
   436                  "/c:/pubs/files/foobar.txt"},
       
   437 
       
   438                 // tests 52..55
       
   439                 {"file://bg710571//hpjavant/bgee/foobar.txt",
       
   440                  "file://bg710571//hpjavant/bgee/foobar.txt",
       
   441                  "bg710571",
       
   442                  "//hpjavant/bgee/foobar.txt"},
       
   443 
       
   444                 // tests 56..59
       
   445                 {"file://bg710571/bgee/foobar.txt",
       
   446                  "file://bg710571/bgee/foobar.txt",
       
   447                  "bg710571",
       
   448                  "/bgee/foobar.txt"},
       
   449 
       
   450                 // tests 60..63
       
   451                 {"file://bg710571/c:/pubs/files/foobar.txt",
       
   452                  "file://bg710571/c:/pubs/files/foobar.txt",
       
   453                  "bg710571",
       
   454                  "/c:/pubs/files/foobar.txt"},
       
   455             };
       
   456 
       
   457             harness.checkPoint("new URL(string)");
       
   458             for (int i = 0; i < s.length; ++i) {
       
   459                try {
       
   460                     URL url = new URL(s[i][0]);
       
   461                     harness.check(url.toExternalForm(), s[i][1]);
       
   462                     harness.check(url.getHost(), s[i][2]);
       
   463                     harness.check(url.getFile(), s[i][3]);
       
   464                 }
       
   465                 catch (Throwable e) {
       
   466                     harness.fail("Should not have thrown exception");
       
   467 		    e.printStackTrace(System.out);
       
   468                 }
       
   469             }
       
   470         }
       
   471 
       
   472         public void test_cr601b() {
       
   473             String[][] s = {
       
   474 
       
   475                 // tests 0..3
       
   476                 {"////", "c:/pub/files/foobar.txt",
       
   477                  "file://////c:/pub/files/foobar.txt",
       
   478                  "////",
       
   479                  "c:/pub/files/foobar.txt"},
       
   480 
       
   481                  // tests 4..7
       
   482                 {"///", "c:/pub/files/foobar.txt",
       
   483                  "file://///c:/pub/files/foobar.txt",
       
   484                  "///",
       
   485                  "c:/pub/files/foobar.txt"},
       
   486 
       
   487                  // tests 8..11
       
   488                 {"//", "c:/pub/files/foobar.txt",
       
   489                  "file:////c:/pub/files/foobar.txt",
       
   490                  "//",
       
   491                  "c:/pub/files/foobar.txt"},
       
   492 
       
   493                  // tests 12..15
       
   494                 {"/", "c:/pub/files/foobar.txt",
       
   495                  "file:///c:/pub/files/foobar.txt",
       
   496                  "/",
       
   497                  "c:/pub/files/foobar.txt"},
       
   498 
       
   499                  // tests 16..19
       
   500                 {"", "c:/pub/files/foobar.txt",
       
   501                  "file:c:/pub/files/foobar.txt",
       
   502                  "",
       
   503                  "c:/pub/files/foobar.txt"},
       
   504 
       
   505                  // tests 20..23
       
   506                 {"hpjavaux", "c:/pub/files/foobar.txt",
       
   507                  "file://hpjavauxc:/pub/files/foobar.txt",
       
   508                  "hpjavaux",
       
   509                  "c:/pub/files/foobar.txt"},
       
   510 
       
   511                  // tests 24..27
       
   512                 {null, "c:/pub/files/foobar.txt",
       
   513                  "file:c:/pub/files/foobar.txt",
       
   514                  null,
       
   515                  "c:/pub/files/foobar.txt"},
       
   516 
       
   517                  // tests 28..31
       
   518                 {"////", "//hpjavant/bgee/foobar.txt",
       
   519                  "file:////////hpjavant/bgee/foobar.txt",
       
   520                  "////",
       
   521                  "//hpjavant/bgee/foobar.txt"},
       
   522 
       
   523                  // tests 32..35
       
   524                 {"///", "//hpjavant/bgee/foobar.txt",
       
   525                  "file:///////hpjavant/bgee/foobar.txt",
       
   526                  "///",
       
   527                  "//hpjavant/bgee/foobar.txt"},
       
   528 
       
   529                  // tests 36..39
       
   530                 {"//", "//hpjavant/bgee/foobar.txt",
       
   531                  "file://////hpjavant/bgee/foobar.txt",
       
   532                  "//",
       
   533                  "//hpjavant/bgee/foobar.txt"},
       
   534 
       
   535                  // tests 40..43
       
   536                 {"/", "//hpjavant/bgee/foobar.txt",
       
   537                  "file://///hpjavant/bgee/foobar.txt",
       
   538                  "/",
       
   539                  "//hpjavant/bgee/foobar.txt"},
       
   540 
       
   541                  // tests 44..47
       
   542                 {"", "//hpjavant/bgee/foobar.txt",
       
   543                  "file:////hpjavant/bgee/foobar.txt",
       
   544                  "",
       
   545                  "//hpjavant/bgee/foobar.txt"},
       
   546 
       
   547                  // tests 48..51
       
   548                 {"hpjavaux", "//hpjavant/bgee/foobar.txt",
       
   549                  "file://hpjavaux//hpjavant/bgee/foobar.txt",
       
   550                  "hpjavaux",
       
   551                  "//hpjavant/bgee/foobar.txt"},
       
   552 
       
   553                  // tests 52..55
       
   554                 {null, "//hpjavant/bgee/foobar.txt",
       
   555                  "file:////hpjavant/bgee/foobar.txt",
       
   556                  null,
       
   557                  "//hpjavant/bgee/foobar.txt"},
       
   558 
       
   559                  // tests 56..59
       
   560                 {"hpjavant", "/bgee/foobar.txt",
       
   561                  "file://hpjavant/bgee/foobar.txt",
       
   562                  "hpjavant",
       
   563                  "/bgee/foobar.txt"},
       
   564 
       
   565                  // tests 60..63
       
   566                 {"hpjavant", "/home/bgee/foobar.txt",
       
   567                  "file://hpjavant/home/bgee/foobar.txt",
       
   568                  "hpjavant",
       
   569                  "/home/bgee/foobar.txt"},
       
   570 
       
   571                  // tests 64..67
       
   572                 {"hpjavaux", "/home/bgee/foobar.txt",
       
   573                  "file://hpjavaux/home/bgee/foobar.txt",
       
   574                  "hpjavaux",
       
   575                  "/home/bgee/foobar.txt"},
       
   576 		
       
   577 		 // 68..71
       
   578 		{"hpjavaux", "c:\\foobar.txt",
       
   579 		 "file://hpjavauxc:\\foobar.txt",
       
   580 		 "hpjavaux",
       
   581 		 "c:\\foobar.txt"},
       
   582 	    };
       
   583             harness.checkPoint("new URL(protocol, host, file)");
       
   584             for (int i = 0; i < s.length; ++i) {
       
   585                try {
       
   586                     URL url = new URL("file", s[i][0], s[i][1]);
       
   587                     harness.check(url.toExternalForm(), s[i][2]);
       
   588                     harness.check(url.getHost(), s[i][3]);
       
   589                     harness.check(url.getFile(), s[i][4]);
       
   590                     harness.check(true);
       
   591                 }
       
   592                 catch (NullPointerException e) {
       
   593                     if ((i != 6) && (i != 13)) {
       
   594 			harness.fail("Should not have thrown NullPointerException");
       
   595 			e.printStackTrace(System.out);
       
   596                     }
       
   597                 }
       
   598                 catch (Throwable e) {
       
   599 		    harness.fail("Should not have thrown exception");
       
   600 		    e.printStackTrace(System.out);
       
   601                 }
       
   602             }
       
   603         }
       
   604 
       
   605         public void test_authority()
       
   606         {
       
   607 	    String[][] s = {
       
   608 		{ "http://sources.redhat.com/",
       
   609 		  "sources.redhat.com"
       
   610 		},
       
   611 		{ "http://user:passwd@sources.redhat.com/",
       
   612 		  "user:passwd@sources.redhat.com"
       
   613 		},
       
   614 		{ "http://sources.redhat.com:90/",
       
   615 		  "sources.redhat.com:90"
       
   616 		}
       
   617 	    };
       
   618 
       
   619 	    harness.checkPoint("Check for authority support");
       
   620 	    for (int i = 0; i < s.length; i++)
       
   621 	      {
       
   622 		try {
       
   623 		  URL url = new URL(s[i][0]);
       
   624 		  
       
   625 		  harness.check(url.getAuthority(), s[i][1]);
       
   626 		}
       
   627 		catch (Throwable t)
       
   628 		  {
       
   629 		    harness.fail("Should not have thrown exception");
       
   630 		    t.printStackTrace(System.out);
       
   631 		  }
       
   632 	      }
       
   633 	}
       
   634 
       
   635     public void test_contextResolution() {
       
   636 	harness.checkPoint("contextResolution");
       
   637 	try {
       
   638 	    String[][] testData = new String[][] {
       
   639 		{"file://www.example.com/foo/bar.txt",
       
   640 		 "../test.txt",
       
   641 		 "file://www.example.com/test.txt"
       
   642 		},
       
   643 		{"file://www.example.com/foo/bar.txt",
       
   644 		 "./test.txt",
       
   645 		 "file://www.example.com/foo/test.txt"
       
   646 		},
       
   647 		{"http://www.example.com/foo/bar.txt",
       
   648 		 "../test.txt",
       
   649 		 "http://www.example.com/test.txt"
       
   650 		},
       
   651 		{"http://www.example.com/foo/bar.txt",
       
   652 		 "./test.txt",
       
   653 		 "http://www.example.com/foo/test.txt"
       
   654 		},
       
   655 		{"jar:file://www.example.com/test.jar!/foo/bar.txt",
       
   656 		 "../test.txt",
       
   657 		 "jar:file://www.example.com/test.jar!/test.txt"
       
   658 		},
       
   659 		{"jar:file://www.example.com/test.jar!/foo/bar.txt",
       
   660 		 "./test.txt",
       
   661 		 "jar:file://www.example.com/test.jar!/foo/test.txt"
       
   662 		},
       
   663 	    };
       
   664 	    
       
   665 	    for (int count = 0; count < testData.length; count++) {
       
   666 		URL base = new URL(testData[count][0]);
       
   667 		String relative = testData[count][1];
       
   668 		URL resolved = new URL(base, relative);
       
   669 		harness.check(resolved.toString(), testData[count][2]);
       
   670 	    }
       
   671 	}
       
   672 	catch (Exception e) {
       
   673 	    harness.debug(e);
       
   674 	    harness.fail("Should not have thrown exception");
       
   675 	}
       
   676     }
       
   677 
       
   678 
       
   679 	public void testall()
       
   680 	{
       
   681 		harness.debug("Running: test_Basics");
       
   682 		test_Basics();
       
   683 		harness.debug("Running: test_openConnection");
       
   684 		test_openConnection();
       
   685 		harness.debug("Running: test_openStream");
       
   686 		test_openStream();
       
   687 		harness.debug("Running: test_sameFile");
       
   688 		test_sameFile();
       
   689 		harness.debug("Running: test_toString");
       
   690 		test_toString();
       
   691 		harness.debug("Running: test_URLStreamHandler");
       
   692 		test_URLStreamHandler();
       
   693 		harness.debug("Running: cr601a");
       
   694                 test_cr601a();
       
   695 		harness.debug("Running: cr601b");
       
   696                 test_cr601b();
       
   697 		harness.debug("Running: authority");
       
   698 		test_authority();
       
   699 		harness.debug("Running: test_contextResolution");
       
   700 		test_contextResolution();
       
   701 	}
       
   702 
       
   703   public void test (TestHarness the_harness)
       
   704   {
       
   705     harness = the_harness;
       
   706     testall ();
       
   707   }
       
   708 
       
   709 }