1 /*
2  * Copyright 2016 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.graphics.SurfaceTexture;
20 import android.hardware.camera2.cts.testcases.Camera2SurfaceViewTestCase;
21 import android.util.Log;
22 import android.util.Size;
23 import android.view.Surface;
24 
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27 import org.junit.Test;
28 
29 import static org.junit.Assert.assertTrue;
30 
31 /**
32  * <p>Basic test for CameraManager class.</p>
33  */
34 
35 @RunWith(Parameterized.class)
36 public class NativeCameraDeviceTest extends Camera2SurfaceViewTestCase {
37     private static final String TAG = "NativeCameraDeviceTest";
38     private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
39 
40     /** Load jni on initialization */
41     static {
42         Log.i("NativeCameraDeviceTest", "before loadlibrary");
43         System.loadLibrary("ctscamera2_jni");
44         Log.i("NativeCameraDeviceTest", "after loadlibrary");
45     }
46 
47     @Test
testCameraDeviceOpenAndClose()48     public void testCameraDeviceOpenAndClose() {
49         assertTrue("testCameraDeviceOpenAndClose fail, see log for details",
50                 testCameraDeviceOpenAndCloseNative(mOverrideCameraId));
51     }
52 
53     @Test
testCameraDeviceCreateCaptureRequest()54     public void testCameraDeviceCreateCaptureRequest() {
55         assertTrue("testCameraDeviceCreateCaptureRequest fail, see log for details",
56                 testCameraDeviceCreateCaptureRequestNative(mOverrideCameraId));
57     }
58 
59     @Test
testCameraDeviceSessionOpenAndClose()60     public void testCameraDeviceSessionOpenAndClose() {
61         // Init preview surface to a guaranteed working size
62         updatePreviewSurface(new Size(640, 480));
63         assertTrue("testCameraDeviceSessionOpenAndClose fail, see log for details",
64                 testCameraDeviceSessionOpenAndCloseNative(mPreviewSurface, mOverrideCameraId));
65     }
66 
67     @Test
testCameraDeviceSimplePreview()68     public void testCameraDeviceSimplePreview() {
69         // Init preview surface to a guaranteed working size
70         updatePreviewSurface(new Size(640, 480));
71         assertTrue("testCameraDeviceSimplePreview fail, see log for details",
72                 testCameraDeviceSimplePreviewNative(mPreviewSurface, mOverrideCameraId));
73     }
74 
75     @Test
testCameraDevicePreviewWithSessionParameters()76     public void testCameraDevicePreviewWithSessionParameters() {
77         // Init preview surface to a guaranteed working size
78         updatePreviewSurface(new Size(640, 480));
79         assertTrue("testCameraDevicePreviewWithSessionParameters fail, see log for details",
80                 testCameraDevicePreviewWithSessionParametersNative(mPreviewSurface,
81                 mOverrideCameraId));
82     }
83 
84     @Test
testCameraDeviceSharedOutputUpdate()85     public void testCameraDeviceSharedOutputUpdate() {
86         // Init preview surface to a guaranteed working size
87         Size previewSize = new Size(640, 480);
88         updatePreviewSurface(previewSize);
89         SurfaceTexture outputTexture = new SurfaceTexture(/* random texture ID*/ 5);
90         outputTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
91         Surface outputSurface = new Surface(outputTexture);
92         assertTrue("testCameraDeviceSharedOutputUpdate fail, see log for details",
93                 testCameraDeviceSharedOutputUpdate(mPreviewSurface, outputSurface,
94                 mOverrideCameraId));
95     }
96 
97     @Test
testCameraDeviceLogicalPhysicalStreaming()98     public void testCameraDeviceLogicalPhysicalStreaming() {
99         // Init preview surface to a guaranteed working size
100         Size previewSize = new Size(640, 480);
101         updatePreviewSurface(previewSize);
102         SurfaceTexture outputTexture = new SurfaceTexture(/* random texture ID*/ 5);
103         outputTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
104         Surface outputSurface = new Surface(outputTexture);
105         assertTrue("testCameraDeviceLogicalPhysicalStreaming fail, see log for details",
106                 testCameraDeviceLogicalPhysicalStreamingNative(mPreviewSurface, mOverrideCameraId));
107     }
108 
109     @Test
testCameraDeviceLogicalPhysicalSettings()110     public void testCameraDeviceLogicalPhysicalSettings() {
111         // Init preview surface to a guaranteed working size
112         Size previewSize = new Size(640, 480);
113         updatePreviewSurface(previewSize);
114         SurfaceTexture outputTexture = new SurfaceTexture(/* random texture ID*/ 5);
115         outputTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
116         Surface outputSurface = new Surface(outputTexture);
117         assertTrue("testCameraDeviceLogicalPhysicalSettings fail, see log for details",
118                 testCameraDeviceLogicalPhysicalSettingsNative(mPreviewSurface, mOverrideCameraId));
119     }
120 
121     @Test
testCameraDeviceCaptureFailure()122     public void testCameraDeviceCaptureFailure() {
123         assertTrue("testCameraDeviceCaptureFailure fail, see log for details",
124                 testCameraDeviceCaptureFailureNative(mOverrideCameraId));
125     }
126 
testCameraDeviceOpenAndCloseNative(String overrideCameraId)127     private static native boolean testCameraDeviceOpenAndCloseNative(String overrideCameraId);
testCameraDeviceCreateCaptureRequestNative( String overrideCameraId)128     private static native boolean testCameraDeviceCreateCaptureRequestNative(
129             String overrideCameraId);
testCameraDeviceSessionOpenAndCloseNative(Surface preview, String overrideCameraId)130     private static native boolean testCameraDeviceSessionOpenAndCloseNative(Surface preview,
131             String overrideCameraId);
testCameraDeviceSimplePreviewNative(Surface preview, String overrideCameraId)132     private static native boolean testCameraDeviceSimplePreviewNative(Surface preview,
133             String overrideCameraId);
testCameraDevicePreviewWithSessionParametersNative( Surface preview, String overrideCameraId)134     private static native boolean testCameraDevicePreviewWithSessionParametersNative(
135             Surface preview, String overrideCameraId);
testCameraDeviceSharedOutputUpdate(Surface src, Surface dst, String overrideCameraId)136     private static native boolean testCameraDeviceSharedOutputUpdate(Surface src, Surface dst,
137             String overrideCameraId);
testCameraDeviceLogicalPhysicalStreamingNative(Surface preview, String overrideCameraId)138     private static native boolean testCameraDeviceLogicalPhysicalStreamingNative(Surface preview,
139             String overrideCameraId);
testCameraDeviceLogicalPhysicalSettingsNative(Surface preview, String overrideCameraId)140     private static native boolean testCameraDeviceLogicalPhysicalSettingsNative(Surface preview,
141             String overrideCameraId);
testCameraDeviceCaptureFailureNative(String overrideCameraId)142     private static native boolean testCameraDeviceCaptureFailureNative(String overrideCameraId);
143 
144 }
145