Home | History | Annotate | Download | only in functional
      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 <VtsHalHidlTargetTestBase.h>
     19 #include <VtsHalHidlTargetTestEnvBase.h>
     20 #include <android-base/logging.h>
     21 #include <android/hardware/vr/1.0/IVr.h>
     22 #include <hardware/vr.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 // Test environment for Vr HIDL HAL.
     31 class VrHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
     32  public:
     33   // get the test environment singleton
     34   static VrHidlEnvironment* Instance() {
     35     static VrHidlEnvironment* instance = new VrHidlEnvironment;
     36     return instance;
     37   }
     38 
     39   virtual void registerTestServices() override { registerTestService<IVr>(); }
     40 };
     41 
     42 // The main test class for VR HIDL HAL.
     43 class VrHidlTest : public ::testing::VtsHalHidlTargetTestBase {
     44  public:
     45   void SetUp() override {
     46     vr = ::testing::VtsHalHidlTargetTestBase::getService<IVr>(
     47         VrHidlEnvironment::Instance()->getServiceName<IVr>());
     48     ASSERT_NE(vr, nullptr);
     49   }
     50 
     51   void TearDown() override {}
     52 
     53   sp<IVr> vr;
     54 };
     55 
     56 // Sanity check that Vr::init does not crash.
     57 TEST_F(VrHidlTest, Init) {
     58   EXPECT_TRUE(vr->init().isOk());
     59 }
     60 
     61 // Sanity check Vr::setVrMode is able to enable and disable VR mode.
     62 TEST_F(VrHidlTest, SetVrMode) {
     63   EXPECT_TRUE(vr->init().isOk());
     64   EXPECT_TRUE(vr->setVrMode(true).isOk());
     65   EXPECT_TRUE(vr->setVrMode(false).isOk());
     66 }
     67 
     68 // Sanity check that Vr::init and Vr::setVrMode can be used in any order.
     69 TEST_F(VrHidlTest, ReInit) {
     70   EXPECT_TRUE(vr->init().isOk());
     71   EXPECT_TRUE(vr->setVrMode(true).isOk());
     72   EXPECT_TRUE(vr->init().isOk());
     73   EXPECT_TRUE(vr->setVrMode(false).isOk());
     74   EXPECT_TRUE(vr->init().isOk());
     75   EXPECT_TRUE(vr->setVrMode(false).isOk());
     76 }
     77 
     78 int main(int argc, char **argv) {
     79   ::testing::AddGlobalTestEnvironment(VrHidlEnvironment::Instance());
     80   ::testing::InitGoogleTest(&argc, argv);
     81   VrHidlEnvironment::Instance()->init(&argc, argv);
     82   int status = RUN_ALL_TESTS();
     83   ALOGI("Test result = %d", status);
     84   return status;
     85 }
     86