-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Windows JVM implementation for NativeKeyboardHandler with t…
…ests. Add runtime dependency to JUnit5 which was failing the tests.
- Loading branch information
Showing
16 changed files
with
311 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
45 changes: 16 additions & 29 deletions
45
keyboard/src/commonTest/kotlin/com/github/animeshz/keyboard/NativeKeyboardHandlerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
package com.github.animeshz.keyboard | ||
|
||
/** | ||
* Tests can be tried out after enabling granular source-set metadata in gradle.properties | ||
import com.github.animeshz.keyboard.entity.Key | ||
import com.github.animeshz.keyboard.events.KeyEvent | ||
import com.github.animeshz.keyboard.events.KeyState | ||
import io.kotest.matchers.comparables.shouldNotBeEqualComparingTo | ||
import kotlin.test.Test | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.take | ||
import kotlinx.coroutines.runBlocking | ||
import kotlin.test.assertNotEquals | ||
|
||
/** | ||
* This is not really a Unit Test (since mocking is not available in Native), | ||
* but rather a real-time test (in other words you have to interact :p). | ||
*/ | ||
@ExperimentalKeyIO | ||
class NativeKeyboardHandlerTest { | ||
@Test | ||
fun `get state of Key`() = runBlocking { | ||
val handler = nativeKbHandlerForPlatform() | ||
@Test | ||
fun `Caps lock key should be toggled when KeyDown event is triggered`() { | ||
val handler = nativeKbHandlerForPlatform() | ||
|
||
delay(3000) // To have a delay to check if KeyDown comes :P | ||
println("State of Key A: ${handler.getKeyState(Key.A)}") | ||
} | ||
val initialState = handler.isCapsLockOn() | ||
|
||
@Test | ||
fun `get state of Caps Lock`() = runBlocking { | ||
val handler = nativeKbHandlerForPlatform() | ||
handler.sendEvent(KeyEvent(Key.CapsLock, KeyState.KeyDown)) | ||
handler.sendEvent(KeyEvent(Key.CapsLock, KeyState.KeyUp)) | ||
|
||
println("Toggle state of CapsLock: ${if (handler.isCapsLockOn()) "On" else "Off"}") | ||
} | ||
val finalState = handler.isCapsLockOn() | ||
|
||
@Test | ||
fun `listening to events`() = runBlocking { | ||
val handler = nativeKbHandlerForPlatform() | ||
// Set the state back to initialState | ||
handler.sendEvent(KeyEvent(Key.CapsLock, KeyState.KeyDown)) | ||
handler.sendEvent(KeyEvent(Key.CapsLock, KeyState.KeyUp)) | ||
|
||
println("Listening for first 5 events") | ||
handler.events.take(5).collect { println(it) } | ||
} | ||
finalState shouldNotBeEqualComparingTo initialState | ||
} | ||
} | ||
*/ |
42 changes: 42 additions & 0 deletions
42
keyboard/src/commonTest/kotlin/com/github/animeshz/keyboard/NativeKeyboardHandlerTestTmp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.animeshz.keyboard | ||
|
||
/** | ||
* Tests can be tried out after enabling granular source-set metadata in gradle.properties | ||
import com.github.animeshz.keyboard.entity.Key | ||
import kotlin.test.Test | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.take | ||
import kotlinx.coroutines.runBlocking | ||
/** | ||
* This is not really a Unit Test (since mocking is not available in Native), | ||
* but rather a real-time test (in other words you have to interact :p). | ||
*/ | ||
@ExperimentalKeyIO | ||
class NativeKeyboardHandlerTest { | ||
@Test | ||
fun `get state of Key`() = runBlocking { | ||
val handler = nativeKbHandlerForPlatform() | ||
delay(3000) // To have a delay to check if KeyDown comes :P | ||
println("State of Key A: ${handler.getKeyState(Key.A)}") | ||
} | ||
@Test | ||
fun `get state of Caps Lock`() = runBlocking { | ||
val handler = nativeKbHandlerForPlatform() | ||
println("Toggle state of CapsLock: ${if (handler.isCapsLockOn()) "On" else "Off"}") | ||
} | ||
@Test | ||
fun `listening to events`() = runBlocking { | ||
val handler = nativeKbHandlerForPlatform() | ||
println("Listening for first 5 events") | ||
handler.events.take(5).collect { println(it) } | ||
} | ||
} | ||
*/ |
40 changes: 40 additions & 0 deletions
40
keyboard/src/jvmMain/generated/jni/com_github_animeshz_keyboard_JvmKeyboardHandler.h
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.