|
| 1 | +package org.utbot.examples.arrays |
| 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.AtLeast |
| 8 | +import org.utbot.tests.infrastructure.CodeGeneration |
| 9 | +import org.utbot.tests.infrastructure.UtValueTestCaseChecker |
| 10 | +import org.utbot.tests.infrastructure.isException |
| 11 | + |
| 12 | +class ArrayStoreExceptionExamplesTest : UtValueTestCaseChecker( |
| 13 | + testClass = ArrayStoreExceptionExamples::class, |
| 14 | + languagePipelines = listOf( |
| 15 | + CodeGenerationLanguageLastStage(CodegenLanguage.JAVA), |
| 16 | + // Type inference errors in generated Kotlin code |
| 17 | + CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration) |
| 18 | + ) |
| 19 | +) { |
| 20 | + @Test |
| 21 | + fun testCorrectAssignmentSamePrimitiveType() { |
| 22 | + checkWithException( |
| 23 | + ArrayStoreExceptionExamples::correctAssignmentSamePrimitiveType, |
| 24 | + eq(3), |
| 25 | + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } |
| 26 | + ) |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + fun testCorrectAssignmentIntToIntegerArray() { |
| 31 | + checkWithException( |
| 32 | + ArrayStoreExceptionExamples::correctAssignmentIntToIntegerArray, |
| 33 | + eq(3), |
| 34 | + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + fun testCorrectAssignmentSubtype() { |
| 40 | + checkWithException( |
| 41 | + ArrayStoreExceptionExamples::correctAssignmentSubtype, |
| 42 | + eq(3), |
| 43 | + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + fun testCorrectAssignmentToObjectArray() { |
| 49 | + checkWithException( |
| 50 | + ArrayStoreExceptionExamples::correctAssignmentToObjectArray, |
| 51 | + eq(3), |
| 52 | + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } |
| 53 | + ) |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun testWrongAssignmentUnrelatedType() { |
| 58 | + checkWithException( |
| 59 | + ArrayStoreExceptionExamples::wrongAssignmentUnrelatedType, |
| 60 | + eq(3), |
| 61 | + { data, result -> data == null && result.isSuccess }, |
| 62 | + { data, result -> data.isEmpty() && result.isSuccess }, |
| 63 | + { data, result -> data.isNotEmpty() && result.isException<ArrayStoreException>() }, |
| 64 | + coverage = AtLeast(91) // TODO: investigate |
| 65 | + ) |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + fun testCheckGenericAssignmentWithCorrectCast() { |
| 70 | + checkWithException( |
| 71 | + ArrayStoreExceptionExamples::checkGenericAssignmentWithCorrectCast, |
| 72 | + eq(1), |
| 73 | + { result -> result.isSuccess } |
| 74 | + ) |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + fun testCheckGenericAssignmentWithWrongCast() { |
| 79 | + checkWithException( |
| 80 | + ArrayStoreExceptionExamples::checkGenericAssignmentWithWrongCast, |
| 81 | + eq(1), |
| 82 | + { result -> result.isException<ArrayStoreException>() }, |
| 83 | + coverage = AtLeast(87) // TODO: investigate |
| 84 | + ) |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + fun testCheckGenericAssignmentWithExtendsSubtype() { |
| 89 | + checkWithException( |
| 90 | + ArrayStoreExceptionExamples::checkGenericAssignmentWithExtendsSubtype, |
| 91 | + eq(1), |
| 92 | + { result -> result.isSuccess } |
| 93 | + ) |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + fun testCheckGenericAssignmentWithExtendsUnrelated() { |
| 98 | + checkWithException( |
| 99 | + ArrayStoreExceptionExamples::checkGenericAssignmentWithExtendsUnrelated, |
| 100 | + eq(1), |
| 101 | + { result -> result.isException<ArrayStoreException>() }, |
| 102 | + coverage = AtLeast(87) // TODO: investigate |
| 103 | + ) |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + fun testCheckObjectAssignment() { |
| 108 | + checkWithException( |
| 109 | + ArrayStoreExceptionExamples::checkObjectAssignment, |
| 110 | + eq(1), |
| 111 | + { result -> result.isSuccess } |
| 112 | + ) |
| 113 | + } |
| 114 | + |
| 115 | + // Should this be allowed at all? |
| 116 | + @Test |
| 117 | + fun testCheckWrongAssignmentOfItself() { |
| 118 | + checkWithException( |
| 119 | + ArrayStoreExceptionExamples::checkWrongAssignmentOfItself, |
| 120 | + eq(1), |
| 121 | + { result -> result.isException<ArrayStoreException>() }, |
| 122 | + coverage = AtLeast(87) |
| 123 | + ) |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + fun testCheckGoodAssignmentOfItself() { |
| 128 | + checkWithException( |
| 129 | + ArrayStoreExceptionExamples::checkGoodAssignmentOfItself, |
| 130 | + eq(1), |
| 131 | + { result -> result.isSuccess } |
| 132 | + ) |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + fun testCheckAssignmentToObjectArray() { |
| 137 | + checkWithException( |
| 138 | + ArrayStoreExceptionExamples::checkAssignmentToObjectArray, |
| 139 | + eq(1), |
| 140 | + { result -> result.isSuccess } |
| 141 | + ) |
| 142 | + } |
| 143 | + |
| 144 | + @Test |
| 145 | + fun testArrayCopyForIncompatiblePrimitiveTypes() { |
| 146 | + checkWithException( |
| 147 | + ArrayStoreExceptionExamples::arrayCopyForIncompatiblePrimitiveTypes, |
| 148 | + eq(3), |
| 149 | + { data, result -> data == null && result.isSuccess && result.getOrNull() == null }, |
| 150 | + { data, result -> data != null && data.isEmpty() && result.isSuccess && result.getOrNull()?.size == 0 }, |
| 151 | + { data, result -> data != null && data.isNotEmpty() && result.isException<ArrayStoreException>() } |
| 152 | + ) |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + fun testFill2DPrimitiveArray() { |
| 157 | + checkWithException( |
| 158 | + ArrayStoreExceptionExamples::fill2DPrimitiveArray, |
| 159 | + eq(1), |
| 160 | + { result -> result.isSuccess } |
| 161 | + ) |
| 162 | + } |
| 163 | + |
| 164 | + @Test |
| 165 | + fun testFillObjectArrayWithList() { |
| 166 | + check( |
| 167 | + ArrayStoreExceptionExamples::fillObjectArrayWithList, |
| 168 | + eq(2), |
| 169 | + { list, result -> list != null && result != null && result[0] != null }, |
| 170 | + { list, result -> list == null && result == null } |
| 171 | + ) |
| 172 | + } |
| 173 | + |
| 174 | + @Test |
| 175 | + fun testFillWithTreeSet() { |
| 176 | + check( |
| 177 | + ArrayStoreExceptionExamples::fillWithTreeSet, |
| 178 | + eq(2), |
| 179 | + { treeSet, result -> treeSet != null && result != null && result[0] != null }, |
| 180 | + { treeSet, result -> treeSet == null && result == null } |
| 181 | + ) |
| 182 | + } |
| 183 | + |
| 184 | + @Test |
| 185 | + fun testFillSomeInterfaceArrayWithSomeInterface() { |
| 186 | + check( |
| 187 | + ArrayStoreExceptionExamples::fillSomeInterfaceArrayWithSomeInterface, |
| 188 | + eq(2), |
| 189 | + { impl, result -> impl == null && result == null }, |
| 190 | + { impl, result -> impl != null && result != null && result[0] != null } |
| 191 | + ) |
| 192 | + } |
| 193 | + |
| 194 | + @Test |
| 195 | + @Disabled("TODO: Not null path is not found, need to investigate") |
| 196 | + fun testFillObjectArrayWithSomeInterface() { |
| 197 | + check( |
| 198 | + ArrayStoreExceptionExamples::fillObjectArrayWithSomeInterface, |
| 199 | + eq(2), |
| 200 | + { impl, result -> impl == null && result == null }, |
| 201 | + { impl, result -> impl != null && result != null && result[0] != null } |
| 202 | + ) |
| 203 | + } |
| 204 | + |
| 205 | + @Test |
| 206 | + fun testFillWithSomeImplementation() { |
| 207 | + check( |
| 208 | + ArrayStoreExceptionExamples::fillWithSomeImplementation, |
| 209 | + eq(2), |
| 210 | + { impl, result -> impl == null && result == null }, |
| 211 | + { impl, result -> impl != null && result != null && result[0] != null } |
| 212 | + ) |
| 213 | + } |
| 214 | +} |
0 commit comments