2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ANDROID_HAL_CAMERA3_TEST_COMMON__
18 #define __ANDROID_HAL_CAMERA3_TEST_COMMON__
20 #include <gtest/gtest.h>
21 #include <hardware/hardware.h>
22 #include <hardware/camera3.h>
26 static const int kMmaxCams = 2;
27 static const uint16_t kVersion3_0 = HARDWARE_MODULE_API_VERSION(3, 0);
29 class Camera3Module : public testing::Test {
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";
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();
48 int num_cams() { return num_cams_; }
49 const camera_module_t * cam_module() { return cam_module_; }
52 const camera_module_t *cam_module_;
55 class Camera3Device : public Camera3Module {
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";
71 ASSERT_LE(kVersion3_0, device->version)
72 << "The device does not support HAL3";
73 cam_device_ = reinterpret_cast<camera3_device_t*>(device);
75 camera3_device_t* cam_device() { return cam_device_; }
77 camera3_device *cam_device_;
82 #endif // __ANDROID_HAL_CAMERA3_TEST_COMMON__