• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 android.hardware.camera2.cts;
18 
19 import android.content.Context;
20 import android.hardware.cts.helpers.CameraParameterizedTestCase;
21 import android.hardware.camera2.cts.CameraTestUtils;
22 import android.hardware.camera2.CameraManager;
23 import android.util.Log;
24 
25 import java.util.Arrays;
26 
27 import org.junit.Ignore;
28 
29 import static junit.framework.Assert.assertNotNull;
30 import static junit.framework.Assert.assertTrue;
31 
32 public class Camera2ParameterizedTestCase extends CameraParameterizedTestCase {
33     private static final String TAG = "Camera2ParameterizedTestCase";
34     protected CameraManager mCameraManager;
35     // The list of camera ids we're testing. If we're testing system cameras
36     // (mAdoptShellPerm == true), we have only system camera ids in the array and not normal camera
37     // ids.
38     protected String[] mCameraIdsUnderTest;
39     protected boolean mUseAll = false;
40 
41     @Override
setUp()42     public void setUp() throws Exception {
43         setUp(/*useAll*/false);
44     }
45 
46     /**
47      * setUp camera2 related properties for parameterized cts tests
48      *
49      * @param useAll whether all camera ids are to be used for system camera tests
50      */
setUp(boolean useAll)51     public void setUp(boolean useAll) throws Exception {
52         super.setUp();
53         mUseAll = useAll;
54         /**
55          * Workaround for mockito and JB-MR2 incompatibility
56          *
57          * Avoid java.lang.IllegalArgumentException: dexcache == null
58          * https://code.google.com/p/dexmaker/issues/detail?id=2
59          */
60         System.setProperty("dexmaker.dexcache", mContext.getCacheDir().toString());
61         mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
62         assertNotNull("Unable to get CameraManager", mCameraManager);
63         mCameraIdsUnderTest = deriveCameraIdsUnderTest();
64         assertNotNull("Unable to get camera ids", mCameraIdsUnderTest);
65     }
66 
67     @Override
tearDown()68     public void tearDown() throws Exception {
69         String[] cameraIdsPostTest = deriveCameraIdsUnderTest();
70         assertNotNull("Camera ids shouldn't be null", cameraIdsPostTest);
71         Log.i(TAG, "Camera ids in setup:" + Arrays.toString(mCameraIdsUnderTest));
72         Log.i(TAG, "Camera ids in tearDown:" + Arrays.toString(cameraIdsPostTest));
73         assertTrue(
74                 "Number of cameras changed from " + mCameraIdsUnderTest.length + " to " +
75                 cameraIdsPostTest.length,
76                 mCameraIdsUnderTest.length == cameraIdsPostTest.length);
77         super.tearDown();
78     }
79 
deriveCameraIdsUnderTest()80     private String[] deriveCameraIdsUnderTest() throws Exception {
81         String[] idsUnderTest =
82                 mAdoptShellPerm && mUseAll ? mCameraManager.getCameraIdListNoLazy() :
83                 CameraTestUtils.getCameraIdListForTesting(mCameraManager, mAdoptShellPerm);
84         assertNotNull("Camera ids shouldn't be null", idsUnderTest);
85         if (mOverrideCameraId != null) {
86             if (Arrays.asList(idsUnderTest).contains(mOverrideCameraId)) {
87                 idsUnderTest = new String[]{mOverrideCameraId};
88             } else {
89                 idsUnderTest = new String[]{};
90             }
91         }
92 
93         return idsUnderTest;
94     }
95 }
96