blob: fc6fd362b8a804bf85d69238f1929bcbe20045fb [file] [log] [blame]
Igor Murashkine302ee32012-11-05 11:14:49 -08001/*
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
Igor Murashkineab33fc2012-11-06 17:02:54 -080019#define LOG_TAG "CameraModuleTest"
Igor Murashkine302ee32012-11-05 11:14:49 -080020#define LOG_NDEBUG 0
21#include <utils/Log.h>
22
23#include "hardware/hardware.h"
24#include "hardware/camera2.h"
25
26#include "Camera2Device.h"
27#include "utils/StrongPointer.h"
28#include "CameraModuleFixture.h"
29
30namespace android {
31namespace camera2 {
32namespace tests {
33
Igor Murashkineab33fc2012-11-06 17:02:54 -080034class CameraModuleTest : public ::testing::Test,
Igor Murashkine302ee32012-11-05 11:14:49 -080035 public CameraModuleFixture<> {
Igor Murashkin7acb21a2012-12-18 13:38:40 -080036
37public:
38 CameraModuleTest() {
39 CameraModuleFixture::SetUp();
40 }
41
42 ~CameraModuleTest() {
43 CameraModuleFixture::TearDown();
44 }
Igor Murashkin0a7a4302012-12-18 14:08:27 -080045
46 status_t initializeDevice(int cameraId) {
47
48 // ignore HAL1s. count as test pass
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080049 status_t stat;
50 if (isDeviceVersionHal2(cameraId, &stat) && stat == OK) {
51 stat = mDevice->initialize(mModule);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080052 }
53
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080054 return stat;
Igor Murashkin0a7a4302012-12-18 14:08:27 -080055 }
56
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080057 int getDeviceVersion(int cameraId, status_t* status) {
Igor Murashkin0a7a4302012-12-18 14:08:27 -080058 camera_info info;
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080059 *status = mModule->get_camera_info(cameraId, &info);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080060
61 return info.device_version;
62 }
63
Igor Murashkine9b0eaa2012-12-20 17:11:56 -080064 bool isDeviceVersionHal2(int cameraId, status_t* status) {
65 return getDeviceVersion(cameraId, status)
66 >= CAMERA_DEVICE_API_VERSION_2_0;
Igor Murashkin0a7a4302012-12-18 14:08:27 -080067 }
Igor Murashkine302ee32012-11-05 11:14:49 -080068};
69
Igor Murashkineab33fc2012-11-06 17:02:54 -080070TEST_F(CameraModuleTest, LoadModule) {
Igor Murashkine302ee32012-11-05 11:14:49 -080071
Igor Murashkineab33fc2012-11-06 17:02:54 -080072 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080073
74 for (int i = 0; i < mNumberOfCameras; ++i) {
75 mDevice = new Camera2Device(i);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080076
77 ASSERT_EQ(OK, initializeDevice(i))
Igor Murashkine302ee32012-11-05 11:14:49 -080078 << "Failed to initialize device " << i;
79 mDevice.clear();
80 }
81
82}
83
Igor Murashkineab33fc2012-11-06 17:02:54 -080084TEST_F(CameraModuleTest, LoadModuleBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080085
Igor Murashkineab33fc2012-11-06 17:02:54 -080086 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080087
88 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
89
90 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
91 mDevice = new Camera2Device(idx[i]);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080092 status_t deviceInitializeCode = initializeDevice(idx[i]);
Igor Murashkine302ee32012-11-05 11:14:49 -080093 EXPECT_NE(OK, deviceInitializeCode);
94 EXPECT_EQ(-ENODEV, deviceInitializeCode)
95 << "Incorrect error code when trying to initialize invalid index "
96 << idx[i];
97 mDevice.clear();
98 }
99}
100
Igor Murashkineab33fc2012-11-06 17:02:54 -0800101TEST_F(CameraModuleTest, GetCameraInfo) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800102
Igor Murashkineab33fc2012-11-06 17:02:54 -0800103 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800104
105 for (int i = 0; i < mNumberOfCameras; ++i) {
106 struct camera_info info;
107 ASSERT_EQ(OK, mModule->get_camera_info(i, &info));
108 }
109
110}
111
Igor Murashkineab33fc2012-11-06 17:02:54 -0800112TEST_F(CameraModuleTest, GetCameraInfoBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800113
Igor Murashkineab33fc2012-11-06 17:02:54 -0800114 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800115
116 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
117 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
118 struct camera_info info;
119 EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info));
120 EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info))
121 << "Incorrect error code for get_camera_info idx= "
122 << idx[i];
123 }
124}
125
126/**
127 * TODO: Additional test to add: open two cameras at once.
128 * (is allowed to fail, at least for now, but should not blow up)
Igor Murashkineab33fc2012-11-06 17:02:54 -0800129 * - open same device multiple times
130 * - close same device multiple times
Igor Murashkine302ee32012-11-05 11:14:49 -0800131 */
132
133
134
135
136}
137}
138}
139