Search in sources :

Example 66 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class TestSolverStringFunctions method buildTestEqualsIgnoreCase.

private static DefaultTestCase buildTestEqualsIgnoreCase() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder tc = new TestCaseBuilder();
    VariableReference string0 = tc.appendStringPrimitive("Hello World");
    Method method = TestCaseStringEqualsIgnoreCase.class.getMethod("test", String.class);
    tc.appendMethod(null, method, string0);
    return tc.getDefaultTestCase();
}
Also used : TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Example 67 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class TestSolverStringFunctions method buildTestSubstringFromTo.

private static DefaultTestCase buildTestSubstringFromTo() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder tc = new TestCaseBuilder();
    VariableReference string0 = tc.appendStringPrimitive("hamburger");
    Method method = TestCaseStringSubstringFromTo.class.getMethod("test", String.class);
    tc.appendMethod(null, method, string0);
    return tc.getDefaultTestCase();
}
Also used : TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Example 68 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class MockJOptionPaneTest method buildTestCase1.

private static TestCase buildTestCase1(InstrumentingClassLoader cl) throws ClassNotFoundException, NoSuchMethodException, SecurityException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference string0 = builder.appendStringPrimitive("input0");
    Class<?> jOptionPaneInputsClass = JOptionPaneInputs.class;
    final String ENQUEUE_INPUT_STRING = "enqueueInputString";
    Method enqueueStringMethod = jOptionPaneInputsClass.getMethod(ENQUEUE_INPUT_STRING, String.class);
    builder.appendMethod(null, enqueueStringMethod, string0);
    Class<?> clazz = cl.loadClass(TARGET_CLASS);
    Constructor<?> constructor = clazz.getConstructor();
    VariableReference showMessageDialogExample0 = builder.appendConstructor(constructor);
    Method showConfirmDialogsMethod = clazz.getMethod("ask");
    builder.appendMethod(showMessageDialogExample0, showConfirmDialogsMethod);
    return builder.getDefaultTestCase();
}
Also used : JOptionPaneInputs(org.evosuite.runtime.util.JOptionPaneInputs) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Example 69 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class TestLocalSearchMIMEType method createTestCase3.

private DefaultTestCase createTestCase3() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException {
    final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(MIMEType.class.getName());
    final Field xmlField = mimeTypeClass.getDeclaredField("XML");
    final Method toString = mimeTypeClass.getMethod("toString");
    final TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference mIMEType0 = builder.appendStaticFieldStmt(xmlField);
    VariableReference string0 = builder.appendMethod(mIMEType0, toString);
    System.out.println("Test Case #3=" + builder.toCode());
    return builder.getDefaultTestCase();
}
Also used : Field(java.lang.reflect.Field) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) MIMEType(com.examples.with.different.packagename.concolic.MIMEType) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Example 70 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class TestLocalSearchMIMEType method createTestCase4.

private DefaultTestCase createTestCase4() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException {
    final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(MIMEType.class.getName());
    final Field rdfField = mimeTypeClass.getDeclaredField("RDF");
    final Field slashField = mimeTypeClass.getDeclaredField("slash");
    final Method equalsMethod = mimeTypeClass.getMethod("equals", Object.class);
    final Constructor<?> constructorString = mimeTypeClass.getConstructor(String.class);
    final Field mimeTypeField = mimeTypeClass.getDeclaredField("mimeType");
    final Method getTypeMethod = mimeTypeClass.getMethod("getType");
    final Method toString = mimeTypeClass.getMethod("toString");
    final TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference mIMEType0 = builder.appendStaticFieldStmt(rdfField);
    VariableReference int0 = builder.appendIntPrimitive(2415);
    VariableReference int1 = builder.appendIntPrimitive(2415);
    VariableReference int2 = builder.appendIntPrimitive(-196);
    builder.appendAssignment(mIMEType0, slashField, int2);
    builder.appendAssignment(mIMEType0, slashField, int0);
    VariableReference int3 = builder.appendIntPrimitive(0);
    builder.appendAssignment(mIMEType0, slashField, int1);
    builder.appendAssignment(mIMEType0, slashField, int3);
    VariableReference boolean0 = builder.appendMethod(mIMEType0, equalsMethod, mIMEType0);
    VariableReference string0 = builder.appendStringPrimitive("/");
    VariableReference string1 = builder.appendStringPrimitive("\"cC3$]nc.<p) u:");
    VariableReference mIMEType1 = builder.appendConstructor(constructorString, string0);
    builder.appendAssignment(mIMEType1, slashField, mIMEType0, slashField);
    VariableReference string2 = builder.appendNull(String.class);
    builder.appendAssignment(mIMEType1, mimeTypeField, string2);
    VariableReference int4 = builder.appendFieldStmt(mIMEType0, slashField);
    builder.appendMethod(mIMEType1, getTypeMethod);
    builder.addException(new NullPointerException());
    VariableReference string3 = builder.appendMethod(mIMEType1, toString);
    System.out.println("Test Case #4=" + builder.toCode());
    return builder.getDefaultTestCase();
}
Also used : Field(java.lang.reflect.Field) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) MIMEType(com.examples.with.different.packagename.concolic.MIMEType) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Aggregations

TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)146 VariableReference (org.evosuite.testcase.variable.VariableReference)143 Method (java.lang.reflect.Method)129 Test (org.junit.Test)16 DowncastExample (com.examples.with.different.packagename.test.DowncastExample)8 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)8 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)7 ArrayReference (org.evosuite.testcase.variable.ArrayReference)7 MIMEType (com.examples.with.different.packagename.concolic.MIMEType)6 ShowMessageDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowMessageDialogExample)6 Field (java.lang.reflect.Field)6 ConcreteSubclass (com.examples.with.different.packagename.test.ConcreteSubclass)4 ShowInternalMessageDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowInternalMessageDialogExample)2 AbstractSuperclass (com.examples.with.different.packagename.test.AbstractSuperclass)2 AssignmentStatement (org.evosuite.testcase.statements.AssignmentStatement)2 FieldReference (org.evosuite.testcase.variable.FieldReference)2 GenericField (org.evosuite.utils.generic.GenericField)2 CBranchExample (com.examples.with.different.packagename.cbranch.CBranchExample)1 ShowConfirmDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowConfirmDialogExample)1 ShowInputDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowInputDialogExample)1