Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include "hardware/hardware.h" |
| 20 | #include "hardware/camera2.h" |
| 21 | |
| 22 | #include "Camera2Device.h" |
| 23 | #include "camera2_utils.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace camera2 { |
| 27 | namespace tests { |
| 28 | |
| 29 | template <bool InfoQuirk = false> |
| 30 | struct CameraModuleFixture { |
| 31 | |
| 32 | CameraModuleFixture(int CameraID = -1) { |
| 33 | mCameraID = CameraID; |
| 34 | |
| 35 | SetUp(); |
| 36 | } |
| 37 | |
| 38 | ~CameraModuleFixture() { |
| 39 | TearDown(); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | |
| 44 | void SetUp() { |
| 45 | ASSERT_LE(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID, |
| 46 | (const hw_module_t **)&mModule)) << "Could not load camera module"; |
| 47 | ASSERT_NE((void*)0, mModule); |
| 48 | |
| 49 | mNumberOfCameras = mModule->get_number_of_cameras(); |
| 50 | ASSERT_LE(0, mNumberOfCameras); |
| 51 | |
| 52 | ASSERT_EQ( |
| 53 | CAMERA_MODULE_API_VERSION_2_0, mModule->common.module_api_version) |
| 54 | << "Wrong module API version"; |
| 55 | |
| 56 | /* For using this fixture in other tests only */ |
| 57 | SetUpMixin(); |
| 58 | } |
| 59 | |
| 60 | void TearDown() { |
| 61 | TearDownMixin(); |
| 62 | |
| 63 | /* important: device must be destructed before closing module, |
| 64 | since it calls back into HAL */ |
| 65 | mDevice.clear(); |
| 66 | |
| 67 | ASSERT_EQ(0, HWModuleHelpers::closeModule(&mModule->common)) |
| 68 | << "Failed to close camera HAL module"; |
| 69 | } |
| 70 | |
| 71 | void SetUpMixin() { |
| 72 | /* For using this fixture in other tests only */ |
| 73 | if (mCameraID != -1) { |
| 74 | EXPECT_LE(0, mCameraID); |
| 75 | EXPECT_LT(mCameraID, mNumberOfCameras); |
| 76 | |
| 77 | /* HALBUG (Exynos5); crashes if trying to initialize |
| 78 | before calling get_camera_info */ |
| 79 | if (InfoQuirk) { |
| 80 | struct camera_info info; |
| 81 | ASSERT_EQ(OK, mModule->get_camera_info(mCameraID, &info)); |
| 82 | } |
| 83 | |
| 84 | mDevice = new Camera2Device(mCameraID); |
| 85 | ASSERT_EQ(OK, mDevice->initialize(mModule)) |
| 86 | << "Failed to initialize device " << mCameraID; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void TearDownMixin() { |
| 91 | |
| 92 | } |
| 93 | |
| 94 | protected: |
| 95 | int mNumberOfCameras; |
| 96 | camera_module_t *mModule; |
| 97 | sp<Camera2Device> mDevice; |
| 98 | |
| 99 | private: |
| 100 | int mCameraID; |
| 101 | }; |
| 102 | |
| 103 | |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |