8057707: TEST library enhancement in lib/testlibrary/jsr292/com/oracle/testlibrary/jsr292/Helper.java

Reviewed-by: iignatyev, vlivanov
This commit is contained in:
Konstantin Shefov 2014-09-12 22:33:09 +04:00
parent 657d8c6e77
commit 9e30841d28
2 changed files with 49 additions and 40 deletions

View File

@ -42,6 +42,7 @@ import java.util.function.Supplier;
public class CatchExceptionTest {
private static final List<Class<?>> ARGS_CLASSES;
protected static final int MAX_ARITY = Helper.MAX_ARITY - 1;
static {
Class<?> classes[] = {
Object.class,
@ -52,11 +53,8 @@ public class CatchExceptionTest {
double[].class,
String.class,
};
List<Class<?>> list = new ArrayList<>(MAX_ARITY);
for (int i = 0; i < MAX_ARITY; ++i) {
list.add(classes[Helper.RNG.nextInt(classes.length)]);
}
ARGS_CLASSES = Collections.unmodifiableList(list);
ARGS_CLASSES = Collections.unmodifiableList(
Helper.randomClasses(classes, MAX_ARITY));
}
private final TestCase testCase;
@ -66,7 +64,6 @@ public class CatchExceptionTest {
private int dropped;
private MethodHandle thrower;
public CatchExceptionTest(TestCase testCase, final boolean isVararg, final int argsCount,
final int catchDrops) {
this.testCase = testCase;
@ -107,37 +104,7 @@ public class CatchExceptionTest {
}
private List<Class<?>> getThrowerParams(boolean isVararg, int argsCount) {
boolean unmodifiable = true;
List<Class<?>> classes;
classes = ARGS_CLASSES.subList(0,
Math.min(argsCount, (MAX_ARITY / 2) - 1));
int extra = 0;
if (argsCount >= MAX_ARITY / 2) {
classes = new ArrayList<>(classes);
unmodifiable = false;
extra = (int) classes.stream().filter(Helper::isDoubleCost).count();
int i = classes.size();
while (classes.size() + extra < argsCount) {
Class<?> aClass = ARGS_CLASSES.get(i);
if (Helper.isDoubleCost(aClass)) {
++extra;
if (classes.size() + extra >= argsCount) {
break;
}
}
classes.add(aClass);
}
}
if (isVararg && classes.size() > 0) {
if (unmodifiable) {
classes = new ArrayList<>(classes);
}
int last = classes.size() - 1;
Class<?> aClass = classes.get(classes.size() - 1);
aClass = Array.newInstance(aClass, 2).getClass();
classes.set(last, aClass);
}
return classes;
return Helper.getParams(ARGS_CLASSES, isVararg, argsCount);
}

View File

@ -52,7 +52,7 @@ public class Helper {
public static final long TEST_LIMIT;
static {
String str = System.getProperty("testLimit");
TEST_LIMIT = str != null ? Long.parseUnsignedLong(str) : 2_000L;
TEST_LIMIT = str != null ? Long.parseUnsignedLong(str) : 2000L;
System.out.printf("-DtestLimit=%d%n", TEST_LIMIT);
}
@ -116,6 +116,48 @@ public class Helper {
return size <= lag ? null : calledLog.get(size - lag - 1);
}
public static List<Class<?>> randomClasses(Class<?>[] classes, int size) {
List<Class<?>> result = new ArrayList<>(size);
for (int i = 0; i < size; ++i) {
result.add(classes[RNG.nextInt(classes.length)]);
}
return result;
}
public static List<Class<?>> getParams(List<Class<?>> classes,
boolean isVararg, int argsCount) {
boolean unmodifiable = true;
List<Class<?>> result = classes.subList(0,
Math.min(argsCount, (MAX_ARITY / 2) - 1));
int extra = 0;
if (argsCount >= MAX_ARITY / 2) {
result = new ArrayList<>(result);
unmodifiable = false;
extra = (int) result.stream().filter(Helper::isDoubleCost).count();
int i = result.size();
while (result.size() + extra < argsCount) {
Class<?> aClass = classes.get(i);
if (Helper.isDoubleCost(aClass)) {
++extra;
if (result.size() + extra >= argsCount) {
break;
}
}
result.add(aClass);
}
}
if (isVararg && result.size() > 0) {
if (unmodifiable) {
result = new ArrayList<>(result);
}
int last = result.size() - 1;
Class<?> aClass = result.get(last);
aClass = Array.newInstance(aClass, 2).getClass();
result.set(last, aClass);
}
return result;
}
public static MethodHandle addTrailingArgs(MethodHandle target, int nargs,
List<Class<?>> classes) {
int targetLen = target.type().parameterCount();
@ -230,7 +272,7 @@ public class Helper {
return randomArgs(params.toArray(new Class<?>[params.size()]));
}
private static Object castToWrapper(Object value, Class<?> dst) {
public static Object castToWrapper(Object value, Class<?> dst) {
Object wrap = null;
if (value instanceof Number) {
wrap = castToWrapperOrNull(((Number) value).longValue(), dst);
@ -268,7 +310,7 @@ public class Helper {
if (dst == byte.class || dst == Byte.class) {
return (byte) (value);
}
if (dst == boolean.class || dst == boolean.class) {
if (dst == boolean.class || dst == Boolean.class) {
return ((value % 29) & 1) == 0;
}
return null;