Fix unit tests
This commit is contained in:
parent
ca3f2328f0
commit
7cbcb267dd
|
@ -3,6 +3,7 @@ package net.shadowfacts.cacao
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
import net.shadowfacts.cacao.geometry.Rect
|
import net.shadowfacts.cacao.geometry.Rect
|
||||||
import net.shadowfacts.cacao.view.View
|
import net.shadowfacts.cacao.view.View
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -12,16 +13,25 @@ import org.junit.jupiter.api.Test
|
||||||
*/
|
*/
|
||||||
class CoordinateConversionTests {
|
class CoordinateConversionTests {
|
||||||
|
|
||||||
|
lateinit var viewController: ViewController
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
|
||||||
|
val view: View
|
||||||
|
get() = viewController.view
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
window = Window()
|
viewController = object: ViewController() {
|
||||||
|
override fun loadView() {
|
||||||
|
view = View()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = Window(viewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testConvertToParent() {
|
fun testConvertToParent() {
|
||||||
val a = window.addView(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
val a = view.addSubview(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
||||||
val b = a.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
val b = a.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
||||||
|
|
||||||
assertEquals(Point(25.0, 25.0), b.convert(Point(0.0, 0.0), to = a))
|
assertEquals(Point(25.0, 25.0), b.convert(Point(0.0, 0.0), to = a))
|
||||||
|
@ -31,7 +41,7 @@ class CoordinateConversionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testConvertToSibling() {
|
fun testConvertToSibling() {
|
||||||
val root = window.addView(View(Rect(0.0, 0.0, 200.0, 200.0)))
|
val root = view.addSubview(View(Rect(0.0, 0.0, 200.0, 200.0)))
|
||||||
val a = root.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
val a = root.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
||||||
val b = root.addSubview(View(Rect(75.0, 75.0, 50.0, 50.0)))
|
val b = root.addSubview(View(Rect(75.0, 75.0, 50.0, 50.0)))
|
||||||
|
|
||||||
|
@ -42,7 +52,7 @@ class CoordinateConversionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testConvertBetweenSubtrees() {
|
fun testConvertBetweenSubtrees() {
|
||||||
val root = window.addView(View(Rect(0.0, 0.0, 200.0, 100.0)))
|
val root = view.addSubview(View(Rect(0.0, 0.0, 200.0, 100.0)))
|
||||||
val a = root.addSubview(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
val a = root.addSubview(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
||||||
val b = root.addSubview(View(Rect(100.0, 0.0, 100.0, 100.0)))
|
val b = root.addSubview(View(Rect(100.0, 0.0, 100.0, 100.0)))
|
||||||
val c = a.addSubview(View(Rect(0.0, 0.0, 50.0, 50.0)))
|
val c = a.addSubview(View(Rect(0.0, 0.0, 50.0, 50.0)))
|
||||||
|
@ -55,8 +65,8 @@ class CoordinateConversionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testConvertBetweenTopLevelViews() {
|
fun testConvertBetweenTopLevelViews() {
|
||||||
val a = window.addView(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
val a = view.addSubview(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
||||||
val b = window.addView(View(Rect(100.0, 100.0, 100.0, 100.0)))
|
val b = view.addSubview(View(Rect(100.0, 100.0, 100.0, 100.0)))
|
||||||
|
|
||||||
assertEquals(Point(0.0, 0.0), a.convert(Point(100.0, 100.0), to = b))
|
assertEquals(Point(0.0, 0.0), a.convert(Point(100.0, 100.0), to = b))
|
||||||
assertEquals(Point(200.0, 200.0), b.convert(Point(100.0, 100.0), to = a))
|
assertEquals(Point(200.0, 200.0), b.convert(Point(100.0, 100.0), to = a))
|
||||||
|
@ -65,8 +75,8 @@ class CoordinateConversionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testConvertBetweenTopLevelSubtrees() {
|
fun testConvertBetweenTopLevelSubtrees() {
|
||||||
val a = window.addView(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
val a = view.addSubview(View(Rect(0.0, 0.0, 100.0, 100.0)))
|
||||||
val b = window.addView(View(Rect(100.0, 100.0, 100.0, 100.0)))
|
val b = view.addSubview(View(Rect(100.0, 100.0, 100.0, 100.0)))
|
||||||
val c = a.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
val c = a.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
||||||
val d = b.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
val d = b.addSubview(View(Rect(25.0, 25.0, 50.0, 50.0)))
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.shadowfacts.cacao
|
||||||
import net.shadowfacts.kiwidsl.dsl
|
import net.shadowfacts.kiwidsl.dsl
|
||||||
import net.shadowfacts.cacao.geometry.Size
|
import net.shadowfacts.cacao.geometry.Size
|
||||||
import net.shadowfacts.cacao.view.View
|
import net.shadowfacts.cacao.view.View
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import org.junit.jupiter.api.Assertions.*
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -12,16 +13,25 @@ import org.junit.jupiter.api.Test
|
||||||
*/
|
*/
|
||||||
class WindowLayoutTests {
|
class WindowLayoutTests {
|
||||||
|
|
||||||
|
lateinit var viewController: ViewController
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
|
||||||
|
val view: View
|
||||||
|
get() = viewController.view
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
window = Window()
|
viewController = object: ViewController() {
|
||||||
|
override fun loadView() {
|
||||||
|
view = View()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = Window(viewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testConstraintToConstant() {
|
fun testConstraintToConstant() {
|
||||||
val view = window.addView(View())
|
val view = view.addSubview(View())
|
||||||
window.solver.dsl {
|
window.solver.dsl {
|
||||||
view.leftAnchor equalTo 100
|
view.leftAnchor equalTo 100
|
||||||
view.rightAnchor equalTo 200
|
view.rightAnchor equalTo 200
|
||||||
|
@ -37,8 +47,8 @@ class WindowLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testConstraintToView() {
|
fun testConstraintToView() {
|
||||||
val one = window.addView(View())
|
val one = view.addSubview(View())
|
||||||
val two = window.addView(View())
|
val two = view.addSubview(View())
|
||||||
window.solver.dsl {
|
window.solver.dsl {
|
||||||
one.leftAnchor equalTo 0
|
one.leftAnchor equalTo 0
|
||||||
one.widthAnchor equalTo 100
|
one.widthAnchor equalTo 100
|
||||||
|
@ -63,7 +73,7 @@ class WindowLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIntrinsicContentSize() {
|
fun testIntrinsicContentSize() {
|
||||||
val view = window.addView(View()).apply {
|
val view = view.addSubview(View()).apply {
|
||||||
intrinsicContentSize = Size(100.0, 200.0)
|
intrinsicContentSize = Size(100.0, 200.0)
|
||||||
}
|
}
|
||||||
window.solver.dsl {
|
window.solver.dsl {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import net.shadowfacts.kiwidsl.dsl
|
||||||
import net.shadowfacts.cacao.Window
|
import net.shadowfacts.cacao.Window
|
||||||
import net.shadowfacts.cacao.geometry.Axis
|
import net.shadowfacts.cacao.geometry.Axis
|
||||||
import net.shadowfacts.cacao.geometry.Size
|
import net.shadowfacts.cacao.geometry.Size
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -14,16 +15,25 @@ import kotlin.math.abs
|
||||||
*/
|
*/
|
||||||
class StackViewLayoutTests {
|
class StackViewLayoutTests {
|
||||||
|
|
||||||
|
lateinit var viewController: ViewController
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
|
||||||
|
val view: View
|
||||||
|
get() = viewController.view
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
window = Window()
|
viewController = object: ViewController() {
|
||||||
|
override fun loadView() {
|
||||||
|
view = View()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = Window(viewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testVerticalLayout() {
|
fun testVerticalLayout() {
|
||||||
val stack = window.addView(StackView(Axis.VERTICAL))
|
val stack = view.addSubview(StackView(Axis.VERTICAL))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
@ -50,7 +60,7 @@ class StackViewLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHorizontalLayout() {
|
fun testHorizontalLayout() {
|
||||||
val stack = window.addView(StackView(Axis.HORIZONTAL))
|
val stack = view.addSubview(StackView(Axis.HORIZONTAL))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
@ -77,7 +87,7 @@ class StackViewLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testVerticalLayoutWithLeading() {
|
fun testVerticalLayoutWithLeading() {
|
||||||
val stack = window.addView(StackView(Axis.VERTICAL, StackView.Distribution.LEADING))
|
val stack = view.addSubview(StackView(Axis.VERTICAL, StackView.Distribution.LEADING))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
@ -106,7 +116,7 @@ class StackViewLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testVerticalLayoutWithTrailing() {
|
fun testVerticalLayoutWithTrailing() {
|
||||||
val stack = window.addView(StackView(Axis.VERTICAL, StackView.Distribution.TRAILING))
|
val stack = view.addSubview(StackView(Axis.VERTICAL, StackView.Distribution.TRAILING))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
@ -135,7 +145,7 @@ class StackViewLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testVerticalLayoutWithCenter() {
|
fun testVerticalLayoutWithCenter() {
|
||||||
val stack = window.addView(StackView(Axis.VERTICAL, StackView.Distribution.CENTER))
|
val stack = view.addSubview(StackView(Axis.VERTICAL, StackView.Distribution.CENTER))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
@ -164,7 +174,7 @@ class StackViewLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testVerticalLayoutWithFill() {
|
fun testVerticalLayoutWithFill() {
|
||||||
val stack = window.addView(StackView(Axis.VERTICAL, StackView.Distribution.FILL))
|
val stack = view.addSubview(StackView(Axis.VERTICAL, StackView.Distribution.FILL))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
@ -193,7 +203,7 @@ class StackViewLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testVerticalLayoutWithSpacing() {
|
fun testVerticalLayoutWithSpacing() {
|
||||||
val stack = window.addView(StackView(Axis.VERTICAL, spacing = 10.0))
|
val stack = view.addSubview(StackView(Axis.VERTICAL, spacing = 10.0))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
@ -220,7 +230,7 @@ class StackViewLayoutTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHorizontalLayoutWithSpacing() {
|
fun testHorizontalLayoutWithSpacing() {
|
||||||
val stack = window.addView(StackView(Axis.HORIZONTAL, spacing = 10.0))
|
val stack = view.addSubview(StackView(Axis.HORIZONTAL, spacing = 10.0))
|
||||||
val one = stack.addArrangedSubview(View().apply {
|
val one = stack.addArrangedSubview(View().apply {
|
||||||
intrinsicContentSize = Size(50.0, 50.0)
|
intrinsicContentSize = Size(50.0, 50.0)
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,6 +5,7 @@ import net.shadowfacts.cacao.Window
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
import net.shadowfacts.cacao.geometry.Rect
|
import net.shadowfacts.cacao.geometry.Rect
|
||||||
import net.shadowfacts.cacao.util.MouseButton
|
import net.shadowfacts.cacao.util.MouseButton
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import org.junit.jupiter.api.Assertions.*
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -17,17 +18,26 @@ class ViewClickTests {
|
||||||
|
|
||||||
lateinit var screen: CacaoScreen
|
lateinit var screen: CacaoScreen
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
lateinit var viewController: ViewController
|
||||||
|
|
||||||
|
val view: View
|
||||||
|
get() = viewController.view
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
screen = CacaoScreen()
|
screen = CacaoScreen()
|
||||||
window = screen.addWindow(Window())
|
viewController = object: ViewController() {
|
||||||
|
override fun loadView() {
|
||||||
|
view = View(Rect(0.0, 0.0, 1000.0, 1000.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = screen.addWindow(Window(viewController))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testClickInsideRootView() {
|
fun testClickInsideRootView() {
|
||||||
val mouse = CompletableFuture<Point>()
|
val mouse = CompletableFuture<Point>()
|
||||||
window.addView(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
|
view.addSubview(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
|
||||||
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
||||||
mouse.complete(point)
|
mouse.complete(point)
|
||||||
return true
|
return true
|
||||||
|
@ -41,7 +51,7 @@ class ViewClickTests {
|
||||||
@Test
|
@Test
|
||||||
fun testClickOutsideRootView() {
|
fun testClickOutsideRootView() {
|
||||||
val clicked = CompletableFuture<Boolean>()
|
val clicked = CompletableFuture<Boolean>()
|
||||||
window.addView(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
|
view.addSubview(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
|
||||||
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
||||||
clicked.complete(true)
|
clicked.complete(true)
|
||||||
return true
|
return true
|
||||||
|
@ -55,7 +65,7 @@ class ViewClickTests {
|
||||||
@Test
|
@Test
|
||||||
fun testClickInsideNestedView() {
|
fun testClickInsideNestedView() {
|
||||||
val mouse = CompletableFuture<Point>()
|
val mouse = CompletableFuture<Point>()
|
||||||
val root = window.addView(View(Rect(50.0, 50.0, 100.0, 100.0)))
|
val root = view.addSubview(View(Rect(50.0, 50.0, 100.0, 100.0)))
|
||||||
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
|
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
|
||||||
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
||||||
mouse.complete(point)
|
mouse.complete(point)
|
||||||
|
@ -70,7 +80,7 @@ class ViewClickTests {
|
||||||
@Test
|
@Test
|
||||||
fun testClickOutsideNestedView() {
|
fun testClickOutsideNestedView() {
|
||||||
val clicked = CompletableFuture<Boolean>()
|
val clicked = CompletableFuture<Boolean>()
|
||||||
val root = window.addView(View(Rect(50.0, 50.0, 100.0, 100.0)))
|
val root = view.addSubview(View(Rect(50.0, 50.0, 100.0, 100.0)))
|
||||||
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
|
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
|
||||||
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
||||||
clicked.complete(true)
|
clicked.complete(true)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.shadowfacts.cacao.view
|
||||||
import net.shadowfacts.cacao.Window
|
import net.shadowfacts.cacao.Window
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
import net.shadowfacts.cacao.geometry.Rect
|
import net.shadowfacts.cacao.geometry.Rect
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.BeforeAll
|
import org.junit.jupiter.api.BeforeAll
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
@ -14,8 +15,12 @@ import java.util.concurrent.CompletableFuture
|
||||||
*/
|
*/
|
||||||
class ViewHoverTests {
|
class ViewHoverTests {
|
||||||
|
|
||||||
|
lateinit var viewController: ViewController
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
|
||||||
|
val view: View
|
||||||
|
get() = viewController.view
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -26,13 +31,18 @@ class ViewHoverTests {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
window = Window()
|
viewController = object: ViewController() {
|
||||||
|
override fun loadView() {
|
||||||
|
view = View()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = Window(viewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHoverRootView() {
|
fun testHoverRootView() {
|
||||||
val point = CompletableFuture<Point>()
|
val point = CompletableFuture<Point>()
|
||||||
window.addView(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
|
view.addSubview(object: View(Rect(50.0, 50.0, 100.0, 100.0)) {
|
||||||
override fun drawContent(mouse: Point, delta: Float) {
|
override fun drawContent(mouse: Point, delta: Float) {
|
||||||
point.complete(mouse)
|
point.complete(mouse)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +55,7 @@ class ViewHoverTests {
|
||||||
@Test
|
@Test
|
||||||
fun testHoverNestedView() {
|
fun testHoverNestedView() {
|
||||||
val point = CompletableFuture<Point>()
|
val point = CompletableFuture<Point>()
|
||||||
val root = window.addView(View(Rect(50.0, 50.0, 100.0, 100.0)))
|
val root = view.addSubview(View(Rect(50.0, 50.0, 100.0, 100.0)))
|
||||||
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
|
root.addSubview(object: View(Rect(25.0, 25.0, 50.0, 50.0)) {
|
||||||
override fun drawContent(mouse: Point, delta: Float) {
|
override fun drawContent(mouse: Point, delta: Float) {
|
||||||
point.complete(mouse)
|
point.complete(mouse)
|
||||||
|
|
|
@ -3,9 +3,11 @@ package net.shadowfacts.cacao.view.button
|
||||||
import net.shadowfacts.cacao.CacaoScreen
|
import net.shadowfacts.cacao.CacaoScreen
|
||||||
import net.shadowfacts.cacao.Window
|
import net.shadowfacts.cacao.Window
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
|
import net.shadowfacts.cacao.geometry.Rect
|
||||||
import net.shadowfacts.cacao.geometry.Size
|
import net.shadowfacts.cacao.geometry.Size
|
||||||
import net.shadowfacts.cacao.util.MouseButton
|
import net.shadowfacts.cacao.util.MouseButton
|
||||||
import net.shadowfacts.cacao.view.View
|
import net.shadowfacts.cacao.view.View
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import net.shadowfacts.kiwidsl.dsl
|
import net.shadowfacts.kiwidsl.dsl
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
@ -20,11 +22,20 @@ class ButtonClickTests {
|
||||||
|
|
||||||
lateinit var screen: CacaoScreen
|
lateinit var screen: CacaoScreen
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
lateinit var viewController: ViewController
|
||||||
|
|
||||||
|
val view: View
|
||||||
|
get() = viewController.view
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
screen = CacaoScreen()
|
screen = CacaoScreen()
|
||||||
window = screen.addWindow(Window())
|
viewController = object: ViewController() {
|
||||||
|
override fun loadView() {
|
||||||
|
view = View(Rect(0.0, 0.0, 1000.0, 1000.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = screen.addWindow(Window(viewController))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -33,7 +44,7 @@ class ButtonClickTests {
|
||||||
val content = View().apply {
|
val content = View().apply {
|
||||||
intrinsicContentSize = Size(25.0, 25.0)
|
intrinsicContentSize = Size(25.0, 25.0)
|
||||||
}
|
}
|
||||||
val button = window.addView(Button(content).apply {
|
val button = view.addSubview(Button(content).apply {
|
||||||
handler = {
|
handler = {
|
||||||
clicked.complete(true)
|
clicked.complete(true)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +65,7 @@ class ButtonClickTests {
|
||||||
val content = View().apply {
|
val content = View().apply {
|
||||||
intrinsicContentSize = Size(25.0, 25.0)
|
intrinsicContentSize = Size(25.0, 25.0)
|
||||||
}
|
}
|
||||||
val button = window.addView(Button(content).apply {
|
val button = view.addSubview(Button(content).apply {
|
||||||
handler = {
|
handler = {
|
||||||
clicked.complete(true)
|
clicked.complete(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import net.shadowfacts.cacao.Window
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
import net.shadowfacts.cacao.geometry.Rect
|
import net.shadowfacts.cacao.geometry.Rect
|
||||||
import net.shadowfacts.cacao.util.MouseButton
|
import net.shadowfacts.cacao.util.MouseButton
|
||||||
|
import net.shadowfacts.cacao.view.View
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import net.shadowfacts.kiwidsl.dsl
|
import net.shadowfacts.kiwidsl.dsl
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
|
@ -32,13 +34,19 @@ class EnumButtonTests {
|
||||||
|
|
||||||
lateinit var screen: CacaoScreen
|
lateinit var screen: CacaoScreen
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
lateinit var viewController: ViewController
|
||||||
lateinit var button: EnumButton<MyEnum>
|
lateinit var button: EnumButton<MyEnum>
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
screen = CacaoScreen()
|
screen = CacaoScreen()
|
||||||
window = screen.addWindow(Window())
|
viewController = object: ViewController() {
|
||||||
button = window.addView(EnumButton(MyEnum.ONE, MyEnum::name))
|
override fun loadView() {
|
||||||
|
view = View(Rect(0.0, 0.0, 1000.0, 1000.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = screen.addWindow(Window(viewController))
|
||||||
|
button = viewController.view.addSubview(EnumButton(MyEnum.ONE, MyEnum::name))
|
||||||
window.solver.dsl {
|
window.solver.dsl {
|
||||||
button.leftAnchor equalTo 0
|
button.leftAnchor equalTo 0
|
||||||
button.topAnchor equalTo 0
|
button.topAnchor equalTo 0
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package net.shadowfacts.cacao.view.button
|
package net.shadowfacts.cacao.view.button
|
||||||
|
|
||||||
|
import net.shadowfacts.cacao.CacaoScreen
|
||||||
import net.shadowfacts.cacao.Window
|
import net.shadowfacts.cacao.Window
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
import net.shadowfacts.cacao.geometry.Rect
|
import net.shadowfacts.cacao.geometry.Rect
|
||||||
import net.shadowfacts.cacao.util.MouseButton
|
import net.shadowfacts.cacao.util.MouseButton
|
||||||
|
import net.shadowfacts.cacao.view.View
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import org.junit.jupiter.api.Assertions.*
|
||||||
import org.junit.jupiter.api.BeforeAll
|
import org.junit.jupiter.api.BeforeAll
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
@ -23,17 +26,28 @@ class ToggleButtonTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lateinit var screen: CacaoScreen
|
||||||
lateinit var window: Window
|
lateinit var window: Window
|
||||||
|
lateinit var viewController: ViewController
|
||||||
|
|
||||||
|
val view: View
|
||||||
|
get() = viewController.view
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setup() {
|
fun setup() {
|
||||||
window = Window()
|
screen = CacaoScreen()
|
||||||
|
viewController = object: ViewController() {
|
||||||
|
override fun loadView() {
|
||||||
|
view = View(Rect(0.0, 0.0, 1000.0, 1000.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window = screen.addWindow(Window(viewController))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHandlerCalled() {
|
fun testHandlerCalled() {
|
||||||
val called = CompletableFuture<Boolean>()
|
val called = CompletableFuture<Boolean>()
|
||||||
val button = window.addView(ToggleButton(false).apply {
|
val button = view.addSubview(ToggleButton(false).apply {
|
||||||
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
||||||
content.frame = bounds
|
content.frame = bounds
|
||||||
handler = {
|
handler = {
|
||||||
|
@ -47,7 +61,7 @@ class ToggleButtonTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testTogglesValues() {
|
fun testTogglesValues() {
|
||||||
val button = window.addView(ToggleButton(false).apply {
|
val button = view.addSubview(ToggleButton(false).apply {
|
||||||
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
||||||
content.frame = bounds
|
content.frame = bounds
|
||||||
})
|
})
|
||||||
|
@ -60,7 +74,7 @@ class ToggleButtonTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMiddleClickDoesNotChangeValue() {
|
fun testMiddleClickDoesNotChangeValue() {
|
||||||
val button = window.addView(ToggleButton(false).apply {
|
val button = view.addSubview(ToggleButton(false).apply {
|
||||||
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
frame = Rect(0.0, 0.0, 25.0, 25.0)
|
||||||
content.frame = bounds
|
content.frame = bounds
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue