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.CONSTANT_REFLECTION_PROVIDER;
  27 import static jdk.vm.ci.hotspot.test.TestHelper.DUMMY_CLASS_INSTANCE;
  28 
  29 import java.util.LinkedList;
  30 import java.util.List;
  31 import jdk.vm.ci.meta.JavaConstant;
  32 import org.testng.annotations.DataProvider;
  33 
  34 public class ReadArrayLengthDataProvider {
  35 
  36     public static List<Object> createListOfDummyArrays(int length) {
  37         List<Object> arrays = new LinkedList<>();
  38         arrays.add(new boolean[length]);
  39         arrays.add(new byte[length]);
  40         arrays.add(new short[length]);
  41         arrays.add(new char[length]);
  42         arrays.add(new int[length]);
  43         arrays.add(new long[length]);
  44         arrays.add(new float[length]);
  45         arrays.add(new double[length]);
  46         arrays.add(new Object[length]);
  47         arrays.add(new boolean[length][2]);
  48         arrays.add(new byte[length][2]);
  49         arrays.add(new short[length][2]);
  50         arrays.add(new char[length][2]);
  51         arrays.add(new int[length][2]);
  52         arrays.add(new long[length][2]);
  53         arrays.add(new float[length][2]);
  54         arrays.add(new double[length][2]);
  55         arrays.add(new Object[length][2]);
  56         return arrays;
  57     }
  58 
  59     @DataProvider(name = "readArrayLengthDataProvider")
  60     public static Object[][] readArrayLengthDataProvider() {
  61         LinkedList<Object[]> cfgSet = new LinkedList<>();
  62         for (int i : new int[]{0, 1, 42}) {
  63             createListOfDummyArrays(i).stream().forEach((array) -> {
  64                 cfgSet.add(new Object[]{CONSTANT_REFLECTION_PROVIDER.forObject(array), i});
  65             });
  66         }
  67         cfgSet.add(new Object[]{null, null});
  68         cfgSet.add(new Object[]{JavaConstant.NULL_POINTER, null});
  69         cfgSet.add(new Object[]{CONSTANT_REFLECTION_PROVIDER.forObject(DUMMY_CLASS_INSTANCE.intField), null});
  70         cfgSet.add(new Object[]{JavaConstant.forInt(DUMMY_CLASS_INSTANCE.intField), null});
  71         return cfgSet.toArray(new Object[0][0]);
  72     }
  73 }