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