1 /*
2  * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 
25 package org.graalvm.compiler.jtt.reflect;
26 
27 import java.lang.reflect.Field;
28 
29 import org.junit.Test;
30 
31 import org.graalvm.compiler.jtt.JTTTest;
32 
33 /*
34  */
35 public class Field_get03 extends JTTTest {
36 
37     private static Field ByteField;
38     private static Field ShortField;
39     private static Field CharField;
40     private static Field IntField;
41     private static Field LongField;
42     private static Field FloatField;
43     private static Field DoubleField;
44     private static Field BooleanField;
45 
46     static {
47         try {
48             ByteField = TestClass.class.getField("byteField");
49             ShortField = TestClass.class.getField("shortField");
50             CharField = TestClass.class.getField("charField");
51             IntField = TestClass.class.getField("intField");
52             LongField = TestClass.class.getField("longField");
53             FloatField = TestClass.class.getField("floatField");
54             DoubleField = TestClass.class.getField("doubleField");
55             BooleanField = TestClass.class.getField("booleanField");
56         } catch (SecurityException | NoSuchFieldException e) {
57             throw new RuntimeException(e);
58         }
59     }
60 
61     private static class TestClass {
62         public final byte byteField = 11;
63         public final short shortField = 12;
64         public final char charField = 13;
65         public final int intField = 14;
66         public final long longField = 15;
67         public final float floatField = 16;
68         public final double doubleField = 17;
69         public final boolean booleanField = true;
70     }
71 
72     private static final TestClass object = new TestClass();
73 
test(int arg)74     public static boolean test(int arg) throws IllegalAccessException {
75         if (arg == 0) {
76             return ByteField.get(object).equals(object.byteField);
77         } else if (arg == 1) {
78             return ShortField.get(object).equals(object.shortField);
79         } else if (arg == 2) {
80             return CharField.get(object).equals(object.charField);
81         } else if (arg == 3) {
82             return IntField.get(object).equals(object.intField);
83         } else if (arg == 4) {
84             return LongField.get(object).equals(object.longField);
85         } else if (arg == 5) {
86             return FloatField.get(object).equals(object.floatField);
87         } else if (arg == 6) {
88             return DoubleField.get(object).equals(object.doubleField);
89         } else if (arg == 7) {
90             return BooleanField.get(object).equals(object.booleanField);
91         }
92         return false;
93     }
94 
95     @Test
run0()96     public void run0() throws Throwable {
97         runTest("test", 0);
98     }
99 
100     @Test
run1()101     public void run1() throws Throwable {
102         runTest("test", 1);
103     }
104 
105     @Test
run2()106     public void run2() throws Throwable {
107         runTest("test", 2);
108     }
109 
110     @Test
run3()111     public void run3() throws Throwable {
112         runTest("test", 3);
113     }
114 
115     @Test
run4()116     public void run4() throws Throwable {
117         runTest("test", 4);
118     }
119 
120     @Test
run5()121     public void run5() throws Throwable {
122         runTest("test", 5);
123     }
124 
125     @Test
run6()126     public void run6() throws Throwable {
127         runTest("test", 6);
128     }
129 
130     @Test
run7()131     public void run7() throws Throwable {
132         runTest("test", 7);
133     }
134 
135     @Test
run8()136     public void run8() throws Throwable {
137         runTest("test", 8);
138     }
139 
140 }
141