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