Craig Donner | 63cd88e | 2016-12-14 14:05:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #define LOG_TAG "vr_hidl_hal_test" |
| 18 | #include <android-base/logging.h> |
| 19 | #include <android/hardware/vr/1.0/IVr.h> |
| 20 | #include <android/log.h> |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 21 | #include <VtsHalHidlTargetTestBase.h> |
Craig Donner | 63cd88e | 2016-12-14 14:05:13 -0800 | [diff] [blame] | 22 | #include <hardware/vr.h> |
| 23 | |
| 24 | using ::android::hardware::vr::V1_0::IVr; |
| 25 | using ::android::hardware::Return; |
| 26 | using ::android::hardware::Void; |
| 27 | using ::android::sp; |
| 28 | |
Craig Donner | 63cd88e | 2016-12-14 14:05:13 -0800 | [diff] [blame] | 29 | // The main test class for VR HIDL HAL. |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 30 | class VrHidlTest : public ::testing::VtsHalHidlTargetTestBase { |
Craig Donner | 63cd88e | 2016-12-14 14:05:13 -0800 | [diff] [blame] | 31 | public: |
| 32 | void SetUp() override { |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 33 | vr = ::testing::VtsHalHidlTargetTestBase::getService<IVr>(); |
Craig Donner | 63cd88e | 2016-12-14 14:05:13 -0800 | [diff] [blame] | 34 | ASSERT_NE(vr, nullptr); |
Craig Donner | 63cd88e | 2016-12-14 14:05:13 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void TearDown() override {} |
| 38 | |
| 39 | sp<IVr> vr; |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | // A class for test environment setup (kept since this file is a template). |
| 44 | class VrHidlEnvironment : public ::testing::Environment { |
| 45 | public: |
| 46 | void SetUp() {} |
| 47 | void TearDown() {} |
| 48 | |
| 49 | private: |
| 50 | }; |
| 51 | |
| 52 | // Sanity check that Vr::init does not crash. |
| 53 | TEST_F(VrHidlTest, Init) { |
| 54 | EXPECT_TRUE(vr->init().isOk()); |
| 55 | } |
| 56 | |
| 57 | // Sanity check Vr::setVrMode is able to enable and disable VR mode. |
| 58 | TEST_F(VrHidlTest, SetVrMode) { |
| 59 | EXPECT_TRUE(vr->init().isOk()); |
| 60 | EXPECT_TRUE(vr->setVrMode(true).isOk()); |
| 61 | EXPECT_TRUE(vr->setVrMode(false).isOk()); |
| 62 | } |
| 63 | |
| 64 | // Sanity check that Vr::init and Vr::setVrMode can be used in any order. |
| 65 | TEST_F(VrHidlTest, ReInit) { |
| 66 | EXPECT_TRUE(vr->init().isOk()); |
| 67 | EXPECT_TRUE(vr->setVrMode(true).isOk()); |
| 68 | EXPECT_TRUE(vr->init().isOk()); |
| 69 | EXPECT_TRUE(vr->setVrMode(false).isOk()); |
| 70 | EXPECT_TRUE(vr->init().isOk()); |
| 71 | EXPECT_TRUE(vr->setVrMode(false).isOk()); |
| 72 | } |
| 73 | |
| 74 | int main(int argc, char **argv) { |
| 75 | ::testing::AddGlobalTestEnvironment(new VrHidlEnvironment); |
| 76 | ::testing::InitGoogleTest(&argc, argv); |
| 77 | int status = RUN_ALL_TESTS(); |
| 78 | ALOGI("Test result = %d", status); |
| 79 | return status; |
| 80 | } |