blob: b5b88fc45550b48a1a2848cafc73618935087303 [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 Murashkine302ee32012-11-05 11:14:49 -080045};
46
Igor Murashkineab33fc2012-11-06 17:02:54 -080047TEST_F(CameraModuleTest, LoadModule) {
Igor Murashkine302ee32012-11-05 11:14:49 -080048
Igor Murashkineab33fc2012-11-06 17:02:54 -080049 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080050
51 for (int i = 0; i < mNumberOfCameras; ++i) {
52 mDevice = new Camera2Device(i);
53 ASSERT_EQ(OK, mDevice->initialize(mModule))
54 << "Failed to initialize device " << i;
55 mDevice.clear();
56 }
57
58}
59
Igor Murashkineab33fc2012-11-06 17:02:54 -080060TEST_F(CameraModuleTest, LoadModuleBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080061
Igor Murashkineab33fc2012-11-06 17:02:54 -080062 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080063
64 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
65
66 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
67 mDevice = new Camera2Device(idx[i]);
68 status_t deviceInitializeCode = mDevice->initialize(mModule);
69 EXPECT_NE(OK, deviceInitializeCode);
70 EXPECT_EQ(-ENODEV, deviceInitializeCode)
71 << "Incorrect error code when trying to initialize invalid index "
72 << idx[i];
73 mDevice.clear();
74 }
75}
76
Igor Murashkineab33fc2012-11-06 17:02:54 -080077TEST_F(CameraModuleTest, GetCameraInfo) {
Igor Murashkine302ee32012-11-05 11:14:49 -080078
Igor Murashkineab33fc2012-11-06 17:02:54 -080079 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080080
81 for (int i = 0; i < mNumberOfCameras; ++i) {
82 struct camera_info info;
83 ASSERT_EQ(OK, mModule->get_camera_info(i, &info));
84 }
85
86}
87
Igor Murashkineab33fc2012-11-06 17:02:54 -080088TEST_F(CameraModuleTest, GetCameraInfoBadIndices) {
Igor Murashkine302ee32012-11-05 11:14:49 -080089
Igor Murashkineab33fc2012-11-06 17:02:54 -080090 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080091
92 int idx[] = { -1, mNumberOfCameras, mNumberOfCameras + 1 };
93 for (unsigned i = 0; i < sizeof(idx)/sizeof(idx[0]); ++i) {
94 struct camera_info info;
95 EXPECT_NE(OK, mModule->get_camera_info(idx[i], &info));
96 EXPECT_EQ(-ENODEV, mModule->get_camera_info(idx[i], &info))
97 << "Incorrect error code for get_camera_info idx= "
98 << idx[i];
99 }
100}
101
102/**
103 * TODO: Additional test to add: open two cameras at once.
104 * (is allowed to fail, at least for now, but should not blow up)
Igor Murashkineab33fc2012-11-06 17:02:54 -0800105 * - open same device multiple times
106 * - close same device multiple times
Igor Murashkine302ee32012-11-05 11:14:49 -0800107 */
108
109
110
111
112}
113}
114}
115