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();
}
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);
}
}
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();
}
Aggregations