Skip to content

Commit 73f070b

Browse files
committed
Fixed copyOf, copyOfRange and asList failures
1 parent 1438c55 commit 73f070b

File tree

10 files changed

+325
-69
lines changed

10 files changed

+325
-69
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.utbot.examples.arrays
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.testing.AtLeast
5+
import org.utbot.testing.FullWithAssumptions
6+
import org.utbot.testing.UtValueTestCaseChecker
7+
import org.utbot.testing.ignoreExecutionsNumber
8+
import org.utbot.testing.isException
9+
10+
class CopyOfExampleTest : UtValueTestCaseChecker(testClass = CopyOfExample::class) {
11+
@Test
12+
fun testCopyOf() {
13+
checkWithException(
14+
CopyOfExample::copyOfExample,
15+
ignoreExecutionsNumber,
16+
{ _, l, r -> l < 0 && r.isException<NegativeArraySizeException>() },
17+
{ arr, l, r -> arr.copyOf(l).contentEquals(r.getOrThrow()) },
18+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
19+
)
20+
}
21+
22+
@Test
23+
fun testCopyOfRange() {
24+
checkWithException(
25+
CopyOfExample::copyOfRangeExample,
26+
ignoreExecutionsNumber,
27+
{ _, from, _, r -> from < 0 && r.isException<ArrayIndexOutOfBoundsException>() },
28+
{ arr, from, _, r -> from > arr.size && r.isException<ArrayIndexOutOfBoundsException>() },
29+
{ _, from, to, r -> from > to && r.isException<IllegalArgumentException>() },
30+
{ arr, from, to, r -> arr.copyOfRange(from, to).contentEquals(r.getOrThrow()) },
31+
coverage = AtLeast(82)
32+
)
33+
}
34+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import org.junit.jupiter.api.Disabled
55
import org.junit.jupiter.api.Test
66
import org.utbot.testcheckers.eq
77
import org.utbot.testcheckers.ge
8+
import org.utbot.testcheckers.withoutConcrete
89
import org.utbot.testing.CodeGeneration
910
import org.utbot.testing.DoNotCalculate
11+
import org.utbot.testing.FullWithAssumptions
1012
import org.utbot.testing.UtValueTestCaseChecker
1113
import org.utbot.testing.between
1214
import org.utbot.testing.isException
@@ -217,6 +219,19 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
217219
)
218220
}
219221

222+
@Test
223+
fun testAsListExample() {
224+
withoutConcrete { // TODO Concrete fail matchers with "Cannot show class" error
225+
check(
226+
Lists::asListExample,
227+
eq(2),
228+
{ arr, r -> arr.isEmpty() && r!!.isEmpty() },
229+
{ arr, r -> arr.isNotEmpty() && arr.contentEquals(r!!.toTypedArray()) },
230+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
231+
)
232+
}
233+
}
234+
220235
@Test
221236
@Disabled("TODO: add choosing proper type in list wrapper")
222237
fun testRemoveFromList() {

utbot-framework/src/main/java/org/utbot/engine/overrides/System.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static void arraycopy(Object src, int srcPos, Object dest, int destPos, i
210210
}
211211

212212
UtArrayMock.arraycopy(srcArray, srcPos, destArray, destPos, length);
213-
} else {
213+
} else if (src instanceof Object[]) {
214214
if (!(dest instanceof Object[])) {
215215
throw new ArrayStoreException();
216216
}
@@ -223,6 +223,9 @@ public static void arraycopy(Object src, int srcPos, Object dest, int destPos, i
223223
}
224224

225225
UtArrayMock.arraycopy(srcArray, srcPos, destArray, destPos, length);
226+
} else {
227+
// From docs: if the src argument refers to an object that is not an array, an ArrayStoreException will be thrown
228+
throw new ArrayStoreException();
226229
}
227230
}
228231
}

utbot-framework/src/main/java/org/utbot/engine/overrides/stream/Arrays.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utbot.engine.overrides.stream;
22

33
import org.utbot.api.annotation.UtClassMock;
4+
import org.utbot.api.mock.UtMock;
45
import org.utbot.engine.overrides.collections.UtArrayList;
56

67
import java.util.List;
@@ -21,7 +22,7 @@ public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusi
2122
return new UtStream<>(array, startInclusive, endExclusive);
2223
}
2324

24-
// from docs - array is assumed to be umnodified during use
25+
// from docs - array is assumed to be unmodified during use
2526
public static IntStream stream(int[] array, int startInclusive, int endExclusive) {
2627
int size = array.length;
2728

@@ -37,7 +38,7 @@ public static IntStream stream(int[] array, int startInclusive, int endExclusive
3738
return new UtIntStream(data, startInclusive, endExclusive);
3839
}
3940

40-
// from docs - array is assumed to be umnodified during use
41+
// from docs - array is assumed to be unmodified during use
4142
public static LongStream stream(long[] array, int startInclusive, int endExclusive) {
4243
int size = array.length;
4344

@@ -53,7 +54,7 @@ public static LongStream stream(long[] array, int startInclusive, int endExclusi
5354
return new UtLongStream(data, startInclusive, endExclusive);
5455
}
5556

56-
// from docs - array is assumed to be umnodified during use
57+
// from docs - array is assumed to be unmodified during use
5758
public static DoubleStream stream(double[] array, int startInclusive, int endExclusive) {
5859
int size = array.length;
5960

@@ -75,6 +76,4 @@ public static <T> List<T> asList(T... a) {
7576
// TODO immutable collection https://github.com/UnitTestBot/UTBotJava/issues/398
7677
return new UtArrayList<>(a);
7778
}
78-
79-
// TODO primitive arrays https://github.com/UnitTestBot/UTBotJava/issues/146
8079
}

utbot-framework/src/main/kotlin/org/utbot/engine/CollectionWrappers.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,24 @@ private val UT_GENERIC_ASSOCIATIVE_CLASS
414414
private val UT_GENERIC_ASSOCIATIVE_SET_EQUAL_GENERIC_TYPE_SIGNATURE =
415415
UT_GENERIC_ASSOCIATIVE_CLASS.getMethodByName(UtGenericAssociative<*, *>::setEqualGenericType.name).signature
416416

417+
val LIST_TYPE: RefType
418+
get() = Scene.v().getSootClass(java.util.List::class.java.canonicalName).type
417419
val ARRAY_LIST_TYPE: RefType
418420
get() = Scene.v().getSootClass(java.util.ArrayList::class.java.canonicalName).type
419421
val LINKED_LIST_TYPE: RefType
420422
get() = Scene.v().getSootClass(java.util.LinkedList::class.java.canonicalName).type
423+
val DEQUE_TYPE: RefType
424+
get() = Scene.v().getSootClass(java.util.Deque::class.java.canonicalName).type
421425

426+
val SET_TYPE: RefType
427+
get() = Scene.v().getSootClass(java.util.Set::class.java.canonicalName).type
422428
val LINKED_HASH_SET_TYPE: RefType
423429
get() = Scene.v().getSootClass(java.util.LinkedHashSet::class.java.canonicalName).type
424430
val HASH_SET_TYPE: RefType
425431
get() = Scene.v().getSootClass(java.util.HashSet::class.java.canonicalName).type
426432

433+
val MAP_TYPE: RefType
434+
get() = Scene.v().getSootClass(java.util.Map::class.java.canonicalName).type
427435
val LINKED_HASH_MAP_TYPE: RefType
428436
get() = Scene.v().getSootClass(java.util.LinkedHashMap::class.java.canonicalName).type
429437
val HASH_MAP_TYPE: RefType

0 commit comments

Comments
 (0)