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 testCameraDeviceSimplePreviewWithV2Callbacks()76 public void testCameraDeviceSimplePreviewWithV2Callbacks() { 77 // Init preview surface to a guaranteed working size 78 updatePreviewSurface(new Size(640, 480)); 79 assertTrue("testCameraDeviceSimplePreview fail, see log for details", 80 testCameraDeviceSimplePreviewNative2(mPreviewSurface, 81 mOverrideCameraId)); 82 } 83 84 @Test testCameraDevicePreviewWithSessionParameters()85 public void testCameraDevicePreviewWithSessionParameters() { 86 // Init preview surface to a guaranteed working size 87 updatePreviewSurface(new Size(640, 480)); 88 assertTrue("testCameraDevicePreviewWithSessionParameters fail, see log for details", 89 testCameraDevicePreviewWithSessionParametersNative(mPreviewSurface, 90 mOverrideCameraId)); 91 } 92 93 @Test testCameraDeviceSharedOutputUpdate()94 public void testCameraDeviceSharedOutputUpdate() { 95 // Init preview surface to a guaranteed working size 96 Size previewSize = new Size(640, 480); 97 updatePreviewSurface(previewSize); 98 SurfaceTexture outputTexture = new SurfaceTexture(/* random texture ID*/ 5); 99 outputTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight()); 100 Surface outputSurface = new Surface(outputTexture); 101 assertTrue("testCameraDeviceSharedOutputUpdate fail, see log for details", 102 testCameraDeviceSharedOutputUpdate(mPreviewSurface, outputSurface, 103 mOverrideCameraId)); 104 } 105 106 @Test testCameraDeviceLogicalPhysicalStreaming()107 public void testCameraDeviceLogicalPhysicalStreaming() { 108 // Init preview surface to a guaranteed working size 109 Size previewSize = new Size(640, 480); 110 updatePreviewSurface(previewSize); 111 assertTrue("testCameraDeviceLogicalPhysicalStreaming fail, see log for details", 112 testCameraDeviceLogicalPhysicalStreamingNative(mPreviewSurface, mOverrideCameraId)); 113 } 114 115 @Test testCameraDeviceLogicalPhysicalStreamingWithV2Callbacks()116 public void testCameraDeviceLogicalPhysicalStreamingWithV2Callbacks() { 117 // Init preview surface to a guaranteed working size 118 Size previewSize = new Size(640, 480); 119 updatePreviewSurface(previewSize); 120 assertTrue("testCameraDeviceLogicalPhysicalStreaming fail, see log for details", 121 testCameraDeviceLogicalPhysicalStreamingNative2(mPreviewSurface, 122 mOverrideCameraId)); 123 } 124 125 @Test testCameraDeviceLogicalPhysicalSettings()126 public void testCameraDeviceLogicalPhysicalSettings() { 127 // Init preview surface to a guaranteed working size 128 Size previewSize = new Size(640, 480); 129 updatePreviewSurface(previewSize); 130 assertTrue("testCameraDeviceLogicalPhysicalSettings fail, see log for details", 131 testCameraDeviceLogicalPhysicalSettingsNative(mPreviewSurface, mOverrideCameraId)); 132 } 133 134 @Test testCameraDeviceLogicalPhysicalSettingsWithV2Callbacks()135 public void testCameraDeviceLogicalPhysicalSettingsWithV2Callbacks() { 136 // Init preview surface to a guaranteed working size 137 Size previewSize = new Size(640, 480); 138 updatePreviewSurface(previewSize); 139 assertTrue("testCameraDeviceLogicalPhysicalSettings fail, see log for details", 140 testCameraDeviceLogicalPhysicalSettingsNative2(mPreviewSurface, mOverrideCameraId)); 141 } 142 143 @Test testCameraDevicePrepareSurface()144 public void testCameraDevicePrepareSurface() { 145 // Init preview surface to a guaranteed working size 146 Size previewSize = new Size(640, 480); 147 updatePreviewSurface(previewSize); 148 assertTrue("testCameraDevicePreapreSurface fail, see log for details", 149 testCameraDevicePrepareSurface(mPreviewSurface, mOverrideCameraId)); 150 } 151 152 @Test testCameraDeviceCaptureFailure()153 public void testCameraDeviceCaptureFailure() { 154 assertTrue("testCameraDeviceCaptureFailure fail, see log for details", 155 testCameraDeviceCaptureFailureNative(mOverrideCameraId)); 156 } 157 testCameraDeviceOpenAndCloseNative(String overrideCameraId)158 private static native boolean testCameraDeviceOpenAndCloseNative(String overrideCameraId); testCameraDeviceCreateCaptureRequestNative( String overrideCameraId)159 private static native boolean testCameraDeviceCreateCaptureRequestNative( 160 String overrideCameraId); testCameraDeviceSessionOpenAndCloseNative(Surface preview, String overrideCameraId)161 private static native boolean testCameraDeviceSessionOpenAndCloseNative(Surface preview, 162 String overrideCameraId); testCameraDeviceSimplePreviewNative(Surface preview, String overrideCameraId)163 private static native boolean testCameraDeviceSimplePreviewNative(Surface preview, 164 String overrideCameraId); testCameraDeviceSimplePreviewNative2( Surface preview, String overrideCameraId)165 private static native boolean testCameraDeviceSimplePreviewNative2( 166 Surface preview, String overrideCameraId); testCameraDevicePreviewWithSessionParametersNative( Surface preview, String overrideCameraId)167 private static native boolean testCameraDevicePreviewWithSessionParametersNative( 168 Surface preview, String overrideCameraId); testCameraDeviceSharedOutputUpdate(Surface src, Surface dst, String overrideCameraId)169 private static native boolean testCameraDeviceSharedOutputUpdate(Surface src, Surface dst, 170 String overrideCameraId); testCameraDeviceLogicalPhysicalStreamingNative(Surface preview, String overrideCameraId)171 private static native boolean testCameraDeviceLogicalPhysicalStreamingNative(Surface preview, 172 String overrideCameraId); testCameraDeviceLogicalPhysicalStreamingNative2(Surface preview, String overrideCameraId)173 private static native boolean testCameraDeviceLogicalPhysicalStreamingNative2(Surface preview, 174 String overrideCameraId); testCameraDeviceLogicalPhysicalSettingsNative(Surface preview, String overrideCameraId)175 private static native boolean testCameraDeviceLogicalPhysicalSettingsNative(Surface preview, 176 String overrideCameraId); testCameraDeviceLogicalPhysicalSettingsNative2(Surface preview, String overrideCameraId)177 private static native boolean testCameraDeviceLogicalPhysicalSettingsNative2(Surface preview, 178 String overrideCameraId); testCameraDevicePrepareSurface(Surface preview, String overrideCameraId)179 private static native boolean testCameraDevicePrepareSurface(Surface preview, 180 String overrideCameraId); testCameraDeviceCaptureFailureNative(String overrideCameraId)181 private static native boolean testCameraDeviceCaptureFailureNative(String overrideCameraId); 182 183 } 184