summaryrefslogtreecommitdiffstats
path: root/camera2/portability/tests
diff options
context:
space:
mode:
authorSol Boucher <solb@google.com>2014-06-09 12:05:13 -0700
committerSol Boucher <solb@google.com>2014-07-08 15:17:16 -0700
commita0842b40441db5332a5290f941021636b1182761 (patch)
treef87677f9a18112b5b8e4bcff2a502c8a416fa70d /camera2/portability/tests
parent858edec400cf5c7cf3171f877f81bbc891fc4bcc (diff)
downloadandroid_frameworks_ex-a0842b40441db5332a5290f941021636b1182761.tar.gz
android_frameworks_ex-a0842b40441db5332a5290f941021636b1182761.tar.bz2
android_frameworks_ex-a0842b40441db5332a5290f941021636b1182761.zip
camera2-portability: Add support for previews using the camera2 API
At the moment, only SurfaceTextures (and not SurfaceViews/SurfaceHolders) are supported. The tests still only cover Stringifier and IntegralStringifier. Change-Id: Ie643c58f8383cd3b9f59c16e0b79239df0ca068d
Diffstat (limited to 'camera2/portability/tests')
-rw-r--r--camera2/portability/tests/Android.mk24
-rw-r--r--camera2/portability/tests/AndroidManifest.xml27
-rw-r--r--camera2/portability/tests/src/com/android/ex/camera2/portability/Camera2PortabilityTest.java189
3 files changed, 240 insertions, 0 deletions
diff --git a/camera2/portability/tests/Android.mk b/camera2/portability/tests/Android.mk
new file mode 100644
index 0000000..5bb09ef
--- /dev/null
+++ b/camera2/portability/tests/Android.mk
@@ -0,0 +1,24 @@
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := android-ex-camera2-portability-tests
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+LOCAL_SRC_FILES := $(call all-java-files-under,src)
+LOCAL_STATIC_JAVA_LIBRARIES := android-ex-camera2-portability android-support-test
+
+include $(BUILD_PACKAGE)
diff --git a/camera2/portability/tests/AndroidManifest.xml b/camera2/portability/tests/AndroidManifest.xml
new file mode 100644
index 0000000..2e6a38b
--- /dev/null
+++ b/camera2/portability/tests/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.ex.camera2.portability.tests">
+ <uses-permission android:name="android.permission.CAMERA" />
+ <application android:label="CameraToo">
+ <!--<uses-library android:name="android.test.runner" />-->
+ </application>
+ <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.ex.camera2.portability.tests" />
+</manifest>
diff --git a/camera2/portability/tests/src/com/android/ex/camera2/portability/Camera2PortabilityTest.java b/camera2/portability/tests/src/com/android/ex/camera2/portability/Camera2PortabilityTest.java
new file mode 100644
index 0000000..b421b98
--- /dev/null
+++ b/camera2/portability/tests/src/com/android/ex/camera2/portability/Camera2PortabilityTest.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ex.camera2.portability;
+
+import static android.hardware.camera2.CameraCharacteristics.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import com.android.ex.camera2.portability.AndroidCamera2Capabilities.IntegralStringifier;
+import com.android.ex.camera2.portability.CameraCapabilities.FlashMode;
+import com.android.ex.camera2.portability.CameraCapabilities.FocusMode;
+import com.android.ex.camera2.portability.CameraCapabilities.SceneMode;
+import com.android.ex.camera2.portability.CameraCapabilities.Stringifier;
+import com.android.ex.camera2.portability.CameraCapabilities.WhiteBalance;
+import org.junit.Test;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+
+public class Camera2PortabilityTest {
+ private <E> void cameraCapabilitiesStringifierEach(Class<E> classy,
+ Stringifier strfy,
+ String call) throws Exception {
+ for(E val : (E[]) classy.getMethod("values").invoke(null)) {
+ String valString =
+ (String) Stringifier.class.getMethod("stringify", classy).invoke(strfy, val);
+ assertEquals(val,
+ Stringifier.class.getMethod(call, String.class).invoke(strfy, valString));
+ }
+ }
+
+ @Test
+ public void cameraCapabilitiesStringifier() throws Exception {
+ Stringifier strfy = new Stringifier();
+ cameraCapabilitiesStringifierEach(FocusMode.class, strfy, "focusModeFromString");
+ cameraCapabilitiesStringifierEach(FlashMode.class, strfy, "flashModeFromString");
+ cameraCapabilitiesStringifierEach(SceneMode.class, strfy, "sceneModeFromString");
+ cameraCapabilitiesStringifierEach(WhiteBalance.class, strfy, "whiteBalanceFromString");
+ }
+
+ @Test
+ public void cameraCapabilitiesStringifierNull() throws Exception {
+ Stringifier strfy = new Stringifier();
+ assertEquals(strfy.focusModeFromString(null), FocusMode.AUTO);
+ assertEquals(strfy.flashModeFromString(null), FlashMode.NO_FLASH);
+ assertEquals(strfy.sceneModeFromString(null), SceneMode.NO_SCENE_MODE);
+ assertEquals(strfy.whiteBalanceFromString(null), WhiteBalance.AUTO);
+ }
+
+ @Test
+ public void cameraCapabilitiesStringifierInvalid() throws Exception {
+ Stringifier strfy = new Stringifier();
+ assertEquals(strfy.focusModeFromString("crap"), FocusMode.AUTO);
+ assertEquals(strfy.flashModeFromString("crap"), FlashMode.NO_FLASH);
+ assertEquals(strfy.sceneModeFromString("crap"), SceneMode.NO_SCENE_MODE);
+ assertEquals(strfy.whiteBalanceFromString("crap"), WhiteBalance.AUTO);
+ }
+
+ private void cameraCapabilitiesIntifierEach(int apiVal,
+ IntegralStringifier intfy,
+ String call) throws Exception {
+ Method toCall = IntegralStringifier.class.getMethod(call, int.class);
+ Class<?> returnType = toCall.getReturnType();
+ Object returnVal = toCall.invoke(intfy, apiVal);
+ assertEquals(apiVal,
+ IntegralStringifier.class.getMethod("intify", returnType).invoke(intfy, returnVal));
+ }
+
+ @Test
+ public void cameraCapabilitiesIntifier() throws Exception {
+ IntegralStringifier intstr = new IntegralStringifier();
+
+ // Focus modes
+ cameraCapabilitiesIntifierEach(CONTROL_AF_MODE_AUTO, intstr, "focusModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AF_MODE_CONTINUOUS_PICTURE, intstr,
+ "focusModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AF_MODE_CONTINUOUS_VIDEO, intstr,
+ "focusModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AF_MODE_EDOF, intstr, "focusModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AF_MODE_OFF, intstr, "focusModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AF_MODE_MACRO, intstr, "focusModeFromInt");
+
+ // Flash modes
+ cameraCapabilitiesIntifierEach(FLASH_MODE_OFF, intstr, "flashModeFromInt");
+ cameraCapabilitiesIntifierEach(FLASH_MODE_SINGLE, intstr, "flashModeFromInt");
+ cameraCapabilitiesIntifierEach(FLASH_MODE_TORCH, intstr, "flashModeFromInt");
+
+ // Scene modes
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_DISABLED, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_ACTION, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_BARCODE, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_BEACH, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_CANDLELIGHT, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_FIREWORKS, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_LANDSCAPE, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_NIGHT, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_PARTY, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_PORTRAIT, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_SNOW, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_SPORTS, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_STEADYPHOTO, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_SUNSET, intstr, "sceneModeFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_SCENE_MODE_THEATRE, intstr, "sceneModeFromInt");
+
+ // White balances
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_AUTO, intstr, "whiteBalanceFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_CLOUDY_DAYLIGHT, intstr,
+ "whiteBalanceFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_DAYLIGHT, intstr, "whiteBalanceFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_FLUORESCENT, intstr,
+ "whiteBalanceFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_INCANDESCENT, intstr,
+ "whiteBalanceFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_SHADE, intstr, "whiteBalanceFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_TWILIGHT, intstr, "whiteBalanceFromInt");
+ cameraCapabilitiesIntifierEach(CONTROL_AWB_MODE_WARM_FLUORESCENT, intstr,
+ "whiteBalanceFromInt");
+ }
+
+ // TODO: Add a test checking whether stringification matches API representation
+
+ @Test
+ public void cameraCapabilitiesIntsMatchApi2Representations() throws Exception {
+ IntegralStringifier intstr = new IntegralStringifier();
+
+ // Focus modes
+ assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_AUTO), FocusMode.AUTO);
+ assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_CONTINUOUS_PICTURE),
+ FocusMode.CONTINUOUS_PICTURE);
+ assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_CONTINUOUS_VIDEO),
+ FocusMode.CONTINUOUS_VIDEO);
+ assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_EDOF), FocusMode.EXTENDED_DOF);
+ assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_OFF), FocusMode.FIXED);
+ assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_MACRO), FocusMode.MACRO);
+
+ // Flash modes
+ assertEquals(intstr.flashModeFromInt(FLASH_MODE_OFF), FlashMode.OFF);
+ assertEquals(intstr.flashModeFromInt(FLASH_MODE_SINGLE), FlashMode.ON);
+ assertEquals(intstr.flashModeFromInt(FLASH_MODE_TORCH), FlashMode.TORCH);
+
+ // Scene modes
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_DISABLED), SceneMode.AUTO);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_ACTION), SceneMode.ACTION);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_BARCODE), SceneMode.BARCODE);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_BEACH), SceneMode.BEACH);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_CANDLELIGHT),
+ SceneMode.CANDLELIGHT);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_FIREWORKS), SceneMode.FIREWORKS);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_LANDSCAPE), SceneMode.LANDSCAPE);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_NIGHT), SceneMode.NIGHT);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_PARTY), SceneMode.PARTY);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_PORTRAIT), SceneMode.PORTRAIT);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_SNOW), SceneMode.SNOW);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_SPORTS), SceneMode.SPORTS);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_STEADYPHOTO),
+ SceneMode.STEADYPHOTO);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_SUNSET), SceneMode.SUNSET);
+ assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_THEATRE), SceneMode.THEATRE);
+
+ // White balances
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_AUTO), WhiteBalance.AUTO);
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_CLOUDY_DAYLIGHT),
+ WhiteBalance.CLOUDY_DAYLIGHT);
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_DAYLIGHT), WhiteBalance.DAYLIGHT);
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_FLUORESCENT),
+ WhiteBalance.FLUORESCENT);
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_INCANDESCENT),
+ WhiteBalance.INCANDESCENT);
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_SHADE), WhiteBalance.SHADE);
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_TWILIGHT), WhiteBalance.TWILIGHT);
+ assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_WARM_FLUORESCENT),
+ WhiteBalance.WARM_FLUORESCENT);
+ }
+}