1 /* 2 * Copyright (c) 2016, 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 package jdk.vm.ci.hotspot.test; 25 26 import static jdk.vm.ci.hotspot.test.TestHelper.ARRAYS_MAP; 27 import static jdk.vm.ci.hotspot.test.TestHelper.ARRAY_ARRAYS_MAP; 28 import static jdk.vm.ci.hotspot.test.TestHelper.CONSTANT_REFLECTION_PROVIDER; 29 import static jdk.vm.ci.hotspot.test.TestHelper.DUMMY_CLASS_CONSTANT; 30 import static jdk.vm.ci.hotspot.test.TestHelper.DUMMY_CLASS_INSTANCE; 31 import static jdk.vm.ci.hotspot.test.TestHelper.STABLE_ARRAYS_MAP; 32 import static jdk.vm.ci.hotspot.test.TestHelper.STABLE_ARRAY_ARRAYS_MAP; 33 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_STABLE_FIELDS_MAP; 34 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_FIELDS_MAP; 35 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_FIELDS_MAP; 36 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_STABLE_FIELDS_MAP; 37 38 import java.util.LinkedList; 39 import jdk.vm.ci.meta.JavaConstant; 40 import org.testng.annotations.DataProvider; 41 42 public class ReadFieldValueDataProvider { 43 44 @DataProvider(name = "readFieldValueDataProvider") 45 public static Object[][] readFieldValueDataProvider() { 46 LinkedList<Object[]> cfgSet = new LinkedList<>(); 47 // Testing instance non-stable fields 48 INSTANCE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> { 49 cfgSet.add(new Object[]{instanceField.getKey(), 50 DUMMY_CLASS_CONSTANT, 51 instanceField.getValue()}); 52 }); 53 // Testing static non-stable fields with null as receiver 54 STATIC_FIELDS_MAP.entrySet().stream().forEach((staticField) -> { 55 cfgSet.add(new Object[]{staticField.getKey(), null, staticField.getValue()}); 56 }); 57 // Testing static non-stable fields with JavaConstant.NULL_POINTER as receiver 58 STATIC_FIELDS_MAP.entrySet().stream().forEach((staticField) -> { 59 cfgSet.add(new Object[]{staticField.getKey(), 60 JavaConstant.NULL_POINTER, 61 staticField.getValue()}); 62 }); 63 // Testing instance stable fields 64 INSTANCE_STABLE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> { 65 cfgSet.add(new Object[]{instanceField.getKey(), 66 DUMMY_CLASS_CONSTANT, 67 instanceField.getValue()}); 68 }); 69 // Testing static stable fields with null as receiver 70 STATIC_STABLE_FIELDS_MAP.entrySet().stream().forEach((staticField) -> { 71 cfgSet.add(new Object[]{staticField.getKey(), null, staticField.getValue()}); 72 }); 73 // Testing static stable fields with JavaConstant.NULL_POINTER as receiver 74 STATIC_STABLE_FIELDS_MAP.entrySet().stream().forEach((staticField) -> { 75 cfgSet.add(new Object[]{staticField.getKey(), 76 JavaConstant.NULL_POINTER, 77 staticField.getValue()}); 78 }); 79 // Testing instance non-stable array fields 80 ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> { 81 cfgSet.add(new Object[]{instanceField.getKey(), 82 DUMMY_CLASS_CONSTANT, 83 instanceField.getValue()}); 84 }); 85 // Testing instance stable array fields 86 STABLE_ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> { 87 cfgSet.add(new Object[]{instanceField.getKey(), 88 DUMMY_CLASS_CONSTANT, 89 instanceField.getValue()}); 90 }); 91 // Testing instance non-stable array-of-array fields 92 ARRAY_ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> { 93 cfgSet.add(new Object[]{instanceField.getKey(), 94 DUMMY_CLASS_CONSTANT, 95 instanceField.getValue()}); 96 }); 97 // Testing instance stable array-of-array fields 98 STABLE_ARRAY_ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> { 99 cfgSet.add(new Object[]{instanceField.getKey(), 100 DUMMY_CLASS_CONSTANT, 101 instanceField.getValue()}); 102 }); 103 // Testing instance fields with JavaConstant.NULL_POINTER as receiver 104 INSTANCE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> { 105 cfgSet.add(new Object[]{instanceField.getKey(), JavaConstant.NULL_POINTER, null}); 106 }); 107 // Testing instance fields with an object that does not have the field 108 INSTANCE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> { 109 cfgSet.add(new Object[]{instanceField.getKey(), 110 CONSTANT_REFLECTION_PROVIDER.forObject(DUMMY_CLASS_INSTANCE.objectField), 111 null}); 112 }); 113 return cfgSet.toArray(new Object[0][0]); 114 } 115 116 @DataProvider(name = "readFieldValueNegativeDataProvider") 117 public static Object[][] readFieldValueNegativeDataProvider() { 118 LinkedList<Object[]> cfgSet = new LinkedList<>(); 119 // Testing instance fields with null as receiver 120 INSTANCE_FIELDS_MAP.keySet().stream().forEach((instanceField) -> { 121 cfgSet.add(new Object[]{instanceField, null}); 122 }); 123 // Testing null as a field argument 124 cfgSet.add(new Object[]{null, null}); 125 return cfgSet.toArray(new Object[0][0]); 126 } 127 }