Skip to content

Commit

Permalink
test: fix video capture mode with analysis test to ignore if analysis…
Browse files Browse the repository at this point in the history
… is not supported
  • Loading branch information
ujizin committed Dec 10, 2023
1 parent e70279f commit f802d9d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
6 changes: 6 additions & 0 deletions camposer/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

<uses-sdk android:targetSdkVersion="31" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera2"
Expand Down
21 changes: 18 additions & 3 deletions camposer/src/androidTest/java/com/ujizin/camposer/CameraTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ujizin.camposer

import android.Manifest
import android.os.Build
import androidx.compose.runtime.Composable
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
Expand All @@ -16,9 +17,23 @@ internal abstract class CameraTest {

@get:Rule
val permissions: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_EXTERNAL_STORAGE
*mutableListOf(
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
).apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
add(Manifest.permission.POST_NOTIFICATIONS)
add(Manifest.permission.READ_MEDIA_AUDIO)
add(Manifest.permission.READ_MEDIA_VIDEO)
add(Manifest.permission.READ_MEDIA_IMAGES)
} else {
add(Manifest.permission.READ_EXTERNAL_STORAGE)
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
}.toTypedArray()
)

protected lateinit var cameraState: CameraState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ internal class CaptureModeTest : CameraTest() {
is VideoCaptureResult.Success -> {
assertEquals(Uri.fromFile(videoFile), result.savedUri)
assertEquals(CaptureMode.Video, cameraState.captureMode)
assertEquals(true, cameraState.isImageAnalysisEnabled)
assertEquals(true, isAnalyzeCalled)
if (cameraState.isImageAnalysisSupported) {
assertEquals(true, cameraState.isImageAnalysisEnabled)
assertEquals(true, isAnalyzeCalled)
}
}
}
}
Expand All @@ -115,7 +117,7 @@ internal class CaptureModeTest : CameraTest() {
}

private companion object {
private const val RECORD_VIDEO_DELAY = 500L
private const val RECORD_VIDEO_DELAY = 1000L
private const val IMAGE_TEST_FILENAME = "capture_mode_test.jpg"
private const val VIDEO_TEST_FILENAME = "capture_mode_test.mp4"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class FlashModeTest : CameraTest() {

FlashMode.values().forEach { mode ->
flashMode.value = mode
onNodeWithTag("$mode").assertIsDisplayed()
onNodeWithTag("${flashMode.value}").assertIsDisplayed()
runOnIdle { assertEquals(mode, cameraState.flashMode) }
}
}
Expand All @@ -39,7 +39,7 @@ internal class FlashModeTest : CameraTest() {
cameraState.hasFlashUnit = false

flashMode.value = FlashMode.On
onNodeWithTag("$flashMode").assertDoesNotExist()
onNodeWithTag("${flashMode.value}").assertDoesNotExist()
runOnIdle { assertEquals(FlashMode.Off, cameraState.flashMode) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ internal class ImageAnalyzerTest : CameraTest() {
waitUntil(ANALYZER_TIME_OUT) { isAnalyzeCalled }

runOnIdle {
assertEquals(true, cameraState.isImageAnalysisEnabled)
assertEquals(true, isAnalyzeCalled)
if (cameraState.isImageAnalysisSupported) {
assertEquals(true, cameraState.isImageAnalysisEnabled)
assertEquals(true, isAnalyzeCalled)
}
}
}

Expand All @@ -38,14 +40,16 @@ internal class ImageAnalyzerTest : CameraTest() {
initImageAnalyzerCamera(isImageAnalyzeEnabled = false) { isAnalyzeCalled = true }

runOnIdle {
assertEquals(false, cameraState.isImageAnalysisEnabled)
assertEquals(false, isAnalyzeCalled)
if (cameraState.isImageAnalysisSupported) {
assertEquals(false, cameraState.isImageAnalysisEnabled)
assertEquals(false, isAnalyzeCalled)
}
}
}

@Test
fun test_imageAnalysisSupported() = with(composeTestRule) {
var expectImageAnalysisSupported = true
var expectImageAnalysisSupported: Boolean? = null
initImageAnalyzerCamera(isImageAnalyzeEnabled = true) {
expectImageAnalysisSupported = cameraState.isImageAnalysisSupported()
}
Expand Down

0 comments on commit f802d9d

Please sign in to comment.