summaryrefslogtreecommitdiff
path: root/libjava/classpath/test/java.lang.reflect/ArrayTest.java
blob: 4433e9b54f0101dedbfb99c7e1dfb1bb1682bcd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import java.lang.reflect.Array;

public class ArrayTest {
	public static void main(String[] args) {
		System.loadLibrary("javalangreflect");

		Object[] objArray = new Object[9];
		boolean[] boolArray = new boolean[9];
		double[] doubleArray = new double[9];
		byte[] byteArray = new byte[9];
		char[] charArray = new char[9];

		try {
			Boolean[][] blahArray = (Boolean[][])Array.newInstance(java.lang.Boolean.class,new int[]{9,1});
			System.out.print(blahArray != null ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
			E.printStackTrace();
		}
		System.out.println(": newInstance(Class,int[])");

		try {
			boolean[] blahArray = (boolean[])Array.newInstance(java.lang.Boolean.TYPE, 9);
			System.out.print(blahArray != null ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
			E.printStackTrace();
		}
		System.out.println(": newInstance(<primitive Class>,int)");
	
		try {
			objArray = (Object[])Array.newInstance(java.lang.Object.class, 9);
			System.out.print(objArray != null ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": newInstance(Class,int)");

		try {
			Boolean obj = new Boolean(true);
			Array.set(objArray,0,obj);
			System.out.print(objArray[0] == obj ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": set()");

		try {
			Array.setBoolean(boolArray,1,true);
			System.out.print(boolArray[1] == true ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setBoolean()");

		try {
			Array.setByte(byteArray,2,(byte)2);
			System.out.print(byteArray[2] == 2 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setByte()");

		try {
			Array.setShort(doubleArray,3,(short)3);
			System.out.print(doubleArray[3] == 3 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setShort()");

		try {
			Array.setChar(charArray,4,(char)4);
			System.out.print(charArray[4] == 4 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setChar()");

		try {
			Array.setInt(doubleArray,5,5);
			System.out.print(doubleArray[5] == 5 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setInt()");

		try {
			Array.setLong(doubleArray,6,6);
			System.out.print(doubleArray[6] == 6 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setLong()");

		try {
			Array.setFloat(doubleArray,7,7);
			System.out.print(doubleArray[7] == 7 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setFloat()");

		try {
			Array.setDouble(doubleArray,8,8);
			System.out.print(doubleArray[8] == 8 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": setDouble()");

		try {
			Boolean obj = (Boolean)Array.get(objArray,0);
			System.out.print(obj != null ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": get()");

		try {
			boolArray[1] = true;
			System.out.print(Array.getBoolean(boolArray,1) == true ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getBoolean()");

		try {
			byteArray[2] = (byte)2;
			System.out.print(Array.getByte(byteArray,2) == 2 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getByte()");

		try {
			byteArray[3] = (byte)3;
			System.out.print(Array.getShort(byteArray,3) == 3 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getShort()");

		try {
			charArray[4] = (char)4;
			System.out.print(Array.getChar(charArray,4) == 4 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getChar()");

		try {
			byteArray[5] = (byte)5;
			System.out.print(Array.getInt(byteArray,5) == 5 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getInt()");

		try {
			byteArray[6] = (byte)6;
			System.out.print(Array.getLong(byteArray,6) == 6 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getLong()");

		try {
			byteArray[7] = (byte)7;
			System.out.print(Array.getFloat(byteArray,7) == 7 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getFloat()");

		try {
			doubleArray[8] = 8;
			System.out.print(Array.getDouble(doubleArray,8) == 8 ? "PASSED" : "FAILED");
		} catch(Exception E) {
			System.out.print("FAILED");
		}
		System.out.println(": getDouble()");
	}
}