OldURITest.java revision 1f8243e3d2b5a3f8e0398c304d1dea0395cbc368
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package libcore.java.net; 19 20import java.net.URI; 21import java.net.URISyntaxException; 22import junit.framework.TestCase; 23 24public class OldURITest extends TestCase { 25 26 String[] constructorTests = new String[] { 27 "http://user@www.google.com:45/search?q=helpinfo#somefragment", 28 // http with authority, query and fragment 29 "ftp://ftp.is.co.za/rfc/rfc1808.txt", // ftp 30 "gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles", // gopher 31 "mailto:mduerst@ifi.unizh.ch", // mailto 32 "news:comp.infosystems.www.servers.unix", // news 33 "telnet://melvyl.ucop.edu/", // telnet 34 "http://123.24.17.98/test", // IPv4 authority 35 "http://www.google.com:80/test",// domain name authority 36 "http://joe@[3ffe:2a00:100:7031::1]:80/test", 37 // IPv6 authority, with userinfo and port 38 "/relative", // relative starting with / 39 "//relative", // relative starting with // 40 "relative", // relative with no / 41 "#fragment",// relative just with fragment 42 "http://user@host:80", // UI, host,port 43 "http://user@host", // ui, host 44 "http://host", // host 45 "http://host:80", // host,port 46 "http://joe@:80", // ui, port (becomes registry-based) 47 "file:///foo/bar", // empty authority, non empty path 48 "ht?tp://hoe@host:80", // miscellaneous tests 49 "mai/lto:hey?joe#man", "http://host/a%20path#frag", 50 // path with an escaped octet for space char 51 "http://host/a%E2%82%ACpath#frag", 52 // path with escaped octet for unicode char, not USASCII 53 "http://host/a\u20ACpath#frag", 54 // path with unicode char, not USASCII equivalent to 55 // = "http://host/a\u0080path#frag", 56 "http://host%20name/", // escaped octets in host (becomes 57 // registry based) 58 "http://host\u00DFname/", // unicodechar in host (becomes 59 // registry based) 60 // equivalent to = "http://host\u00dfname/", 61 "ht123-+tp://www.google.com:80/test", // legal chars in scheme 62 }; 63 64 String[] constructorTestsInvalid = new String[] { 65 "http:///a path#frag", // space char in path, not in escaped 66 // octet form, with no host 67 "http://host/a[path#frag", // an illegal char, not in escaped 68 // octet form, should throw an 69 // exception 70 "http://host/a%path#frag", // invalid escape sequence in path 71 "http://host/a%#frag", // incomplete escape sequence in path 72 73 "http://host#a frag", // space char in fragment, not in 74 // escaped octet form, no path 75 "http://host/a#fr#ag", // illegal char in fragment 76 "http:///path#fr%ag", // invalid escape sequence in fragment, 77 // with no host 78 "http://host/path#frag%", // incomplete escape sequence in 79 // fragment 80 81 "http://host/path?a query#frag", // space char in query, not 82 // in escaped octet form 83 "http://host?query%ag", // invalid escape sequence in query, no 84 // path 85 "http:///path?query%", // incomplete escape sequence in query, 86 // with no host 87 88 "mailto:user^name@fklkf.com" // invalid char in scheme specific part 89 }; 90 91 public void test_createLjava_lang_String() { 92 for (String s : constructorTests) { 93 try { 94 new URI(s); 95 } catch (URISyntaxException e) { 96 fail("Failed to construct URI for: " + s + " : " + e); 97 } 98 } 99 100 for (String s : constructorTestsInvalid) { 101 try { 102 URI.create(s); 103 fail("IllegalArgumentException expected but not received."); 104 } catch (IllegalArgumentException expected) { 105 } 106 } 107 } 108 109 public void test_relativizeLjava_net_URI() throws URISyntaxException { 110 try { 111 URI b = new URI("http://www.google.com/dir1/dir2"); 112 b.relativize(null); 113 fail("NullPointerException was not thrown."); 114 } catch(NullPointerException expected) { 115 } 116 } 117 118 public void test_resolveLjava_net_URI() throws URISyntaxException { 119 try { 120 URI b = new URI("http://www.test.com/dir"); 121 b.resolve((URI) null); 122 fail("NullPointerException was not thrown."); 123 } catch(NullPointerException expected) { 124 } 125 } 126 127 public void test_resolveLjava_lang_String() throws URISyntaxException { 128 try { 129 URI b = new URI("http://www.test.com/dir"); 130 b.resolve((String) null); 131 fail("NullPointerException was not thrown."); 132 } catch(NullPointerException expected) { 133 } 134 135 try { 136 URI b = new URI("http://www.test.com/dir"); 137 b.resolve("http://a/b/c/g?y/./x\n"); 138 fail("IllegalArgumentException was not thrown."); 139 } catch(IllegalArgumentException expected) { 140 } 141 } 142 143 public void test_ConstructorLjava_lang_String() throws URISyntaxException { 144 try { 145 new URI(null); 146 fail("NullPointerException was not thrown."); 147 } catch(NullPointerException expected) { 148 } 149 } 150} 151