1 /*
2 * Copyright (C) 2025 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 "codec_capability_adapter_unittest.h"
17 #include "gmock/gmock.h"
18
19 using namespace OHOS;
20 using namespace OHOS::Media;
21 using namespace testing;
22 using namespace testing::ext;
23
24 const static int32_t TEST_TIMES_ONE = 1;
25 const static int32_t TEST_TIMES_THREE = 3;
26 const static int32_t TEST_TIMES_FOUR = 4;
27 const static int32_t TEST_VIDEO_WATERMARK = 3;
28 const static int32_t TEST_VIDEO_RPR = 4;
29
30 namespace OHOS {
31 namespace Media {
32 namespace Pipeline {
SetUpTestCase(void)33 void CodecCapabilityAdapterUnitTest::SetUpTestCase(void) {}
34
TearDownTestCase(void)35 void CodecCapabilityAdapterUnitTest::TearDownTestCase(void) {}
36
SetUp(void)37 void CodecCapabilityAdapterUnitTest::SetUp(void)
38 {
39 mockAvcodecList_ = std::make_shared<MockAVCodecList>();
40 codecCapabilityAdapter_ = std::make_shared<CodecCapabilityAdapter>();
41 }
42
TearDown(void)43 void CodecCapabilityAdapterUnitTest::TearDown(void)
44 {
45 mockAvcodecList_ = nullptr;
46 codecCapabilityAdapter_ = nullptr;
47 }
48
49 /**
50 * @tc.name : Test IsWatermarkSupported
51 * @tc.number: IsWatermarkSupported_001
52 * @tc.desc : Test IsWatermarkSupported (capabilityData->featuresMap.count(
53 static_cast<int32_t>(MediaAVCodec::AVCapabilityFeature::VIDEO_WATERMARK))) == false
54 */
55 HWTEST_F(CodecCapabilityAdapterUnitTest, IsWatermarkSupported_001, TestSize.Level1)
56 {
57 capabilityData_.featuresMap.insert(std::pair<int32_t, Format>(TEST_VIDEO_RPR, Format()));
58 EXPECT_CALL(*(mockAvcodecList_), GetCapability(_, _, _)).Times(TEST_TIMES_ONE).WillOnce(Return(&capabilityData_));
59 codecCapabilityAdapter_->codeclist_ = mockAvcodecList_;
60 std::string codecMimeType = "";
61 bool isWatermarkSupported = true;
62 codecCapabilityAdapter_->IsWatermarkSupported(codecMimeType, isWatermarkSupported);
63 EXPECT_TRUE(!isWatermarkSupported);
64 }
65
66 /**
67 * @tc.name : Test IsWatermarkSupported
68 * @tc.number: IsWatermarkSupported_002
69 * @tc.desc : Test IsWatermarkSupported if (capabilityData->featuresMap.count(
70 static_cast<int32_t>(MediaAVCodec::AVCapabilityFeature::VIDEO_WATERMARK)))
71 */
72 HWTEST_F(CodecCapabilityAdapterUnitTest, IsWatermarkSupported_002, TestSize.Level1)
73 {
74 EXPECT_CALL(*(mockAvcodecList_), GetCapability(_, _, _))
75 .Times(TEST_TIMES_FOUR)
76 .WillOnce(Return(nullptr))
77 .WillOnce(Return(&capabilityData_))
78 .WillOnce(Return(nullptr))
79 .WillOnce(Return(&capabilityData_));
80 codecCapabilityAdapter_->codeclist_ = mockAvcodecList_;
81 std::string codecMimeType = "";
82 bool isWatermarkSupported = true;
83 codecCapabilityAdapter_->IsWatermarkSupported(codecMimeType, isWatermarkSupported);
84 EXPECT_TRUE(!isWatermarkSupported);
85
86 capabilityData_.featuresMap.insert(std::pair<int32_t, Format>(TEST_VIDEO_WATERMARK, Format()));
87 codecCapabilityAdapter_->IsWatermarkSupported(codecMimeType, isWatermarkSupported);
88 EXPECT_TRUE(isWatermarkSupported);
89 }
90
91 /**
92 * @tc.name : Test IsWatermarkSupported
93 * @tc.number: IsWatermarkSupported_003
94 * @tc.desc : Test IsWatermarkSupported capabilityData == nullptr
95 */
96 HWTEST_F(CodecCapabilityAdapterUnitTest, IsWatermarkSupported_003, TestSize.Level1)
97 {
98 EXPECT_CALL(*(mockAvcodecList_), GetCapability(_, _, _)).WillRepeatedly(Return(nullptr));
99 codecCapabilityAdapter_->codeclist_ = mockAvcodecList_;
100 std::string codecMimeType = "";
101 bool isWatermarkSupported = true;
102 Status status = codecCapabilityAdapter_->IsWatermarkSupported(codecMimeType, isWatermarkSupported);
103 EXPECT_EQ(status, Status::ERROR_UNKNOWN);
104 }
105
106 /**
107 * @tc.name : Test GetAudioEncoder
108 * @tc.number: GetAudioEncoder_001
109 * @tc.desc : Test GetVideoEncoder capabilityData == nullptr
110 */
111 HWTEST_F(CodecCapabilityAdapterUnitTest, GetAudioEncoder_001, TestSize.Level1)
112 {
113 EXPECT_CALL(*(mockAvcodecList_), GetCapability(_, _, _))
114 .Times(TEST_TIMES_ONE)
115 .WillOnce(Return(nullptr));
116 codecCapabilityAdapter_->codeclist_ = mockAvcodecList_;
117 std::vector<MediaAVCodec::CapabilityData*> dataVector;
118 codecCapabilityAdapter_->GetAudioEncoder(dataVector);
119 EXPECT_TRUE(dataVector.empty());
120 }
121
122 /**
123 * @tc.name : Test GetVideoEncoder
124 * @tc.number: GetVideoEncoder_001
125 * @tc.desc : Test GetAudioEncoder capabilityDataAVC == nullptr
126 * Test GetAudioEncoder capabilityDataAVCSoft == nullptr
127 * Test GetAudioEncoder capabilityDataHEVC == nullptr
128 */
129 HWTEST_F(CodecCapabilityAdapterUnitTest, GetVideoEncoder_001, TestSize.Level1)
130 {
131 EXPECT_CALL(*(mockAvcodecList_), GetCapability(_, _, _)).WillRepeatedly(Return(nullptr));
132 codecCapabilityAdapter_->codeclist_ = mockAvcodecList_;
133 std::vector<MediaAVCodec::CapabilityData*> dataVector;
134 codecCapabilityAdapter_->GetVideoEncoder(dataVector);
135 EXPECT_TRUE(dataVector.empty());
136 }
137
138 /**
139 * @tc.name : Test GetVideoEncoder
140 * @tc.number: GetVideoEncoder_002
141 * @tc.desc : Test GetAudioEncoder capabilityDataAVCSoft != nullptr
142 * Test ~CodecCapabilityAdapter codeclist_ == nullptr
143 */
144 HWTEST_F(CodecCapabilityAdapterUnitTest, GetVideoEncoder_002, TestSize.Level1)
145 {
146 EXPECT_CALL(*(mockAvcodecList_), GetCapability(_, _, _))
147 .Times(TEST_TIMES_THREE)
148 .WillOnce(Return(nullptr))
149 .WillOnce(Return(&capabilityData_))
150 .WillOnce(Return(nullptr));
151 codecCapabilityAdapter_->codeclist_ = mockAvcodecList_;
152 std::vector<MediaAVCodec::CapabilityData*> dataVector;
153 codecCapabilityAdapter_->GetVideoEncoder(dataVector);
154 EXPECT_EQ(dataVector.size(), 1);
155
156 codecCapabilityAdapter_->codeclist_ = nullptr;
157 }
158 } // namespace Pipeline
159 } // namespace Media
160 } // namespace OHOS