Skip to content

Commit

Permalink
clean up test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Dec 26, 2024
1 parent c5d9bf5 commit ac6c15d
Showing 1 changed file with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
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
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)
Expand All @@ -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))
}
}

0 comments on commit ac6c15d

Please sign in to comment.