blob: cf34f04c2d46fe08fef74d83c3394c9c7b189355 [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
49 if (!isDeviceVersionHal2(cameraId)) {
50 return OK;
51 }
52
53 return mDevice->initialize(mModule);
54 }
55
56 int getDeviceVersion(int cameraId) {
57 camera_info info;
58 status_t res = mModule->get_camera_info(cameraId, &info);
59 EXPECT_EQ(OK, res);
60
61 return info.device_version;
62 }
63
64 bool isDeviceVersionHal2(int cameraId) {
65 return getDeviceVersion(cameraId) >= CAMERA_DEVICE_API_VERSION_2_0;
66 }
Igor Murashkine302ee32012-11-05 11:14:49 -080067};
68
Igor Murashkineab33fc2012-11-06 17:02:54 -080069TEST_F(CameraModuleTest, LoadModule) {
Igor Murashkine302ee32012-11-05 11:14:49 -080070
Igor Murashkineab33fc2012-11-06 17:02:54 -080071 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080072
73 for (int i = 0; i < mNumberOfCameras; ++i) {
74 mDevice = new Camera2Device(i);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080075
76 ASSERT_EQ(OK, initializeDevice(i))
Igor Murashkine302ee32012-11-05 11:14:49 -080077 << "Failed to initialize device " << i;
78 mDevice.clear();
79 }
80
81}
82
Igor Murashkineab33fc2012-11-06 17:02:54 -080083TEST_F(CameraModuleTest, LoadModuleBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080084
Igor Murashkineab33fc2012-11-06 17:02:54 -080085 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080086
87 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
88
89 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
90 mDevice = new Camera2Device(idx[i]);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080091 status_t deviceInitializeCode = initializeDevice(idx[i]);
Igor Murashkine302ee32012-11-05 11:14:49 -080092 EXPECT_NE(OK, deviceInitializeCode);
93 EXPECT_EQ(-ENODEV, deviceInitializeCode)
94 << "Incorrect error code when trying to initialize invalid index "
95 << idx[i];
96 mDevice.clear();
97 }
98}
99
Igor Murashkineab33fc2012-11-06 17:02:54 -0800100TEST_F(CameraModuleTest, GetCameraInfo) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800101
Igor Murashkineab33fc2012-11-06 17:02:54 -0800102 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800103
104 for (int i = 0; i < mNumberOfCameras; ++i) {
105 struct camera_info info;
106 ASSERT_EQ(OK, mModule->get_camera_info(i, &info));
107 }
108
109}
110
Igor Murashkineab33fc2012-11-06 17:02:54 -0800111TEST_F(CameraModuleTest, GetCameraInfoBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800112
Igor Murashkineab33fc2012-11-06 17:02:54 -0800113 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800114
115 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
116 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
117 struct camera_info info;
118 EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info));
119 EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info))
120 << "Incorrect error code for get_camera_info idx= "
121 << idx[i];
122 }
123}
124
125/**
126 * TODO: Additional test to add: open two cameras at once.
127 * (is allowed to fail, at least for now, but should not blow up)
Igor Murashkineab33fc2012-11-06 17:02:54 -0800128 * - open same device multiple times
129 * - close same device multiple times
Igor Murashkine302ee32012-11-05 11:14:49 -0800130 */
131
132
133
134
135}
136}
137}
138