• 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 
16 #define private public
17 #define protected public
18 
19 #include "gtest/gtest.h"
20 
21 #include <fstream>
22 #include <iostream>
23 #include <sstream>
24 #include <iservice_registry.h>
25 #include <system_ability_definition.h>
26 #include "algorithm_errors.h"
27 #include "surface_buffer.h"
28 #include "vpe_model_path.h"
29 #include "vpe_sa_constants.h"
30 
31 #include "video_processing_server_test.h"
32 #include "video_processing_server.h"
33 // #include "system_ability_ondemand_reason.h"
34 
35 using namespace std;
36 using namespace testing::ext;
37 
38 namespace OHOS {
39 namespace Media {
40 namespace VideoProcessingEngine {
41 const std::string UNLOAD_HANLDER = "unload_vpe_sa_handler";
42 const std::string UNLOAD_TASK_ID = "unload_vpe_sa";
43 class VideoProcessingServerTest : public testing::Test {
44 public:
45     static void SetUpTestCase(void);
46     static void TearDownTestCase(void);
47     void SetUp();
48     void TearDown();
49 };
50 
SetUpTestCase(void)51 void VideoProcessingServerTest::SetUpTestCase(void)
52 {
53     cout << "[SetUpTestCase]: " << endl;
54 }
55 
TearDownTestCase(void)56 void VideoProcessingServerTest::TearDownTestCase(void)
57 {
58     cout << "[TearDownTestCase]: " << endl;
59 }
60 
SetUp(void)61 void VideoProcessingServerTest::SetUp(void)
62 {
63     cout << "[SetUp]: SetUp!!!" << endl;
64 }
65 
TearDown(void)66 void VideoProcessingServerTest::TearDown(void)
67 {
68     cout << "[TearDown]: over!!!" << endl;
69 }
70 
71 /**
72  * @tc.name  : LoadInfo_Test_01
73  * @tc.number: VideoProcessingServerTest_01
74  * @tc.desc  : Test LoadInfo function when key is invalid.
75  */
76 HWTEST_F(VideoProcessingServerTest, LoadInfo_Test_01, TestSize.Level0)
77 {
78     VPE_LOGI("LoadInfo_Test_01: begin!");
79     VideoProcessingServer videoProcessingServer(1, true);
80     SurfaceBufferInfo bufferInfo;
81     ErrCode result = videoProcessingServer.LoadInfo(-1, bufferInfo);
82     EXPECT_EQ(result, ERR_INVALID_DATA);
83     VPE_LOGI("LoadInfo_Test_01: end!");
84 }
85 
86 /**
87  * @tc.name  : LoadInfo_Test_02
88  * @tc.number: VideoProcessingServerTest_02
89  * @tc.desc  : Test LoadInfo function when key is valid but file is not open.
90  */
91 HWTEST_F(VideoProcessingServerTest, LoadInfo_Test_02, TestSize.Level0)
92 {
93     VPE_LOGI("LoadInfo_Test_02: begin!");
94     VideoProcessingServer videoProcessingServer(1, true);
95     SurfaceBufferInfo bufferInfo;
96     ErrCode result = videoProcessingServer.LoadInfo(0, bufferInfo);
97     EXPECT_NE(result, ERR_NULL_OBJECT);
98     VPE_LOGI("LoadInfo_Test_02: end!");
99 }
100 
101 /**
102  * @tc.name  : LoadInfo_Test_03
103  * @tc.number: VideoProcessingServerTest_03
104  * @tc.desc  : Test LoadInfo function when file length is too short or too long.
105  */
106 HWTEST_F(VideoProcessingServerTest, LoadInfo_Test_03, TestSize.Level0)
107 {
108     VPE_LOGI("LoadInfo_Test_03: begin!");
109     VideoProcessingServer videoProcessingServer(1, true);
110     SurfaceBufferInfo bufferInfo;
111     ErrCode result = videoProcessingServer.LoadInfo(1, bufferInfo);
112     EXPECT_NE(result, ERR_INVALID_DATA);
113     VPE_LOGI("LoadInfo_Test_03: end!");
114 }
115 
116 /**
117  * @tc.name  : LoadInfo_Test_04
118  * @tc.number: VideoProcessingServerTest_04
119  * @tc.desc  : Test LoadInfo function when Alloc surface buffer failed.
120  */
121 HWTEST_F(VideoProcessingServerTest, LoadInfo_Test_04, TestSize.Level0)
122 {
123     VPE_LOGI("LoadInfo_Test_04: begin!");
124     VideoProcessingServer videoProcessingServer(1, true);
125     SurfaceBufferInfo bufferInfo;
126     ErrCode result = videoProcessingServer.LoadInfo(2, bufferInfo);
127     EXPECT_EQ(result, 0);
128     VPE_LOGI("LoadInfo_Test_04: end!");
129 }
130 
131 /**
132  * @tc.name  : LoadInfo_Test_05
133  * @tc.number: VideoProcessingServerTest_05
134  * @tc.desc  : Test LoadInfo function when everything is fine.
135  */
136 HWTEST_F(VideoProcessingServerTest, LoadInfo_Test_05, TestSize.Level0)
137 {
138     VPE_LOGI("LoadInfo_Test_05: begin!");
139     VideoProcessingServer videoProcessingServer(1, true);
140     SurfaceBufferInfo bufferInfo;
141     ErrCode result = videoProcessingServer.LoadInfo(3, bufferInfo);
142     EXPECT_EQ(result, ERR_NONE);
143     VPE_LOGI("LoadInfo_Test_05: end!");
144 }
145 
146 
147 /**
148  * @tc.name  : Create_Success_WhenValidFeatureAndClientName
149  * @tc.number: VideoProcessingServerTest_001
150  * @tc.desc  : Test Create method when valid feature and clientName are provided.
151  */
152 HWTEST_F(VideoProcessingServerTest, Create_Success_WhenValidFeatureAndClientName, TestSize.Level0)
153 {
154     VPE_LOGI("Create_Success_WhenValidFeatureAndClientName: begin!");
155     VideoProcessingServer server(1, true);
156     std::string feature = "testFeature";
157     std::string clientName = "testClient";
158     int32_t clientID = 0;
159     EXPECT_NE(server.Create(feature, clientName, clientID), VPE_ALGO_ERR_OK);
160     VPE_LOGI("Create_Success_WhenValidFeatureAndClientName: end!");
161 }
162 
163 /**
164  * @tc.name  : Create_Fail_WhenNoMemory
165  * @tc.number: VideoProcessingServerTest_002
166  * @tc.desc  : Test Create method when no memory is available.
167  */
168 HWTEST_F(VideoProcessingServerTest, Create_Fail_WhenNoMemory, TestSize.Level0)
169 {
170     VPE_LOGI("Create_Fail_WhenNoMemory: begin!");
171     VideoProcessingServer server(1, true);
172     std::string feature = "testFeature";
173     std::string clientName = "testClient";
174     int32_t clientID = 0;
175     EXPECT_EQ(server.Create(feature, clientName, clientID), VPE_ALGO_ERR_NO_MEMORY);
176     VPE_LOGI("Create_Fail_WhenNoMemory: end!");
177 }
178 
179 /**
180  * @tc.name  : Create_Fail_WhenInitializeFails
181  * @tc.number: VideoProcessingServerTest_003
182  * @tc.desc  : Test Create method when initialization fails.
183  */
184 HWTEST_F(VideoProcessingServerTest, Create_Fail_WhenInitializeFails, TestSize.Level0)
185 {
186     VPE_LOGI("Create_Fail_WhenInitializeFails: begin!");
187     VideoProcessingServer server(1, true);
188     std::string feature = "testFeature";
189     std::string clientName = "testClient";
190     int32_t clientID = 0;
191     EXPECT_NE(server.Create(feature, clientName, clientID), ERR_INVALID_STATE);
192     VPE_LOGI("Create_Fail_WhenInitializeFails: end!");
193 }
194 
195 /**
196  * @tc.name  : Create_Fail_WhenAddClientFails
197  * @tc.number: VideoProcessingServerTest_004
198  * @tc.desc  : Test Create method when adding client fails.
199  */
200 HWTEST_F(VideoProcessingServerTest, Create_Fail_WhenAddClientFails, TestSize.Level0)
201 {
202     VPE_LOGI("Create_Fail_WhenAddClientFails: begin!");
203     VideoProcessingServer server(1, true);
204     std::string feature = "testFeature";
205     std::string clientName = "testClient";
206     int32_t clientID = 0;
207     EXPECT_NE(server.Create(feature, clientName, clientID), ERR_INVALID_DATA);
208     VPE_LOGI("Create_Fail_WhenAddClientFails: end!");
209 }
210 
211 HWTEST_F(VideoProcessingServerTest, Destroy_ShouldReturnErrOk_WhenDestroyLockedReturnsErrOk, TestSize.Level0)
212 {
213     VPE_LOGI("Destroy_ShouldReturnErrOk_WhenDestroyLockedReturnsErrOk: begin!");
214     // Arrange
215     VideoProcessingServer videoProcessingServer(1, true);
216     // Act
217     auto result = videoProcessingServer.Destroy(1);
218 
219     // Assert
220     EXPECT_NE(result, ERR_OK);
221     VPE_LOGI("Destroy_ShouldReturnErrOk_WhenDestroyLockedReturnsErrOk: end!");
222 }
223 
224 HWTEST_F(VideoProcessingServerTest, UpdateMetadata_ShouldReturnErrOk_WhenImageIsNotNull, TestSize.Level0)
225 {
226     VPE_LOGI("UpdateMetadata_ShouldReturnErrOk_WhenImageIsNotNull: begin!");
227     // Arrange
228     int32_t clientID = 1;
229     SurfaceBufferInfo image;
230     image.surfacebuffer = SurfaceBuffer::Create();
231     VideoProcessingServer videoProcessingServer(1, true);
232 
233     // Act
234     ErrCode result = videoProcessingServer.UpdateMetadata(clientID, image);
235 
236     // Assert
237     EXPECT_NE(result, ERR_OK);
238     VPE_LOGI("UpdateMetadata_ShouldReturnErrOk_WhenImageIsNotNull: end!");
239 }
240 
241 /**
242  * @tc.name  : UpdateMetadata_ShouldReturnErrFail_WhenImageIsNull
243  * @tc.number: VideoProcessingServerTest_002
244  * @tc.desc  : Test UpdateMetadata function when image is null.
245  */
246 HWTEST_F(VideoProcessingServerTest, UpdateMetadata_ShouldReturnErrFail_WhenImageIsNull, TestSize.Level0)
247 {
248     VPE_LOGI("UpdateMetadata_ShouldReturnErrFail_WhenImageIsNull: begin!");
249     // Arrange
250     int32_t clientID = 1;
251     SurfaceBufferInfo image;
252     VideoProcessingServer videoProcessingServer(1, true);
253 
254     // Act
255     ErrCode result = videoProcessingServer.UpdateMetadata(clientID, image);
256 
257     // Assert
258     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
259     VPE_LOGI("UpdateMetadata_ShouldReturnErrFail_WhenImageIsNull: end!");
260 }
261 
262 HWTEST_F(VideoProcessingServerTest, Process_ShouldReturnErrOk_WhenInputOutputNotNull, TestSize.Level0)
263 {
264     VPE_LOGI("Process_ShouldReturnErrOk_WhenInputOutputNotNull: begin!");
265     VideoProcessingServer videoProcessingServer(1, true);
266     SurfaceBufferInfo input;
267     SurfaceBufferInfo output;
268     output.surfacebuffer = SurfaceBuffer::Create();
269     EXPECT_NE(videoProcessingServer.Process(1, input, output), ERR_OK);
270     VPE_LOGI("Process_ShouldReturnErrOk_WhenInputOutputNotNull: end!");
271 }
272 
273 /**
274  * @tc.name  : Process_ShouldReturnErrInvalidParam_WhenOutputIsNull
275  * @tc.number: VideoProcessingServerTest_002
276  * @tc.desc  : Test if Process method returns ERR_FAIL when output is null.
277  */
278 HWTEST_F(VideoProcessingServerTest, Process_ShouldReturnErrInvalidParam_WhenOutputIsNull, TestSize.Level0)
279 {
280     VPE_LOGI("Process_ShouldReturnErrInvalidParam_WhenOutputIsNull: begin!");
281     VideoProcessingServer videoProcessingServer(1, true);
282     SurfaceBufferInfo input;
283     SurfaceBufferInfo output;
284     EXPECT_EQ(videoProcessingServer.Process(1, input, output), VPE_ALGO_ERR_INVALID_PARAM);
285     VPE_LOGI("Process_ShouldReturnErrInvalidParam_WhenOutputIsNull: end!");
286 }
287 
288 /**
289  * @tc.name  : UnloadVideoProcessingSA_Success
290  * @tc.number: VideoProcessingServerTest_001
291  * @tc.desc  : Test when CreateUnloadHandler returns true then UnloadVideoProcessingSA should call DelayUnloadTask
292  */
293 HWTEST_F(VideoProcessingServerTest, UnloadVideoProcessingSA_Success, TestSize.Level0)
294 {
295     VPE_LOGI("UnloadVideoProcessingSA_Success: begin!");
296     int32_t systemAbilityId = 123;
297     VideoProcessingServer videoProcessingServer(1, true);
298     // Verify that DelayUnloadTask was called
299     videoProcessingServer.UnloadVideoProcessingSA();
300     EXPECT_EQ(systemAbilityId, 123);
301     VPE_LOGI("UnloadVideoProcessingSA_Success: end!");
302 }
303 
304 HWTEST_F(VideoProcessingServerTest, ComposeImage_ShouldReturnErrOk_WhenInputIsValid, TestSize.Level0)
305 {
306     VPE_LOGI("ComposeImage_ShouldReturnErrOk_WhenInputIsValid: begin!");
307     // Arrange
308     int32_t clientID = 1;
309     SurfaceBufferInfo inputSdrImage;
310     SurfaceBufferInfo inputGainmap;
311     SurfaceBufferInfo outputHdrImage;
312     outputHdrImage.surfacebuffer = SurfaceBuffer::Create();
313     bool legacy = false;
314 
315     VideoProcessingServer videoProcessingServer(clientID, legacy);
316 
317     // Act
318     ErrCode result = videoProcessingServer.ComposeImage(clientID, inputSdrImage, inputGainmap, outputHdrImage, legacy);
319 
320     // Assert
321     EXPECT_NE(result, ERR_OK);
322     VPE_LOGI("ComposeImage_ShouldReturnErrOk_WhenInputIsValid: end!");
323 }
324 
325 /**
326  * @tc.name  : ComposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull
327  * @tc.number: VideoProcessingServerTest_002
328  * @tc.desc  : Test ComposeImage function when output is null.
329  */
330 HWTEST_F(VideoProcessingServerTest, ComposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull, TestSize.Level0)
331 {
332     VPE_LOGI("ComposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull: begin!");
333     // Arrange
334     int32_t clientID = 1;
335     SurfaceBufferInfo inputSdrImage;
336     SurfaceBufferInfo inputGainmap;
337     SurfaceBufferInfo outputHdrImage;
338     bool legacy = false;
339 
340     VideoProcessingServer videoProcessingServer(clientID, legacy);
341 
342     // Act
343     ErrCode result = videoProcessingServer.ComposeImage(clientID, inputSdrImage, inputGainmap, outputHdrImage, legacy);
344 
345     // Assert
346     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
347     VPE_LOGI("ComposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull: end!");
348 }
349 
350 
351 /**
352  * @tc.name  : DecomposeImage_ShouldReturnErrOk_WhenInputIsValid
353  * @tc.number: VideoProcessingServerTest_001
354  * @tc.desc  : Test DecomposeImage function when input is valid.
355  */
356 HWTEST_F(VideoProcessingServerTest, DecomposeImage_ShouldReturnErrOk_WhenInputIsValid, TestSize.Level0)
357 {
358     VPE_LOGI("DecomposeImage_ShouldReturnErrOk_WhenInputIsValid: begin!");
359     // Arrange
360     int32_t clientID = 1;
361     SurfaceBufferInfo inputImage;
362     SurfaceBufferInfo outputSdrImage;
363     SurfaceBufferInfo outputGainmap;
364     VideoProcessingServer videoProcessingServer(clientID, true);
365 
366     // Act
367     ErrCode result = videoProcessingServer.DecomposeImage(clientID, inputImage, outputSdrImage, outputGainmap);
368 
369     // Assert
370     EXPECT_NE(result, ERR_OK);
371     VPE_LOGI("DecomposeImage_ShouldReturnErrOk_WhenInputIsValid: end!");
372 }
373 
374 /**
375  * @tc.name  : DecomposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull
376  * @tc.number: VideoProcessingServerTest_002
377  * @tc.desc  : Test DecomposeImage function when output is null.
378  */
379 HWTEST_F(VideoProcessingServerTest, DecomposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull, TestSize.Level0)
380 {
381     VPE_LOGI("DecomposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull: begin!");
382     // Arrange
383     int32_t clientID = 1;
384     SurfaceBufferInfo inputImage;
385     SurfaceBufferInfo outputSdrImage;
386     SurfaceBufferInfo outputGainmap;
387     outputSdrImage.surfacebuffer = nullptr;
388     outputGainmap.surfacebuffer = nullptr;
389     VideoProcessingServer videoProcessingServer(clientID, true);
390 
391     // Act
392     ErrCode result = videoProcessingServer.DecomposeImage(clientID, inputImage, outputSdrImage, outputGainmap);
393 
394     // Assert
395     EXPECT_EQ(result, VPE_ALGO_ERR_INVALID_PARAM);
396     VPE_LOGI("DecomposeImage_ShouldReturnErrInvalidParam_WhenOutputIsNull: end!");
397 }
398 
399 /**
400  * @tc.name  : DestroyLocked_ShouldReturnErrOk_WhenClientExistsAndAlgoNotNull
401  * @tc.number: VideoProcessingServerTest_001
402  * @tc.desc  : Test DestroyLocked function when client exists and algorithm is not null.
403  */
404 HWTEST_F(VideoProcessingServerTest, DestroyLocked_ShouldReturnErrOk_WhenClientExistsAndAlgoNotNull, TestSize.Level0)
405 {
406     VPE_LOGI("DestroyLocked_ShouldReturnErrOk_WhenClientExistsAndAlgoNotNull: begin!");
407     VideoProcessingServer server(1, true);
408     uint32_t id = 1;
409     server.DestroyLocked(id);
410     EXPECT_EQ(id, 1);
411     VPE_LOGI("DestroyLocked_ShouldReturnErrOk_WhenClientExistsAndAlgoNotNull: end!");
412 }
413 
414 /**
415  * @tc.name  : DestroyLocked_ShouldReturnErrInvalidVal_WhenClientNotExists
416  * @tc.number: VideoProcessingServerTest_002
417  * @tc.desc  : Test DestroyLocked function when client not exists.
418  */
419 HWTEST_F(VideoProcessingServerTest, DestroyLocked_ShouldReturnErrInvalidVal_WhenClientNotExists, TestSize.Level0)
420 {
421     VPE_LOGI("DestroyLocked_ShouldReturnErrInvalidVal_WhenClientNotExists: begin!");
422     VideoProcessingServer server(1, true);
423     uint32_t id = 2;
424     EXPECT_EQ(server.DestroyLocked(id), VPE_ALGO_ERR_INVALID_CLIENT_ID);
425     VPE_LOGI("DestroyLocked_ShouldReturnErrInvalidVal_WhenClientNotExists: end!");
426 }
427 
428 /**
429  * @tc.name  : DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoNotExists
430  * @tc.number: VideoProcessingServerTest_003
431  * @tc.desc  : Test DestroyLocked function when algorithm not exists.
432  */
433 HWTEST_F(VideoProcessingServerTest, DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoNotExists, TestSize.Level0)
434 {
435     VPE_LOGI("DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoNotExists: begin!");
436     VideoProcessingServer server(1, true);
437     uint32_t id = 1;
438     std::string feature = "feature1";
439     server.clients_[id] = feature;
440     EXPECT_EQ(server.DestroyLocked(id), VPE_ALGO_ERR_INVALID_VAL);
441     VPE_LOGI("DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoNotExists: end!");
442 }
443 
444 /**
445  * @tc.name  : DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoIsNull
446  * @tc.number: VideoProcessingServerTest_004
447  * @tc.desc  : Test DestroyLocked function when algorithm is null.
448  */
449 HWTEST_F(VideoProcessingServerTest, DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoIsNull, TestSize.Level0)
450 {
451     VPE_LOGI("DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoIsNull: begin!");
452     VideoProcessingServer server(1, true);
453     uint32_t id = 1;
454     std::string feature = "feature1";
455     server.clients_[id] = feature;
456     server.algorithms_[feature] = nullptr;
457     EXPECT_EQ(server.DestroyLocked(id), VPE_ALGO_ERR_INVALID_VAL);
458     VPE_LOGI("DestroyLocked_ShouldReturnErrInvalidVal_WhenAlgoIsNull: end!");
459 }
460 
461 /**
462  * @tc.name  : CreateUnloadHandler_ShouldCreateHandler_WhenHandlerIsNull
463  * @tc.number: VideoProcessingServerTest_001
464  * @tc.desc  : Test if CreateUnloadHandler creates a handler when the handler is null.
465  */
466 HWTEST_F(VideoProcessingServerTest, CreateUnloadHandler_ShouldCreateHandler_WhenHandlerIsNull, TestSize.Level0)
467 {
468     VPE_LOGI("CreateUnloadHandler_ShouldCreateHandler_WhenHandlerIsNull: begin!");
469     // Arrange
470     VideoProcessingServer videoProcessingServer(1, true);
471     videoProcessingServer.unloadHandler_ = nullptr;
472 
473     // Act
474     bool result = videoProcessingServer.CreateUnloadHandler();
475 
476     // Assert
477     EXPECT_TRUE(result);
478     EXPECT_NE(videoProcessingServer.unloadHandler_, nullptr);
479     VPE_LOGI("CreateUnloadHandler_ShouldCreateHandler_WhenHandlerIsNull: end!");
480 }
481 
482 /**
483  * @tc.name  : DestroyUnloadHandler_ShouldNotRemoveAllEventsAndRemoveTask_WhenUnloadHandlerIsNull
484  * @tc.number: VideoProcessingServerTest_002
485  * @tc.desc  : Test DestroyUnloadHandler method when unloadHandler is null
486  */
487 HWTEST_F(VideoProcessingServerTest, DestroyUnloadHandler_ShouldNotRemoveAllEventsAndRemoveTask_WhenUnloadHandlerIsNull, TestSize.Level0)
488 {
489     VPE_LOGI("DestroyUnloadHandler_ShouldNotRemoveAllEventsAndRemoveTask_WhenUnloadHandlerIsNull: begin!");
490     // Arrange
491     VideoProcessingServer videoProcessingServer(1, true);
492     videoProcessingServer.unloadHandler_ = nullptr;
493 
494     // Act
495     videoProcessingServer.DestroyUnloadHandler();
496 
497     // Assert
498     EXPECT_EQ(videoProcessingServer.unloadHandler_, nullptr);
499     VPE_LOGI("DestroyUnloadHandler_ShouldNotRemoveAllEventsAndRemoveTask_WhenUnloadHandlerIsNull: end!");
500 }
501 
502 HWTEST_F(VideoProcessingServerTest, DestroyUnloadHandler_ShouldNotRemoveAllEventsAndRemoveTask_WhenUnloadHandlerNotNull, TestSize.Level0)
503 {
504     VPE_LOGI("DestroyUnloadHandler_ShouldNotRemoveAllEventsAndRemoveTask_WhenUnloadHandlerIsNull: begin!");
505     // Arrange
506     VideoProcessingServer videoProcessingServer(1, true);
507     videoProcessingServer.unloadHandler_ =  std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::Create(UNLOAD_HANLDER));
508 
509     // Act
510     videoProcessingServer.DestroyUnloadHandler();
511 
512     // Assert
513     EXPECT_EQ(videoProcessingServer.unloadHandler_, nullptr);
514     VPE_LOGI("DestroyUnloadHandler_ShouldNotRemoveAllEventsAndRemoveTask_WhenUnloadHandlerIsNull: end!");
515 }
516 
517 /**
518  * @tc.name  : DelayUnloadTask_ShouldLockAndUnlock_WhenCalled
519  * @tc.number: VideoProcessingServerTest_001
520  * @tc.desc  : Test that DelayUnloadTask locks and unlocks the mutex
521  */
522 HWTEST_F(VideoProcessingServerTest, DelayUnloadTask_ShouldLockAndUnlock_WhenCalled, TestSize.Level0)
523 {
524     VPE_LOGI("DelayUnloadTask_ShouldLockAndUnlock_WhenCalled: begin!");
525     VideoProcessingServer videoProcessingServer(1, true);
526     videoProcessingServer.DelayUnloadTask();
527     VPE_LOGI("DelayUnloadTask_ShouldLockAndUnlock_WhenCalled: end!");
528 }
529 
530 /**
531  * @tc.name  : DelayUnloadTaskLocked_WhenIsWorkingIsTrue
532  * @tc.number: VideoProcessingServerTest_001
533  * @tc.desc  : Test when isWorking_ is true, the function will return immediately
534  */
535 HWTEST_F(VideoProcessingServerTest, DelayUnloadTaskLocked_WhenIsWorkingIsTrue, TestSize.Level0)
536 {
537     VPE_LOGI("DelayUnloadTaskLocked_WhenIsWorkingIsTrue: begin!");
538     VideoProcessingServer videoProcessingServer(1, true);
539     videoProcessingServer.isWorking_ = true;
540     videoProcessingServer.DelayUnloadTaskLocked();
541     ASSERT_TRUE(videoProcessingServer.isWorking_);
542     VPE_LOGI("DelayUnloadTaskLocked_WhenIsWorkingIsTrue: end!");
543 }
544 
545 /**
546  * @tc.name  : DelayUnloadTaskLocked_WhenUnloadHandlerIsNull
547  * @tc.number: VideoProcessingServerTest_002
548  * @tc.desc  : Test when unloadHandler_ is null, the function will return immediately
549  */
550 HWTEST_F(VideoProcessingServerTest, DelayUnloadTaskLocked_WhenUnloadHandlerIsNull, TestSize.Level0)
551 {
552     VPE_LOGI("DelayUnloadTaskLocked_WhenUnloadHandlerIsNull: begin!");
553     VideoProcessingServer videoProcessingServer(1, true);
554     videoProcessingServer.unloadHandler_ = nullptr;
555     videoProcessingServer.DelayUnloadTaskLocked();
556     ASSERT_TRUE(videoProcessingServer.unloadHandler_ != nullptr);
557     VPE_LOGI("DelayUnloadTaskLocked_WhenUnloadHandlerIsNull: end!");
558 }
559 
560 HWTEST_F(VideoProcessingServerTest, DelayUnloadTaskLocked_WhenUnloadHandlerNotNull, TestSize.Level0)
561 {
562     VPE_LOGI("DelayUnloadTaskLocked_WhenUnloadHandlerIsNull: begin!");
563     VideoProcessingServer videoProcessingServer(1, true);
564     videoProcessingServer.unloadHandler_ = std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::Create(UNLOAD_HANLDER));
565     videoProcessingServer.DelayUnloadTaskLocked();
566     ASSERT_TRUE(videoProcessingServer.unloadHandler_ != nullptr);
567     VPE_LOGI("DelayUnloadTaskLocked_WhenUnloadHandlerIsNull: end!");
568 }
569 
570 HWTEST_F(VideoProcessingServerTest, ClearAlgorithms_ShouldClearAlgorithms_WhenCalled, TestSize.Level0)
571 {
572     VPE_LOGI("ClearAlgorithms_ShouldClearAlgorithms_WhenCalled: begin!");
573     VideoProcessingServer server(1, true);
574     server.algorithms_["test_algo"] = nullptr;
575     server.clients_[1] = "test_client";
576     server.isWorking_ = true;
577 
578     server.ClearAlgorithms();
579 
580     EXPECT_TRUE(server.algorithms_.empty());
581     EXPECT_TRUE(server.clients_.empty());
582     EXPECT_FALSE(server.isWorking_.load());
583     VPE_LOGI("ClearAlgorithms_ShouldClearAlgorithms_WhenCalled: end!");
584 }
585 
TEST_F(VideoProcessingServerTest,SetParameter_ShouldReturnError_WhenInvalidClientID)586 TEST_F(VideoProcessingServerTest, SetParameter_ShouldReturnError_WhenInvalidClientID)
587 {
588     VideoProcessingServer videoProcessingServer(1, true);
589     int32_t clientID = -1;
590     int32_t tag = 2;
591     std::vector<uint8_t> parameter = {1, 2, 3, 4, 5};
592 
593     ErrCode result = videoProcessingServer.SetParameter(clientID, tag, parameter);
594 
595     EXPECT_NE(result, VPE_ALGO_ERR_OK);
596 }
TEST_F(VideoProcessingServerTest,SetParameter_ShouldReturnError_WhenEmptyParameter)597 TEST_F(VideoProcessingServerTest, SetParameter_ShouldReturnError_WhenEmptyParameter)
598 {
599     VideoProcessingServer videoProcessingServer(1, true);
600     int32_t clientID = 1;
601     int32_t tag = 2;
602     std::vector<uint8_t> parameter = {};
603 
604     ErrCode result = videoProcessingServer.SetParameter(clientID, tag, parameter);
605 
606     EXPECT_NE(result, VPE_ALGO_ERR_OK);
607 }
608 
TEST_F(VideoProcessingServerTest,GetParameter_ShouldReturnSuccess_WhenValidParameters)609 TEST_F(VideoProcessingServerTest, GetParameter_ShouldReturnSuccess_WhenValidParameters)
610 {
611     VideoProcessingServer videoProcessingServer(1, true);
612     int32_t clientID = 1;
613     int32_t tag = 1;
614     std::vector<uint8_t> parameter;
615 
616     ErrCode result = videoProcessingServer.GetParameter(clientID, tag, parameter);
617 
618     EXPECT_NE(result, VPE_ALGO_ERR_OK);
619 }
620 
TEST_F(VideoProcessingServerTest,GetParameter_ShouldReturnError_WhenInvalidClientID)621 TEST_F(VideoProcessingServerTest, GetParameter_ShouldReturnError_WhenInvalidClientID)
622 {
623     VideoProcessingServer videoProcessingServer(1, true);
624     int32_t clientID = -1;
625     int32_t tag = 1;
626     std::vector<uint8_t> parameter;
627 
628     ErrCode result = videoProcessingServer.GetParameter(clientID, tag, parameter);
629 
630     EXPECT_NE(result, VPE_ALGO_ERR_OK);
631 }
632 
TEST_F(VideoProcessingServerTest,GetParameter_ShouldReturnError_WhenInvalidTag)633 TEST_F(VideoProcessingServerTest, GetParameter_ShouldReturnError_WhenInvalidTag)
634 {
635     VideoProcessingServer videoProcessingServer(1, true);
636     int32_t clientID = 1;
637     int32_t tag = -1;
638     std::vector<uint8_t> parameter;
639 
640     ErrCode result = videoProcessingServer.GetParameter(clientID, tag, parameter);
641 
642     EXPECT_NE(result, VPE_ALGO_ERR_OK);
643 }
644 
645 } // namespace VideoProcessingEngine
646 } // namespace Media
647 } // namespace OHOS
648