Skip to content

Commit

Permalink
Add failing test for parent static field instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaMuravjov committed Feb 21, 2024
1 parent 1d00c9b commit bcf7820
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example;

public class ClassWithStaticField {
public static String STATIC_FIELD = "static field content";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package example;

public class ParentStaticFieldUser extends ClassWithStaticField {
public static String getParentStaticField() {
return ParentStaticFieldUser.STATIC_FIELD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.usvm.instrumentation.testcase.api.UTestExecutionExceptionResult
import org.usvm.instrumentation.testcase.api.UTestExecutionSuccessResult
import org.usvm.instrumentation.testcase.descriptor.UTestConstantDescriptor
import org.usvm.instrumentation.util.UTestCreator
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -248,4 +249,16 @@ class ConcreteExecutorTests: UTestConcreteExecutorTest() {
assertIs<UTestExecutionSuccessResult>(res)
}

@Test
fun `get parent static field`() = executeTest {
val uTest = UTestCreator.ParentStaticFieldUser.getParentStaticField(jcClasspath)
val res = uTestConcreteExecutor.executeAsync(uTest)
assertIs<UTestExecutionSuccessResult>(res)
val result = res.result
assertNotNull(result)
assertIs<UTestConstantDescriptor.String>(result)
assertEquals("static field content", result.value)
assertContains(res.resultState.statics.keys.map { it.name }, "STATIC_FIELD")
}.also { println(0) }

}
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,13 @@ object UTestCreator {
return UTest(listOf(), methodCall)
}
}

object ParentStaticFieldUser {
fun getParentStaticField(jcClasspath: JcClasspath): UTest {
val jcClass = jcClasspath.findClass("example.ParentStaticFieldUser")
val jcMethod = jcClass.declaredMethods.find { it.name == "getParentStaticField" }!!

return UTest(listOf(), UTestStaticMethodCall(jcMethod, emptyList()))
}
}
}

0 comments on commit bcf7820

Please sign in to comment.