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
24namespace tests {
25
26static const int kMmaxCams = 2;
27static const uint16_t kVersion3_0 = HARDWARE_MODULE_API_VERSION(3, 0);
28
29class Camera3Module : public testing::Test {
30 public:
31    Camera3Module() :
32        num_cams_(0),
33        cam_module_(NULL) {}
34    ~Camera3Module() {}
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
55class 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";
71        ASSERT_LE(kVersion3_0, device->version)
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
80}  // namespace tests
81
82#endif  // __ANDROID_HAL_CAMERA3_TEST_COMMON__
83