Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed some places
  • Loading branch information
amandelpie committed Aug 8, 2022
commit 0af780c480675409f61f08153a0d7cdae486cd75
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,7 @@ package org.utbot.engine

import org.utbot.common.invokeCatching
import org.utbot.common.withAccessibility
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.ConstructorId
import org.utbot.framework.plugin.api.EnvironmentModels
import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.FieldMockTarget
import org.utbot.framework.plugin.api.MethodId
import org.utbot.framework.plugin.api.MockId
import org.utbot.framework.plugin.api.MockInfo
import org.utbot.framework.plugin.api.MockTarget
import org.utbot.framework.plugin.api.ObjectMockTarget
import org.utbot.framework.plugin.api.ParameterMockTarget
import org.utbot.framework.plugin.api.UtArrayModel
import org.utbot.framework.plugin.api.UtAssembleModel
import org.utbot.framework.plugin.api.UtClassRefModel
import org.utbot.framework.plugin.api.UtCompositeModel
import org.utbot.framework.plugin.api.UtConcreteValue
import org.utbot.framework.plugin.api.UtDirectSetFieldModel
import org.utbot.framework.plugin.api.UtEnumConstantModel
import org.utbot.framework.plugin.api.UtExecutableCallModel
import org.utbot.framework.plugin.api.UtSymbolicExecution
import org.utbot.framework.plugin.api.UtExecutionFailure
import org.utbot.framework.plugin.api.UtExecutionResult
import org.utbot.framework.plugin.api.UtExecutionSuccess
import org.utbot.framework.plugin.api.UtMockValue
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.UtNullModel
import org.utbot.framework.plugin.api.UtPrimitiveModel
import org.utbot.framework.plugin.api.UtReferenceModel
import org.utbot.framework.plugin.api.UtValueExecution
import org.utbot.framework.plugin.api.UtValueExecutionState
import org.utbot.framework.plugin.api.UtVoidModel
import org.utbot.framework.plugin.api.isMockModel
import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.util.constructor
import org.utbot.framework.plugin.api.util.jField
import org.utbot.framework.plugin.api.util.jClass
Expand Down Expand Up @@ -118,22 +87,36 @@ class ValueConstructor {
/**
* Constructs value based execution from model based.
*/
fun construct(execution: UtSymbolicExecution): UtValueExecution<*> {
fun construct(execution: UtExecution): UtValueExecution<*> {
val (stateBefore, mocks) = constructState(execution.stateBefore)
val (stateAfter, _) = constructState(execution.stateAfter)
val returnValue = execution.result.map { construct(listOf(it)).single().value }

return UtValueExecution(
stateBefore,
stateAfter,
returnValue,
execution.path,
mocks,
execution.instrumentation,
execution.summary,
execution.testMethodName,
execution.displayName
)
if (execution is UtSymbolicExecution) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: return if

return UtValueExecution(
stateBefore,
stateAfter,
returnValue,
execution.path,
mocks,
execution.instrumentation,
execution.summary,
execution.testMethodName,
execution.displayName
)
} else {
return UtValueExecution(
stateBefore,
stateAfter,
returnValue,
emptyList(),
mocks,
emptyList(),
execution.summary,
execution.testMethodName,
execution.displayName
)
}
}

private fun constructParamsAndMocks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1147,9 +1147,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
//TODO: orientation on generic execution may be misleading, but what is the alternative?
//may be a heuristic to select a model with minimal number of internal nulls should be used
val genericExecution = testSet.executions
.filterIsInstance<UtSymbolicExecution>()
.firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel }
?: testSet.executions.filterIsInstance<UtSymbolicExecution>().first()
?: testSet.executions.first()

return withTestMethodScope(genericExecution) {
val testName = nameGenerator.parameterizedTestMethodName(dataProviderMethodName)
Expand Down Expand Up @@ -1197,7 +1196,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c

private fun createParameterDeclarations(
testSet: CgMethodTestSet,
genericExecution: UtSymbolicExecution,
genericExecution: UtExecution,
): List<CgParameterDeclaration> {
val executableUnderTest = testSet.executableId
val executableUnderTestParameters = testSet.executableId.executable.parameters
Expand Down Expand Up @@ -1295,7 +1294,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c

emptyLine()

for ((execIndex, execution) in testSet.executions.filterIsInstance<UtSymbolicExecution>().withIndex()) {
for ((execIndex, execution) in testSet.executions.withIndex()) {
// create a block for current test case
innerBlock {
val arguments = createExecutionArguments(testSet, execution)
Expand All @@ -1310,7 +1309,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
}
}

private fun createExecutionArguments(testSet: CgMethodTestSet, execution: UtSymbolicExecution): List<CgExpression> {
private fun createExecutionArguments(testSet: CgMethodTestSet, execution: UtExecution): List<CgExpression> {
val arguments = mutableListOf<CgExpression>()
execution.stateBefore.thisInstance?.let {
arguments += variableConstructor.getOrCreateVariable(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ val instanceCounter = AtomicInteger(0)
fun nextModelName(base: String): String = "$base${instanceCounter.incrementAndGet()}"

fun UtMethodTestSet.toValueTestCase(): UtMethodValueTestSet<*> {
val valueExecutions = executions.filterIsInstance<UtSymbolicExecution>().map { ValueConstructor().construct(it) }
val valueExecutions = executions.map { ValueConstructor().construct(it) } // TODO: make something about UTExecution
return UtMethodValueTestSet(method, valueExecutions, errors)
}

Expand Down