Search in sources :

Example 1 with EvoSuiteURL

use of org.evosuite.runtime.testdata.EvoSuiteURL in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(UrlPrimitiveStatement s, Scope scope) {
    EvoSuiteURL conc_url = s.getValue();
    VariableReference varRef = s.getReturnValue();
    String varRefName = varRef.getName();
    ReferenceExpression urlRef;
    if (conc_url == null) {
        urlRef = env.heap.getReference(null);
        if (urlRef.getConcreteValue() != null) {
            throw new IllegalStateException("Expected null concrete value");
        }
    } else {
        urlRef = (ReferenceConstant) env.heap.getReference(conc_url);
        if (urlRef.getConcreteValue() == null) {
            throw new IllegalStateException("Expected non-null concrete value");
        }
    }
    symb_references.put(varRefName, urlRef);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) EvoSuiteURL(org.evosuite.runtime.testdata.EvoSuiteURL) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 2 with EvoSuiteURL

use of org.evosuite.runtime.testdata.EvoSuiteURL in project evosuite by EvoSuite.

the class ConcolicExecutionEnvironmentTest method buildTestCaseWithURL.

private static DefaultTestCase buildTestCaseWithURL() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder tc = new TestCaseBuilder();
    // int int0 = 10;
    VariableReference int0 = tc.appendIntPrimitive(10);
    // String urlString = "http://evosuite.org/hello.txt";
    VariableReference urlStringVarRef = tc.appendStringPrimitive("http://evosuite.org/hello.txt");
    // MockURL mockURL0 = MockURL.URL(urlString);
    Method urlMethod = MockURL.class.getMethod("URL", String.class);
    VariableReference mockURLVarRef = tc.appendMethod(null, urlMethod, urlStringVarRef);
    // EvoSuiteURL evosuiteURL = new EvoSuiteURL();
    Constructor<EvoSuiteURL> evoSuiteURLCtor = EvoSuiteURL.class.getConstructor(String.class);
    VariableReference evosuiteURL = tc.appendConstructor(evoSuiteURLCtor, urlStringVarRef);
    // String string0 = "<<FILE CONTENT>>"
    VariableReference string0VarRef = tc.appendStringPrimitive("<<FILE CONTENT>>");
    // NetworkHandling.createRemoteTextFile(url, string0)
    Method appendStringToFileMethod = NetworkHandling.class.getMethod("createRemoteTextFile", EvoSuiteURL.class, String.class);
    tc.appendMethod(null, appendStringToFileMethod, evosuiteURL, string0VarRef);
    // TestCaseWithURL testCaseWithURL0 = new TestCaseWithURL();
    Constructor<TestCaseWithURL> ctor = TestCaseWithURL.class.getConstructor();
    VariableReference testCaseWithURLVarRef = tc.appendConstructor(ctor);
    // String ret_val = dseWithFile0.test((URL) mockURL0);
    Method testMethod = TestCaseWithURL.class.getMethod("test", URL.class);
    tc.appendMethod(testCaseWithURLVarRef, testMethod, mockURLVarRef);
    // DseWithFile.isiZero(int0)
    Method isZeroMethod = TestCaseWithFile.class.getMethod("isZero", int.class);
    tc.appendMethod(null, isZeroMethod, int0);
    return tc.getDefaultTestCase();
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) EvoSuiteURL(org.evosuite.runtime.testdata.EvoSuiteURL) Method(java.lang.reflect.Method) TestCaseWithURL(com.examples.with.different.packagename.concolic.TestCaseWithURL)

Example 3 with EvoSuiteURL

use of org.evosuite.runtime.testdata.EvoSuiteURL in project evosuite by EvoSuite.

the class MockUrlSystemTest method testLoading_ReadFromURL.

@Test(timeout = 5000)
public void testLoading_ReadFromURL() throws Exception {
    // for some reason, this class failed when using loop limit in the search
    RuntimeSettings.useVNET = true;
    RuntimeSettings.maxNumberOfIterationsPerLoop = 100_000;
    MethodCallReplacementCache.resetSingleton();
    org.evosuite.runtime.Runtime.getInstance().resetRuntime();
    EvoClassLoader loader = new EvoClassLoader();
    Class<?> clazz = loader.loadClass(ReadFromURL.class.getCanonicalName());
    Method m = clazz.getMethod("checkResource");
    boolean b = (Boolean) m.invoke(null);
    Assert.assertFalse(b);
    EvoSuiteURL evoURL = new EvoSuiteURL("http://www.evosuite.org/index.html");
    NetworkHandling.createRemoteTextFile(evoURL, "foo");
    b = (Boolean) m.invoke(null);
    Assert.assertTrue(b);
}
Also used : ReadFromURL(com.examples.with.different.packagename.mock.java.net.ReadFromURL) EvoSuiteURL(org.evosuite.runtime.testdata.EvoSuiteURL) EvoClassLoader(org.evosuite.runtime.instrumentation.EvoClassLoader) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

EvoSuiteURL (org.evosuite.runtime.testdata.EvoSuiteURL)3 Method (java.lang.reflect.Method)2 VariableReference (org.evosuite.testcase.variable.VariableReference)2 TestCaseWithURL (com.examples.with.different.packagename.concolic.TestCaseWithURL)1 ReadFromURL (com.examples.with.different.packagename.mock.java.net.ReadFromURL)1 EvoClassLoader (org.evosuite.runtime.instrumentation.EvoClassLoader)1 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)1 Test (org.junit.Test)1