am 7c2a4681: am e0c252ae: Merge "hardware: add ro.hardware.<class> to HAL loading properites list"

* commit '7c2a468127bbfb48f7cb239c992edfa48fd54cd2':
  hardware: add ro.hardware.<class> to HAL loading properites list
diff --git a/tests/camera3/Android.mk b/tests/camera3/Android.mk
new file mode 100644
index 0000000..652851a
--- /dev/null
+++ b/tests/camera3/Android.mk
@@ -0,0 +1,20 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+    camera3tests.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+    liblog \
+    libhardware \
+    libcamera_metadata \
+
+LOCAL_C_INCLUDES += \
+    system/media/camera/include \
+
+LOCAL_CFLAGS += -Wall -Wextra
+
+LOCAL_MODULE:= camera3_tests
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_NATIVE_TEST)
diff --git a/tests/camera3/camera3test_fixtures.h b/tests/camera3/camera3test_fixtures.h
new file mode 100644
index 0000000..81d1997
--- /dev/null
+++ b/tests/camera3/camera3test_fixtures.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#ifndef __ANDROID_HAL_CAMERA3_TEST_COMMON__
+#define __ANDROID_HAL_CAMERA3_TEST_COMMON__
+
+#include <gtest/gtest.h>
+#include <hardware/hardware.h>
+#include <hardware/camera3.h>
+
+namespace tests {
+
+static const int kMmaxCams = 2;
+static const uint16_t kVersion3_0 = HARDWARE_MODULE_API_VERSION(3, 0);
+
+class Camera3Module : public testing::Test {
+ public:
+    Camera3Module() :
+        num_cams_(0),
+        cam_module_(NULL) {}
+    ~Camera3Module() {}
+ protected:
+    virtual void SetUp() {
+        const hw_module_t *hw_module = NULL;
+        ASSERT_EQ(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID, &hw_module))
+                    << "Can't get camera module";
+        ASSERT_TRUE(NULL != hw_module)
+                    << "hw_get_module didn't return a valid camera module";
+
+        cam_module_ = reinterpret_cast<const camera_module_t*>(hw_module);
+        ASSERT_TRUE(NULL != cam_module_->get_number_of_cameras)
+                    << "get_number_of_cameras is not implemented";
+        num_cams_ = cam_module_->get_number_of_cameras();
+    }
+    int num_cams() { return num_cams_; }
+    const camera_module_t * cam_module() { return cam_module_; }
+ private:
+    int num_cams_;
+    const camera_module_t *cam_module_;
+};
+
+class Camera3Device : public Camera3Module {
+ public:
+    Camera3Device() :
+        cam_device_(NULL) {}
+    ~Camera3Device() {}
+ protected:
+    virtual void SetUp() {
+        Camera3Module::SetUp();
+        hw_device_t *device = NULL;
+        ASSERT_TRUE(NULL != cam_module()->common.methods->open)
+                    << "Camera open() is unimplemented";
+        ASSERT_EQ(0, cam_module()->common.methods->open(
+            (const hw_module_t*)cam_module(), "0", &device))
+                << "Can't open camera device";
+        ASSERT_TRUE(NULL != device)
+                    << "Camera open() returned a NULL device";
+        ASSERT_EQ(kVersion3_0, device->version)
+                    << "The device does not support HAL3";
+        cam_device_ = reinterpret_cast<camera3_device_t*>(device);
+    }
+    camera3_device_t* cam_device() { return cam_device_; }
+ private:
+    camera3_device *cam_device_;
+};
+
+}  // namespace tests
+
+#endif  // __ANDROID_HAL_CAMERA3_TEST_COMMON__
diff --git a/tests/camera3/camera3tests.cpp b/tests/camera3/camera3tests.cpp
new file mode 100644
index 0000000..5dbe588
--- /dev/null
+++ b/tests/camera3/camera3tests.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <gtest/gtest.h>
+#include "camera3test_fixtures.h"
+
+namespace tests {
+
+TEST_F(Camera3Module, NumberOfCameras) {
+    ASSERT_LT(0, num_cams()) << "No cameras found";
+    ASSERT_GE(kMmaxCams, num_cams()) << "Too many cameras found";
+}
+
+TEST_F(Camera3Module, IsActiveArraySizeSubsetPixelArraySize) {
+    for (int i = 0; i < num_cams(); ++i) {
+        ASSERT_TRUE(NULL != cam_module()->get_camera_info)
+            << "get_camera_info is not implemented";
+
+        camera_info info;
+        ASSERT_EQ(0, cam_module()->get_camera_info(i, &info))
+                    << "Can't get camera info for" << i;
+
+        camera_metadata_entry entry;
+        ASSERT_EQ(0, find_camera_metadata_entry(
+                    const_cast<camera_metadata_t*>(
+                        info.static_camera_characteristics),
+                        ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, &entry))
+                            << "Can't find the sensor pixel array size.";
+        int pixel_array_w = entry.data.i32[0];
+        int pixel_array_h = entry.data.i32[1];
+
+        ASSERT_EQ(0, find_camera_metadata_entry(
+                    const_cast<camera_metadata_t*>(
+                        info.static_camera_characteristics),
+                        ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, &entry))
+                            << "Can't find the sensor active array size.";
+        int active_array_w = entry.data.i32[0];
+        int active_array_h = entry.data.i32[1];
+
+        EXPECT_LE(active_array_h, pixel_array_h);
+        EXPECT_LE(active_array_w, pixel_array_w);
+    }
+}
+
+TEST_F(Camera3Device, DefaultSettingsStillCaptureHasAndroidControlMode) {
+    ASSERT_TRUE(NULL != cam_device()->ops) << "Camera device ops are NULL";
+    const camera_metadata_t *default_settings =
+        cam_device()->ops->construct_default_request_settings(cam_device(),
+            CAMERA3_TEMPLATE_STILL_CAPTURE);
+    ASSERT_TRUE(NULL != default_settings) << "Camera default settings are NULL";
+    camera_metadata_entry entry;
+    ASSERT_EQ(0, find_camera_metadata_entry(
+                const_cast<camera_metadata_t*>(default_settings),
+                ANDROID_CONTROL_MODE, &entry))
+                    << "Can't find ANDROID_CONTROL_MODE in default settings.";
+}
+
+}  // namespace tests