Search in sources :

Example 1 with TestCaseBuilder

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

the class TestLocalSearchMIMEType method createTestCase0.

private DefaultTestCase createTestCase0() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException {
    TestCaseBuilder builder = new TestCaseBuilder();
    final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(MIMEType.class.getName());
    final Field memField = mimeTypeClass.getField("MEM");
    final Method toString = mimeTypeClass.getMethod("toString");
    VariableReference mIMEType0 = builder.appendStaticFieldStmt(memField);
    builder.appendMethod(mIMEType0, toString);
    System.out.println("Test Case #0=" + 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 2 with TestCaseBuilder

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

the class TestLocalSearchMIMEType method createTestCase2.

private DefaultTestCase createTestCase2() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException {
    final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(MIMEType.class.getName());
    final Field rdfField = mimeTypeClass.getDeclaredField("RDF");
    final Method hashCode = mimeTypeClass.getMethod("hashCode");
    final Field slashField = mimeTypeClass.getDeclaredField("slash");
    final Method getTypeMethod = mimeTypeClass.getMethod("getType");
    final Method getSubTypeMethod = mimeTypeClass.getMethod("getSubType");
    final Method equalsMethod = mimeTypeClass.getMethod("equals", Object.class);
    final Field mimeTypeField = mimeTypeClass.getDeclaredField("mimeType");
    final Constructor<?> constructorStringBoolean = mimeTypeClass.getConstructor(String.class, boolean.class);
    final TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference mIMEType0 = builder.appendStaticFieldStmt(rdfField);
    VariableReference string0 = builder.appendStringPrimitive("");
    VariableReference int0 = builder.appendMethod(mIMEType0, hashCode);
    VariableReference string1 = builder.appendStringPrimitive("");
    VariableReference int1 = builder.appendIntPrimitive(0);
    VariableReference string2 = builder.appendStringPrimitive("com.examples.with.different.packagename.concolic.MalformedMIMETypeException");
    builder.appendAssignment(mIMEType0, slashField, int1);
    VariableReference int2 = builder.appendFieldStmt(mIMEType0, slashField);
    VariableReference string3 = builder.appendMethod(mIMEType0, getTypeMethod);
    VariableReference string4 = builder.appendMethod(mIMEType0, getSubTypeMethod);
    VariableReference boolean0 = builder.appendMethod(mIMEType0, equalsMethod, string3);
    VariableReference string5 = builder.appendFieldStmt(mIMEType0, mimeTypeField);
    VariableReference string6 = builder.appendMethod(mIMEType0, getSubTypeMethod);
    VariableReference int3 = builder.appendFieldStmt(mIMEType0, slashField);
    VariableReference string7 = builder.appendStringPrimitive("xT7vo\"<|[E{4");
    builder.appendConstructor(constructorStringBoolean, string7, boolean0);
    builder.addException(new Error());
    System.out.println("Test Case #2=" + 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 3 with TestCaseBuilder

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

the class TestLocalSearchMIMEType method createTestCase1.

private DefaultTestCase createTestCase1() throws NoSuchFieldException, SecurityException, NoSuchMethodException, ClassNotFoundException {
    final TestCaseBuilder builder = new TestCaseBuilder();
    final Class<?> mimeTypeClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(MIMEType.class.getName());
    final Class<?> objectClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Object.class.getName());
    final Constructor<?> constructorStringBoolean = mimeTypeClass.getConstructor(String.class, boolean.class);
    final Constructor<?> constructorString = mimeTypeClass.getConstructor(String.class);
    final Field mimeTypeField = mimeTypeClass.getDeclaredField("mimeType");
    final Field slashField = mimeTypeClass.getDeclaredField("slash");
    final Method getSubTypeMethod = mimeTypeClass.getMethod("getSubType");
    final Method equalsMethod = mimeTypeClass.getMethod("equals", Object.class);
    final Method getTypeMethod = mimeTypeClass.getMethod("getType");
    VariableReference string0 = builder.appendStringPrimitive("Y.8p>:/]WybaL");
    VariableReference boolean0 = builder.appendBooleanPrimitive(false);
    VariableReference mIMEType0 = builder.appendConstructor(constructorStringBoolean, string0, boolean0);
    VariableReference int0 = builder.appendIntPrimitive(-1);
    VariableReference int1 = builder.appendIntPrimitive(-1);
    VariableReference int2 = builder.appendIntPrimitive(1);
    builder.appendAssignment(mIMEType0, slashField, int2);
    builder.appendAssignment(mIMEType0, slashField, int0);
    builder.appendAssignment(mIMEType0, slashField, int1);
    VariableReference int3 = builder.appendIntPrimitive(0);
    VariableReference string1 = builder.appendStringPrimitive("Jm");
    builder.appendAssignment(mIMEType0, mimeTypeField, string1);
    VariableReference int4 = builder.appendIntPrimitive(2556);
    VariableReference int5 = builder.appendIntPrimitive(2556);
    builder.appendAssignment(mIMEType0, slashField, int4);
    builder.appendAssignment(mIMEType0, slashField, int3);
    VariableReference string2 = builder.appendMethod(mIMEType0, getSubTypeMethod);
    VariableReference object0 = builder.appendNull(objectClass);
    VariableReference boolean1 = builder.appendMethod(mIMEType0, equalsMethod, object0);
    VariableReference object1 = builder.appendNull(objectClass);
    VariableReference boolean2 = builder.appendMethod(mIMEType0, equalsMethod, object1);
    VariableReference string3 = builder.appendStringPrimitive("");
    VariableReference mIMEType1 = builder.appendConstructor(constructorString, string3);
    builder.addException(new Exception());
    builder.appendAssignment(mIMEType1, slashField, int5);
    VariableReference string4 = builder.appendStringPrimitive("DI'XL>AQzq1");
    builder.appendAssignment(mIMEType1, mimeTypeField, string4);
    VariableReference string5 = builder.appendFieldStmt(mIMEType1, mimeTypeField);
    VariableReference string6 = builder.appendStringPrimitive("bjvXpt%");
    VariableReference boolean3 = builder.appendBooleanPrimitive(true);
    VariableReference mIMEType2 = builder.appendConstructor(constructorStringBoolean, string6, boolean3);
    builder.appendAssignment(mIMEType2, slashField, mIMEType0, slashField);
    VariableReference string7 = builder.appendMethod(mIMEType0, getTypeMethod);
    VariableReference mIMEType3 = builder.appendConstructor(constructorStringBoolean, string5, boolean1);
    builder.appendAssignment(mIMEType1, mimeTypeField, string7);
    VariableReference string8 = builder.appendStringPrimitive("g");
    VariableReference mIMEType4 = builder.appendConstructor(constructorString, string8);
    VariableReference string9 = builder.appendMethod(mIMEType1, getTypeMethod);
    System.out.println("Test Case #1=" + 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 4 with TestCaseBuilder

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

the class TestDefaultValue method testLong.

@Test
public void testLong() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference longArray0 = builder.appendArrayStmt(Long[].class, 10);
    VariableReference long0 = builder.appendNull(Long.class);
    builder.appendAssignment(longArray0, 0, long0);
    builder.appendAssignment(long0, longArray0, 0);
    builder.appendMethod(long0, Long.class.getMethod("toString"));
    DefaultTestCase tc = builder.getDefaultTestCase();
    ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
    assertNotNull(ret_val);
    assertFalse(ret_val.explicitExceptions.isEmpty());
}
Also used : ArrayReference(org.evosuite.testcase.variable.ArrayReference) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

Example 5 with TestCaseBuilder

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

the class TestDefaultValue method testFloat.

@Test
public void testFloat() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference floatArray0 = builder.appendArrayStmt(Float[].class, 10);
    VariableReference float0 = builder.appendNull(Float.class);
    builder.appendAssignment(floatArray0, 0, float0);
    builder.appendAssignment(float0, floatArray0, 0);
    builder.appendMethod(float0, Float.class.getMethod("toString"));
    DefaultTestCase tc = builder.getDefaultTestCase();
    System.out.println(tc.toCode());
    ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
    assertNotNull(ret_val);
    assertFalse(ret_val.explicitExceptions.isEmpty());
}
Also used : ArrayReference(org.evosuite.testcase.variable.ArrayReference) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

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