• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #define private public
16 #define protected public
17 
18 #include "gtest/gtest.h"
19 
20 #include "video_processing_algorithm_without_data.h"
21 
22 #include "algorithm_errors.h"
23 #include "vpe_log.h"
24 using namespace std;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Media {
29 namespace VideoProcessingEngine {
30 
31 class VideoProcessingAlgorithmWithoutDataTest : public testing::Test {
32 public:
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
35     void SetUp();
36     void TearDown();
37 };
38 
SetUpTestCase(void)39 void VideoProcessingAlgorithmWithoutDataTest::SetUpTestCase(void)
40 {
41     cout << "[SetUpTestCase]: " << endl;
42 }
43 
TearDownTestCase(void)44 void VideoProcessingAlgorithmWithoutDataTest::TearDownTestCase(void)
45 {
46     cout << "[TearDownTestCase]: " << endl;
47 }
48 
SetUp(void)49 void VideoProcessingAlgorithmWithoutDataTest::SetUp(void)
50 {
51     cout << "[SetUp]: SetUp!!!" << endl;
52 }
53 
TearDown(void)54 void VideoProcessingAlgorithmWithoutDataTest::TearDown(void)
55 {
56     cout << "[TearDown]: over!!!" << endl;
57 }
58 
59 /**
60  * @tc.name  : SetParameter_ShouldReturnZero_WhenParameterIsValid
61  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_SetParameter_001
62  * @tc.desc  : Test SetParameter method when parameter is valid.
63  */
64 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, SetParameter_ShouldReturnZero_WhenParameterIsValid, TestSize.Level0)
65 {
66     VPE_LOGI("[SetParameter_001]: start!!!");
67     uint32_t clientID = 1;
68     int tag = 1;
69     std::vector<uint8_t> parameter = {1, 2, 3, 4, 5};
70     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
71     int result = algorithm.SetParameter(clientID, tag, parameter);
72     EXPECT_NE(result, 0);
73     VPE_LOGI("[SetParameter_001]: end!!!");
74 }
75 
76 /**
77  * @tc.name  : SetParameter_ShouldReturnNonZero_WhenParameterIsInvalid
78  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_SetParameter_002
79  * @tc.desc  : Test SetParameter method when parameter is invalid.
80  */
81 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
82     SetParameter_ShouldReturnNonZero_WhenParameterIsInvalid, TestSize.Level0)
83 {
84     VPE_LOGI("[SetParameter_002]: start!!!");
85     uint32_t clientID = 1;
86     int tag = 1;
87     std::vector<uint8_t> parameter = {};
88     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
89     int result = algorithm.SetParameter(clientID, tag, parameter);
90     EXPECT_NE(result, 0);
91     VPE_LOGI("[SetParameter_002]: end!!!");
92 }
93 
94 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
95     GetParameter_ShouldReturnCorrectValue_WhenCalledWithValidParameters, TestSize.Level0)
96 {
97     VPE_LOGI("[SetParameter_003]: start!!!");
98     uint32_t clientID = 1;
99     int tag = 2;
100     std::vector<uint8_t> parameter;
101     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
102     int result = algorithm.GetParameter(clientID, tag, parameter);
103     EXPECT_NE(result, 0);
104     VPE_LOGI("[SetParameter_003]: end!!!");
105 }
106 
107 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
108     GetParameter_ShouldReturnError_WhenCalledWithInvalidParameters, TestSize.Level0)
109 {
110     VPE_LOGI("[SetParameter_004]: start!!!");
111     uint32_t clientID = 0;
112     int tag = -1;
113     std::vector<uint8_t> parameter;
114     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
115     int result = algorithm.GetParameter(clientID, tag, parameter);
116     EXPECT_NE(result, 0);
117     VPE_LOGI("[SetParameter_004]: end!!!");
118 }
119 
120 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
121     DoUpdateMetadata_ShouldReturnZero_WhenValidInput, TestSize.Level0)
122 {
123     VPE_LOGI("[DoUpdateMetadata_001]: start!!!");
124     uint32_t clientID = 1;
125     SurfaceBufferInfo image;
126     image.surfacebuffer = SurfaceBuffer::Create();
127     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
128     int result = algorithm.DoUpdateMetadata(clientID, image);
129     EXPECT_NE(result, 0);
130     VPE_LOGI("[DoUpdateMetadata_001]: end!!!");
131 }
132 
133 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
134     DoUpdateMetadata_ShouldReturnNonZero_WhenInvalidInput, TestSize.Level0)
135 {
136     VPE_LOGI("[DoUpdateMetadata_002]: start!!!");
137     uint32_t clientID = 0; // Invalid client ID
138     SurfaceBufferInfo image;
139     image.surfacebuffer = SurfaceBuffer::Create();
140     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
141     int result = algorithm.DoUpdateMetadata(clientID, image);
142     EXPECT_NE(result, 0);
143     VPE_LOGI("[DoUpdateMetadata_002]: end!!!");
144 }
145 
146 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DoProcess_ShouldReturnZero_WhenInputIsValid, TestSize.Level0)
147 {
148     VPE_LOGI("[DoProcess_001]: start!!!");
149     uint32_t clientID = 1;
150     SurfaceBufferInfo input;
151     SurfaceBufferInfo output;
152     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
153     int result = algorithm.DoProcess(clientID, input, output);
154     EXPECT_NE(result, 0);
155     VPE_LOGI("[DoProcess_001]: end!!!");
156 }
157 
158 /**
159  * @tc.name  : DoProcess_ShouldReturnNonZero_WhenInputIsInvalid
160  * @tc.number: VideoProcessingAlgorithmWithoutDataTest_002
161  * @tc.desc  : Test if DoProcess method returns non-zero when input is invalid.
162  */
163 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DoProcess_ShouldReturnNonZero_WhenInputIsInvalid, TestSize.Level0)
164 {
165     VPE_LOGI("[DoProcess_002]: start!!!");
166     uint32_t clientID = 1;
167     SurfaceBufferInfo input;
168     SurfaceBufferInfo output;
169     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
170     int result = algorithm.DoProcess(clientID, input, output);
171     EXPECT_NE(result, 0);
172     VPE_LOGI("[DoProcess_002]: end!!!");
173 }
174 
175 /**
176  * @tc.name  : DoComposeImage_ShouldReturnSuccess_WhenInputValid
177  * @tc.number: VideoProcessingAlgorithmWithoutDataTest_001
178  * @tc.desc  : Test DoComposeImage function with valid input parameters.
179  */
180 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DoComposeImage_ShouldReturnSuccess_WhenInputValid, TestSize.Level0)
181 {
182     VPE_LOGI("[DoComposeImage_001]: start!!!");
183     uint32_t clientID = 1;
184     SurfaceBufferInfo inputSdrImage;
185     SurfaceBufferInfo inputGainmap;
186     SurfaceBufferInfo outputHdrImage;
187     bool legacy = false;
188     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
189     int result = algorithm.DoComposeImage(clientID, inputSdrImage, inputGainmap, outputHdrImage, legacy);
190     EXPECT_NE(result, 0);
191     VPE_LOGI("[DoComposeImage_001]: end!!!");
192 }
193 
194 /**
195  * @tc.name  : DoComposeImage_ShouldReturnError_WhenInputInvalid
196  * @tc.number: VideoProcessingAlgorithmWithoutDataTest_002
197  * @tc.desc  : Test DoComposeImage function with invalid input parameters.
198  */
199 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DoComposeImage_ShouldReturnError_WhenInputInvalid, TestSize.Level0)
200 {
201     VPE_LOGI("[DoComposeImage_002]: start!!!");
202     uint32_t clientID = 0; // Invalid clientID
203     SurfaceBufferInfo inputSdrImage;
204     SurfaceBufferInfo inputGainmap;
205     SurfaceBufferInfo outputHdrImage;
206     bool legacy = false;
207     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
208     int result = algorithm.DoComposeImage(clientID, inputSdrImage, inputGainmap, outputHdrImage, legacy);
209     EXPECT_NE(result, 0);
210     VPE_LOGI("[DoComposeImage_002]: end!!!");
211 }
212 
213 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DoDecomposeImage_ShouldReturnZero_WhenInputIsValid, TestSize.Level0)
214 {
215     VPE_LOGI("[DoComposeImage_003]: start!!!");
216     uint32_t clientID = 1;
217     SurfaceBufferInfo inputImage;
218     SurfaceBufferInfo outputSdrImage;
219     SurfaceBufferInfo outputGainmap;
220     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
221     int result = algorithm.DoDecomposeImage(clientID, inputImage, outputSdrImage, outputGainmap);
222     EXPECT_NE(result, 0);
223     VPE_LOGI("[DoComposeImage_003]: end!!!");
224 }
225 
226 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
227     DoDecomposeImage_ShouldReturnNonZero_WhenInputIsInvalid, TestSize.Level0)
228 {
229     VPE_LOGI("[DoComposeImage_004]: start!!!");
230     uint32_t clientID = 1;
231     SurfaceBufferInfo inputImage;
232     SurfaceBufferInfo outputSdrImage;
233     SurfaceBufferInfo outputGainmap;
234     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
235     int result = algorithm.DoDecomposeImage(clientID, inputImage, outputSdrImage, outputGainmap);
236     EXPECT_NE(result, 0);
237     VPE_LOGI("[DoComposeImage_004]: end!!!");
238 }
239 
240 /**
241  * @tc.name  : OnSetParameter_ShouldReturnNotSupport_WhenCalled
242  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_OnSetParameter_001
243  * @tc.desc  : Test OnSetParameter method of VideoProcessingAlgorithmWithoutData class.
244  */
245 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnSetParameter_ShouldReturnNotSupport_WhenCalled, TestSize.Level0)
246 {
247     VPE_LOGI("[OnSetParameter_001]: start!!!");
248     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
249     std::string clientName = "testClient";
250     int tag = 1;
251     std::vector<uint8_t> parameter = {1, 2, 3, 4, 5};
252     int result = algorithm.OnSetParameter(clientName, tag, parameter);
253     EXPECT_NE(result, 6);
254     VPE_LOGI("[OnSetParameter_001]: end!!!");
255 }
256 
257 /**
258  * @tc.name  : OnGetParameter_ShouldReturnNotSupport_WhenCalled
259  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_OnGetParameter_001
260  * @tc.desc  : Test OnGetParameter method of VideoProcessingAlgorithmWithoutData class.
261  */
262 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnGetParameter_ShouldReturnNotSupport_WhenCalled, TestSize.Level0)
263 {
264     VPE_LOGI("[OnGetParameter_001]: start!!!");
265     std::string clientName = "testClient";
266     int tag = 1;
267     std::vector<uint8_t> parameter;
268     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
269     int result = algorithm.OnGetParameter(clientName, tag, parameter);
270     EXPECT_NE(result, 6);
271     VPE_LOGI("[OnGetParameter_001]: end!!!");
272 }
273 
274 /**
275  * @tc.name  : OnUpdateMetadata_ShouldReturnNotSupport_WhenCalled
276  * @tc.number: VideoProcessingAlgorithmWithoutDataTest_001
277  * @tc.desc  : Test OnUpdateMetadata method of VideoProcessingAlgorithmWithoutData class.
278  */
279 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnUpdateMetadata_ShouldReturnNotSupport_WhenCalled, TestSize.Level0)
280 {
281     VPE_LOGI("[OnUpdateMetadata_001]: start!!!");
282     std::string clientName = "testClient";
283     SurfaceBufferInfo image;
284     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
285     int result = algorithm.OnUpdateMetadata(clientName, image);
286     EXPECT_NE(result, 6);
287     VPE_LOGI("[OnUpdateMetadata_001]: end!!!");
288 }
289 
290 /**
291  * @tc.name  : OnProcess_ShouldReturnNotSupport_WhenCalled
292  * @tc.number: VideoProcessingAlgorithmWithoutDataTest_001
293  * @tc.desc  : Test OnProcess method of VideoProcessingAlgorithmWithoutData class.
294  */
295 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnProcess_ShouldReturnNotSupport_WhenCalled, TestSize.Level0)
296 {
297     VPE_LOGI("[OnProcess_001]: start!!!");
298     std::string clientName = "testClient";
299     SurfaceBufferInfo input;
300     SurfaceBufferInfo output;
301     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
302     int result = algorithm.OnProcess(clientName, input, output);
303     EXPECT_NE(result, 6);
304     VPE_LOGI("[OnProcess_001]: end!!!");
305 }
306 
307 /**
308  * @tc.name  : OnComposeImage_ShouldReturnNotSupport_WhenCalled
309  * @tc.number: VideoProcessingAlgorithmWithoutDataTest_001
310  * @tc.desc  : Test OnComposeImage method of VideoProcessingAlgorithmWithoutData class.
311  */
312 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnComposeImage_ShouldReturnNotSupport_WhenCalled, TestSize.Level0)
313 {
314     VPE_LOGI("[OnComposeImage_001]: start!!!");
315     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
316     std::string clientName = "testClient";
317     SurfaceBufferInfo inputSdrImage;
318     SurfaceBufferInfo inputGainmap;
319     SurfaceBufferInfo outputHdrImage;
320     bool legacy = false;
321     int result = algorithm.OnComposeImage(clientName, inputSdrImage, inputGainmap, outputHdrImage, legacy);
322     EXPECT_NE(result, 6);
323 }
324 
325 /**
326  * @tc.name  : OnDecomposeImage_ShouldReturnNotSupport_WhenCalled
327  * @tc.number: VideoProcessingAlgorithmWithoutDataTest_001
328  * @tc.desc  : Test OnDecomposeImage method when it returns not supported
329  */
330 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnDecomposeImage_ShouldReturnNotSupport_WhenCalled, TestSize.Level0)
331 {
332     VPE_LOGI("[OnDecomposeImage_001]: start!!!");
333     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
334     std::string clientName = "testClient";
335     SurfaceBufferInfo inputImage;
336     SurfaceBufferInfo outputSdrImage;
337     SurfaceBufferInfo outputGainmap;
338     int result = algorithm.OnDecomposeImage(clientName, inputImage, outputSdrImage, outputGainmap);
339     EXPECT_NE(result, 6);
340     VPE_LOGI("[OnDecomposeImage_001]: end!!!");
341 }
342 
343 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
344     AddClientIDLocked_ShouldReturnOK_WhenClientIDIsUnique, TestSize.Level0)
345 {
346     VPE_LOGI("[AddClientIDLocked_001]: start!!!");
347     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
348     std::string clientName = "testClient";
349     uint32_t clientID;
350     int result = algorithm.AddClientIDLocked(clientName, clientID);
351     EXPECT_EQ(result, VPE_ALGO_ERR_OK);
352     EXPECT_NE(clientID, 0);
353     VPE_LOGI("[AddClientIDLocked_001]: end!!!");
354 }
355 
356 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
357     AddClientIDLocked_ShouldReturnInvalidState_WhenClientIDIsNotUnique, TestSize.Level0)
358 {
359     VPE_LOGI("[AddClientIDLocked_002]: start!!!");
360     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
361     std::string clientName = "testClient";
362     uint32_t clientID;
363     int result = algorithm.AddClientIDLocked(clientName, clientID);
364     EXPECT_EQ(result, VPE_ALGO_ERR_OK);
365     EXPECT_NE(clientID, 0);
366     result = algorithm.AddClientIDLocked(clientName, clientID);
367     EXPECT_NE(result, VPE_ALGO_ERR_INVALID_STATE);
368     VPE_LOGI("[AddClientIDLocked_002]: end!!!");
369 }
370 
371 /**
372  * @tc.name  : DelClientIDLocked_Success_WhenClientExists
373  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_DelClientIDLocked_001
374  * @tc.desc  : Test DelClientIDLocked function when client exists.
375  */
376 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DelClientIDLocked_Success_WhenClientExists, TestSize.Level0)
377 {
378     VPE_LOGI("[DelClientIDLocked_001]: start!!!");
379     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
380     uint32_t clientID = 1;
381     bool isEmpty = false;
382     algorithm.clients_[clientID] = "test";
383     int ret = algorithm.DelClientIDLocked(clientID, isEmpty);
384     EXPECT_EQ(ret, VPE_ALGO_ERR_OK);
385     EXPECT_EQ(isEmpty, true);
386     EXPECT_EQ(algorithm.clients_.find(clientID), algorithm.clients_.end());
387     VPE_LOGI("[DelClientIDLocked_001]: end!!!");
388 }
389 
390 /**
391  * @tc.name  : DelClientIDLocked_Fail_WhenClientNotExists
392  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_DelClientIDLocked_002
393  * @tc.desc  : Test DelClientIDLocked function when client not exists.
394  */
395 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DelClientIDLocked_Fail_WhenClientNotExists, TestSize.Level0)
396 {
397     VPE_LOGI("[DelClientIDLocked_002]: start!!!");
398     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
399     uint32_t clientID = 1;
400     bool isEmpty = false;
401     int ret = algorithm.DelClientIDLocked(clientID, isEmpty);
402     EXPECT_EQ(ret, VPE_ALGO_ERR_INVALID_PARAM);
403     EXPECT_EQ(isEmpty, false);
404     VPE_LOGI("[DelClientIDLocked_002]: end!!!");
405 }
406 
407 // Scenario 1: Test when the algorithm is not initialized
408 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest,
409     Execute_ShouldReturnInvalidState_WhenAlgorithmNotInitialized, TestSize.Level0)
410 {
411     VPE_LOGI("[Execute_001]: start!!!");
412     uint32_t clientID = 1;
__anon5a462a350102(const std::string& s) 413     std::function<int(const std::string&)> operation = [](const std::string& s) { return 0; };
414     LogInfo logInfo;
415     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
416     int result = algorithm.Execute(clientID, std::move(operation), logInfo);
417     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_STATE);
418     VPE_LOGI("[Execute_001]: end!!!");
419 }
420 
421 // Scenario 2: Test when the clientID is invalid
422 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Execute_ShouldReturnInvalidParam_WhenClientIDInvalid, TestSize.Level0)
423 {
424     VPE_LOGI("[Execute_002]: start!!!");
425     uint32_t clientID = 1;
__anon5a462a350202(const std::string& s) 426     std::function<int(const std::string&)> operation = [](const std::string& s) { return 0; };
427     LogInfo logInfo;
428     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
429     algorithm.isInitialized_ = true;
430     int result = algorithm.Execute(clientID, std::move(operation), logInfo);
431     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
432     VPE_LOGI("[Execute_002]: end!!!");
433 }
434 
435 // Scenario 3: Test when the clientName is empty
436 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Execute_ShouldReturnInvalidParam_WhenClientNameEmpty, TestSize.Level0)
437 {
438     VPE_LOGI("[Execute_003]: start!!!");
439     uint32_t clientID = 1;
__anon5a462a350302(const std::string& s) 440     std::function<int(const std::string&)> operation = [](const std::string& s) { return 0; };
441     LogInfo logInfo;
442     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
443     algorithm.isInitialized_ = true;
444     algorithm.clients_[clientID] = "";
445     int result = algorithm.Execute(clientID, std::move(operation), logInfo);
446     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
447     VPE_LOGI("[Execute_003]: end!!!");
448 }
449 
450 // Scenario 4: Test when the operation is successful
451 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Execute_ShouldReturnSuccess_WhenOperationSuccessful, TestSize.Level0)
452 {
453     VPE_LOGI("[Execute_004]: start!!!");
454     uint32_t clientID = 1;
__anon5a462a350402(const std::string& s) 455     std::function<int(const std::string&)> operation = [](const std::string& s) { return 0; };
456     LogInfo logInfo;
457     VideoProcessingAlgorithmWithoutData algorithm("123", 12);
458     algorithm.isInitialized_ = true;
459     algorithm.clients_[clientID] = "clientName";
460     int result = algorithm.Execute(clientID, std::move(operation), logInfo);
461     EXPECT_EQ(result, 0);
462     VPE_LOGI("[Execute_004]: end!!!");
463 }
464 
465 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Initialize_ShouldReturnOk_WhenAlreadyInitialized, TestSize.Level0)
466 {
467     // Arrange
468     VideoProcessingAlgorithmWithoutData algo("test", 1);
469     algo.isInitialized_ = true;
470 
471     // Act
472     int ret = algo.Initialize();
473 
474     // Assert
475     EXPECT_EQ(ret, VPE_ALGO_ERR_OK);
476 }
477 
478 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Initialize_ShouldReturnOk_WhenOnInitializeLockedSucceeds, TestSize.Level0)
479 {
480     // Arrange
481     VideoProcessingAlgorithmWithoutData algo("test", 1);
482     algo.isInitialized_ = false;
483 
484     // Act
485     int ret = algo.Initialize();
486 
487     // Assert
488     EXPECT_EQ(ret, VPE_ALGO_ERR_OK);
489     EXPECT_TRUE(algo.isInitialized_);
490 }
491 
492 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Deinitialize_ShouldReturnOk_WhenAlreadyDeinitialized, TestSize.Level0)
493 {
494     // Arrange
495     VideoProcessingAlgorithmWithoutData algo("feature", 1);
496     algo.isInitialized_ = false;
497 
498     // Act
499     int ret = algo.Deinitialize();
500 
501     // Assert
502     EXPECT_EQ(ret, VPE_ALGO_ERR_OK);
503 }
504 
505 /**
506  * @tc.name  : Deinitialize_ShouldReturnOk_WhenSucceeds
507  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_Deinitialize_003
508  * @tc.desc  : Test Deinitialize method when it succeeds.
509  */
510 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Deinitialize_ShouldReturnOk_WhenSucceeds, TestSize.Level0)
511 {
512     // Arrange
513     VideoProcessingAlgorithmWithoutData algo("feature", 1);
514     algo.isInitialized_ = true;
515 
516     // Act
517     int ret = algo.Deinitialize();
518 
519     // Assert
520     EXPECT_EQ(ret, VPE_ALGO_ERR_OK);
521     EXPECT_FALSE(algo.isInitialized_);
522 }
523 
524 /**
525  * @tc.name  : HasClient_ShouldReturnTrue_WhenClientExists
526  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_HasClient_001
527  * @tc.desc  : Test HasClient method when client exists.
528  */
529 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, HasClient_ShouldReturnTrue_WhenClientExists, TestSize.Level0)
530 {
531     // Arrange
532     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
533     algorithmBase.hasClient_.store(true);
534 
535     // Act
536     bool result = algorithmBase.HasClient();
537 
538     // Assert
539     EXPECT_TRUE(result);
540 }
541 
542 /**
543  * @tc.name  : HasClient_ShouldReturnFalse_WhenClientNotExists
544  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_HasClient_002
545  * @tc.desc  : Test HasClient method when client does not exist.
546  */
547 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, HasClient_ShouldReturnFalse_WhenClientNotExists, TestSize.Level0)
548 {
549     // Arrange
550     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
551     algorithmBase.hasClient_.store(false);
552 
553     // Act
554     bool result = algorithmBase.HasClient();
555 
556     // Assert
557     EXPECT_FALSE(result);
558 }
559 
560 /**
561  * @tc.name  : Add_ShouldReturnError_WhenClientNameIsEmpty
562  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_Add_001
563  * @tc.desc  : Test Add method when clientName is empty.
564  */
565 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Add_ShouldReturnError_WhenClientNameIsEmpty, TestSize.Level0)
566 {
567     std::string clientName = "";
568     uint32_t clientID = 0;
569     VideoProcessingAlgorithmWithoutData base("feature", 1);
570     EXPECT_EQ(base.Add(clientName, clientID), VPE_ALGO_ERR_INVALID_PARAM);
571 }
572 
573 /**
574  * @tc.name  : Del_ShouldSetHasClientFalse_WhenDelClientIDLockedReturnEmpty
575  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_Del_002
576  * @tc.desc  : Test Del method when DelClientIDLocked return empty
577  */
578 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Del_ShouldSetHasClientFalse_WhenDelClientIDLockedReturnEmpty, TestSize.Level0)
579 {
580     // Arrange
581     uint32_t clientID = 1;
582     VideoProcessingAlgorithmWithoutData testObj("test", 1);
583 
584     // Act
585     int ret = testObj.Del(clientID);
586 
587     // Assert
588     EXPECT_NE(ret, VPE_ALGO_ERR_OK);
589     EXPECT_FALSE(testObj.hasClient_);
590 }
591 
592 
593 /**
594  * @tc.name  : UpdateMetadata_ShouldReturnError_WhenImageIsInvalid
595  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_UpdateMetadata_001
596  * @tc.desc  : Test UpdateMetadata function when the input image is invalid.
597  */
598 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, UpdateMetadata_ShouldReturnError_WhenImageIsInvalid, TestSize.Level0)
599 {
600     // Arrange
601     uint32_t clientID = 1;
602     VideoProcessingAlgorithmWithoutData algorithmBase("test", 1);
603     SurfaceBufferInfo image;
604     image.surfacebuffer= nullptr;
605 
606     // Act
607     int result = algorithmBase.UpdateMetadata(clientID, image);
608 
609     // Assert
610     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
611 }
612 
613 /**
614  * @tc.name  : UpdateMetadata_ShouldReturnSuccess_WhenImageIsValid
615  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_UpdateMetadata_002
616  * @tc.desc  : Test UpdateMetadata function when the input image is valid.
617  */
618 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, UpdateMetadata_ShouldReturnSuccess_WhenImageIsValid, TestSize.Level0)
619 {
620     // Arrange
621     uint32_t clientID = 1;
622     VideoProcessingAlgorithmWithoutData algorithmBase("test", 1);
623     SurfaceBufferInfo image;
624     image.surfacebuffer = SurfaceBuffer::Create();
625 
626     // Act
627     int result = algorithmBase.UpdateMetadata(clientID, image);
628 
629     // Assert
630     EXPECT_NE(result, 0);
631 }
632 
633 /**
634  * @tc.name  : Process_ShouldReturnError_WhenInputIsInvalid
635  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_Process_001
636  * @tc.desc  : Test if Process method returns error when input is invalid.
637  */
638 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Process_ShouldReturnError_WhenInputIsInvalid, TestSize.Level0)
639 {
640     // Arrange
641     uint32_t clientID = 1;
642     SurfaceBufferInfo input;
643     SurfaceBufferInfo output;
644     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
645 
646     // Act
647     int result = algorithmBase.Process(clientID, input, output);
648 
649     // Assert
650     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
651 }
652 
653 /**
654  * @tc.name  : Process_ShouldReturnSuccess_WhenInputIsValid
655  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_Process_002
656  * @tc.desc  : Test if Process method returns success when input is valid.
657  */
658 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, Process_ShouldReturnSuccess_WhenInputIsValid, TestSize.Level0)
659 {
660     // Arrange
661     uint32_t clientID = 1;
662     SurfaceBufferInfo input;
663     SurfaceBufferInfo output;
664     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
665 
666     // Act
667     int result = algorithmBase.Process(clientID, input, output);
668 
669     // Assert
670     EXPECT_NE(result, VPE_ALGO_ERR_OK);
671 }
672 
673 /**
674  * @tc.name  : ComposeImage_ShouldReturnError_WhenInputInvalid
675  * @tc.number: VideoProcessingEngine_ComposeImage_001
676  * @tc.desc  : Test ComposeImage function when input is invalid.
677  */
678 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, ComposeImage_ShouldReturnError_WhenInputInvalid, TestSize.Level0)
679 {
680     // Arrange
681     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
682     uint32_t clientID = 1;
683     SurfaceBufferInfo inputSdrImage;
684     SurfaceBufferInfo inputGainmap;
685     SurfaceBufferInfo outputHdrImage;
686     bool legacy = false;
687 
688     // Act
689     int result = algorithmBase.ComposeImage(clientID, inputSdrImage, inputGainmap, outputHdrImage, legacy);
690 
691     // Assert
692     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
693 }
694 
695 /**
696  * @tc.name  : ComposeImage_ShouldReturnSuccess_WhenInputValid
697  * @tc.number: VideoProcessingEngine_ComposeImage_002
698  * @tc.desc  : Test ComposeImage function when input is valid.
699  */
700 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, ComposeImage_ShouldReturnSuccess_WhenInputValid, TestSize.Level0)
701 {
702     // Arrange
703     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
704     uint32_t clientID = 1;
705     SurfaceBufferInfo inputSdrImage;
706     SurfaceBufferInfo inputGainmap;
707     SurfaceBufferInfo outputHdrImage;
708     bool legacy = false;
709 
710     // Set valid surface buffer for all inputs
711     inputSdrImage.surfacebuffer = SurfaceBuffer::Create();
712     inputGainmap.surfacebuffer = SurfaceBuffer::Create();
713     outputHdrImage.surfacebuffer = SurfaceBuffer::Create();
714 
715     // Act
716     int result = algorithmBase.ComposeImage(clientID, inputSdrImage, inputGainmap, outputHdrImage, legacy);
717 
718     // Assert
719     EXPECT_NE(result, 0);
720 }
721 
722 /**
723  * @tc.name  : DecomposeImage_ShouldReturnError_WhenInputInvalid
724  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_DecomposeImage_001
725  * @tc.desc  : Test DecomposeImage function with invalid input.
726  */
727 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DecomposeImage_ShouldReturnError_WhenInputInvalid, TestSize.Level0)
728 {
729     VideoProcessingAlgorithmWithoutData algorithmBase("test", 1);
730     SurfaceBufferInfo inputImage;
731     SurfaceBufferInfo outputSdrImage;
732     SurfaceBufferInfo outputGainmap;
733 
734     // Set inputImage to invalid
735     inputImage.surfacebuffer= nullptr;
736 
737     // Expect that the function will return an error
738     EXPECT_EQ(algorithmBase.DecomposeImage(1, inputImage, outputSdrImage, outputGainmap), VPE_ALGO_ERR_INVALID_PARAM);
739 }
740 
741 /**
742  * @tc.name  : DecomposeImage_ShouldReturnSuccess_WhenInputValid
743  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_DecomposeImage_002
744  * @tc.desc  : Test DecomposeImage function with valid input.
745  */
746 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DecomposeImage_ShouldReturnSuccess_WhenInputValid, TestSize.Level0)
747 {
748     VideoProcessingAlgorithmWithoutData algorithmBase("test", 1);
749     SurfaceBufferInfo inputImage;
750     SurfaceBufferInfo outputSdrImage;
751     SurfaceBufferInfo outputGainmap;
752 
753     // Set inputImage to valid
754     inputImage.surfacebuffer= SurfaceBuffer::Create();
755 
756     // Expect that the function will return success
757     EXPECT_NE(algorithmBase.DecomposeImage(1, inputImage, outputSdrImage, outputGainmap), 0);
758 }
759 
760 /**
761  * @tc.name  : OnInitializeLocked_ShouldReturnOk_WhenCalled
762  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_OnInitializeLocked_001
763  * @tc.desc  : Test OnInitializeLocked method of VideoProcessingAlgorithmWithoutData class.
764  */
765 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnInitializeLocked_ShouldReturnOk_WhenCalled, TestSize.Level0)
766 {
767     // Arrange
768     VideoProcessingAlgorithmWithoutData algo("feature", 1);
769 
770     // Act
771     int result = algo.OnInitializeLocked();
772 
773     // Assert
774     EXPECT_EQ(result, VPE_ALGO_ERR_OK);
775 }
776 
777 /**
778  * @tc.name  : OnDeinitializeLocked_ShouldReturnOk_WhenCalled
779  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_001
780  * @tc.desc  : Test OnDeinitializeLocked method of VideoProcessingAlgorithmWithoutData class.
781  */
782 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, OnDeinitializeLocked_ShouldReturnOk_WhenCalled, TestSize.Level0)
783 {
784     // Arrange
785     VideoProcessingAlgorithmWithoutData algo("feature", 1);
786 
787     // Act
788     int result = algo.OnDeinitializeLocked();
789 
790     // Assert
791     EXPECT_EQ(result, VPE_ALGO_ERR_OK);
792 }
793 
794 /**
795  * @tc.name  : AddClientIDLocked_ShouldReturnOK_WhenCalled
796  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_AddClientIDLocked_001
797  * @tc.desc  : Test AddClientIDLocked method when called with valid parameters.
798  */
799 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, AddClientIDLocked_ShouldReturnOK_WhenCalled, TestSize.Level0)
800 {
801     VideoProcessingAlgorithmWithoutData algoBase("feature", 1);
802     std::string clientName = "testClient";
803     uint32_t clientID = 0;
804 
805     int result = algoBase.AddClientIDLocked(clientName, clientID);
806 
807     EXPECT_EQ(result, VPE_ALGO_ERR_OK);
808 }
809 
810 
811 /**
812  * @tc.name  : DelClientIDLocked_ShouldReturnOK_WhenCalled
813  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_DelClientIDLocked_001
814  * @tc.desc  : Test DelClientIDLocked function when called with valid parameters.
815  */
816 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DelClientIDLocked_ShouldReturnOK_WhenCalled, TestSize.Level0)
817 {
818     // Arrange
819     uint32_t clientID = 12345;
820     bool isEmpty = false;
821     VideoProcessingAlgorithmWithoutData algoBase("feature", 1);
822 
823     // Act
824     int result = algoBase.DelClientIDLocked(clientID, isEmpty);
825 
826     // Assert
827     EXPECT_NE(result, VPE_ALGO_ERR_OK);
828 }
829 
830 
831 /**
832  * @tc.name  : GetClientSizeLocked_ShouldReturnZero_WhenCalled
833  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_001
834  * @tc.desc  : Test GetClientSizeLocked method when it should return zero.
835  */
836 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, GetClientSizeLocked_ShouldReturnZero_WhenCalled, TestSize.Level0)
837 {
838     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
839     EXPECT_EQ(algorithmBase.GetClientSizeLocked(), 0);
840 }
841 
842 /**
843  * @tc.name  : DoUpdateMetadata_ShouldReturnOk_WhenValidParameters
844  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_DoUpdateMetadata_001
845  * @tc.desc  : Test DoUpdateMetadata function with valid parameters.
846  */
847 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, DoUpdateMetadata_ShouldReturnOk_WhenValidParameters, TestSize.Level0)
848 {
849     // Arrange
850     VideoProcessingAlgorithmWithoutData algorithmBase("test", 1);
851     uint32_t clientID = 1;
852     SurfaceBufferInfo image;
853 
854     // Act
855     int result = algorithmBase.DoUpdateMetadata(clientID, image);
856 
857     // Assert
858     EXPECT_NE(result, VPE_ALGO_ERR_OK);
859 }
860 
861 
862 /**
863  * @tc.name  : ReturnNotSupport_ShouldReturnError_WhenCalled
864  * @tc.number: VideoProcessingEngine_VideoProcessingAlgorithmWithoutData_ReturnNotSupport_001
865  * @tc.desc  : Test ReturnNotSupport method of VideoProcessingAlgorithmWithoutData class.
866  */
867 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, ReturnNotSupport_ShouldReturnError_WhenCalled, TestSize.Level0)
868 {
869     // Arrange
870     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
871     LogInfo logInfo;
872 
873     // Act
874     int result = algorithmBase.ReturnNotSupport(logInfo);
875 
876     // Assert
877     EXPECT_EQ(result, VPE_ALGO_ERR_OPERATION_NOT_SUPPORTED);
878 }
879 
880 
881 
882 // Scenario 1: Test when isDuplicate function returns true
883 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, GenerateClientID_ShouldReturnFalse_WhenIsDuplicateReturnsTrue, TestSize.Level0)
884 {
885     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
__anon5a462a350502(uint32_t id) 886     std::function<bool(uint32_t)> isDuplicate = [](uint32_t id) { return true; };
887     uint32_t clientID = 0;
888     EXPECT_FALSE(algorithmBase.GenerateClientID(std::move(isDuplicate), clientID));
889 }
890 
891 // Scenario 2: Test when isDuplicate function returns false
892 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, GenerateClientID_ShouldReturnTrue_WhenIsDuplicateReturnsFalse, TestSize.Level0)
893 {
894     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
__anon5a462a350602(uint32_t id) 895     std::function<bool(uint32_t)> isDuplicate = [](uint32_t id) { return false; };
896     uint32_t clientID = 0;
897     EXPECT_TRUE(algorithmBase.GenerateClientID(std::move(isDuplicate), clientID));
898 }
899 
900 // Scenario 3: Test when MAX_CLIENT_GEN_COUNT is exceeded
901 HWTEST_F(VideoProcessingAlgorithmWithoutDataTest, GenerateClientID_ShouldReturnFalse_WhenMaxClientGenCountExceeded, TestSize.Level0)
902 {
903     VideoProcessingAlgorithmWithoutData algorithmBase("feature", 1);
__anon5a462a350702(uint32_t id) 904     std::function<bool(uint32_t)> isDuplicate = [](uint32_t id) { return true; };
905     uint32_t clientID = 0;
906     EXPECT_FALSE(algorithmBase.GenerateClientID(std::move(isDuplicate), clientID));
907 }
908 
909 }
910 }
911 }