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