blob: 6ad1ae8b9f5576120300ae4e8c6bc3e116f2dab6 [file] [log] [blame]
Igor Murashkine302ee32012-11-05 11:14:49 -08001/*
2 * Copyright (C) 2012 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
Igor Murashkineab33fc2012-11-06 17:02:54 -080017#ifndef __ANDROID_HAL_CAMERA2_TESTS_MODULE_FIXTURE__
18#define __ANDROID_HAL_CAMERA2_TESTS_MODULE_FIXTURE__
19
Igor Murashkine302ee32012-11-05 11:14:49 -080020#include <gtest/gtest.h>
21
22#include "hardware/hardware.h"
23#include "hardware/camera2.h"
24
25#include "Camera2Device.h"
26#include "camera2_utils.h"
Igor Murashkineab33fc2012-11-06 17:02:54 -080027#include "TestExtensions.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080028
29namespace android {
30namespace camera2 {
31namespace tests {
32
33template <bool InfoQuirk = false>
34struct CameraModuleFixture {
35
36 CameraModuleFixture(int CameraID = -1) {
Igor Murashkineab33fc2012-11-06 17:02:54 -080037 TEST_EXTENSION_FORKING_CONSTRUCTOR;
38
Igor Murashkine302ee32012-11-05 11:14:49 -080039 mCameraID = CameraID;
40
41 SetUp();
42 }
43
44 ~CameraModuleFixture() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080045 TEST_EXTENSION_FORKING_DESTRUCTOR;
46
Igor Murashkine302ee32012-11-05 11:14:49 -080047 TearDown();
48 }
49
Igor Murashkin02f3ac02012-12-14 16:33:46 -080050 camera_metadata_ro_entry GetStaticEntry(uint32_t tag) const {
51 const CameraMetadata& staticInfo = mDevice->info();
52 camera_metadata_ro_entry entry = staticInfo.find(tag);
53 return entry;
54 }
55
Igor Murashkine302ee32012-11-05 11:14:49 -080056private:
57
58 void SetUp() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080059 TEST_EXTENSION_FORKING_SET_UP;
60
Igor Murashkine302ee32012-11-05 11:14:49 -080061 ASSERT_LE(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID,
62 (const hw_module_t **)&mModule)) << "Could not load camera module";
63 ASSERT_NE((void*)0, mModule);
64
65 mNumberOfCameras = mModule->get_number_of_cameras();
66 ASSERT_LE(0, mNumberOfCameras);
67
68 ASSERT_EQ(
69 CAMERA_MODULE_API_VERSION_2_0, mModule->common.module_api_version)
70 << "Wrong module API version";
71
72 /* For using this fixture in other tests only */
73 SetUpMixin();
74 }
75
76 void TearDown() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080077 TEST_EXTENSION_FORKING_TEAR_DOWN;
78
Igor Murashkine302ee32012-11-05 11:14:49 -080079 TearDownMixin();
80
81 /* important: device must be destructed before closing module,
82 since it calls back into HAL */
83 mDevice.clear();
84
Igor Murashkineab33fc2012-11-06 17:02:54 -080085 if (!TEST_EXTENSION_FORKING_ENABLED) {
86 ASSERT_EQ(0, HWModuleHelpers::closeModule(&mModule->common))
87 << "Failed to close camera HAL module";
88 }
Igor Murashkine302ee32012-11-05 11:14:49 -080089 }
90
91 void SetUpMixin() {
92 /* For using this fixture in other tests only */
93 if (mCameraID != -1) {
94 EXPECT_LE(0, mCameraID);
95 EXPECT_LT(mCameraID, mNumberOfCameras);
96
97 /* HALBUG (Exynos5); crashes if trying to initialize
98 before calling get_camera_info */
99 if (InfoQuirk) {
100 struct camera_info info;
101 ASSERT_EQ(OK, mModule->get_camera_info(mCameraID, &info));
102 }
103
104 mDevice = new Camera2Device(mCameraID);
105 ASSERT_EQ(OK, mDevice->initialize(mModule))
106 << "Failed to initialize device " << mCameraID;
107 }
108 }
109
110 void TearDownMixin() {
111
112 }
113
114protected:
115 int mNumberOfCameras;
116 camera_module_t *mModule;
117 sp<Camera2Device> mDevice;
118
119private:
120 int mCameraID;
121};
122
123
124}
125}
126}
127
Igor Murashkineab33fc2012-11-06 17:02:54 -0800128#endif