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_NDEBUG 0
18 #define LOG_TAG "codec2_hidl_hal_master_test"
19
20 #include <android-base/logging.h>
21 #include <gtest/gtest.h>
22 #include <hidl/GtestPrinter.h>
23 #include <hidl/ServiceManagement.h>
24
25 #include <codec2/hidl/client.h>
26
27 #include <VtsHalHidlTargetTestBase.h>
28 #include "media_c2_hidl_test_common.h"
29
30 namespace {
31
32 // google.codec2 Master test setup
33 class Codec2MasterHalTest : public ::testing::TestWithParam<std::string> {
34 public:
SetUp()35 virtual void SetUp() override {
36 mClient = android::Codec2Client::CreateFromService(GetParam().c_str());
37 ASSERT_NE(mClient, nullptr);
38 }
39
40 protected:
description(const std::string & description)41 static void description(const std::string& description) {
42 RecordProperty("description", description);
43 }
44
45 std::shared_ptr<android::Codec2Client> mClient;
46 };
47
displayComponentInfo(const std::vector<C2Component::Traits> & compList)48 void displayComponentInfo(const std::vector<C2Component::Traits>& compList) {
49 for (size_t i = 0; i < compList.size(); i++) {
50 std::cout << compList[i].name << " | " << compList[i].domain;
51 std::cout << " | " << compList[i].kind << "\n";
52 }
53 }
54
55 // List Components
TEST_P(Codec2MasterHalTest,ListComponents)56 TEST_P(Codec2MasterHalTest, ListComponents) {
57 ALOGV("ListComponents Test");
58
59 C2String name = mClient->getName();
60 EXPECT_NE(name.empty(), true) << "Invalid Codec2Client Name";
61
62 // Get List of components from all known services
63 const std::vector<C2Component::Traits> listTraits = mClient->ListComponents();
64
65 if (listTraits.size() == 0)
66 ALOGE("Warning, ComponentInfo list empty");
67 else {
68 (void)displayComponentInfo;
69 for (size_t i = 0; i < listTraits.size(); i++) {
70 std::shared_ptr<android::Codec2Client::Listener> listener;
71 std::shared_ptr<android::Codec2Client::Component> component;
72 listener.reset(new CodecListener());
73 ASSERT_NE(listener, nullptr);
74
75 // Create component from all known services
76 const c2_status_t status =
77 android::Codec2Client::CreateComponentByName(
78 listTraits[i].name.c_str(), listener, &component, &mClient);
79 ASSERT_EQ(status, C2_OK)
80 << "Create component failed for " << listTraits[i].name.c_str();
81 }
82 }
83 }
84
85 } // anonymous namespace
86
87 INSTANTIATE_TEST_SUITE_P(PerInstance, Codec2MasterHalTest,
88 testing::ValuesIn(android::Codec2Client::GetServiceNames()),
89 android::hardware::PrintInstanceNameToString);
90