use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class Matcher_Matches method executeFunction.
@Override
public Object executeFunction() {
Matcher conc_matcher = (Matcher) this.getConcReceiver();
ReferenceConstant symb_matcher = (ReferenceConstant) this.getSymbReceiver();
boolean res = this.getConcBooleanRetVal();
String conc_regex = conc_matcher.pattern().pattern();
StringValue symb_input = (StringValue) env.heap.getField(Types.JAVA_UTIL_REGEX_MATCHER, SymbolicHeap.$MATCHER_INPUT, conc_matcher, symb_matcher);
if (symb_input != null && symb_input.containsSymbolicVariable()) {
int concrete_value = res ? 1 : 0;
StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(conc_regex);
StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, symb_input, (long) concrete_value);
return strComp;
} else {
return this.getSymbIntegerRetVal();
}
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class EndsWith method executeFunction.
@Override
public Object executeFunction() {
String conc_left = (String) this.getConcReceiver();
ReferenceConstant symb_left = this.getSymbReceiver();
StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
String conc_right = (String) this.getConcArgument(0);
ReferenceConstant symb_right = (ReferenceConstant) this.getSymbArgument(0);
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right, symb_right, conc_right);
boolean res = this.getConcBooleanRetVal();
if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
int conV = res ? 1 : 0;
StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.ENDSWITH, right_expr, (long) conV);
return strBExpr;
} else {
return this.getSymbIntegerRetVal();
}
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class EqualsIgnoreCase method executeFunction.
@Override
public Object executeFunction() {
String conc_left = (String) this.getConcReceiver();
ReferenceConstant symb_left = this.getSymbReceiver();
String conc_right = (String) this.getConcArgument(0);
ReferenceExpression symb_right = this.getSymbArgument(0);
boolean res = this.getConcBooleanRetVal();
StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
if (symb_right instanceof ReferenceConstant && conc_right != null) {
ReferenceConstant ref_constant_right = (ReferenceConstant) symb_right;
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right, ref_constant_right, conc_right);
if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
int conV = res ? 1 : 0;
StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.EQUALSIGNORECASE, right_expr, (long) conV);
return strBExpr;
}
}
return this.getSymbIntegerRetVal();
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class Matches method executeFunction.
@Override
public Object executeFunction() {
// receiver
ReferenceConstant symb_receiver = this.getSymbReceiver();
String conc_receiver = (String) this.getConcReceiver();
// argument
String conc_argument = (String) this.getConcArgument(0);
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
// return val
boolean res = this.getConcBooleanRetVal();
if (right_expr.containsSymbolicVariable()) {
StringConstant left_expr = ExpressionFactory.buildNewStringConstant(conc_argument);
int conV = res ? 1 : 0;
StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.PATTERNMATCHES, right_expr, (long) conV);
return strBExpr;
}
return this.getSymbIntegerRetVal();
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class DistanceCalculator method visit.
@Override
public Object visit(StringConstraint n, Void arg) {
Expression<?> exprLeft = n.getLeftOperand();
Comparator cmpr = n.getComparator();
double distance = 0.0;
if (exprLeft instanceof StringBinaryComparison) {
StringBinaryComparison scTarget = (StringBinaryComparison) exprLeft;
distance = getStringDistance(scTarget);
log.debug("Calculating distance of constraint " + n);
} else if (exprLeft instanceof StringMultipleComparison) {
StringMultipleComparison scTarget = (StringMultipleComparison) exprLeft;
distance = getStringDistance(scTarget);
log.debug("Calculating distance of constraint " + n);
} else if (exprLeft instanceof HasMoreTokensExpr) {
HasMoreTokensExpr hasMoreTokensExpr = (HasMoreTokensExpr) exprLeft;
distance = getStringDistance(hasMoreTokensExpr);
log.debug("Calculating distance of constraint " + n);
} else {
assert (false) : "Invalid string comparison";
}
assert (((Long) n.getRightOperand().getConcreteValue()).intValue() == 0);
if (cmpr == Comparator.NE) {
return distance;
} else {
// if not satisfied Long.MAX_VALUE else
return distance > 0 ? 0.0 : Double.MAX_VALUE;
}
}
Aggregations