2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @summary Test for array cloning and slicing methods. 0N/A static int muzzle;
// if !=0, suppresses ("muzzles") messages 0N/A static int maxLen =
40;
// maximum length of test arrays 0N/A // very simple tests, mainly to test the framework itself 0N/A // negative test of testing framework: 0N/A // the following check should fail! 0N/A throw new Error(
"Should Not Reach Here");
0N/A // quick test of copyOfRange 0N/A // the framework: a fixed series of test values 0N/A /** Return a canonical test value of a desired index and type. 0N/A * The original test values are random ints. Derive other test 0N/A * values as follows: 0N/A * int tv = testValues[i] 0N/A * (C)tv C is byte, short, char, long, float, double 0N/A * (tv&1)!=0 C is boolean 0N/A * (Integer)tv C is Object and tv%16 != 0 0N/A * null C is Object and tv%16 == 0 0N/A * Integer.toHexString(tv) C is String and tv != 0 0N/A * null C is String and tv == 0 0N/A * are derived by ordinary Java coercions, except that boolean 0N/A * samples the LSB of the int value, and String is the hex numeral. 0N/A * (Also, the 0th String is null, and the 0th Object mod 16 is null, 0N/A * regardless of the original int test value.) 0N/A // Turn the canonical int to a float, boolean, String, whatever: 0N/A /** Build a test array of the given length, 0N/A * packed with a subsequence of the test values. 0N/A * The first element of the array is always testValue(0). 0N/A for (
int i =
0; i <
len; i++) {
0N/A /** Check that the given array has the required length. 0N/A * Check also that it is packed, up to firstNull, with 0N/A * a particular subsequence of the canonical test values. 0N/A * The subsequence must begin with a[0] == testValue(offset). 0N/A * At a[firstNull] and beyond, the array must contain null values. 0N/A // Note: asserts in here are not part of the test program. 0N/A // They verify the integrity of the test method itself. 0N/A // Check required length first. 0N/A // Typical comparison helper. Why isn't this a method somewhere. 0N/A // Exception-ignoring invoke function. 0N/A // version of assert() that runs unconditionally 0N/A /** Run about 10**5 distinct parameter combinations 0N/A * on copyOf and copyOfRange. Use all primitive types, 0N/A * and String and Object. 0N/A * Try to all critical values, looking for fencepost errors. 0N/A // Note: asserts in here are not part of the test program. 0N/A // They verify the integrity of the test method itself. 0N/A // b = Arrays.copyOf(a, j); 0N/A // r = Arrays.copyOfRange(a, i, j); 0N/A //System.out.println("case c="+c+" src="+src+" i="+i+" j="+j); 0N/A // Increment x by at least one. Increment by a little more unless 0N/A // it is near a critical value, either zero, crit1, or crit2. 0N/A assert(x <=
crit2);
// next1 or next2 must be the limit value 0N/A muzzle =
0;
// turn on print statements (affects failures only) 0N/A // test much larger arrays, more sparsely 0N/A // We must run all the our tests on each of 8 distinct primitive types, 0N/A // and two reference types (Object, String) for good measure. 0N/A // This would be a pain to write out by hand, statically typed. 0N/A // So, use reflection. Following are the tables of methods we use. 0N/A // (The initial simple tests exercise enough of the static typing 0N/A // features of the API to ensure that they compile as advertised.) 0N/A // This guy exercises the API based on a type-token. 0N/A // Note the static typing. 0N/A // This guy exercises the API based on a type-token. 0N/A // Note the static typing. 0N/A byte.
class,
short.
class,
int.
class,
long.
class,
0N/A char.
class,
float.
class,
double.
class,