blob: 17e3d45490b30fea232b87652e3da3859ea314b7 [file] [log] [blame]
Sasha Levitskiy4a7b2172013-12-10 09:37:58 -08001/*
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
24namespace tests {
25
26static const int kMmaxCams = 2;
27static const uint16_t kVersion3_0 = HARDWARE_MODULE_API_VERSION(3, 0);
28
Sasha Levitskiy024c1532013-12-12 14:08:55 -080029class Camera3Module : public testing::Test {
Sasha Levitskiy4a7b2172013-12-10 09:37:58 -080030 public:
Sasha Levitskiy024c1532013-12-12 14:08:55 -080031 Camera3Module() :
Sasha Levitskiy4a7b2172013-12-10 09:37:58 -080032 num_cams_(0),
33 cam_module_(NULL) {}
Sasha Levitskiy024c1532013-12-12 14:08:55 -080034 ~Camera3Module() {}
Sasha Levitskiy4a7b2172013-12-10 09:37:58 -080035 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 Levitskiy024c1532013-12-12 14:08:55 -080055class 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 Yeh8df990b2014-10-31 15:10:11 -070071 ASSERT_LE(kVersion3_0, device->version)
Sasha Levitskiy024c1532013-12-12 14:08:55 -080072 << "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 Levitskiy4a7b2172013-12-10 09:37:58 -080080} // namespace tests
81
82#endif // __ANDROID_HAL_CAMERA3_TEST_COMMON__