blob: 23f4c71dfb1e8dc4fbe3df74ba0dcf7c7e62bdd8 [file] [log] [blame]
Craig Donner63cd88e2016-12-14 14:05:13 -08001/*
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"
Steven Moreland3eb7df72017-04-06 12:15:23 -070018#include <VtsHalHidlTargetTestBase.h>
Craig Donner63cd88e2016-12-14 14:05:13 -080019#include <android-base/logging.h>
20#include <android/hardware/vr/1.0/IVr.h>
Craig Donner63cd88e2016-12-14 14:05:13 -080021#include <hardware/vr.h>
Steven Moreland3eb7df72017-04-06 12:15:23 -070022#include <log/log.h>
Craig Donner63cd88e2016-12-14 14:05:13 -080023
24using ::android::hardware::vr::V1_0::IVr;
25using ::android::hardware::Return;
26using ::android::hardware::Void;
27using ::android::sp;
28
Craig Donner63cd88e2016-12-14 14:05:13 -080029// The main test class for VR HIDL HAL.
Yuexi Maed2bb4e2017-03-10 00:44:45 -080030class VrHidlTest : public ::testing::VtsHalHidlTargetTestBase {
Craig Donner63cd88e2016-12-14 14:05:13 -080031 public:
32 void SetUp() override {
Yuexi Maed2bb4e2017-03-10 00:44:45 -080033 vr = ::testing::VtsHalHidlTargetTestBase::getService<IVr>();
Craig Donner63cd88e2016-12-14 14:05:13 -080034 ASSERT_NE(vr, nullptr);
Craig Donner63cd88e2016-12-14 14:05:13 -080035 }
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}