1 /* 2 * Copyright (C) 2020 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 #pragma once 17 18 #include <android/hardware/contexthub/1.0/IContexthubCallback.h> 19 #include <gtest/gtest.h> 20 21 #include <string> 22 #include <tuple> 23 24 namespace android { 25 namespace hardware { 26 namespace contexthub { 27 namespace vts_utils { 28 29 // Base fixture for Context Hub HAL tests. Parameterized by service name and hub ID. 30 template <class IContexthubVersion> 31 class ContexthubHidlTestBase 32 : public ::testing::TestWithParam<std::tuple<std::string, std::string>> { 33 public: SetUp()34 virtual void SetUp() override { fetchHubApi(); } 35 fetchHubApi()36 void fetchHubApi() { 37 hubApi = IContexthubVersion::getService(std::get<0>(GetParam())); 38 ASSERT_NE(hubApi, nullptr); 39 } 40 getHubId()41 uint32_t getHubId() { return std::stoi(std::get<1>(GetParam())); } 42 registerCallback(sp<V1_0::IContexthubCallback> cb)43 V1_0::Result registerCallback(sp<V1_0::IContexthubCallback> cb) { 44 return hubApi->registerCallback(getHubId(), cb); 45 } 46 47 sp<IContexthubVersion> hubApi; 48 }; 49 50 } // namespace vts_utils 51 } // namespace contexthub 52 } // namespace hardware 53 } // namespace android 54