1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.camera.integration.extensions
18 
19 import androidx.camera.integration.extensions.CameraExtensionsActivity.CAMERA_PIPE_IMPLEMENTATION_OPTION
20 import androidx.camera.integration.extensions.util.CameraXExtensionsTestUtil
21 import androidx.camera.integration.extensions.util.CameraXExtensionsTestUtil.CameraXExtensionTestParams
22 import androidx.camera.testing.impl.CameraPipeConfigTestRule
23 import androidx.camera.testing.impl.CameraUtil
24 import androidx.test.filters.LargeTest
25 import androidx.test.filters.SdkSuppress
26 import org.junit.After
27 import org.junit.Before
28 import org.junit.Rule
29 import org.junit.Test
30 import org.junit.runner.RunWith
31 import org.junit.runners.Parameterized
32 
33 /**
34  * Validation test for OEMs' advanced extender implementation.
35  *
36  * <p>All testings are forwarded to AdvancedExtenderValidation. This is because JUnit test will
37  * check all types exist in the test class and on the devices that don't support extensions, the
38  * extensions interface classes doesn't exist and will cause a class-not-found exception. Accessing
39  * these extensions interface classes in the AdvancedExtenderValidation can avoid this issue.
40  */
41 @LargeTest
42 @RunWith(Parameterized::class)
43 @SdkSuppress(minSdkVersion = 28)
44 class AdvancedExtenderValidationTest(config: CameraXExtensionTestParams) {
45     private val validation =
46         AdvancedExtenderValidation(config.cameraXConfig, config.cameraId, config.extensionMode)
47 
48     companion object {
49         @JvmStatic
50         @get:Parameterized.Parameters(name = "config = {0}")
51         val parameters: Collection<CameraXExtensionTestParams>
52             get() = CameraXExtensionsTestUtil.getAllCameraIdExtensionModeCombinations()
53     }
54 
55     @get:Rule
56     val cameraPipeConfigTestRule =
57         CameraPipeConfigTestRule(active = config.implName == CAMERA_PIPE_IMPLEMENTATION_OPTION)
58 
59     @get:Rule
60     val useCamera =
61         CameraUtil.grantCameraPermissionAndPreTestAndPostTest(
62             CameraUtil.PreTestCameraIdList(config.cameraXConfig)
63         )
64 
setUpnull65     @Before fun setUp() = validation.setUp()
66 
67     @After fun tearDown() = validation.tearDown()
68 
69     @Test
70     fun getSupportedPreviewOutputResolutions_returnValidData() =
71         validation.getSupportedPreviewOutputResolutions_returnValidData()
72 
73     @Test
74     fun getSupportedCaptureOutputResolutions_returnValidData() =
75         validation.getSupportedCaptureOutputResolutions_returnValidData()
76 
77     @Test
78     fun getAvailableCaptureRequestKeys_existAfter1_3() =
79         validation.getAvailableCaptureRequestKeys_existAfter1_3()
80 
81     @Test
82     fun getAvailableCaptureResultKeys_existAfter1_3() =
83         validation.getAvailableCaptureResultKeys_existAfter1_3()
84 
85     @Test
86     fun initSession_maxSize_canConfigureSession() =
87         validation.initSession_maxSize_canConfigureSession()
88 
89     @Test
90     fun initSession_minSize_canConfigureSession() =
91         validation.initSession_minSize_canConfigureSession()
92 
93     @Test
94     fun initSession_medianSize_canConfigureSession() =
95         validation.initSession_medianSize_canConfigureSession()
96 
97     @Test
98     fun initSessionWithAnalysis_maxSize_canConfigureSession() =
99         validation.initSessionWithAnalysis_maxSize_canConfigureSession()
100 
101     @Test
102     fun initSessionWithAnalysis_minSize_canConfigureSession() =
103         validation.initSessionWithAnalysis_minSize_canConfigureSession()
104 
105     @Test
106     fun initSessionWithAnalysis_medianSize_canConfigureSession() =
107         validation.initSessionWithAnalysis_medianSize_canConfigureSession()
108 
109     @Test
110     fun initSessionWithOutputSurfaceConfigurationImpl_maxSize_canConfigureSession() =
111         validation.initSessionWithOutputSurfaceConfigurationImpl_maxSize_canConfigureSession()
112 
113     @Test
114     fun validateSessionTypeSupport_sinceVersion_1_4() =
115         validation.validateSessionTypeSupport_sinceVersion_1_4()
116 
117     @Test
118     fun validateSessionTypeSupportWithOutputSurfaceConfigurationImpl_sinceVersion_1_4() =
119         validation.validateSessionTypeSupportWithOutputSurfaceConfigurationImpl_sinceVersion_1_4()
120 
121     @Test
122     fun validatePostviewSupport_sinceVersion_1_4() =
123         validation.validatePostviewSupport_sinceVersion_1_4()
124 
125     @Test
126     fun validateProcessProgressSupport_sinceVersion_1_4() =
127         validation.validateProcessProgressSupport_sinceVersion_1_4()
128 
129     @Test
130     @SdkSuppress(minSdkVersion = 30)
131     fun validateAvailableCharacteristicsKeyValuesSupport_sinceVersion_1_5() =
132         validation.validateAvailableCharacteristicsKeyValuesSupport_sinceVersion_1_5()
133 }
134