VtsHalVrV1_0TargetTest.cpp revision 50d7e27b3c13885d2bd90dc0f0f2366cd0523f77
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>
21#include <VtsHalHidlTargetBaseTest.h>
22#include <hardware/vr.h>
23
24using ::android::hardware::vr::V1_0::IVr;
25using ::android::hardware::Return;
26using ::android::hardware::Void;
27using ::android::sp;
28
29// The main test class for VR HIDL HAL.
30class VrHidlTest : public ::testing::VtsHalHidlTargetBaseTest {
31 public:
32  void SetUp() override {
33    vr = ::testing::VtsHalHidlTargetBaseTest::getService<IVr>();
34    ASSERT_NE(vr, nullptr);
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).
44class 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.
53TEST_F(VrHidlTest, Init) {
54  EXPECT_TRUE(vr->init().isOk());
55}
56
57// Sanity check Vr::setVrMode is able to enable and disable VR mode.
58TEST_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.
65TEST_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
74int 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}
81