blob: 00943fd4d63e6a5c0302dd9d1160a87f84931138 [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"
18#include <android-base/logging.h>
19#include <android/hardware/vr/1.0/IVr.h>
nelsonli6edb7e22019-10-29 16:16:55 +080020#include <gtest/gtest.h>
nelsonli6edb7e22019-10-29 16:16:55 +080021#include <hidl/GtestPrinter.h>
22#include <hidl/ServiceManagement.h>
Steven Moreland3eb7df72017-04-06 12:15:23 -070023#include <log/log.h>
Craig Donner63cd88e2016-12-14 14:05:13 -080024
25using ::android::hardware::vr::V1_0::IVr;
26using ::android::hardware::Return;
27using ::android::hardware::Void;
28using ::android::sp;
29
Craig Donner63cd88e2016-12-14 14:05:13 -080030// The main test class for VR HIDL HAL.
nelsonli6edb7e22019-10-29 16:16:55 +080031class VrHidlTest : public ::testing::TestWithParam<std::string> {
Craig Donner63cd88e2016-12-14 14:05:13 -080032 public:
33 void SetUp() override {
nelsonli6edb7e22019-10-29 16:16:55 +080034 vr = IVr::getService(GetParam());
Craig Donner63cd88e2016-12-14 14:05:13 -080035 ASSERT_NE(vr, nullptr);
Craig Donner63cd88e2016-12-14 14:05:13 -080036 }
37
38 void TearDown() override {}
39
40 sp<IVr> vr;
41};
42
Craig Donner63cd88e2016-12-14 14:05:13 -080043// Sanity check that Vr::init does not crash.
nelsonli6edb7e22019-10-29 16:16:55 +080044TEST_P(VrHidlTest, Init) {
Craig Donner63cd88e2016-12-14 14:05:13 -080045 EXPECT_TRUE(vr->init().isOk());
46}
47
48// Sanity check Vr::setVrMode is able to enable and disable VR mode.
nelsonli6edb7e22019-10-29 16:16:55 +080049TEST_P(VrHidlTest, SetVrMode) {
Craig Donner63cd88e2016-12-14 14:05:13 -080050 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.
nelsonli6edb7e22019-10-29 16:16:55 +080056TEST_P(VrHidlTest, ReInit) {
Craig Donner63cd88e2016-12-14 14:05:13 -080057 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
Dan Shiba4d5322020-07-28 13:09:30 -070065GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VrHidlTest);
nelsonli6edb7e22019-10-29 16:16:55 +080066INSTANTIATE_TEST_SUITE_P(
67 PerInstance, VrHidlTest,
68 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IVr::descriptor)),
69 android::hardware::PrintInstanceNameToString);
70