URLPermissionTest.java (8382:dd0deeb04933) URLPermissionTest.java (8701:7bc67bed3c14)
1/*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *

--- 12 unchanged lines hidden (view full) ---

21 * questions.
22 */
23
24import java.net.URLPermission;
25import java.io.*;
26
27/**
28 * @test
1/*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *

--- 12 unchanged lines hidden (view full) ---

21 * questions.
22 */
23
24import java.net.URLPermission;
25import java.io.*;
26
27/**
28 * @test
29 * @bug 8010464
29 * @bug 8010464 8027570
30 */
31
32public class URLPermissionTest {
33
34 // super class for all test types
35 abstract static class Test {
36 boolean expected;
37 abstract boolean execute();

--- 67 unchanged lines hidden (view full) ---

105 return result == expected;
106 }
107 }
108
109 static ActionImpliesTest actest(String arg1, String arg2, boolean expected) {
110 return new ActionImpliesTest(arg1, arg2, expected);
111 }
112
30 */
31
32public class URLPermissionTest {
33
34 // super class for all test types
35 abstract static class Test {
36 boolean expected;
37 abstract boolean execute();

--- 67 unchanged lines hidden (view full) ---

105 return result == expected;
106 }
107 }
108
109 static ActionImpliesTest actest(String arg1, String arg2, boolean 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);
133 }
134
113 static class URLEqualityTest extends Test {
114 String arg1, arg2;
115
116 URLEqualityTest(String arg1, String arg2, boolean expected) {
117 this.arg1 = arg1;
118 this.arg2 = arg2;
119 this.expected = expected;
120 }

--- 52 unchanged lines hidden (view full) ---

173 extest("http://1.2.3.4.5/a/b/c"),
174 extest("http://www.*.com"),
175 //extest("http://www.foo.com:1-X"),
176 extest("http://[foo.com]:99"),
177 extest("http://[fec0::X]:99"),
178 extest("http:")
179 };
180
135 static class URLEqualityTest extends Test {
136 String arg1, arg2;
137
138 URLEqualityTest(String arg1, String arg2, boolean expected) {
139 this.arg1 = arg1;
140 this.arg2 = arg2;
141 this.expected = expected;
142 }

--- 52 unchanged lines hidden (view full) ---

195 extest("http://1.2.3.4.5/a/b/c"),
196 extest("http://www.*.com"),
197 //extest("http://www.foo.com:1-X"),
198 extest("http://[foo.com]:99"),
199 extest("http://[fec0::X]:99"),
200 extest("http:")
201 };
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 = {
182 imtest("http://[FE80::]:99", "http://[fe80:0::]:99", true),
183
184 // hostnames
185 imtest("http://*.foo.com/a/b/-", "http://www.foo.com/a/b/c/d", true),
186 imtest("http://*.foo.com/a/b/-", "http://www.bar.com/a/b/c/d", false),
187 imtest("http://*.foo.com/a/b/-", "http://www.biz.bar.foo.com/a/b/c/d", true),
188 imtest("http://*.foo.com/a/b/-", "http://www.biz.bar.foo.como/a/b/c/d", false),

--- 132 unchanged lines hidden (view full) ---

321 System.out.printf("equality test %d failed: %s : %s\n", i, test.arg1,
322 test.arg2);
323 } else {
324 System.out.println ("equality test " + i + " OK");
325 }
326
327 }
328
208 static Test[] pathImplies2 = {
209 imtest("http://[FE80::]:99", "http://[fe80:0::]:99", true),
210
211 // hostnames
212 imtest("http://*.foo.com/a/b/-", "http://www.foo.com/a/b/c/d", true),
213 imtest("http://*.foo.com/a/b/-", "http://www.bar.com/a/b/c/d", false),
214 imtest("http://*.foo.com/a/b/-", "http://www.biz.bar.foo.com/a/b/c/d", true),
215 imtest("http://*.foo.com/a/b/-", "http://www.biz.bar.foo.como/a/b/c/d", false),

--- 132 unchanged lines hidden (view full) ---

348 System.out.printf("equality test %d failed: %s : %s\n", i, test.arg1,
349 test.arg2);
350 } else {
351 System.out.println ("equality test " + i + " OK");
352 }
353
354 }
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++) {
330 ExTest test = (ExTest)exceptionTests[i];
331 boolean result = test.execute();
332 if (!result) {
333 System.out.println ("test failed: " + test.arg);
334 failed = true;
335 } else {
336 System.out.println ("exception test " + i + " OK");

--- 52 unchanged lines hidden ---
367 for (int i=0; i<exceptionTests.length; i++) {
368 ExTest test = (ExTest)exceptionTests[i];
369 boolean result = test.execute();
370 if (!result) {
371 System.out.println ("test failed: " + test.arg);
372 failed = true;
373 } else {
374 System.out.println ("exception test " + i + " OK");

--- 52 unchanged lines hidden ---