-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23ab3f7
commit 66d9530
Showing
9 changed files
with
75 additions
and
92 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
35 changes: 23 additions & 12 deletions
35
orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RotationTest.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,45 +1,56 @@ | ||
package universe.constellation.orion.viewer.test | ||
|
||
import android.content.pm.ActivityInfo | ||
import androidx.test.filters.SdkSuppress | ||
import org.junit.Assert | ||
import org.junit.Ignore | ||
import org.junit.Test | ||
import universe.constellation.orion.viewer.OrionScene | ||
import universe.constellation.orion.viewer.test.framework.BookDescription | ||
import universe.constellation.orion.viewer.test.framework.InstrumentationTestCase | ||
|
||
class RotationTest : InstrumentationTestCase() { | ||
class RotationTest : InstrumentationTestCase(BookDescription.SICP.toOpenIntent()) { | ||
|
||
@Test | ||
@Ignore | ||
@SdkSuppress(minSdkVersion = 21) | ||
fun testRotation() { | ||
startActivityWithBook(BookDescription.SICP.toOpenIntent()) | ||
lateinit var view: OrionScene | ||
activityScenarioRule.scenario.onActivity { | ||
view = it.view | ||
} | ||
|
||
val view = activity.view | ||
val width = view.sceneWidth | ||
val height = view.sceneHeight | ||
|
||
Assert.assertTrue(width != 0) | ||
Assert.assertTrue(height != 0) | ||
val orientation = activity.resources!!.configuration.orientation | ||
|
||
mActivityRule.runOnUiThread { | ||
getController().changeOrinatation(if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) "PORTRAIT" else "LANDSCAPE") | ||
var orientation: Int = Int.MIN_VALUE | ||
activityScenarioRule.scenario.onActivity { | ||
orientation = it.resources!!.configuration.orientation | ||
it.controller!!.changeOrinatation(if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) "PORTRAIT" else "LANDSCAPE") | ||
} | ||
|
||
Thread.sleep(1000) | ||
|
||
try { | ||
Assert.assertTrue("Orientation not changed: $orientation", orientation != activity.resources!!.configuration.orientation) | ||
var newOrientation: Int = Int.MAX_VALUE | ||
activityScenarioRule.scenario.onActivity { | ||
newOrientation = it.resources!!.configuration.orientation | ||
} | ||
|
||
Assert.assertNotEquals("Orientation not changed: $orientation", orientation, newOrientation) | ||
val width2 = view.sceneWidth | ||
val height2 = view.sceneHeight | ||
Assert.assertTrue("w1: $width, w2: $width2, original orientation: $orientation", width != width2) | ||
Assert.assertTrue("h1: $height, h2: $$height2, original orientation: $orientation", height != height2) | ||
} finally { | ||
mActivityRule.runOnUiThread { | ||
getController().changeOrinatation("PORTRAIT") | ||
activityScenarioRule.scenario.onActivity { | ||
it.controller!!.changeOrinatation("PORTRAIT") | ||
} | ||
Thread.sleep(1000) | ||
mActivityRule.finishActivity() | ||
activityScenarioRule.scenario.onActivity { | ||
it.finishActivity(0) | ||
} | ||
} | ||
} | ||
} |
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
29 changes: 15 additions & 14 deletions
29
...Test/kotlin/universe/constellation/orion/viewer/test/framework/InstrumentationTestCase.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,29 +1,30 @@ | ||
package universe.constellation.orion.viewer.test.framework | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.test.rule.ActivityTestRule | ||
import androidx.test.ext.junit.rules.activityScenarioRule | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.rule.GrantPermissionRule | ||
import org.junit.Rule | ||
import universe.constellation.orion.viewer.Controller | ||
import universe.constellation.orion.viewer.OrionViewerActivity | ||
import universe.constellation.orion.viewer.prefs.GlobalOptions | ||
import universe.constellation.orion.viewer.prefs.OrionApplication | ||
|
||
|
||
abstract class InstrumentationTestCase : TestUtil { | ||
abstract class InstrumentationTestCase(intent: Intent, private val showTapHelp: Boolean = false) : TestUtil { | ||
|
||
@get:Rule | ||
val mRuntimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.READ_EXTERNAL_STORAGE) | ||
|
||
@get:Rule | ||
val mActivityRule: ActivityTestRule<OrionViewerActivity> = ActivityTestRule(OrionViewerActivity::class.java, true, false) | ||
|
||
val activity: OrionViewerActivity | ||
get() = mActivityRule.activity | ||
|
||
fun getController() : Controller = mActivityRule.activity.controller!! | ||
|
||
fun startActivityWithBook(intent: Intent) { | ||
mActivityRule.launchActivity(intent) | ||
activity.orionContext.isTesting = true | ||
var activityScenarioRule = activityScenarioRule<OrionViewerActivity>(intent.apply { | ||
if (showTapHelp) { | ||
putExtra(GlobalOptions.SHOW_TAP_HELP, true) | ||
} else { | ||
putExtra(GlobalOptions.SHOW_TAP_HELP, false) | ||
} | ||
}) | ||
|
||
val globalOptions by lazy { | ||
(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as OrionApplication).options | ||
} | ||
} |
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