equal
deleted
inserted
replaced
24 import java.net.URLPermission; |
24 import java.net.URLPermission; |
25 import java.io.*; |
25 import java.io.*; |
26 |
26 |
27 /** |
27 /** |
28 * @test |
28 * @test |
29 * @bug 8010464 |
29 * @bug 8010464 8027570 |
30 */ |
30 */ |
31 |
31 |
32 public class URLPermissionTest { |
32 public class URLPermissionTest { |
33 |
33 |
34 // super class for all test types |
34 // super class for all test types |
106 } |
106 } |
107 } |
107 } |
108 |
108 |
109 static ActionImpliesTest actest(String arg1, String arg2, boolean expected) { |
109 static ActionImpliesTest actest(String arg1, String arg2, boolean expected) { |
110 return new ActionImpliesTest(arg1, arg2, expected); |
110 return new ActionImpliesTest(arg1, arg2, expected); |
|
111 } |
|
112 |
|
113 static class HashCodeTest extends Test { |
|
114 String arg1, arg2; |
|
115 int hash; |
|
116 |
|
117 HashCodeTest(String arg1, String arg2, int hash) { |
|
118 this.arg1 = arg1; |
|
119 this.arg2 = arg2; |
|
120 this.hash = hash; |
|
121 } |
|
122 |
|
123 @Override |
|
124 boolean execute() { |
|
125 URLPermission p = new URLPermission(arg1, arg2); |
|
126 int h = p.hashCode(); |
|
127 return h == hash; |
|
128 } |
|
129 } |
|
130 |
|
131 static HashCodeTest hashtest(String arg1, String arg2, int expected) { |
|
132 return new HashCodeTest(arg1, arg2, expected); |
111 } |
133 } |
112 |
134 |
113 static class URLEqualityTest extends Test { |
135 static class URLEqualityTest extends Test { |
114 String arg1, arg2; |
136 String arg1, arg2; |
115 |
137 |
176 extest("http://[foo.com]:99"), |
198 extest("http://[foo.com]:99"), |
177 extest("http://[fec0::X]:99"), |
199 extest("http://[fec0::X]:99"), |
178 extest("http:") |
200 extest("http:") |
179 }; |
201 }; |
180 |
202 |
|
203 static Test[] hashTests = { |
|
204 hashtest("http://www.foo.com/path", "GET:X-Foo", 388644203), |
|
205 hashtest("http:*", "*:*", 3255810) |
|
206 }; |
|
207 |
181 static Test[] pathImplies2 = { |
208 static Test[] pathImplies2 = { |
182 imtest("http://[FE80::]:99", "http://[fe80:0::]:99", true), |
209 imtest("http://[FE80::]:99", "http://[fe80:0::]:99", true), |
183 |
210 |
184 // hostnames |
211 // hostnames |
185 imtest("http://*.foo.com/a/b/-", "http://www.foo.com/a/b/c/d", true), |
212 imtest("http://*.foo.com/a/b/-", "http://www.foo.com/a/b/c/d", true), |
324 System.out.println ("equality test " + i + " OK"); |
351 System.out.println ("equality test " + i + " OK"); |
325 } |
352 } |
326 |
353 |
327 } |
354 } |
328 |
355 |
|
356 for (int i=0; i<hashTests.length; i++) { |
|
357 HashCodeTest test = (HashCodeTest)hashTests[i]; |
|
358 boolean result = test.execute(); |
|
359 if (!result) { |
|
360 System.out.printf ("test failed: %s %s %d\n", test.arg1, test.arg2, test.hash); |
|
361 failed = true; |
|
362 } else { |
|
363 System.out.println ("hash test " + i + " OK"); |
|
364 } |
|
365 } |
|
366 |
329 for (int i=0; i<exceptionTests.length; i++) { |
367 for (int i=0; i<exceptionTests.length; i++) { |
330 ExTest test = (ExTest)exceptionTests[i]; |
368 ExTest test = (ExTest)exceptionTests[i]; |
331 boolean result = test.execute(); |
369 boolean result = test.execute(); |
332 if (!result) { |
370 if (!result) { |
333 System.out.println ("test failed: " + test.arg); |
371 System.out.println ("test failed: " + test.arg); |