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