Skip to content

Commit 84ef0b1

Browse files
Add wrappers for queues #524 (#822)
1 parent 248c196 commit 84ef0b1

File tree

20 files changed

+510
-94
lines changed

20 files changed

+510
-94
lines changed

utbot-framework-test/src/main/java/org/utbot/examples/manual/KotlinWrappers.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
package org.utbot.examples.manual
22

3-
import org.utbot.common.FileUtil
43
import org.utbot.framework.plugin.api.ClassId
54
import org.utbot.framework.plugin.api.FieldId
65
import org.utbot.framework.plugin.api.UtModel
76
import org.utbot.framework.plugin.api.UtPrimitiveModel
8-
import java.nio.file.Path
97

108
object SootUtils {
119
@JvmStatic
1210
fun runSoot(clazz: Class<*>) {
13-
val buildDir = FileUtil.locateClassPath(clazz.kotlin) ?: FileUtil.isolateClassFiles(clazz.kotlin)
14-
val buildDirPath = buildDir.toPath()
15-
16-
if (buildDirPath != previousBuildDir) {
17-
org.utbot.framework.util.runSoot(buildDirPath, null)
18-
previousBuildDir = buildDirPath
19-
}
11+
org.utbot.framework.util.SootUtils.runSoot(clazz.kotlin)
2012
}
21-
22-
private var previousBuildDir: Path? = null
2313
}
2414

2515
fun fields(

utbot-framework-test/src/test/kotlin/org/utbot/examples/manual/UtBotJavaApiTest.java renamed to utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
import java.lang.reflect.Method;
3232
import java.net.URISyntaxException;
3333
import java.net.URL;
34-
import java.util.*;
34+
import java.net.URLClassLoader;
35+
import java.util.Arrays;
36+
import java.util.Collections;
37+
import java.util.HashMap;
38+
import java.util.IdentityHashMap;
39+
import java.util.List;
40+
import java.util.Map;
3541
import java.util.stream.Collectors;
3642

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

6167
@BeforeEach
6268
public void setUp() {
63-
SootUtils.runSoot(PrimitiveFields.class);
6469
context = UtContext.Companion.setUtContext(new UtContext(PrimitiveFields.class.getClassLoader()));
6570
modelFactory = new UtModelFactory();
6671
}
@@ -1221,6 +1226,7 @@ public void testOnObjectWithArrayOfComplexArrays() {
12211226

12221227
@Test
12231228
public void testFuzzingSimple() {
1229+
SootUtils.runSoot(StringSwitchExample.class);
12241230
UtBotJavaApi.setStopConcreteExecutorOnExit(false);
12251231

12261232
String classpath = getClassPath(StringSwitchExample.class);
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package org.utbot.examples.collections
2+
3+
import org.junit.jupiter.api.Disabled
4+
import org.junit.jupiter.api.Test
5+
import org.utbot.framework.plugin.api.CodegenLanguage
6+
import org.utbot.testcheckers.eq
7+
import org.utbot.tests.infrastructure.CodeGeneration
8+
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
9+
import org.utbot.tests.infrastructure.isException
10+
11+
class QueueUsagesTest : UtValueTestCaseChecker(
12+
testClass = QueueUsages::class,
13+
testCodeGeneration = true,
14+
languagePipelines = listOf(
15+
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
16+
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
17+
)
18+
) {
19+
@Test
20+
fun testCreateArrayDeque() {
21+
checkWithException(
22+
QueueUsages::createArrayDeque,
23+
eq(3),
24+
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() },
25+
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() },
26+
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 },
27+
)
28+
}
29+
30+
@Test
31+
fun testCreateLinkedList() {
32+
checkWithException(
33+
QueueUsages::createLinkedList,
34+
eq(1),
35+
{ _, _, r -> r.getOrNull()!! == 2 },
36+
)
37+
}
38+
39+
@Test
40+
fun testCreateLinkedBlockingDeque() {
41+
checkWithException(
42+
QueueUsages::createLinkedBlockingDeque,
43+
eq(3),
44+
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() },
45+
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() },
46+
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 },
47+
)
48+
}
49+
50+
@Test
51+
fun testContainsQueue() {
52+
checkWithException(
53+
QueueUsages::containsQueue,
54+
eq(3),
55+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
56+
{ q, x, r -> x in q && r.getOrNull() == 1 },
57+
{ q, x, r -> x !in q && r.getOrNull() == 0 },
58+
)
59+
}
60+
61+
@Test
62+
fun testAddQueue() {
63+
checkWithException(
64+
QueueUsages::addQueue,
65+
eq(3),
66+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
67+
{ q, x, r -> q != null && x in r.getOrNull()!! },
68+
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() }, )
69+
}
70+
71+
@Test
72+
fun testAddAllQueue() {
73+
checkWithException(
74+
QueueUsages::addAllQueue,
75+
eq(3),
76+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
77+
{ q, x, r -> q != null && x in r.getOrNull()!! }, // we can cover this line with x == null or x != null
78+
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() },
79+
)
80+
}
81+
82+
@Test
83+
fun testCastQueueToDeque() {
84+
check(
85+
QueueUsages::castQueueToDeque,
86+
eq(2),
87+
{ q, r -> q !is java.util.Deque<*> && r == null },
88+
{ q, r -> q is java.util.Deque<*> && r is java.util.Deque<*> },
89+
)
90+
}
91+
92+
@Test
93+
fun testCheckSubtypesOfQueue() {
94+
check(
95+
QueueUsages::checkSubtypesOfQueue,
96+
eq(4),
97+
{ q, r -> q == null && r == 0 },
98+
{ q, r -> q is java.util.LinkedList<*> && r == 1 },
99+
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 },
100+
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 }
101+
)
102+
}
103+
104+
@Test
105+
@Disabled("TODO: Related to https://github.com/UnitTestBot/UTBotJava/issues/820")
106+
fun testCheckSubtypesOfQueueWithUsage() {
107+
check(
108+
QueueUsages::checkSubtypesOfQueueWithUsage,
109+
eq(4),
110+
{ q, r -> q == null && r == 0 },
111+
{ q, r -> q is java.util.LinkedList<*> && r == 1 },
112+
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 },
113+
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } // this is uncovered
114+
)
115+
}
116+
117+
@Test
118+
fun testAddConcurrentLinkedQueue() {
119+
checkWithException(
120+
QueueUsages::addConcurrentLinkedQueue,
121+
eq(3),
122+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
123+
{ q, x, r -> q != null && x != null && x in r.getOrNull()!! },
124+
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() },
125+
)
126+
}
127+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ import java.util.LinkedList
1212
import java.util.TreeMap
1313
import org.junit.jupiter.api.Disabled
1414
import org.junit.jupiter.api.Test
15+
import org.utbot.framework.plugin.api.CodegenLanguage
1516
import org.utbot.testcheckers.eq
17+
import org.utbot.tests.infrastructure.CodeGeneration
1618

17-
internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = StandardStructures::class) {
19+
internal class StandardStructuresTest : UtValueTestCaseChecker(
20+
testClass = StandardStructures::class,
21+
languagePipelines = listOf(
22+
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
23+
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
24+
)
25+
) {
1826
@Test
1927
@Disabled("TODO down cast for object wrapper JIRA:1480")
2028
fun testGetList() {
@@ -45,7 +53,6 @@ internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = Stand
4553
}
4654

4755
@Test
48-
@Disabled("TODO use correct wrapper JIRA:1495")
4956
fun testGetDeque() {
5057
val dequeSummary = listOf<DocStatement>(
5158
DocPreTagStatement(
@@ -72,7 +79,7 @@ internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = Stand
7279
{ d, r -> d is LinkedList && r is LinkedList },
7380
{ d, r -> d == null && r == null },
7481
{ d, r ->
75-
d !is ArrayDeque<*> && d !is LinkedList && d != null && r !is ArrayDeque<*> && r !is LinkedList && r != null
82+
d !is java.util.ArrayDeque<*> && d !is LinkedList && d != null && r !is java.util.ArrayDeque<*> && r !is LinkedList && r != null
7683
},
7784
coverage = DoNotCalculate,
7885
summaryTextChecks = listOf(

utbot-framework-test/src/test/kotlin/org/utbot/framework/SootUtils.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.

utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import org.utbot.examples.assemble.constructors.PrivateConstructor
3131
import org.utbot.examples.assemble.defaults.DefaultFieldWithSetter
3232
import org.utbot.examples.assemble.defaults.DefaultPackagePrivateField
3333
import org.utbot.examples.assemble.statics.StaticField
34-
import org.utbot.framework.SootUtils
3534
import org.utbot.framework.plugin.api.ClassId
3635
import org.utbot.framework.plugin.api.FieldId
3736
import org.utbot.framework.plugin.api.MethodId
@@ -56,6 +55,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
5655
import org.junit.jupiter.api.BeforeEach
5756
import org.junit.jupiter.api.Disabled
5857
import org.junit.jupiter.api.Test
58+
import org.utbot.framework.util.SootUtils
5959

6060
/**
6161
* Test classes must be located in the same folder as [AssembleTestUtils] class.

utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import org.utbot.examples.modificators.StronglyConnectedComponents
1212
import org.utbot.examples.modificators.coupling.ClassA
1313
import org.utbot.examples.modificators.coupling.ClassB
1414
import org.utbot.examples.modificators.hierarchy.InheritedModifications
15-
import org.utbot.framework.SootUtils
1615
import org.utbot.framework.modifications.AnalysisMode
1716
import org.utbot.framework.modifications.AnalysisMode.AllModificators
1817
import org.utbot.framework.modifications.AnalysisMode.SettersAndDirectAccessors
@@ -25,6 +24,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
2524
import org.junit.jupiter.api.Assertions.assertTrue
2625
import org.junit.jupiter.api.BeforeEach
2726
import org.junit.jupiter.api.Test
27+
import org.utbot.framework.util.SootUtils
2828

2929
internal class UtBotFieldModificatorsTest {
3030
private lateinit var fieldsModificatorsSearcher: UtBotFieldsModificatorsSearcher

utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtLinkedList.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public UtLinkedList(Collection<? extends E> c) {
7272
* <li> elementData is marked as parameter </li>
7373
* <li> elementData.storage and it's elements are marked as parameters </li>
7474
*/
75-
private void preconditionCheck() {
75+
protected void preconditionCheck() {
7676
if (alreadyVisited(this)) {
7777
return;
7878
}
@@ -88,13 +88,13 @@ private void preconditionCheck() {
8888
visit(this);
8989
}
9090

91-
private void rangeCheck(int index) {
91+
protected void rangeCheck(int index) {
9292
if (index < 0 || index >= elementData.end - elementData.begin) {
9393
throw new IndexOutOfBoundsException();
9494
}
9595
}
9696

97-
private void rangeCheckForAdd(int index) {
97+
protected void rangeCheckForAdd(int index) {
9898
if (index < 0 || index > elementData.end - elementData.begin) {
9999
throw new IndexOutOfBoundsException();
100100
}

0 commit comments

Comments
 (0)