1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "gtest/gtest.h" 17 18 #include "port.h" 19 #include "filter.h" 20 21 using namespace testing::ext; 22 23 namespace OHOS { 24 namespace Media { 25 namespace Effect { 26 namespace Test { 27 28 class TestPort : public testing::Test { 29 public: 30 TestPort() = default; 31 32 ~TestPort() override = default; SetUpTestCase()33 static void SetUpTestCase() {} 34 TearDownTestCase()35 static void TearDownTestCase() {} 36 SetUp()37 void SetUp() override{} 38 TearDown()39 void TearDown() override{} 40 }; 41 42 HWTEST_F(TestPort, PullData001, TestSize.Level1) { 43 InfoTransfer *filterPtr = nullptr; 44 45 InPort inPort(filterPtr); 46 std::shared_ptr<EffectBuffer> buffer = nullptr; 47 ErrorCode result = inPort.PullData(buffer); 48 EXPECT_NE(result, ErrorCode::SUCCESS); 49 50 OutPort outPort(filterPtr); 51 result = outPort.PullData(buffer); 52 EXPECT_NE(result, ErrorCode::SUCCESS); 53 54 EmptyInPort emptyInPort; 55 result = emptyInPort.PullData(buffer); 56 EXPECT_NE(result, ErrorCode::SUCCESS); 57 58 EmptyOutPort emptyOutPort; 59 result = emptyOutPort.PullData(buffer); 60 EXPECT_NE(result, ErrorCode::SUCCESS); 61 62 std::shared_ptr<Port> port = nullptr; 63 result = outPort.Connect(port); 64 EXPECT_NE(result, ErrorCode::SUCCESS); 65 66 result = outPort.Disconnect(); 67 EXPECT_EQ(result, ErrorCode::SUCCESS); 68 69 result = emptyInPort.Connect(port); 70 EXPECT_NE(result, ErrorCode::SUCCESS); 71 72 result = emptyOutPort.Connect(port); 73 EXPECT_NE(result, ErrorCode::SUCCESS); 74 75 std::vector<WorkMode> modes; 76 WorkMode outMode; 77 result = outPort.Activate(modes, outMode); 78 EXPECT_NE(result, ErrorCode::SUCCESS); 79 80 result = emptyInPort.Activate(modes, outMode); 81 EXPECT_NE(result, ErrorCode::SUCCESS); 82 83 result = emptyOutPort.Activate(modes, outMode); 84 EXPECT_NE(result, ErrorCode::SUCCESS); 85 86 std::shared_ptr<Port> res = outPort.GetPeerPort(); 87 EXPECT_EQ(res, nullptr); 88 89 res = inPort.GetPeerPort(); 90 EXPECT_EQ(res, nullptr); 91 92 const std::shared_ptr<Capability> capability; 93 std::shared_ptr<EffectContext> context; 94 emptyInPort.Negotiate(capability, context); 95 96 emptyOutPort.Negotiate(capability, context); 97 98 std::string capabilityName = "test"; 99 const std::shared_ptr<Capability> capabilityShared = std::make_shared<Capability>(capabilityName); 100 std::shared_ptr<EffectContext> contextShared = std::make_shared<EffectContext>(); 101 emptyOutPort.Negotiate(capabilityShared, contextShared); 102 103 emptyInPort.Negotiate(capabilityShared, contextShared); 104 } 105 } 106 } 107 } 108 }