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 | 7acb21a | 2012-12-18 13:38:40 -0800 | [diff] [blame] | 36 | |
| 37 | public: |
| 38 | CameraModuleTest() { |
| 39 | CameraModuleFixture::SetUp(); |
| 40 | } |
| 41 | |
| 42 | ~CameraModuleTest() { |
| 43 | CameraModuleFixture::TearDown(); |
| 44 | } |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 47 | TEST_F(CameraModuleTest, LoadModule) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 48 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 49 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 50 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 60 | TEST_F(CameraModuleTest, LoadModuleBadIndices) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 61 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 62 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 63 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 77 | TEST_F(CameraModuleTest, GetCameraInfo) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 78 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 79 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 80 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 88 | TEST_F(CameraModuleTest, GetCameraInfoBadIndices) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 89 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 90 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 91 | |
| 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 Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 105 | * - open same device multiple times |
| 106 | * - close same device multiple times |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 107 | */ |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |