Skip to content

Commit

Permalink
Update RotationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kammerer committed Feb 7, 2024
1 parent 9d3fe62 commit 759d685
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 56 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package universe.constellation.orion.viewer.test.espresso

import android.content.pm.ActivityInfo
import androidx.test.filters.SdkSuppress
import org.junit.After
import org.junit.Assert
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import universe.constellation.orion.viewer.test.framework.BookDescription
import universe.constellation.orion.viewer.view.OrionDrawScene

class RotationTest : BaseEspressoTest(BookDescription.SICP) {

@Test
@SdkSuppress(minSdkVersion = 21)
fun testScreenRotationAndViewSize() {
assertTrue(device.isNaturalOrientation)

val width = device.displayWidth
val height = device.displayHeight
assertTrue(width != 0)
assertTrue(height != 0)
val originSize = getViewSize()

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")
}
device.waitForIdle()
assertFalse(device.isNaturalOrientation)
getViewSize()

var newOrientation: Int = Int.MAX_VALUE
activityScenarioRule.scenario.onActivity {
newOrientation = it.resources!!.configuration.orientation
}
val rotatedSize = getViewSize()

Assert.assertNotEquals("Orientation not changed: $orientation", orientation, newOrientation)
val width2 = device.displayWidth
val height2 = device.displayHeight
assertTrue("w1: $width, w2: $width2, original orientation: $orientation", width != width2)
assertTrue("h1: $height, h2: $$height2, original orientation: $orientation", height != height2)

assertTrue("origin: $originSize, rotated: $rotatedSize, original orientation: $orientation", originSize != rotatedSize)

activityScenarioRule.scenario.onActivity {
it.controller!!.changeOrinatation("PORTRAIT")
}
device.waitForIdle()
assertTrue(device.isNaturalOrientation)
}

private fun getViewSize(): Pair<Int, Int> {
lateinit var view: OrionDrawScene
activityScenarioRule.scenario.onActivity {
view = it.view
}

val width = view.sceneWidth
val height = view.sceneHeight

assertTrue(width != 0)
assertTrue(height != 0)
return width to height
}

@After
fun afterTest() {
device.setOrientationNatural()
}
}

0 comments on commit 759d685

Please sign in to comment.