jaroslav@477
|
1 |
/**
|
jaroslav@477
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@477
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@477
|
4 |
*
|
jaroslav@477
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@477
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@477
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@477
|
8 |
*
|
jaroslav@477
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@477
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@477
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@477
|
12 |
* GNU General Public License for more details.
|
jaroslav@477
|
13 |
*
|
jaroslav@477
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@477
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@477
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@477
|
17 |
*/
|
jaroslav@477
|
18 |
package org.apidesign.bck2brwsr.tck;
|
jaroslav@477
|
19 |
|
jaroslav@477
|
20 |
import java.lang.reflect.Array;
|
jaroslav@477
|
21 |
import org.apidesign.bck2brwsr.vmtest.Compare;
|
jaroslav@477
|
22 |
import org.apidesign.bck2brwsr.vmtest.VMTest;
|
jaroslav@477
|
23 |
import org.testng.annotations.Factory;
|
jaroslav@477
|
24 |
|
jaroslav@477
|
25 |
/**
|
jaroslav@477
|
26 |
*
|
jaroslav@477
|
27 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@477
|
28 |
*/
|
jaroslav@477
|
29 |
public class ReflectionArrayTest {
|
jaroslav@477
|
30 |
@Compare public int lengthOfStringArray() {
|
jaroslav@477
|
31 |
String[] arr = (String[]) Array.newInstance(String.class, 10);
|
jaroslav@477
|
32 |
return arr.length;
|
jaroslav@477
|
33 |
}
|
jaroslav@477
|
34 |
|
jaroslav@477
|
35 |
@Compare public String compTypeOfStringArray() {
|
jaroslav@477
|
36 |
String[] arr = (String[]) Array.newInstance(String.class, 10);
|
jaroslav@477
|
37 |
return arr.getClass().getComponentType().getName();
|
jaroslav@477
|
38 |
}
|
jaroslav@477
|
39 |
|
jaroslav@477
|
40 |
@Compare public Object negativeArrayExcp() {
|
jaroslav@477
|
41 |
return Array.newInstance(String.class, -5);
|
jaroslav@477
|
42 |
}
|
jaroslav@477
|
43 |
|
jaroslav@477
|
44 |
@Compare public int lengthOfIntArray() {
|
jaroslav@477
|
45 |
int[] arr = (int[]) Array.newInstance(Integer.TYPE, 10);
|
jaroslav@477
|
46 |
return arr.length;
|
jaroslav@477
|
47 |
}
|
jaroslav@477
|
48 |
|
jaroslav@477
|
49 |
@Compare public String compTypeOfIntArray() {
|
jaroslav@477
|
50 |
int[] arr = (int[]) Array.newInstance(int.class, 10);
|
jaroslav@477
|
51 |
return arr.getClass().getComponentType().getName();
|
jaroslav@477
|
52 |
}
|
jaroslav@477
|
53 |
|
jaroslav@477
|
54 |
@Compare public Object intNegativeArrayExcp() {
|
jaroslav@477
|
55 |
return Array.newInstance(int.class, -5);
|
jaroslav@477
|
56 |
}
|
jaroslav@477
|
57 |
|
jaroslav@480
|
58 |
@Compare public int multiIntArray() {
|
jaroslav@480
|
59 |
int[][][] arr = (int[][][]) Array.newInstance(int.class, 3, 3, 3);
|
jaroslav@480
|
60 |
return arr[0][1][2] + 5 + arr[2][2][0];
|
jaroslav@480
|
61 |
}
|
jaroslav@480
|
62 |
|
jaroslav@480
|
63 |
@Compare public String multiIntArrayCompType() {
|
jaroslav@480
|
64 |
return Array.newInstance(int.class, 3, 3, 3).getClass().getName();
|
jaroslav@480
|
65 |
}
|
jaroslav@480
|
66 |
|
jaroslav@477
|
67 |
|
jaroslav@477
|
68 |
@Factory
|
jaroslav@477
|
69 |
public static Object[] create() {
|
jaroslav@477
|
70 |
return VMTest.create(ReflectionArrayTest.class);
|
jaroslav@477
|
71 |
}
|
jaroslav@477
|
72 |
}
|