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 <gtest/gtest.h>
21 #include <hardware/vr.h>
22 #include <hidl/GtestPrinter.h>
23 #include <hidl/ServiceManagement.h>
24 #include <log/log.h>
25
26 using ::android::hardware::vr::V1_0::IVr;
27 using ::android::hardware::Return;
28 using ::android::hardware::Void;
29 using ::android::sp;
30
31 // The main test class for VR HIDL HAL.
32 class VrHidlTest : public ::testing::TestWithParam<std::string> {
33 public:
SetUp()34 void SetUp() override {
35 vr = IVr::getService(GetParam());
36 ASSERT_NE(vr, nullptr);
37 }
38
TearDown()39 void TearDown() override {}
40
41 sp<IVr> vr;
42 };
43
44 // Sanity check that Vr::init does not crash.
TEST_P(VrHidlTest,Init)45 TEST_P(VrHidlTest, Init) {
46 EXPECT_TRUE(vr->init().isOk());
47 }
48
49 // Sanity check Vr::setVrMode is able to enable and disable VR mode.
TEST_P(VrHidlTest,SetVrMode)50 TEST_P(VrHidlTest, SetVrMode) {
51 EXPECT_TRUE(vr->init().isOk());
52 EXPECT_TRUE(vr->setVrMode(true).isOk());
53 EXPECT_TRUE(vr->setVrMode(false).isOk());
54 }
55
56 // Sanity check that Vr::init and Vr::setVrMode can be used in any order.
TEST_P(VrHidlTest,ReInit)57 TEST_P(VrHidlTest, ReInit) {
58 EXPECT_TRUE(vr->init().isOk());
59 EXPECT_TRUE(vr->setVrMode(true).isOk());
60 EXPECT_TRUE(vr->init().isOk());
61 EXPECT_TRUE(vr->setVrMode(false).isOk());
62 EXPECT_TRUE(vr->init().isOk());
63 EXPECT_TRUE(vr->setVrMode(false).isOk());
64 }
65
66 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VrHidlTest);
67 INSTANTIATE_TEST_SUITE_P(
68 PerInstance, VrHidlTest,
69 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IVr::descriptor)),
70 android::hardware::PrintInstanceNameToString);
71
72