blob: ae4267b87df3b9375bc5a26f43ae58bb8c502a23 [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>
Eino-Ville Talvala48bb03f2013-07-25 17:09:14 -070022#include <utils/StrongPointer.h>
23#include <common/CameraDeviceBase.h>
Igor Murashkine302ee32012-11-05 11:14:49 -080024
25#include "hardware/hardware.h"
26#include "hardware/camera2.h"
27
Igor Murashkine302ee32012-11-05 11:14:49 -080028#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 bool isDeviceVersionHal2(int cameraId, status_t* status) {
58 return getDeviceVersion(cameraId, status)
59 >= CAMERA_DEVICE_API_VERSION_2_0;
Igor Murashkin0a7a4302012-12-18 14:08:27 -080060 }
Igor Murashkine302ee32012-11-05 11:14:49 -080061};
62
Igor Murashkineab33fc2012-11-06 17:02:54 -080063TEST_F(CameraModuleTest, LoadModule) {
Igor Murashkine302ee32012-11-05 11:14:49 -080064
Igor Murashkineab33fc2012-11-06 17:02:54 -080065 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080066
67 for (int i = 0; i < mNumberOfCameras; ++i) {
Eino-Ville Talvala4c543a12013-06-25 18:12:19 -070068 CreateCamera(i, &mDevice);
Igor Murashkin0a7a4302012-12-18 14:08:27 -080069 ASSERT_EQ(OK, initializeDevice(i))
Igor Murashkine302ee32012-11-05 11:14:49 -080070 << "Failed to initialize device " << i;
71 mDevice.clear();
72 }
73
74}
75
Igor Murashkineab33fc2012-11-06 17:02:54 -080076TEST_F(CameraModuleTest, LoadModuleBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080077
Igor Murashkineab33fc2012-11-06 17:02:54 -080078 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080079
80 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
Zhijun He60cbb522013-09-18 09:44:19 -070081 hw_device_t *device = NULL;
Igor Murashkine302ee32012-11-05 11:14:49 -080082
83 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
Zhijun He60cbb522013-09-18 09:44:19 -070084 String8 deviceName = String8::format("%d", idx[i]);
85 status_t res =
86 mModule->common.methods->open(
87 &mModule->common,
88 deviceName,
89 &device);
90 EXPECT_NE(OK, res);
91 EXPECT_EQ(-ENODEV, res)
92 << "Incorrect error code when trying to open camera with invalid id "
93 << deviceName;
Igor Murashkine302ee32012-11-05 11:14:49 -080094 }
95}
96
Igor Murashkineab33fc2012-11-06 17:02:54 -080097TEST_F(CameraModuleTest, GetCameraInfo) {
Igor Murashkine302ee32012-11-05 11:14:49 -080098
Igor Murashkineab33fc2012-11-06 17:02:54 -080099 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800100
101 for (int i = 0; i < mNumberOfCameras; ++i) {
102 struct camera_info info;
103 ASSERT_EQ(OK, mModule->get_camera_info(i, &info));
104 }
105
106}
107
Igor Murashkineab33fc2012-11-06 17:02:54 -0800108TEST_F(CameraModuleTest, GetCameraInfoBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -0800109
Igor Murashkineab33fc2012-11-06 17:02:54 -0800110 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -0800111
112 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
113 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
114 struct camera_info info;
115 EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info));
116 EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info))
117 << "Incorrect error code for get_camera_info idx= "
118 << idx[i];
119 }
120}
121
122/**
123 * TODO: Additional test to add: open two cameras at once.
124 * (is allowed to fail, at least for now, but should not blow up)
Igor Murashkineab33fc2012-11-06 17:02:54 -0800125 * - open same device multiple times
126 * - close same device multiple times
Igor Murashkine302ee32012-11-05 11:14:49 -0800127 */
128
129
130
131
132}
133}
134}