use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class SymbolicObserver method pushParameterList.
private void pushParameterList(List<VariableReference> parameters, Scope scope, String desc) {
Type[] argTypes = Type.getArgumentTypes(desc);
for (int i = 0; i < parameters.size(); i++) {
VariableReference varRef = parameters.get(i);
Type argType = argTypes[i];
ReferenceExpressionPair readResult = this.read(varRef, scope);
Expression<?> symb_expr = readResult.getExpression();
ReferenceExpression symb_ref = readResult.getReference();
if (isValue(argType)) {
if (symb_expr instanceof RealValue) {
RealValue realExpr = (RealValue) symb_expr;
if (isFp32(argType)) {
env.topFrame().operandStack.pushFp32(realExpr);
} else if (isFp64(argType)) {
env.topFrame().operandStack.pushFp64(realExpr);
} else if (isBv32(argType)) {
int concV = realExpr.getConcreteValue().intValue();
RealToIntegerCast castExpr = new RealToIntegerCast(realExpr, (long) concV);
env.topFrame().operandStack.pushBv32(castExpr);
} else if (isBv64(argType)) {
long concV = realExpr.getConcreteValue().longValue();
RealToIntegerCast castExpr = new RealToIntegerCast(realExpr, concV);
env.topFrame().operandStack.pushBv64(castExpr);
} else {
/* unreachable code */
}
} else if (symb_expr instanceof IntegerValue) {
IntegerValue integerExpr = (IntegerValue) symb_expr;
if (isBv32(argType)) {
env.topFrame().operandStack.pushBv32(integerExpr);
} else if (isBv64(argType)) {
env.topFrame().operandStack.pushBv64(integerExpr);
} else if (isFp32(argType)) {
float concV = integerExpr.getConcreteValue().floatValue();
IntegerToRealCast castExpr = new IntegerToRealCast(integerExpr, (double) concV);
env.topFrame().operandStack.pushFp32(castExpr);
} else if (isFp64(argType)) {
double concV = integerExpr.getConcreteValue().doubleValue();
IntegerToRealCast castExpr = new IntegerToRealCast(integerExpr, concV);
env.topFrame().operandStack.pushFp64(castExpr);
} else {
/* unreachable code */
}
} else {
if (symb_ref.getConcreteValue() == null) {
// although this will lead in the JVM to a NPE, we push
// a dummy
// value to prevent the DSE VM from crashing
pushDummyValue(argType);
} else {
// auto unboxing reference
ReferenceConstant non_null_symb_ref = (ReferenceConstant) symb_ref;
Object conc_object = scope.getObject(varRef);
Expression<?> unboxed_expr = unboxReference(argType, conc_object, non_null_symb_ref);
pushValue(argType, unboxed_expr);
}
}
} else {
ReferenceExpression ref = readResult.getReference();
env.topFrame().operandStack.pushRef(ref);
}
}
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(FunctionalMockStatement statement, Scope scope) {
Type returnType = Type.getType(statement.getReturnClass());
VariableReference varRef = statement.getReturnValue();
String varName = varRef.getName();
try {
if (varRef.getType().equals(void.class)) {
} else if (returnType.equals(Type.INT_TYPE) || returnType.equals(Type.BOOLEAN_TYPE) || returnType.equals(Type.DOUBLE_TYPE) || returnType.equals(Type.FLOAT_TYPE) || returnType.equals(Type.LONG_TYPE) || returnType.equals(Type.SHORT_TYPE) || returnType.equals(Type.BYTE_TYPE) || returnType.equals(Type.CHAR_TYPE)) {
throw new EvosuiteError("mocking of primitive types is not supported!");
} else {
Object res = varRef.getObject(scope);
ReferenceExpression ref = env.heap.getReference(res);
if (res != null && res instanceof String) {
String string = (String) res;
ReferenceConstant newStringRef = (ReferenceConstant) env.heap.getReference(string);
StringValue str_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, newStringRef, string);
symb_references.put(varName, newStringRef);
symb_expressions.put(varName, str_expr);
} else {
symb_references.put(varName, ref);
if (res != null && isWrapper(res)) {
ReferenceConstant nonNullRef = (ReferenceConstant) ref;
Expression<?> expr = findOrCreate(res, nonNullRef);
symb_expressions.put(varName, expr);
}
}
}
} catch (CodeUnderTestException e) {
throw new RuntimeException(e);
}
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(StringPrimitiveStatement statement, Scope scope) {
String valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
StringVariable stringVariable = buildStringVariable(varRefName, valueOf);
symb_expressions.put(varRefName, stringVariable);
String string_instance;
try {
String string_interned = (String) varRef.getObject(scope);
string_instance = new String(string_interned);
scope.setObject(varRef, string_instance);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant stringRef = newStringReference(string_instance, stringVariable);
symb_references.put(varRefName, stringRef);
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(AssignmentStatement s, Scope scope) {
VariableReference lhs = s.getReturnValue();
VariableReference rhs = s.getValue();
ReferenceExpressionPair readResult = read(rhs, scope);
if (lhs instanceof FieldReference) {
writeField((FieldReference) lhs, readResult, scope);
} else if (lhs instanceof ArrayIndex) {
writeArray((ArrayIndex) lhs, readResult, scope);
} else {
writeVariable(lhs, readResult);
}
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(ClassPrimitiveStatement s, Scope scope) {
VariableReference varRef = s.getReturnValue();
Class<?> concrete_reference = s.getValue();
String varName = varRef.getName();
ReferenceExpression symb_ref = env.heap.getReference(concrete_reference);
symb_references.put(varName, symb_ref);
}
Aggregations