• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #include <codec2/hidl/client.h>
24 
25 #include <VtsHalHidlTargetTestBase.h>
26 #include "media_c2_hidl_test_common.h"
27 
28 static ComponentTestEnvironment* gEnv = nullptr;
29 
30 namespace {
31 
32 // google.codec2 Master test setup
33 class Codec2MasterHalTest : public ::testing::VtsHalHidlTargetTestBase {
34    private:
35     typedef ::testing::VtsHalHidlTargetTestBase Super;
36 
37    public:
SetUp()38     virtual void SetUp() override {
39         Super::SetUp();
40         mClient = android::Codec2Client::CreateFromService(
41             gEnv->getInstance().c_str());
42         ASSERT_NE(mClient, nullptr);
43     }
44 
45    protected:
description(const std::string & description)46     static void description(const std::string& description) {
47         RecordProperty("description", description);
48     }
49 
50     std::shared_ptr<android::Codec2Client> mClient;
51 };
52 
displayComponentInfo(const std::vector<C2Component::Traits> & compList)53 void displayComponentInfo(const std::vector<C2Component::Traits>& compList) {
54     for (size_t i = 0; i < compList.size(); i++) {
55         std::cout << compList[i].name << " | " << compList[i].domain;
56         std::cout << " | " << compList[i].kind << "\n";
57     }
58 }
59 
60 // List Components
TEST_F(Codec2MasterHalTest,ListComponents)61 TEST_F(Codec2MasterHalTest, ListComponents) {
62     ALOGV("ListComponents Test");
63 
64     C2String name = mClient->getName();
65     EXPECT_NE(name.empty(), true) << "Invalid Codec2Client Name";
66 
67     // Get List of components from HIDL Codec2Client instance
68     const std::vector<C2Component::Traits> listTraits =
69         mClient->ListComponents();
70 
71     if (listTraits.size() == 0)
72         ALOGE("Warning, ComponentInfo list empty");
73     else {
74         (void)displayComponentInfo;
75         for (size_t i = 0; i < listTraits.size(); i++) {
76             std::shared_ptr<android::Codec2Client::Listener> listener;
77             std::shared_ptr<android::Codec2Client::Component> component;
78             listener.reset(new CodecListener());
79             ASSERT_NE(listener, nullptr);
80 
81             mClient->createComponent(listTraits[i].name.c_str(), listener,
82                                      &component);
83             ASSERT_NE(component, nullptr) << "Create component failed for "
84                                           << listTraits[i].name.c_str();
85         }
86     }
87 }
88 
89 }  // anonymous namespace
90 
main(int argc,char ** argv)91 int main(int argc, char** argv) {
92     gEnv = new ComponentTestEnvironment();
93     ::testing::InitGoogleTest(&argc, argv);
94     gEnv->init(&argc, argv);
95     int status = gEnv->initFromOptions(argc, argv);
96     if (status == 0) {
97         status = RUN_ALL_TESTS();
98         LOG(INFO) << "C2 Test result = " << status;
99     }
100     return status;
101 }
102