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 "media_errors.h"
17 #include "hitranscode_unit_test.h"
18
19 namespace OHOS {
20 namespace Media {
21 using namespace std;
22 using namespace testing::ext;
23
SetUpTestCase(void)24 void HitranscodeUnitTest::SetUpTestCase(void)
25 {
26 }
27
TearDownTestCase(void)28 void HitranscodeUnitTest::TearDownTestCase(void)
29 {
30 }
31
SetUp(void)32 void HitranscodeUnitTest::SetUp(void)
33 {
34 transcode_ = std::make_unique<HiTransCoderImpl>(0, 0, 0, 0);
35 }
36
TearDown(void)37 void HitranscodeUnitTest::TearDown(void)
38 {
39 transcode_ = nullptr;
40 }
41
42 /**
43 * @tc.name : Test ProcessMetaKey API
44 * @tc.number : HitranscodeUnitTest_ProcessMetaKey001
45 * @tc.desc : Test ProcessMetaKey interface, set metaKey to int32_t.
46 * @tc.require : issueI5NZAQ
47 */
HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey001, TestSize.Level0)48 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey001, TestSize.Level0)
49 {
50 // 1. Set up the test environment
51 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
52 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
53 std::string metaKey = Tag::MEDIA_DURATION;
54 int64_t intVal = 100;
55 innerMeta->SetData(metaKey, intVal);
56
57 // 2. Call the function to be tested
58 bool result = transcode_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
59
60 // 3. Verify the result
61 EXPECT_TRUE(result);
62 int64_t outputIntVal;
63 EXPECT_TRUE(outputMeta->GetData(metaKey, outputIntVal));
64 EXPECT_EQ(intVal, outputIntVal);
65 }
66
67 /**
68 * @tc.name : Test ProcessMetaKey API
69 * @tc.number : HitranscodeUnitTest_ProcessMetaKey002
70 * @tc.desc : Test ProcessMetaKey interface, set metaKey to std::string.
71 * @tc.require : issueI5NZAQ
72 */
HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey002, TestSize.Level0)73 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey002, TestSize.Level0)
74 {
75 // 1. Set up the test environment
76 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
77 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
78 std::string metaKey = Tag::MEDIA_ALBUM;
79 std::string strVal = "test";
80 innerMeta->SetData(metaKey, strVal);
81
82 // 2. Call the function to be tested
83 bool result = transcode_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
84
85 // 3. Verify the result
86 EXPECT_TRUE(result);
87 std::string outputStrVal;
88 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
89 EXPECT_EQ(strVal, outputStrVal);
90 }
91
HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey003, TestSize.Level0)92 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey003, TestSize.Level0)
93 {
94 // 1. Set up the test environment
95 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
96 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
97 std::string metaKey = Tag::VIDEO_HEIGHT;
98 int32_t intVal = 100;
99 innerMeta->SetData(metaKey, intVal);
100
101 // 2. Call the function to be tested
102 bool result = transcode_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
103
104 // 3. Verify the result
105 EXPECT_TRUE(result);
106 int32_t outputStrVal;
107 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
108 EXPECT_EQ(intVal, outputStrVal);
109 }
110
HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey004, TestSize.Level0)111 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey004, TestSize.Level0)
112 {
113 // 1. Set up the test environment
114 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
115 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
116 std::string metaKey = Tag::VIDEO_CAPTURE_RATE;
117 double doubleVal = 0.1;
118 innerMeta->SetData(metaKey, doubleVal);
119
120 // 2. Call the function to be tested
121 bool result = transcode_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
122
123 // 3. Verify the result
124 EXPECT_TRUE(result);
125 double outputStrVal;
126 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
127 EXPECT_EQ(doubleVal, outputStrVal);
128 }
129
HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey005, TestSize.Level0)130 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey005, TestSize.Level0)
131 {
132 // 1. Set up the test environment
133 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
134 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
135 std::string metaKey = Tag::VIDEO_ROTATION;
136 Plugins::VideoRotation rotation = Plugins::VideoRotation::VIDEO_ROTATION_0;
137 innerMeta->SetData(metaKey, rotation);
138
139 // 2. Call the function to be tested
140 bool result = transcode_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
141
142 // 3. Verify the result
143 EXPECT_TRUE(result);
144 Plugins::VideoRotation outputStrVal;
145 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
146 EXPECT_EQ(rotation, outputStrVal);
147 }
148
HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey006, TestSize.Level0)149 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey006, TestSize.Level0)
150 {
151 // 1. Set up the test environment
152 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
153 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
154 std::string metaKey = Tag::VIDEO_COLOR_RANGE;
155 bool boolVal = true;
156 innerMeta->SetData(metaKey, boolVal);
157
158 // 2. Call the function to be tested
159 bool result = transcode_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
160
161 // 3. Verify the result
162 EXPECT_TRUE(result);
163 bool outputStrVal;
164 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
165 EXPECT_EQ(boolVal, outputStrVal);
166 }
167
HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey007, TestSize.Level0)168 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey007, TestSize.Level0)
169 {
170 // 1. Set up the test environment
171 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
172 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
173 std::string metaKey = Tag::MEDIA_LATITUDE;
174 float floatVal = 0.9;
175 innerMeta->SetData(metaKey, floatVal);
176
177 // 2. Call the function to be tested
178 bool result = transcode_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
179
180 // 3. Verify the result
181 EXPECT_TRUE(result);
182 float outputStrVal;
183 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
184 EXPECT_EQ(floatVal, outputStrVal);
185 }
186
187 /**
188 * @tc.name : Test SetValueByType API
189 * @tc.number : SetValueByType_001
190 * @tc.desc : Test SetValueByType interface, set innerMeta or outputMeta to nullptr.
191 * @tc.require : issueI5NZAQ
192 */
HWTEST_F(HitranscodeUnitTest, SetValueByType_001, TestSize.Level0)193 HWTEST_F(HitranscodeUnitTest, SetValueByType_001, TestSize.Level0)
194 {
195 // 1. Set up the test environment
196 std::shared_ptr<Meta> innerMeta = nullptr;
197 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
198
199 // 2. Call the function to be tested
200 bool result = transcode_->SetValueByType(innerMeta, outputMeta);
201
202 // 3. Verify the result
203 EXPECT_FALSE(result);
204 }
205
206 /**
207 * @tc.name : Test SetValueByType API
208 * @tc.number : SetValueByType_002
209 * @tc.desc : Test SetValueByType interface, set both innerMeta and outputMeta to nullptr.
210 * @tc.require : issueI5NZAQ
211 */
HWTEST_F(HitranscodeUnitTest, SetValueByType_002, TestSize.Level0)212 HWTEST_F(HitranscodeUnitTest, SetValueByType_002, TestSize.Level0)
213 {
214 // 1. Set up the test environment
215 std::shared_ptr<Meta> innerMeta = nullptr;
216 std::shared_ptr<Meta> outputMeta = nullptr;
217
218 // 2. Call the function to be tested
219 bool result = transcode_->SetValueByType(innerMeta, outputMeta);
220
221 // 3. Verify the result
222 EXPECT_FALSE(result);
223 }
224
225 /**
226 * @tc.name : Test SetValueByType API
227 * @tc.number : SetValueByType_003
228 * @tc.desc : Test SetValueByType interface, set valid innerMeta and outputMeta.
229 * @tc.require : issueI5NZAQ
230 */
HWTEST_F(HitranscodeUnitTest, SetValueByType_003, TestSize.Level0)231 HWTEST_F(HitranscodeUnitTest, SetValueByType_003, TestSize.Level0)
232 {
233 // 1. Set up the test environment
234 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
235 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
236 std::string metaKey = Tag::MEDIA_DURATION;
237 int64_t intVal = 100;
238 innerMeta->SetData(metaKey, intVal);
239
240 bool result = transcode_->SetValueByType(innerMeta, outputMeta);
241
242 EXPECT_TRUE(result);
243 }
244 } // namespace Media
245 } // namespace OHOS