|
@@ -30,15 +30,19 @@
|
|
|
|
|
|
|
|
package com.godot.game
|
|
package com.godot.game
|
|
|
|
|
|
|
|
|
|
+import android.content.ComponentName
|
|
|
|
|
+import android.content.Intent
|
|
|
import android.util.Log
|
|
import android.util.Log
|
|
|
-import androidx.test.ext.junit.rules.ActivityScenarioRule
|
|
|
|
|
|
|
+import androidx.test.core.app.ActivityScenario
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
|
import com.godot.game.test.GodotAppInstrumentedTestPlugin
|
|
import com.godot.game.test.GodotAppInstrumentedTestPlugin
|
|
|
|
|
+import org.godotengine.godot.GodotActivity.Companion.EXTRA_COMMAND_LINE_PARAMS
|
|
|
import org.godotengine.godot.plugin.GodotPluginRegistry
|
|
import org.godotengine.godot.plugin.GodotPluginRegistry
|
|
|
-import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
import org.junit.Test
|
|
|
import org.junit.runner.RunWith
|
|
import org.junit.runner.RunWith
|
|
|
|
|
+import kotlin.test.assertEquals
|
|
|
import kotlin.test.assertNotNull
|
|
import kotlin.test.assertNotNull
|
|
|
|
|
+import kotlin.test.assertNull
|
|
|
import kotlin.test.assertTrue
|
|
import kotlin.test.assertTrue
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -49,28 +53,94 @@ class GodotAppTest {
|
|
|
|
|
|
|
|
companion object {
|
|
companion object {
|
|
|
private val TAG = GodotAppTest::class.java.simpleName
|
|
private val TAG = GodotAppTest::class.java.simpleName
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- @get:Rule
|
|
|
|
|
- val godotAppRule = ActivityScenarioRule(GodotApp::class.java)
|
|
|
|
|
|
|
+ private const val GODOT_APP_LAUNCHER_CLASS_NAME = "com.godot.game.GodotAppLauncher"
|
|
|
|
|
+ private const val GODOT_APP_CLASS_NAME = "com.godot.game.GodotApp"
|
|
|
|
|
+
|
|
|
|
|
+ private val TEST_COMMAND_LINE_PARAMS = arrayOf("This is a test")
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Runs the JavaClassWrapper tests via the GodotAppInstrumentedTestPlugin.
|
|
* Runs the JavaClassWrapper tests via the GodotAppInstrumentedTestPlugin.
|
|
|
*/
|
|
*/
|
|
|
@Test
|
|
@Test
|
|
|
fun runJavaClassWrapperTests() {
|
|
fun runJavaClassWrapperTests() {
|
|
|
- val testPlugin = GodotPluginRegistry.getPluginRegistry()
|
|
|
|
|
- .getPlugin("GodotAppInstrumentedTestPlugin") as GodotAppInstrumentedTestPlugin?
|
|
|
|
|
- assertNotNull(testPlugin)
|
|
|
|
|
|
|
+ ActivityScenario.launch(GodotApp::class.java).use { scenario ->
|
|
|
|
|
+ scenario.onActivity { activity ->
|
|
|
|
|
+ val testPlugin = GodotPluginRegistry.getPluginRegistry()
|
|
|
|
|
+ .getPlugin("GodotAppInstrumentedTestPlugin") as GodotAppInstrumentedTestPlugin?
|
|
|
|
|
+ assertNotNull(testPlugin)
|
|
|
|
|
+
|
|
|
|
|
+ Log.d(TAG, "Waiting for the Godot main loop to start...")
|
|
|
|
|
+ testPlugin.waitForGodotMainLoopStarted()
|
|
|
|
|
+
|
|
|
|
|
+ Log.d(TAG, "Running JavaClassWrapper tests...")
|
|
|
|
|
+ val result = testPlugin.runJavaClassWrapperTests()
|
|
|
|
|
+ assertNotNull(result)
|
|
|
|
|
+ result.exceptionOrNull()?.let { throw it }
|
|
|
|
|
+ assertTrue(result.isSuccess)
|
|
|
|
|
+ Log.d(TAG, "Passed ${result.getOrNull()} tests")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- Log.d(TAG, "Waiting for the Godot main loop to start...")
|
|
|
|
|
- testPlugin.waitForGodotMainLoopStarted()
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Test implicit launch of the Godot app, and validates this resolves to the `GodotAppLauncher` activity alias.
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ fun testImplicitGodotAppLauncherLaunch() {
|
|
|
|
|
+ val implicitLaunchIntent = Intent().apply {
|
|
|
|
|
+ setPackage(BuildConfig.APPLICATION_ID)
|
|
|
|
|
+ action = Intent.ACTION_MAIN
|
|
|
|
|
+ addCategory(Intent.CATEGORY_LAUNCHER)
|
|
|
|
|
+ putExtra(EXTRA_COMMAND_LINE_PARAMS, TEST_COMMAND_LINE_PARAMS)
|
|
|
|
|
+ }
|
|
|
|
|
+ ActivityScenario.launch<GodotApp>(implicitLaunchIntent).use { scenario ->
|
|
|
|
|
+ scenario.onActivity { activity ->
|
|
|
|
|
+ assertEquals(activity.intent.component?.className, GODOT_APP_LAUNCHER_CLASS_NAME)
|
|
|
|
|
+
|
|
|
|
|
+ val commandLineParams = activity.intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
|
|
|
|
|
+ assertNull(commandLineParams)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Test explicit launch of the Godot app via its activity-alias launcher, and validates it resolves properly.
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ fun testExplicitGodotAppLauncherLaunch() {
|
|
|
|
|
+ val explicitIntent = Intent().apply {
|
|
|
|
|
+ component = ComponentName(BuildConfig.APPLICATION_ID, GODOT_APP_LAUNCHER_CLASS_NAME)
|
|
|
|
|
+ putExtra(EXTRA_COMMAND_LINE_PARAMS, TEST_COMMAND_LINE_PARAMS)
|
|
|
|
|
+ }
|
|
|
|
|
+ ActivityScenario.launch<GodotApp>(explicitIntent).use { scenario ->
|
|
|
|
|
+ scenario.onActivity { activity ->
|
|
|
|
|
+ assertEquals(activity.intent.component?.className, GODOT_APP_LAUNCHER_CLASS_NAME)
|
|
|
|
|
+
|
|
|
|
|
+ val commandLineParams = activity.intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
|
|
|
|
|
+ assertNull(commandLineParams)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Test explicit launch of the `GodotApp` activity.
|
|
|
|
|
+ */
|
|
|
|
|
+ @Test
|
|
|
|
|
+ fun testExplicitGodotAppLaunch() {
|
|
|
|
|
+ val explicitIntent = Intent().apply {
|
|
|
|
|
+ component = ComponentName(BuildConfig.APPLICATION_ID, GODOT_APP_CLASS_NAME)
|
|
|
|
|
+ putExtra(EXTRA_COMMAND_LINE_PARAMS, TEST_COMMAND_LINE_PARAMS)
|
|
|
|
|
+ }
|
|
|
|
|
+ ActivityScenario.launch<GodotApp>(explicitIntent).use { scenario ->
|
|
|
|
|
+ scenario.onActivity { activity ->
|
|
|
|
|
+ assertEquals(activity.intent.component?.className, GODOT_APP_CLASS_NAME)
|
|
|
|
|
|
|
|
- Log.d(TAG, "Running JavaClassWrapper tests...")
|
|
|
|
|
- val result = testPlugin.runJavaClassWrapperTests()
|
|
|
|
|
- assertNotNull(result)
|
|
|
|
|
- result.exceptionOrNull()?.let { throw it }
|
|
|
|
|
- assertTrue(result.isSuccess)
|
|
|
|
|
- Log.d(TAG, "Passed ${result.getOrNull()} tests")
|
|
|
|
|
|
|
+ val commandLineParams = activity.intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
|
|
|
|
|
+ assertNotNull(commandLineParams)
|
|
|
|
|
+ assertTrue(commandLineParams.contentEquals(TEST_COMMAND_LINE_PARAMS))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|