ASMR/src/test/kotlin/net/shadowfacts/cacao/view/ViewHoverTests.kt

72 lines
1.5 KiB
Kotlin

package net.shadowfacts.cacao.view
import net.shadowfacts.cacao.Window
import net.shadowfacts.cacao.geometry.Point
import net.shadowfacts.cacao.geometry.Rect
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.util.concurrent.CompletableFuture
/**
* @author shadowfacts
*/
class ViewHoverTests {
lateinit var window: Window
companion object {
@BeforeAll
@JvmStatic
fun setupAll() {
System.setProperty("cacao.drawing.disabled", "true")
}
}
@BeforeEach
fun setup() {
window = Window()
}
@Test
fun testHoverRootView() {
val point = CompletableFuture<Point>()
window.addView(object: View() {
init {
frame = Rect(50.0, 50.0, 100.0, 100.0)
bounds = Rect(0.0, 0.0, 100.0, 100.0)
}
override fun drawContent(mouse: Point, delta: Float) {
point.complete(mouse)
}
})
window.draw(Point(75.0, 75.0), 0f)
assertEquals(Point(25.0, 25.0), point.getNow(null))
}
@Test
fun testHoverNestedView() {
val point = CompletableFuture<Point>()
val root = window.addView(View().apply {
frame = Rect(50.0, 50.0, 100.0, 100.0)
bounds = Rect(0.0, 0.0, 100.0, 100.0)
})
root.addSubview(object: View() {
init {
frame = Rect(25.0, 25.0, 50.0, 50.0)
bounds = Rect(0.0, 0.0, 50.0, 50.0)
}
override fun drawContent(mouse: Point, delta: Float) {
point.complete(mouse)
}
})
window.draw(Point(100.0, 100.0), 0f)
assertEquals(Point(25.0, 25.0), point.getNow(null))
}
}