/** {@inheritDoc} */ @Override public Object getObject(Scope scope) throws CodeUnderTestException { return scope.getObject(this); }
protected Collection<VariableReference> getAllVariables(Scope scope) { final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); return scope.getElements(targetClass); }
/** * <p> * getAllObjects * </p> * * @param scope * a {@link org.evosuite.testcase.execution.Scope} object. * @return a {@link java.util.Collection} object. */ protected Collection<Object> getAllObjects(Scope scope) { // TODO: Assignable classes and subclasses? final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); return scope.getObjects(targetClass); }
for (VariableReference vref : scope.getVariables()) { Object scope_object = scope.getObject(vref);
/** * Execute a test case on a new scope * * @param tc * a {@link org.evosuite.testcase.TestCase} object. * @return a {@link org.evosuite.testcase.execution.ExecutionResult} object. */ public ExecutionResult execute(TestCase tc, int timeout) { Scope scope = new Scope(); ExecutionResult result = execute(tc, scope, timeout); if (Properties.RESET_STATIC_FIELDS) { logger.debug("Resetting classes after execution"); ClassReInitializer.getInstance().reInitializeClassesAfterTestExecution(tc, result); } return result; }
/** * {@inheritDoc} * * Set the actual object represented by this variable in a given scope */ @Override public void setObject(Scope scope, Object value) throws CodeUnderTestException { scope.setObject(this, value); }
private Scope execute(TestCase tc) throws Exception{ Scope scope = new Scope(); for(Statement st : tc){ st.execute(scope,System.out); } return scope; }
/** {@inheritDoc} */ @Override public void setObject(Scope scope, Object value) throws CodeUnderTestException { scope.setObject(this, value); }
/** * {@inheritDoc} * * Return the actual object represented by this variable for a given scope */ @Override public Object getObject(Scope scope) throws CodeUnderTestException { return scope.getObject(this); }
protected Collection<Pair<VariableReference>> getAllVariablePairs(Scope scope) { Set<Pair<VariableReference>> pairs = new HashSet<Pair<VariableReference>>(); final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); List<VariableReference> objects = scope.getElements(targetClass); for (int i = 0; i < objects.size(); i++) { for (int j = i; j < objects.size(); j++) { pairs.add(new Pair<VariableReference>(objects.get(i), objects.get(j))); } } // for (VariableReference o1 : scope.getElements(Properties.getTargetClass())) { // for (VariableReference o2 : scope.getElements(o1.getVariableClass())) { // pairs.add(new Pair<VariableReference>(o1, o2)); // } // } return pairs; }
/** {@inheritDoc} */ @Override public Throwable execute(Scope scope, PrintStream out) throws IllegalArgumentException { try { Object o1 = leftOperand.getObject(scope); Object o2 = rightOperand.getObject(scope); switch (operator) { case EQUALS: if(Objects.equals(o1, o2)) { scope.setObject(retval, true); } else { scope.setObject(retval, false); } break; default: throw new UnsupportedOperationException("Method execute not implemented!"); } } catch(CodeUnderTestException e) { return e; } return null; }
/** * <p> * getAllObjectPairs * </p> * * @param scope * a {@link org.evosuite.testcase.execution.Scope} object. * @return a {@link java.util.Collection} object. */ protected Collection<Pair<Object>> getAllObjectPairs(Scope scope) { Set<Pair<Object>> pairs = new HashSet<Pair<Object>>(); Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); for (Object o1 : scope.getObjects(targetClass)) { for (Object o2 : scope.getObjects(o1.getClass())) { pairs.add(new Pair<Object>(o1, o2)); } } return pairs; }
/** {@inheritDoc} */ @Override public ContractViolation check(Statement statement, Scope scope, Throwable exception) { for(VariableReference var : getAllVariables(scope)) { Object object = scope.getObject(var); if (object == null) continue; // We do not want to call hashCode if it is the default implementation Class<?>[] parameters = {}; try { Method equalsMethod = object.getClass().getMethod("hashCode", parameters); if (equalsMethod.getDeclaringClass().equals(Object.class)) continue; } catch (SecurityException e1) { continue; } catch (NoSuchMethodException e1) { continue; } try { // hashCode must not throw an exception object.hashCode(); } catch (Throwable t) { if (!(t instanceof TimeoutExceeded)) return new ContractViolation(this, statement, t, var); } } return null; }
otherVariables.addAll(scope.getElements(parameterType)); for(int i = 0; i <= statement.getPosition(); i++) { for(VariableReference candidateVar : currentTest.getStatement(i).getVariableReferences()) {
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); }
for(VariableReference var : getAllVariables(scope)) { logger.debug("Current variable: "+var); Object object = scope.getObject(var);
int position = statement.getPosition(); for (VariableReference other : scope.getElements(var.getType())) { Object otherObject = other.getObject(scope);
for(VariableReference var : getAllVariables(scope)) { logger.debug("Current variable: "+var); Object object = scope.getObject(var); logger.debug("Current object: "+object); if (object == null)
for (VariableReference other : scope.getElements(var.getType())) { if (other == var) continue;