Skip to content

Add wrappers for queues #524 #822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package org.utbot.examples.manual

import org.utbot.common.FileUtil
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.UtPrimitiveModel
import java.nio.file.Path

object SootUtils {
@JvmStatic
fun runSoot(clazz: Class<*>) {
val buildDir = FileUtil.locateClassPath(clazz.kotlin) ?: FileUtil.isolateClassFiles(clazz.kotlin)
val buildDirPath = buildDir.toPath()

if (buildDirPath != previousBuildDir) {
org.utbot.framework.util.runSoot(buildDirPath, null)
previousBuildDir = buildDirPath
}
org.utbot.framework.util.SootUtils.runSoot(clazz.kotlin)
}

private var previousBuildDir: Path? = null
}

fun fields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.utbot.external.api.UtModelFactoryKt.classIdForType;
Expand Down Expand Up @@ -60,7 +66,6 @@ public class UtBotJavaApiTest {

@BeforeEach
public void setUp() {
SootUtils.runSoot(PrimitiveFields.class);
context = UtContext.Companion.setUtContext(new UtContext(PrimitiveFields.class.getClassLoader()));
modelFactory = new UtModelFactory();
}
Expand Down Expand Up @@ -1221,6 +1226,7 @@ public void testOnObjectWithArrayOfComplexArrays() {

@Test
public void testFuzzingSimple() {
SootUtils.runSoot(StringSwitchExample.class);
UtBotJavaApi.setStopConcreteExecutorOnExit(false);

String classpath = getClassPath(StringSwitchExample.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.utbot.examples.collections

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.tests.infrastructure.CodeGeneration
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.isException

class QueueUsagesTest : UtValueTestCaseChecker(
testClass = QueueUsages::class,
testCodeGeneration = true,
languagePipelines = listOf(
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
)
) {
@Test
fun testCreateArrayDeque() {
checkWithException(
QueueUsages::createArrayDeque,
eq(3),
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() },
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() },
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 },
)
}

@Test
fun testCreateLinkedList() {
checkWithException(
QueueUsages::createLinkedList,
eq(1),
{ _, _, r -> r.getOrNull()!! == 2 },
)
}

@Test
fun testCreateLinkedBlockingDeque() {
checkWithException(
QueueUsages::createLinkedBlockingDeque,
eq(3),
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() },
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() },
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 },
)
}

@Test
fun testContainsQueue() {
checkWithException(
QueueUsages::containsQueue,
eq(3),
{ q, _, r -> q == null && r.isException<NullPointerException>() },
{ q, x, r -> x in q && r.getOrNull() == 1 },
{ q, x, r -> x !in q && r.getOrNull() == 0 },
)
}

@Test
fun testAddQueue() {
checkWithException(
QueueUsages::addQueue,
eq(3),
{ q, _, r -> q == null && r.isException<NullPointerException>() },
{ q, x, r -> q != null && x in r.getOrNull()!! },
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() }, )
}

@Test
fun testAddAllQueue() {
checkWithException(
QueueUsages::addAllQueue,
eq(3),
{ q, _, r -> q == null && r.isException<NullPointerException>() },
{ q, x, r -> q != null && x in r.getOrNull()!! }, // we can cover this line with x == null or x != null
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() },
)
}

@Test
fun testCastQueueToDeque() {
check(
QueueUsages::castQueueToDeque,
eq(2),
{ q, r -> q !is java.util.Deque<*> && r == null },
{ q, r -> q is java.util.Deque<*> && r is java.util.Deque<*> },
)
}

@Test
fun testCheckSubtypesOfQueue() {
check(
QueueUsages::checkSubtypesOfQueue,
eq(4),
{ q, r -> q == null && r == 0 },
{ q, r -> q is java.util.LinkedList<*> && r == 1 },
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 },
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 }
)
}

@Test
@Disabled("TODO: Related to https://github.com/UnitTestBot/UTBotJava/issues/820")
fun testCheckSubtypesOfQueueWithUsage() {
check(
QueueUsages::checkSubtypesOfQueueWithUsage,
eq(4),
{ q, r -> q == null && r == 0 },
{ q, r -> q is java.util.LinkedList<*> && r == 1 },
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 },
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } // this is uncovered
)
}

@Test
fun testAddConcurrentLinkedQueue() {
checkWithException(
QueueUsages::addConcurrentLinkedQueue,
eq(3),
{ q, _, r -> q == null && r.isException<NullPointerException>() },
{ q, x, r -> q != null && x != null && x in r.getOrNull()!! },
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ import java.util.LinkedList
import java.util.TreeMap
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.tests.infrastructure.CodeGeneration

internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = StandardStructures::class) {
internal class StandardStructuresTest : UtValueTestCaseChecker(
testClass = StandardStructures::class,
languagePipelines = listOf(
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
)
) {
@Test
@Disabled("TODO down cast for object wrapper JIRA:1480")
fun testGetList() {
Expand Down Expand Up @@ -45,7 +53,6 @@ internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = Stand
}

@Test
@Disabled("TODO use correct wrapper JIRA:1495")
fun testGetDeque() {
val dequeSummary = listOf<DocStatement>(
DocPreTagStatement(
Expand All @@ -72,7 +79,7 @@ internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = Stand
{ d, r -> d is LinkedList && r is LinkedList },
{ d, r -> d == null && r == null },
{ d, r ->
d !is ArrayDeque<*> && d !is LinkedList && d != null && r !is ArrayDeque<*> && r !is LinkedList && r != null
d !is java.util.ArrayDeque<*> && d !is LinkedList && d != null && r !is java.util.ArrayDeque<*> && r !is LinkedList && r != null
},
coverage = DoNotCalculate,
summaryTextChecks = listOf(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.utbot.examples.assemble.constructors.PrivateConstructor
import org.utbot.examples.assemble.defaults.DefaultFieldWithSetter
import org.utbot.examples.assemble.defaults.DefaultPackagePrivateField
import org.utbot.examples.assemble.statics.StaticField
import org.utbot.framework.SootUtils
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.MethodId
Expand All @@ -56,6 +55,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.framework.util.SootUtils

/**
* Test classes must be located in the same folder as [AssembleTestUtils] class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.utbot.examples.modificators.StronglyConnectedComponents
import org.utbot.examples.modificators.coupling.ClassA
import org.utbot.examples.modificators.coupling.ClassB
import org.utbot.examples.modificators.hierarchy.InheritedModifications
import org.utbot.framework.SootUtils
import org.utbot.framework.modifications.AnalysisMode
import org.utbot.framework.modifications.AnalysisMode.AllModificators
import org.utbot.framework.modifications.AnalysisMode.SettersAndDirectAccessors
Expand All @@ -25,6 +24,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.utbot.framework.util.SootUtils

internal class UtBotFieldModificatorsTest {
private lateinit var fieldsModificatorsSearcher: UtBotFieldsModificatorsSearcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public UtLinkedList(Collection<? extends E> c) {
* <li> elementData is marked as parameter </li>
* <li> elementData.storage and it's elements are marked as parameters </li>
*/
private void preconditionCheck() {
protected void preconditionCheck() {
if (alreadyVisited(this)) {
return;
}
Expand All @@ -88,13 +88,13 @@ private void preconditionCheck() {
visit(this);
}

private void rangeCheck(int index) {
protected void rangeCheck(int index) {
if (index < 0 || index >= elementData.end - elementData.begin) {
throw new IndexOutOfBoundsException();
}
}

private void rangeCheckForAdd(int index) {
protected void rangeCheckForAdd(int index) {
if (index < 0 || index > elementData.end - elementData.begin) {
throw new IndexOutOfBoundsException();
}
Expand Down
Loading