Skip to content

Commit ababf12

Browse files
reynderspenberg
authored andcommitted
malva: Added implementation of SystemTest
[ penberg@kernel.org: disable broken tests, cleanups ] Signed-off-by: Pekka Enberg <penberg@kernel.org>
1 parent b1bb3f6 commit ababf12

File tree

2 files changed

+304
-0
lines changed

2 files changed

+304
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CLASSES += src/malva/java/lang/FloatTest.class
2222
CLASSES += src/malva/java/lang/MathTest.class
2323
CLASSES += src/malva/java/lang/RuntimeTest.class
2424
CLASSES += src/malva/java/lang/StringTest.class
25+
CLASSES += src/malva/java/lang/SystemTest.class
2526
CLASSES += src/malva/java/lang/ThrowableTest.class
2627

2728
SRC := $(patsubst %.class,%.java,$(CLASSES))

src/malva/java/lang/SystemTest.java

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
package malva.java.lang;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.PrintStream;
8+
import java.nio.channels.Channel;
9+
import java.util.Properties;
10+
11+
import malva.TestCase;
12+
13+
public class SystemTest extends TestCase {
14+
public static void testArraycopy() {
15+
String[] source = new String[] {"1", "2"};
16+
String[] dest = new String[2];
17+
System.arraycopy(source, 0, dest, 0, 2);
18+
assertEquals(source[1], dest[1]);
19+
System.arraycopy(source, 0, source, 1, 1);
20+
assertEquals("1", source[1]);
21+
System.arraycopy(new String[0], 0, new String[0], 0, 0);
22+
23+
assertThrows(new Block() {
24+
@Override public void run() {
25+
System.arraycopy(new String[0], 0, null, 0, 0);
26+
}
27+
}, NullPointerException.class);
28+
assertThrows(new Block() {
29+
@Override public void run() {
30+
System.arraycopy(null, 0, new String[0], 0, 0);
31+
}
32+
}, NullPointerException.class);
33+
34+
assertThrows(new Block() {
35+
@Override public void run() {
36+
System.arraycopy("", 0, new String[0], 0, 0);
37+
}
38+
}, ArrayStoreException.class);
39+
40+
assertThrows(new Block() {
41+
@Override public void run() {
42+
System.arraycopy(new String[0], 0, "", 0, 0);
43+
}
44+
}, ArrayStoreException.class);
45+
46+
assertThrows(new Block() {
47+
@Override public void run() {
48+
System.arraycopy(new float[0], 0, new int[0], 0, 0);
49+
}
50+
}, ArrayStoreException.class);
51+
52+
assertThrows(new Block() {
53+
@Override public void run() {
54+
System.arraycopy(new float[0], 0, new Float[0], 0, 0);
55+
}
56+
}, ArrayStoreException.class);
57+
58+
assertThrows(new Block() {
59+
@Override public void run() {
60+
System.arraycopy(new Float[0], 0, new float[0], 0, 0);
61+
}
62+
}, ArrayStoreException.class);
63+
64+
assertThrows(new Block() {
65+
@Override public void run() {
66+
System.arraycopy(new float[0], -1, new float[0], 0, 0);
67+
}
68+
}, ArrayIndexOutOfBoundsException.class);
69+
70+
assertThrows(new Block() {
71+
@Override public void run() {
72+
System.arraycopy(new float[0], 0, new float[0], -1, 0);
73+
}
74+
}, ArrayIndexOutOfBoundsException.class);
75+
76+
assertThrows(new Block() {
77+
@Override public void run() {
78+
System.arraycopy(new float[0], 0, new float[0], 0, -1);
79+
}
80+
}, ArrayIndexOutOfBoundsException.class);
81+
82+
assertThrows(new Block() {
83+
@Override public void run() {
84+
System.arraycopy(new float[0], 0, new float[0], 0, 1);
85+
}
86+
}, ArrayIndexOutOfBoundsException.class);
87+
88+
final Object[] mixSrc = new Object[] {new Integer(0), new Integer(1), ""};
89+
final Integer[] mixDest = new Integer[3];
90+
assertThrows(new Block() {
91+
@Override public void run() {
92+
System.arraycopy(mixSrc, 0, mixDest, 0, 3);
93+
}
94+
}, ArrayStoreException.class);
95+
96+
assertEquals(mixDest[1], new Integer(1));
97+
}
98+
99+
public static void testClearProperty() {
100+
assertEquals(null, System.clearProperty("DOES_NOT_EXIST_42"));
101+
102+
assertThrows(new Block() {
103+
@Override public void run() {
104+
System.clearProperty(null);
105+
}
106+
}, NullPointerException.class );
107+
108+
assertThrows(new Block() {
109+
@Override public void run() {
110+
System.clearProperty("");
111+
}
112+
}, IllegalArgumentException.class );
113+
}
114+
115+
public static void testConsole() {
116+
}
117+
118+
public static void testCurrentTimeMillis() {
119+
assertTrue((System.currentTimeMillis() - System.currentTimeMillis()) <= 0);
120+
}
121+
122+
public static void testExit() {
123+
}
124+
125+
public static void testGc() {
126+
}
127+
128+
public static void testGetenv() {
129+
java.util.Map<String, String> env = System.getenv();
130+
for(String value: env.keySet()) {
131+
assertNotNull(value);
132+
assertNotNull(env.get(value));
133+
}
134+
135+
assertThrows(new Block() {
136+
@Override public void run() {
137+
System.getenv(null);
138+
}
139+
}, NullPointerException.class);
140+
}
141+
142+
public static void testGetProperties() {
143+
Properties props = System.getProperties();
144+
assertNotNull(props.getProperty("java.version"));
145+
assertNotNull(props.getProperty("java.vendor"));
146+
assertNotNull(props.getProperty("java.vendor.url"));
147+
assertNotNull(props.getProperty("java.home"));
148+
assertNotNull(props.getProperty("java.vm.specification.version"));
149+
assertNotNull(props.getProperty("java.vm.specification.vendor"));
150+
assertNotNull(props.getProperty("java.vm.specification.name"));
151+
assertNotNull(props.getProperty("java.vm.version"));
152+
assertNotNull(props.getProperty("java.vm.vendor"));
153+
assertNotNull(props.getProperty("java.vm.name"));
154+
assertNotNull(props.getProperty("java.specification.version"));
155+
assertNotNull(props.getProperty("java.specification.vendor"));
156+
assertNotNull(props.getProperty("java.specification.name"));
157+
assertNotNull(props.getProperty("java.class.version"));
158+
assertNotNull(props.getProperty("java.class.path"));
159+
assertNotNull(props.getProperty("java.library.path"));
160+
assertNotNull(props.getProperty("java.io.tmpdir"));
161+
assertNull(props.getProperty("java.compiler"));
162+
assertNotNull(props.getProperty("java.ext.dirs"));
163+
assertNotNull(props.getProperty("os.name"));
164+
assertNotNull(props.getProperty("os.arch"));
165+
assertNotNull(props.getProperty("file.separator"));
166+
assertNotNull(props.getProperty("path.separator"));
167+
assertNotNull(props.getProperty("line.separator"));
168+
assertNotNull(props.getProperty("user.name"));
169+
assertNotNull(props.getProperty("user.home"));
170+
assertNotNull(props.getProperty("user.dir"));
171+
}
172+
173+
public static void testGetProperty() {
174+
assertEquals("testValue", System.getProperty("DOES_NOT_EXIST_TEST", "testValue"));
175+
}
176+
177+
public static void testGetSecurityManager() {
178+
}
179+
180+
public static void testIdentityHashCode() {
181+
assertEquals(0, System.identityHashCode(null));
182+
}
183+
184+
public static void testInheritedChannel() {
185+
try {
186+
if (System.inheritedChannel() != null) {
187+
assertTrue(Channel.class.isInstance(System.inheritedChannel().getClass()));
188+
}
189+
} catch (IOException e) {
190+
fail("testInheritedChannel failed: " + e.getMessage());
191+
}
192+
}
193+
194+
public static void testLoad() {
195+
assertThrows(new Block() {
196+
@Override public void run() {
197+
System.load(null);
198+
}
199+
}, NullPointerException.class);
200+
}
201+
202+
public static void testLoadLibrary() {
203+
assertThrows(new Block() {
204+
@Override public void run() {
205+
System.loadLibrary(null);
206+
}
207+
}, NullPointerException.class);
208+
}
209+
210+
public static void testMapLibraryName() {
211+
assertThrows(new Block() {
212+
@Override public void run() {
213+
System.mapLibraryName(null);
214+
}
215+
}, NullPointerException.class);
216+
}
217+
218+
public static void testNanoTime() {
219+
assertTrue((System.nanoTime() - System.nanoTime()) <= 0);
220+
}
221+
222+
public static void testRunFinalization() {
223+
}
224+
225+
public static void testSetErr() {
226+
PrintStream originalErr = System.err;
227+
try {
228+
PrintStream newErr = new PrintStream(new ByteArrayOutputStream());
229+
System.setErr(newErr);
230+
assertEquals(newErr, System.err);
231+
} finally {
232+
System.setErr(originalErr);
233+
}
234+
}
235+
236+
public static void testSetIn() {
237+
InputStream originalIn = System.in;
238+
try {
239+
InputStream newIn = new ByteArrayInputStream(new byte[0]);
240+
System.setIn(newIn);
241+
assertEquals(newIn, System.in);
242+
} finally {
243+
System.setIn(originalIn);
244+
}
245+
}
246+
247+
public static void testSetOut() {
248+
PrintStream originalOut = System.out;
249+
try {
250+
PrintStream newOut = new PrintStream(new ByteArrayOutputStream());
251+
System.setErr(newOut);
252+
assertEquals(newOut, System.out);
253+
} finally {
254+
System.setOut(originalOut);
255+
}
256+
}
257+
258+
public static void testSetProperties() {
259+
Properties originalProperties = System.getProperties();
260+
261+
try {
262+
// FIXME: FAILS
263+
// System.setProperties(null);
264+
// assertTrue(System.getProperties().isEmpty());
265+
Properties newProperties = new Properties();
266+
newProperties.setProperty("key", "value");
267+
System.setProperties(newProperties);
268+
assertEquals("value", System.getProperty("key"));
269+
assertEquals(1, System.getProperties().size());
270+
} finally {
271+
System.setProperties(originalProperties);
272+
}
273+
}
274+
275+
public static void testSetSecurityManager() {
276+
}
277+
278+
public static void main(String[] args) {
279+
testArraycopy();
280+
testClearProperty();
281+
testConsole();
282+
testCurrentTimeMillis();
283+
testExit();
284+
testGc();
285+
testGetenv();
286+
testGetProperties();
287+
testGetProperty();
288+
testGetSecurityManager();
289+
testIdentityHashCode();
290+
testInheritedChannel();
291+
testLoad();
292+
testLoadLibrary();
293+
testMapLibraryName();
294+
testNanoTime();
295+
testRunFinalization();
296+
testSetErr();
297+
testSetIn();
298+
// FIXME: FAILS
299+
// testSetOut();
300+
testSetProperties();
301+
testSetSecurityManager();
302+
}
303+
}

0 commit comments

Comments
 (0)