1 /* 2 * Copyright (C) 2018 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 "codec2_hidl_hal_master_test" 18 19 #include <android-base/logging.h> 20 #include <gtest/gtest.h> 21 22 #include <hardware/google/media/c2/1.0/IComponent.h> 23 #include <hardware/google/media/c2/1.0/IComponentStore.h> 24 25 using hardware::google::media::c2::V1_0::IComponent; 26 using hardware::google::media::c2::V1_0::IComponentStore; 27 using ::android::hardware::hidl_vec; 28 using ::android::hardware::hidl_string; 29 using ::android::sp; 30 31 #include <VtsHalHidlTargetTestBase.h> 32 #include "media_c2_hidl_test_common.h" 33 34 static ComponentTestEnvironment* gEnv = nullptr; 35 36 namespace { 37 38 // google.codec2 Master test setup 39 class Codec2MasterHalTest : public ::testing::VtsHalHidlTargetTestBase { 40 private: 41 typedef ::testing::VtsHalHidlTargetTestBase Super; 42 43 public: 44 virtual void SetUp() override { 45 Super::SetUp(); 46 mStore = Super::getService<IComponentStore>(gEnv->getInstance()); 47 ASSERT_NE(mStore, nullptr); 48 } 49 50 protected: 51 static void description(const std::string& description) { 52 RecordProperty("description", description); 53 } 54 55 sp<IComponentStore> mStore; 56 }; 57 58 void displayComponentInfo( 59 hidl_vec<IComponentStore::ComponentTraits>& compList) { 60 for (size_t i = 0; i < compList.size(); i++) { 61 std::cout << compList[i].name << " | " << toString(compList[i].domain); 62 std::cout << " | " << toString(compList[i].kind) << "\n"; 63 } 64 } 65 66 // List Components 67 TEST_F(Codec2MasterHalTest, ListComponents) { 68 ALOGV("ListComponents Test"); 69 mStore->getName([](const ::android::hardware::hidl_string& name) { 70 EXPECT_NE(name.empty(), true) << "Invalid Component Store Name"; 71 }); 72 73 android::hardware::hidl_vec<IComponentStore::ComponentTraits> listTraits; 74 mStore->listComponents( 75 [&](const android::hardware::hidl_vec<IComponentStore::ComponentTraits>& 76 traits) { listTraits = traits; }); 77 78 bool isPass = true; 79 if (listTraits.size() == 0) 80 ALOGE("Warning, ComponentInfo list empty"); 81 else { 82 (void)displayComponentInfo; 83 // displayComponentInfo(listTraits); 84 for (size_t i = 0; i < listTraits.size(); i++) { 85 sp<CodecListener> listener = new CodecListener(); 86 ASSERT_NE(listener, nullptr); 87 88 mStore->createComponent( 89 listTraits[i].name.c_str(), listener, nullptr, 90 [&](Status _s, const sp<IComponent>& _nl) { 91 ASSERT_EQ(_s, Status::OK); 92 if (!_nl) { 93 isPass = false; 94 std::cerr << "[ !OK ] " 95 << listTraits[i].name.c_str() << "\n"; 96 } 97 }); 98 } 99 } 100 EXPECT_TRUE(isPass); 101 } 102 103 } // anonymous namespace 104 105 int main(int argc, char** argv) { 106 gEnv = new ComponentTestEnvironment(); 107 ::testing::InitGoogleTest(&argc, argv); 108 gEnv->init(&argc, argv); 109 int status = gEnv->initFromOptions(argc, argv); 110 if (status == 0) { 111 status = RUN_ALL_TESTS(); 112 LOG(INFO) << "C2 Test result = " << status; 113 } 114 return status; 115 } 116