1 // Tags: JDK1.0 |
|
2 |
|
3 // Copyright (C) 1998, 2001 Cygnus Solutions |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Mauve is free software; you can redistribute it and/or modify |
|
8 // it under the terms of the GNU General Public License as published by |
|
9 // the Free Software Foundation; either version 2, or (at your option) |
|
10 // any later version. |
|
11 |
|
12 // Mauve is distributed in the hope that it will be useful, |
|
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 // GNU General Public License for more details. |
|
16 |
|
17 // You should have received a copy of the GNU General Public License |
|
18 // along with Mauve; see the file COPYING. If not, write to |
|
19 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 // Boston, MA 02111-1307, USA. */ |
|
21 |
|
22 package gnu.testlet.java.lang.Integer; |
|
23 import gnu.testlet.Testlet; |
|
24 import gnu.testlet.TestHarness; |
|
25 import java.util.Properties; |
|
26 import java.util.PropertyPermission; |
|
27 import java.security.Permission; |
|
28 import java.security.SecurityPermission; |
|
29 |
|
30 public class getInteger extends SecurityManager implements Testlet |
|
31 { |
|
32 public void test (TestHarness harness) |
|
33 { |
|
34 // Augment the System properties with the following. |
|
35 // Overwriting is bad because println needs the |
|
36 // platform-dependent line.separator property. |
|
37 Properties p = System.getProperties(); |
|
38 p.put("e1", Integer.toString(Integer.MIN_VALUE)); |
|
39 p.put("e2", Integer.toString(Integer.MAX_VALUE)); |
|
40 p.put("e3", "0" + Integer.toOctalString(Integer.MIN_VALUE)); |
|
41 p.put("e4", "0" + Integer.toOctalString(Integer.MAX_VALUE)); |
|
42 p.put("e5", "0x" + Integer.toHexString(Integer.MIN_VALUE)); |
|
43 p.put("e6", "0x" + Integer.toHexString(Integer.MAX_VALUE)); |
|
44 p.put("e7", "0" + Integer.toString(Integer.MAX_VALUE, 8)); |
|
45 p.put("e8", "#" + Integer.toString(Integer.MAX_VALUE, 16)); |
|
46 p.put("e9", ""); |
|
47 p.put("e10", " "); |
|
48 p.put("e11", "foo"); |
|
49 p.put("e12", "-#1"); |
|
50 |
|
51 harness.check (Integer.getInteger("e1").toString(), "-2147483648"); |
|
52 harness.check (Integer.getInteger("e2").toString(), "2147483647"); |
|
53 harness.check (Integer.getInteger("e3"), null); |
|
54 harness.check (Integer.getInteger("e4").toString(), "2147483647"); |
|
55 harness.check (Integer.getInteger("e5", 12345).toString(), "12345"); |
|
56 harness.check (Integer.getInteger("e6", new Integer(56789)).toString(), |
|
57 "2147483647"); |
|
58 harness.check (Integer.getInteger("e7", null).toString(), "2147483647"); |
|
59 harness.check (Integer.getInteger("e8", 12345).toString(), "2147483647"); |
|
60 harness.check (Integer.getInteger("e9", new Integer(56789)).toString(), |
|
61 "56789"); |
|
62 harness.check (Integer.getInteger("e10", null), null); |
|
63 harness.check (Integer.getInteger("e11"), null); |
|
64 harness.check (Integer.getInteger("e12"), new Integer(-1)); |
|
65 harness.check (Integer.getInteger("junk", 12345).toString(), "12345"); |
|
66 harness.check (Integer.getInteger("junk", new Integer(56789)).toString(), |
|
67 "56789"); |
|
68 harness.check (Integer.getInteger("junk", null), null); |
|
69 harness.check (Integer.getInteger("junk"), null); |
|
70 try |
|
71 { |
|
72 harness.check (Integer.getInteger(null), null); |
|
73 } |
|
74 catch (NullPointerException npe) |
|
75 { |
|
76 harness.check (false); |
|
77 } |
|
78 harness.check (Integer.getInteger(""), null); |
|
79 |
|
80 boolean ok = true; |
|
81 SecurityManager old_security_manager = System.getSecurityManager(); |
|
82 try |
|
83 { |
|
84 try |
|
85 { |
|
86 System.setSecurityManager(this); |
|
87 } |
|
88 catch (Throwable e) |
|
89 { |
|
90 harness.debug(e); |
|
91 ok = false; // can't run this test |
|
92 } |
|
93 if (ok) |
|
94 { |
|
95 try |
|
96 { |
|
97 Integer.getInteger("secure"); |
|
98 ok = false; |
|
99 } |
|
100 catch (SecurityException se) |
|
101 { |
|
102 } |
|
103 } |
|
104 } |
|
105 finally |
|
106 { |
|
107 // undo our change |
|
108 System.setSecurityManager(old_security_manager); |
|
109 } |
|
110 harness.check(ok); |
|
111 } |
|
112 |
|
113 // Method needed for SecurityManager |
|
114 |
|
115 /** |
|
116 * Croak on checking a property named "secure" |
|
117 */ |
|
118 public void checkPropertyAccess(String s) |
|
119 { |
|
120 if ("secure".equals(s)) |
|
121 throw new SecurityException("'Croak'"); |
|
122 else |
|
123 super.checkPropertyAccess(s); |
|
124 } |
|
125 |
|
126 /** |
|
127 * Allow restoration of the existing security manager, and various other |
|
128 * things that happen under the hood in various VMs. (HACK!) |
|
129 */ |
|
130 public void checkPermission(Permission p) |
|
131 { |
|
132 if (new RuntimePermission("setSecurityManager").implies(p)) |
|
133 return; |
|
134 if (new SecurityPermission("getProperty.networkaddress.*").implies(p)) |
|
135 return; |
|
136 if (new PropertyPermission("sun.net.inetaddr.ttl", "read").implies(p)) |
|
137 return; |
|
138 super.checkPermission(p); |
|
139 } |
|
140 |
|
141 } |
|