blob: 5e856982190a55c7d8be17c46de8bfe7d802a15a [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 Murashkine302ee32012-11-05 11:14:49 -080036};
37
Igor Murashkineab33fc2012-11-06 17:02:54 -080038TEST_F(CameraModuleTest, LoadModule) {
Igor Murashkine302ee32012-11-05 11:14:49 -080039
Igor Murashkineab33fc2012-11-06 17:02:54 -080040 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080041
42 for (int i = 0; i < mNumberOfCameras; ++i) {
43 mDevice = new Camera2Device(i);
44 ASSERT_EQ(OK, mDevice->initialize(mModule))
45 << "Failed to initialize device " << i;
46 mDevice.clear();
47 }
48
49}
50
Igor Murashkineab33fc2012-11-06 17:02:54 -080051TEST_F(CameraModuleTest, LoadModuleBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080052
Igor Murashkineab33fc2012-11-06 17:02:54 -080053 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080054
55 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
56
57 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
58 mDevice = new Camera2Device(idx[i]);
59 status_t deviceInitializeCode = mDevice->initialize(mModule);
60 EXPECT_NE(OK, deviceInitializeCode);
61 EXPECT_EQ(-ENODEV, deviceInitializeCode)
62 << "Incorrect error code when trying to initialize invalid index "
63 << idx[i];
64 mDevice.clear();
65 }
66}
67
Igor Murashkineab33fc2012-11-06 17:02:54 -080068TEST_F(CameraModuleTest, GetCameraInfo) {
Igor Murashkine302ee32012-11-05 11:14:49 -080069
Igor Murashkineab33fc2012-11-06 17:02:54 -080070 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080071
72 for (int i = 0; i < mNumberOfCameras; ++i) {
73 struct camera_info info;
74 ASSERT_EQ(OK, mModule->get_camera_info(i, &info));
75 }
76
77}
78
Igor Murashkineab33fc2012-11-06 17:02:54 -080079TEST_F(CameraModuleTest, GetCameraInfoBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080080
Igor Murashkineab33fc2012-11-06 17:02:54 -080081 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080082
83 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
84 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
85 struct camera_info info;
86 EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info));
87 EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info))
88 << "Incorrect error code for get_camera_info idx= "
89 << idx[i];
90 }
91}
92
93/**
94 * TODO: Additional test to add: open two cameras at once.
95 * (is allowed to fail, at least for now, but should not blow up)
Igor Murashkineab33fc2012-11-06 17:02:54 -080096 * - open same device multiple times
97 * - close same device multiple times
Igor Murashkine302ee32012-11-05 11:14:49 -080098 */
99
100
101
102
103}
104}
105}
106