Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 1 | /* |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 19 | #define LOG_TAG "CameraModuleTest" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 20 | #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 | |
| 30 | namespace android { |
| 31 | namespace camera2 { |
| 32 | namespace tests { |
| 33 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 34 | class CameraModuleTest : public ::testing::Test, |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 35 | public CameraModuleFixture<> { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 38 | TEST_F(CameraModuleTest, LoadModule) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 39 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 40 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 41 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 51 | TEST_F(CameraModuleTest, LoadModuleBadIndices) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 52 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 53 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 54 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 68 | TEST_F(CameraModuleTest, GetCameraInfo) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 69 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 70 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 71 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 79 | TEST_F(CameraModuleTest, GetCameraInfoBadIndices) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 80 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 81 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 82 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 96 | * - open same device multiple times |
| 97 | * - close same device multiple times |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 98 | */ |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |