-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add exposure compensation for camera preview
- Loading branch information
ujizin
committed
Aug 15, 2023
1 parent
ff9354e
commit eafa66f
Showing
3 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
camposer/src/androidTest/java/com/ujizin/camposer/ExposureCompensationTest.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,70 @@ | ||
package com.ujizin.camposer | ||
|
||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.test.junit4.ComposeContentTestRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Assert.assertNotEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
internal class ExposureCompensationTest: CameraTest() { | ||
|
||
private lateinit var exposureCompensation: MutableState<Int> | ||
|
||
private val currentExposure: Int? | ||
get() = cameraState.controller.cameraInfo?.exposureState?.exposureCompensationIndex | ||
|
||
@Test | ||
fun test_minExposureCompensation() = with(composeTestRule) { | ||
initCameraWithExposure(0) | ||
|
||
exposureCompensation.value = cameraState.minExposure | ||
|
||
runOnIdle { | ||
assertEquals(cameraState.minExposure, currentExposure) | ||
assertEquals(exposureCompensation.value, currentExposure) | ||
} | ||
} | ||
|
||
@Test | ||
fun test_maxExposureCompensation() = with(composeTestRule) { | ||
initCameraWithExposure(0) | ||
|
||
exposureCompensation.value = cameraState.maxExposure | ||
|
||
runOnIdle { | ||
assertEquals(cameraState.maxExposure, currentExposure) | ||
assertEquals(exposureCompensation.value, currentExposure) | ||
} | ||
} | ||
|
||
|
||
@Test | ||
fun test_invalidExposureCompensation() = with(composeTestRule) { | ||
initCameraWithExposure(0) | ||
|
||
exposureCompensation.value = Int.MAX_VALUE | ||
|
||
runOnIdle { | ||
assertNotEquals(cameraState.maxExposure, currentExposure) | ||
assertNotEquals(exposureCompensation.value, currentExposure) | ||
assertEquals(cameraState.initialExposure, currentExposure) | ||
} | ||
} | ||
|
||
private fun ComposeContentTestRule.initCameraWithExposure( | ||
exposure: Int, | ||
) = initCameraState { state -> | ||
exposureCompensation = remember { mutableStateOf(exposure) } | ||
CameraPreview( | ||
cameraState = state, | ||
exposureCompensation = exposureCompensation.value | ||
) | ||
} | ||
} |
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