001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Serguei S.Zapreyev
020: * @version $Revision$
021: *
022: * This ArrayTest class ("Software") is furnished under license and may only be
023: * used or copied in accordance with the terms of that license.
024: *
025: */package java.lang.reflect;
026:
027: import junit.framework.TestCase;
028:
029: /*
030: * Created on 01.28.2006
031: */
032:
033: @SuppressWarnings(value={"all"})
034: public class ArrayTest extends TestCase {
035:
036: /**
037: *
038: */
039: public void test_get_Obj_I() {
040: class X {
041: public int fld;
042:
043: public X() {
044: return;
045: }
046:
047: public X(X a9) {
048: return;
049: }
050: }
051: try {
052: Object o = Array.newInstance(X.class, 777);
053: X inst[] = (X[]) o;
054: inst[776] = new X();
055: inst[776].fld = 777;
056: assertTrue("Error1", ((X) Array.get(o, 776)).fld == 777);
057: } catch (Exception e) {
058: fail("Error2: " + e.toString());
059: }
060: }
061:
062: /**
063: *
064: */
065: public void test_getBoolean_I() {
066: try {
067: Object o = Array.newInstance(boolean.class, 777);
068: boolean inst[] = (boolean[]) o;
069: inst[776] = false;
070: assertTrue("Error1", (((Boolean) Array.get(o, 776))
071: .booleanValue()) == false);
072: } catch (Exception e) {
073: fail("Error2: " + e.toString());
074: }
075: }
076:
077: /**
078: *
079: */
080: public void test_getByte_I() {
081: try {
082: Object o = Array.newInstance(byte.class, 777);
083: byte inst[] = (byte[]) o;
084: inst[776] = (byte) 7;
085: assertTrue("Error1", (((Byte) Array.get(o, 776))
086: .byteValue()) == (byte) 7);
087: } catch (Exception e) {
088: fail("Error2: " + e.toString());
089: }
090: }
091:
092: /**
093: *
094: */
095: public void test_getChar_I() {
096: try {
097: Object o = Array.newInstance(char.class, 777);
098: char inst[] = (char[]) o;
099: inst[776] = 'Z';
100: assertTrue("Error1", (((Character) Array.get(o, 776))
101: .charValue()) == 'Z');
102: } catch (Exception e) {
103: fail("Error2: " + e.toString());
104: }
105: }
106:
107: /**
108: *
109: */
110: public void test_getDouble_I() {
111: try {
112: Object o = Array.newInstance(double.class, 777);
113: double inst[] = (double[]) o;
114: inst[776] = 345.543d;
115: assertTrue("Error1", (((Double) Array.get(o, 776))
116: .doubleValue()) == 345.543d);
117: } catch (Exception e) {
118: fail("Error2: " + e.toString());
119: }
120: }
121:
122: /**
123: *
124: */
125: public void test_getFloat_I() {
126: try {
127: Object o = Array.newInstance(float.class, 777);
128: float inst[] = (float[]) o;
129: inst[776] = 543.345f;
130: assertTrue("Error1", (((Float) Array.get(o, 776))
131: .floatValue()) == 543.345f);
132: } catch (Exception e) {
133: fail("Error2: " + e.toString());
134: }
135: }
136:
137: /**
138: *
139: */
140: public void test_getInt_I() {
141: try {
142: Object o = Array.newInstance(int.class, 777);
143: int inst[] = (int[]) o;
144: inst[776] = Integer.MAX_VALUE;
145: assertTrue("Error1", (((Integer) Array.get(o, 776))
146: .intValue()) == Integer.MAX_VALUE);
147: } catch (Exception e) {
148: fail("Error2: " + e.toString());
149: }
150: }
151:
152: /**
153: *
154: */
155: public void test_getLength_Obj() {
156: try {
157: Object o = Array.newInstance(ArrayTest.class, 777);
158: assertTrue("Error1", Array.getLength(o) == 777);
159: } catch (Exception e) {
160: fail("Error2: " + e.toString());
161: }
162: }
163:
164: /**
165: *
166: */
167: public void test_getLong_I() {
168: try {
169: Object o = Array.newInstance(long.class, 777);
170: long inst[] = (long[]) o;
171: inst[776] = 999999999999l;
172: assertTrue("Error1", (((Long) Array.get(o, 776))
173: .longValue()) == 999999999999l);
174: } catch (Exception e) {
175: fail("Error2: " + e.toString());
176: }
177: }
178:
179: /**
180: *
181: */
182: public void test_getShort_I() {
183: try {
184: Object o = Array.newInstance(short.class, 777);
185: short inst[] = (short[]) o;
186: inst[776] = Short.MAX_VALUE;
187: assertTrue("Error1", (((Short) Array.get(o, 776))
188: .shortValue()) == Short.MAX_VALUE);
189: } catch (Exception e) {
190: fail("Error2: " + e.toString());
191: }
192: }
193:
194: /**
195: *
196: */
197: public void test_newInstance_Obj() {
198: class X {
199: public X() {
200: return;
201: }
202:
203: public X(X a9) {
204: return;
205: }
206: }
207: new X(new X());
208: try {
209: Object o = Array.newInstance(X.class, 777);
210: assertTrue("Error1", o.getClass().getName().equals(
211: "[Ljava.lang.reflect.ArrayTest$2X;"));
212: } catch (Exception e) {
213: fail("Error2: " + e.toString());
214: }
215: }
216:
217: /**
218: *
219: */
220: public void test_newInstance_Obj_IArr() {
221: class X {
222: public X() {
223: return;
224: }
225:
226: public X(X a9) {
227: return;
228: }
229: }
230: new X(new X());
231: try {
232: Object o = Array.newInstance(X.class, 777);
233: Object o2 = Array.newInstance(o.getClass(), 255);
234: assertTrue("Error1" + o2.getClass().getName(), o2
235: .getClass().getName().equals(
236: "[[Ljava.lang.reflect.ArrayTest$3X;"));
237: } catch (Exception e) {
238: fail("Error2: " + e.toString());
239: }
240: }
241:
242: /**
243: *
244: */
245: public void test_set_Obj_I() {
246: class X {
247: public int fld;
248:
249: public X() {
250: return;
251: }
252:
253: public X(X a9) {
254: return;
255: }
256: }
257: try {
258: Object o = Array.newInstance(X.class, 777);
259: X x = new X();
260: x.fld = 777;
261: Array.set(o, 776, (Object) x);
262: assertTrue("Error1", ((X) Array.get(o, 776)).fld == 777);
263: } catch (Exception e) {
264: fail("Error2: " + e.toString());
265: }
266: }
267:
268: /**
269: *
270: */
271: public void test_setBoolean_I() {
272: try {
273: Object o = Array.newInstance(boolean.class, 777);
274: Array.set(o, 776, (Object) new Boolean(false));
275: assertTrue("Error1", (((Boolean) Array.get(o, 776))
276: .booleanValue()) == false);
277: } catch (Exception e) {
278: fail("Error2: " + e.toString());
279: }
280: }
281:
282: /**
283: *
284: */
285: public void test_setByte_I() {
286: try {
287: Object o = Array.newInstance(byte.class, 777);
288: Array.set(o, 776, (Object) new Byte((byte) 7));
289: assertTrue("Error1", (((Byte) Array.get(o, 776))
290: .byteValue()) == (byte) 7);
291: } catch (Exception e) {
292: fail("Error2: " + e.toString());
293: }
294: }
295:
296: /**
297: *
298: */
299: public void test_setChar_I() {
300: try {
301: Object o = Array.newInstance(char.class, 777);
302: Array.set(o, 776, (Object) new Character('Z'));
303: assertTrue("Error1", (((Character) Array.get(o, 776))
304: .charValue()) == 'Z');
305: } catch (Exception e) {
306: fail("Error2: " + e.toString());
307: }
308: }
309:
310: /**
311: *
312: */
313: public void test_setDouble_I() {
314: try {
315: Object o = Array.newInstance(double.class, 777);
316: Array.set(o, 776, (Object) new Double(345.543d));
317: assertTrue("Error1", (((Double) Array.get(o, 776))
318: .doubleValue()) == 345.543d);
319: } catch (Exception e) {
320: fail("Error2: " + e.toString());
321: }
322: }
323:
324: /**
325: *
326: */
327: public void test_setFloat_I() {
328: try {
329: Object o = Array.newInstance(float.class, 777);
330: Array.set(o, 776, (Object) new Float(543.345f));
331: assertTrue("Error1", (((Float) Array.get(o, 776))
332: .floatValue()) == 543.345f);
333: } catch (Exception e) {
334: fail("Error2: " + e.toString());
335: }
336: }
337:
338: /**
339: *
340: */
341: public void test_setInt_I() {
342: try {
343: Object o = Array.newInstance(int.class, 777);
344: Array.set(o, 776, (Object) new Integer(Integer.MAX_VALUE));
345: assertTrue("Error1", (((Integer) Array.get(o, 776))
346: .intValue()) == Integer.MAX_VALUE);
347: } catch (Exception e) {
348: fail("Error2: " + e.toString());
349: }
350: }
351:
352: /**
353: *
354: */
355: public void test_setLong_I() {
356: try {
357: Object o = Array.newInstance(long.class, 777);
358: Array.set(o, 776, (Object) new Long(999999999999l));
359: assertTrue("Error1", (((Long) Array.get(o, 776))
360: .longValue()) == 999999999999l);
361: } catch (Exception e) {
362: fail("Error2: " + e.toString());
363: }
364: }
365:
366: /**
367: *
368: */
369: public void test_setShort_I() {
370: try {
371: Object o = Array.newInstance(short.class, 777);
372: Array.set(o, 776, (Object) new Short(Short.MAX_VALUE));
373: assertTrue("Error1", (((Short) Array.get(o, 776))
374: .shortValue()) == Short.MAX_VALUE);
375: } catch (Exception e) {
376: fail("Error2: " + e.toString());
377: }
378: }
379: }
|