summaryrefslogtreecommitdiffstats
path: root/tests/camera2/CameraModuleFixture.h
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2012-11-05 11:14:49 -0800
committerIgor Murashkin <iam@google.com>2012-11-06 11:31:01 -0800
commite302ee3dd3abacebeb32263654186ab433efc14c (patch)
tree2a35257861421a7037b3eece5fed74e05dc12aa4 /tests/camera2/CameraModuleFixture.h
parentb0acad33a7891d38100aa84c673280bbd8c1a90d (diff)
downloadhardware_libhardware-e302ee3dd3abacebeb32263654186ab433efc14c.zip
hardware_libhardware-e302ee3dd3abacebeb32263654186ab433efc14c.tar.gz
hardware_libhardware-e302ee3dd3abacebeb32263654186ab433efc14c.tar.bz2
Camera2: Automated tests for testing HAL2.0 interface
Change-Id: I1f1afd5afc346d5493d5019af35c3026efcf19b5
Diffstat (limited to 'tests/camera2/CameraModuleFixture.h')
-rw-r--r--tests/camera2/CameraModuleFixture.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/camera2/CameraModuleFixture.h b/tests/camera2/CameraModuleFixture.h
new file mode 100644
index 0000000..f000fdf
--- /dev/null
+++ b/tests/camera2/CameraModuleFixture.h
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2012 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 "hardware/hardware.h"
+#include "hardware/camera2.h"
+
+#include "Camera2Device.h"
+#include "camera2_utils.h"
+
+namespace android {
+namespace camera2 {
+namespace tests {
+
+template <bool InfoQuirk = false>
+struct CameraModuleFixture {
+
+ CameraModuleFixture(int CameraID = -1) {
+ mCameraID = CameraID;
+
+ SetUp();
+ }
+
+ ~CameraModuleFixture() {
+ TearDown();
+ }
+
+private:
+
+ void SetUp() {
+ ASSERT_LE(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID,
+ (const hw_module_t **)&mModule)) << "Could not load camera module";
+ ASSERT_NE((void*)0, mModule);
+
+ mNumberOfCameras = mModule->get_number_of_cameras();
+ ASSERT_LE(0, mNumberOfCameras);
+
+ ASSERT_EQ(
+ CAMERA_MODULE_API_VERSION_2_0, mModule->common.module_api_version)
+ << "Wrong module API version";
+
+ /* For using this fixture in other tests only */
+ SetUpMixin();
+ }
+
+ void TearDown() {
+ TearDownMixin();
+
+ /* important: device must be destructed before closing module,
+ since it calls back into HAL */
+ mDevice.clear();
+
+ ASSERT_EQ(0, HWModuleHelpers::closeModule(&mModule->common))
+ << "Failed to close camera HAL module";
+ }
+
+ void SetUpMixin() {
+ /* For using this fixture in other tests only */
+ if (mCameraID != -1) {
+ EXPECT_LE(0, mCameraID);
+ EXPECT_LT(mCameraID, mNumberOfCameras);
+
+ /* HALBUG (Exynos5); crashes if trying to initialize
+ before calling get_camera_info */
+ if (InfoQuirk) {
+ struct camera_info info;
+ ASSERT_EQ(OK, mModule->get_camera_info(mCameraID, &info));
+ }
+
+ mDevice = new Camera2Device(mCameraID);
+ ASSERT_EQ(OK, mDevice->initialize(mModule))
+ << "Failed to initialize device " << mCameraID;
+ }
+ }
+
+ void TearDownMixin() {
+
+ }
+
+protected:
+ int mNumberOfCameras;
+ camera_module_t *mModule;
+ sp<Camera2Device> mDevice;
+
+private:
+ int mCameraID;
+};
+
+
+}
+}
+}
+