VtsHalVrV1_0TargetTest.cpp revision 8422f6aa046e86ccd06e62dcbd611073355cfa08
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 <gtest/gtest.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#define VR_SERVICE_NAME "vr" 30 31// The main test class for VR HIDL HAL. 32class VrHidlTest : public ::testing::Test { 33 public: 34 void SetUp() override { 35 vr = IVr::getService(VR_SERVICE_NAME); 36 ASSERT_NE(vr, nullptr); 37 } 38 39 void TearDown() override {} 40 41 sp<IVr> vr; 42}; 43 44 45// A class for test environment setup (kept since this file is a template). 46class VrHidlEnvironment : public ::testing::Environment { 47 public: 48 void SetUp() {} 49 void TearDown() {} 50 51 private: 52}; 53 54// Sanity check that Vr::init does not crash. 55TEST_F(VrHidlTest, Init) { 56 EXPECT_TRUE(vr->init().isOk()); 57} 58 59// Sanity check Vr::setVrMode is able to enable and disable VR mode. 60TEST_F(VrHidlTest, SetVrMode) { 61 EXPECT_TRUE(vr->init().isOk()); 62 EXPECT_TRUE(vr->setVrMode(true).isOk()); 63 EXPECT_TRUE(vr->setVrMode(false).isOk()); 64} 65 66// Sanity check that Vr::init and Vr::setVrMode can be used in any order. 67TEST_F(VrHidlTest, ReInit) { 68 EXPECT_TRUE(vr->init().isOk()); 69 EXPECT_TRUE(vr->setVrMode(true).isOk()); 70 EXPECT_TRUE(vr->init().isOk()); 71 EXPECT_TRUE(vr->setVrMode(false).isOk()); 72 EXPECT_TRUE(vr->init().isOk()); 73 EXPECT_TRUE(vr->setVrMode(false).isOk()); 74} 75 76int main(int argc, char **argv) { 77 ::testing::AddGlobalTestEnvironment(new VrHidlEnvironment); 78 ::testing::InitGoogleTest(&argc, argv); 79 int status = RUN_ALL_TESTS(); 80 ALOGI("Test result = %d", status); 81 return status; 82} 83