Sasha Levitskiy | 4a7b217 | 2013-12-10 09:37:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #ifndef __ANDROID_HAL_CAMERA3_TEST_COMMON__ |
| 18 | #define __ANDROID_HAL_CAMERA3_TEST_COMMON__ |
| 19 | |
| 20 | #include <gtest/gtest.h> |
| 21 | #include <hardware/hardware.h> |
| 22 | #include <hardware/camera3.h> |
| 23 | |
| 24 | namespace tests { |
| 25 | |
| 26 | static const int kMmaxCams = 2; |
| 27 | static const uint16_t kVersion3_0 = HARDWARE_MODULE_API_VERSION(3, 0); |
| 28 | |
Sasha Levitskiy | 024c153 | 2013-12-12 14:08:55 -0800 | [diff] [blame] | 29 | class Camera3Module : public testing::Test { |
Sasha Levitskiy | 4a7b217 | 2013-12-10 09:37:58 -0800 | [diff] [blame] | 30 | public: |
Sasha Levitskiy | 024c153 | 2013-12-12 14:08:55 -0800 | [diff] [blame] | 31 | Camera3Module() : |
Sasha Levitskiy | 4a7b217 | 2013-12-10 09:37:58 -0800 | [diff] [blame] | 32 | num_cams_(0), |
| 33 | cam_module_(NULL) {} |
Sasha Levitskiy | 024c153 | 2013-12-12 14:08:55 -0800 | [diff] [blame] | 34 | ~Camera3Module() {} |
Sasha Levitskiy | 4a7b217 | 2013-12-10 09:37:58 -0800 | [diff] [blame] | 35 | protected: |
| 36 | virtual void SetUp() { |
| 37 | const hw_module_t *hw_module = NULL; |
| 38 | ASSERT_EQ(0, hw_get_module(CAMERA_HARDWARE_MODULE_ID, &hw_module)) |
| 39 | << "Can't get camera module"; |
| 40 | ASSERT_TRUE(NULL != hw_module) |
| 41 | << "hw_get_module didn't return a valid camera module"; |
| 42 | |
| 43 | cam_module_ = reinterpret_cast<const camera_module_t*>(hw_module); |
| 44 | ASSERT_TRUE(NULL != cam_module_->get_number_of_cameras) |
| 45 | << "get_number_of_cameras is not implemented"; |
| 46 | num_cams_ = cam_module_->get_number_of_cameras(); |
| 47 | } |
| 48 | int num_cams() { return num_cams_; } |
| 49 | const camera_module_t * cam_module() { return cam_module_; } |
| 50 | private: |
| 51 | int num_cams_; |
| 52 | const camera_module_t *cam_module_; |
| 53 | }; |
| 54 | |
Sasha Levitskiy | 024c153 | 2013-12-12 14:08:55 -0800 | [diff] [blame] | 55 | class Camera3Device : public Camera3Module { |
| 56 | public: |
| 57 | Camera3Device() : |
| 58 | cam_device_(NULL) {} |
| 59 | ~Camera3Device() {} |
| 60 | protected: |
| 61 | virtual void SetUp() { |
| 62 | Camera3Module::SetUp(); |
| 63 | hw_device_t *device = NULL; |
| 64 | ASSERT_TRUE(NULL != cam_module()->common.methods->open) |
| 65 | << "Camera open() is unimplemented"; |
| 66 | ASSERT_EQ(0, cam_module()->common.methods->open( |
| 67 | (const hw_module_t*)cam_module(), "0", &device)) |
| 68 | << "Can't open camera device"; |
| 69 | ASSERT_TRUE(NULL != device) |
| 70 | << "Camera open() returned a NULL device"; |
Yin-Chia Yeh | 8df990b | 2014-10-31 15:10:11 -0700 | [diff] [blame] | 71 | ASSERT_LE(kVersion3_0, device->version) |
Sasha Levitskiy | 024c153 | 2013-12-12 14:08:55 -0800 | [diff] [blame] | 72 | << "The device does not support HAL3"; |
| 73 | cam_device_ = reinterpret_cast<camera3_device_t*>(device); |
| 74 | } |
| 75 | camera3_device_t* cam_device() { return cam_device_; } |
| 76 | private: |
| 77 | camera3_device *cam_device_; |
| 78 | }; |
| 79 | |
Sasha Levitskiy | 4a7b217 | 2013-12-10 09:37:58 -0800 | [diff] [blame] | 80 | } // namespace tests |
| 81 | |
| 82 | #endif // __ANDROID_HAL_CAMERA3_TEST_COMMON__ |