diff --git a/fxgl-core/src/test/kotlin/com/almasb/fxgl/core/reflect/ForeignFunctionCallerTest.kt b/fxgl-core/src/test/kotlin/com/almasb/fxgl/core/reflect/ForeignFunctionCallerTest.kt index 23b9aef35..62919a567 100644 --- a/fxgl-core/src/test/kotlin/com/almasb/fxgl/core/reflect/ForeignFunctionCallerTest.kt +++ b/fxgl-core/src/test/kotlin/com/almasb/fxgl/core/reflect/ForeignFunctionCallerTest.kt @@ -7,9 +7,7 @@ package com.almasb.fxgl.core.reflect import com.almasb.fxgl.core.util.ResourceExtractor -import org.hamcrest.CoreMatchers import org.hamcrest.CoreMatchers.* -import org.hamcrest.MatcherAssert import org.hamcrest.MatcherAssert.* import org.junit.jupiter.api.Test import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable @@ -17,8 +15,8 @@ import org.junit.jupiter.api.condition.EnabledOnOs import org.junit.jupiter.api.condition.OS import java.lang.foreign.FunctionDescriptor import java.lang.foreign.ValueLayout -import java.nio.file.Files import java.util.concurrent.CountDownLatch +import java.util.concurrent.atomic.AtomicInteger /** * @author Almas Baim (https://github.com/AlmasB) @@ -32,34 +30,35 @@ class ForeignFunctionCallerTest { val file = ResourceExtractor.extractNativeLibAsPath("native-lib-test.dll") val countDown = CountDownLatch(1) + val count = AtomicInteger() val ffc = ForeignFunctionCaller(listOf(file)) + ffc.setOnLoaded { - countDown.countDown() - } + ffc.execute { + val result = it.call( + "testDownCall", + FunctionDescriptor.of( + ValueLayout.JAVA_INT, + ValueLayout.JAVA_INT + ), + 5 + ) as Int - ffc.load() + count.set(result) + } - ffc.execute { - val result = it.call( - "testDownCall", - FunctionDescriptor.of( - ValueLayout.JAVA_INT, - ValueLayout.JAVA_INT - ), - 5 - ) as Int + ffc.unload() + } - assertThat(result, `is`(25)) + ffc.setOnUnloaded { + countDown.countDown() } - ffc.unload() + ffc.load() countDown.await() - // block some time until the native lib is fully unloaded - Thread.sleep(2500) - - Files.deleteIfExists(file) + assertThat(count.get(), `is`(25)) } } \ No newline at end of file