Search in sources :

Example 1 with TokenizerExpr

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

the class NextToken method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_receiver = this.getSymbReceiver();
    StringTokenizer conc_receiver = (StringTokenizer) this.getConcReceiver();
    TokenizerExpr tokenizerExpr = (TokenizerExpr) env.heap.getField(Types.JAVA_UTIL_STRING_TOKENIZER, SymbolicHeap.$STRING_TOKENIZER_VALUE, conc_receiver, symb_receiver);
    if (tokenizerExpr != null && tokenizerExpr.containsSymbolicVariable()) {
        ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
        String conc_ret_val = (String) this.getConcRetVal();
        // create new NEXT_TOKEN string expression
        StringNextTokenExpr string_next_token_expr = new StringNextTokenExpr(tokenizerExpr, conc_ret_val);
        env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, string_next_token_expr);
        // update StringTokenizer's symbolic state
        NextTokenizerExpr nextTokenizerExpr = new NextTokenizerExpr(tokenizerExpr);
        env.heap.putField(Types.JAVA_UTIL_STRING_TOKENIZER, SymbolicHeap.$STRING_TOKENIZER_VALUE, conc_receiver, symb_receiver, nextTokenizerExpr);
    }
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) NextTokenizerExpr(org.evosuite.symbolic.expr.token.NextTokenizerExpr) StringTokenizer(java.util.StringTokenizer) StringNextTokenExpr(org.evosuite.symbolic.expr.token.StringNextTokenExpr) NextTokenizerExpr(org.evosuite.symbolic.expr.token.NextTokenizerExpr) TokenizerExpr(org.evosuite.symbolic.expr.token.TokenizerExpr)

Example 2 with TokenizerExpr

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

the class DistanceCalculator method getStringDistance.

private static double getStringDistance(HasMoreTokensExpr hasMoreTokensExpr) {
    TokenizerExpr tokenizerExpr = hasMoreTokensExpr.getTokenizerExpr();
    StringValue string = tokenizerExpr.getString();
    StringValue delimiter = tokenizerExpr.getDelimiter();
    int nextTokenCount = tokenizerExpr.getNextTokenCount();
    ExpressionExecutor exprExecutor = new ExpressionExecutor();
    String concreteString = (String) string.accept(exprExecutor, null);
    String concreteDelimiter = (String) delimiter.accept(exprExecutor, null);
    if (concreteString.length() < concreteDelimiter.length() * nextTokenCount) {
        // nextToken operations
        return Double.MAX_VALUE;
    }
    StringTokenizer tokenizer = new StringTokenizer(concreteString, concreteDelimiter);
    Vector<String> tokens = new Vector<String>();
    while (tokenizer.hasMoreTokens()) {
        tokens.add(tokenizer.nextToken());
    }
    if (tokens.size() > nextTokenCount) {
        // we already have enough tokens to make n true
        return 0;
    } else {
        return StrEquals("", concreteDelimiter);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) StringValue(org.evosuite.symbolic.expr.str.StringValue) TokenizerExpr(org.evosuite.symbolic.expr.token.TokenizerExpr) Vector(java.util.Vector)

Example 3 with TokenizerExpr

use of org.evosuite.symbolic.expr.token.TokenizerExpr 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

StringTokenizer (java.util.StringTokenizer)3 TokenizerExpr (org.evosuite.symbolic.expr.token.TokenizerExpr)3 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)2 Vector (java.util.Vector)1 StringValue (org.evosuite.symbolic.expr.str.StringValue)1 HasMoreTokensExpr (org.evosuite.symbolic.expr.token.HasMoreTokensExpr)1 NextTokenizerExpr (org.evosuite.symbolic.expr.token.NextTokenizerExpr)1 StringNextTokenExpr (org.evosuite.symbolic.expr.token.StringNextTokenExpr)1