Search in sources :

Example 1 with HasMoreTokensExpr

use of org.evosuite.symbolic.expr.token.HasMoreTokensExpr in project evosuite by EvoSuite.

the class StringAVM method getTokenDelimiters.

private static Set<StringValue> getTokenDelimiters(Collection<Constraint<?>> constraints) {
    Set<StringValue> delimiters = new HashSet<StringValue>();
    for (Constraint<?> constraint : constraints) {
        if (constraint instanceof StringConstraint) {
            StringConstraint stringConstraint = (StringConstraint) constraint;
            if (stringConstraint.getLeftOperand() instanceof HasMoreTokensExpr) {
                HasMoreTokensExpr hasMoreTokensExpr = (HasMoreTokensExpr) stringConstraint.getLeftOperand();
                StringValue delimiter = hasMoreTokensExpr.getTokenizerExpr().getDelimiter();
                delimiters.add(delimiter);
            }
        }
    }
    return delimiters;
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) HasMoreTokensExpr(org.evosuite.symbolic.expr.token.HasMoreTokensExpr) StringValue(org.evosuite.symbolic.expr.str.StringValue) HashSet(java.util.HashSet)

Example 2 with HasMoreTokensExpr

use of org.evosuite.symbolic.expr.token.HasMoreTokensExpr 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;
    }
}
Also used : StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) HasMoreTokensExpr(org.evosuite.symbolic.expr.token.HasMoreTokensExpr) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison)

Example 3 with HasMoreTokensExpr

use of org.evosuite.symbolic.expr.token.HasMoreTokensExpr in project evosuite by EvoSuite.

the class HasMoreTokens method executeFunction.

@Override
public Object executeFunction() {
    StringTokenizer conc_tokenizer = (StringTokenizer) this.getConcReceiver();
    ReferenceConstant symb_tokenizer = this.getSymbReceiver();
    boolean res = this.getConcBooleanRetVal();
    TokenizerExpr tokenizerExpr = (TokenizerExpr) env.heap.getField(Types.JAVA_UTIL_STRING_TOKENIZER, SymbolicHeap.$STRING_TOKENIZER_VALUE, conc_tokenizer, symb_tokenizer);
    if (tokenizerExpr != null && tokenizerExpr.containsSymbolicVariable()) {
        HasMoreTokensExpr hasMoreTokenExpr = new HasMoreTokensExpr(tokenizerExpr, (long) (res ? 1L : 0L));
        return hasMoreTokenExpr;
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringTokenizer(java.util.StringTokenizer) HasMoreTokensExpr(org.evosuite.symbolic.expr.token.HasMoreTokensExpr) TokenizerExpr(org.evosuite.symbolic.expr.token.TokenizerExpr)

Aggregations

HasMoreTokensExpr (org.evosuite.symbolic.expr.token.HasMoreTokensExpr)3 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)1 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)1 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)1 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)1 StringValue (org.evosuite.symbolic.expr.str.StringValue)1 TokenizerExpr (org.evosuite.symbolic.expr.token.TokenizerExpr)1