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 package org.graalvm.compiler.jtt.reflect;
  24 
  25 import org.junit.Test;
  26 
  27 import org.graalvm.compiler.jtt.JTTTest;
  28 
  29 /*
  30  */
  31 public class Field_set02 extends JTTTest {
  32 
  33     private static class TestClass {
  34         public byte byteField;
  35         public short shortField;
  36         public char charField;
  37         public int intField;
  38         public long longField;
  39         public float floatField;
  40         public double doubleField;
  41         public boolean booleanField;
  42     }
  43 
  44     private static final TestClass object = new TestClass();
  45 
  46     public static boolean test(int arg) throws NoSuchFieldException, IllegalAccessException {
  47         if (arg == 0) {
  48             TestClass.class.getField("byteField").set(object, Byte.valueOf((byte) 11));
  49             return object.byteField == 11;
  50         } else if (arg == 1) {
  51             TestClass.class.getField("shortField").set(object, Short.valueOf((short) 12));
  52             return object.shortField == 12;
  53         } else if (arg == 2) {
  54             TestClass.class.getField("charField").set(object, Character.valueOf((char) 13));
  55             return object.charField == 13;
  56         } else if (arg == 3) {
  57             TestClass.class.getField("intField").set(object, Integer.valueOf(14));
  58             return object.intField == 14;
  59         } else if (arg == 4) {
  60             TestClass.class.getField("longField").set(object, Long.valueOf(15L));
  61             return object.longField == 15;
  62         } else if (arg == 5) {
  63             TestClass.class.getField("floatField").set(object, Float.valueOf(16));
  64             return object.floatField == 16;
  65         } else if (arg == 6) {
  66             TestClass.class.getField("doubleField").set(object, Double.valueOf(17));
  67             return object.doubleField == 17;
  68         } else if (arg == 7) {
  69             TestClass.class.getField("booleanField").set(object, true);
  70             return object.booleanField == true;
  71         }
  72         return false;
  73     }
  74 
  75     @Test
  76     public void run0() throws Throwable {
  77         runTest("test", 0);
  78     }
  79 
  80     @Test
  81     public void run1() throws Throwable {
  82         runTest("test", 1);
  83     }
  84 
  85     @Test
  86     public void run2() throws Throwable {
  87         runTest("test", 2);
  88     }
  89 
  90     @Test
  91     public void run3() throws Throwable {
  92         runTest("test", 3);
  93     }
  94 
  95     @Test
  96     public void run4() throws Throwable {
  97         runTest("test", 4);
  98     }
  99 
 100     @Test
 101     public void run5() throws Throwable {
 102         runTest("test", 5);
 103     }
 104 
 105     @Test
 106     public void run6() throws Throwable {
 107         runTest("test", 6);
 108     }
 109 
 110     @Test
 111     public void run7() throws Throwable {
 112         runTest("test", 7);
 113     }
 114 
 115     @Test
 116     public void run8() throws Throwable {
 117         runTest("test", 8);
 118     }
 119 
 120 }