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 #define BUFF_SIZE 100
17 #include "intention_service_test.h"
18 
19 #include "drag_data_manager.h"
20 #include "drag_params.h"
21 #include "drag_server.h"
22 #include "dsoftbus_adapter.h"
23 #include "fi_log.h"
24 #include "input_adapter.h"
25 #include "intention_service.h"
26 #include "interaction_manager.h"
27 #include "ipc_skeleton.h"
28 #include "plugin_manager.h"
29 
30 #undef LOG_TAG
31 #define LOG_TAG "IntentionServiceTest"
32 
33 namespace OHOS {
34 namespace Msdp {
35 namespace DeviceStatus {
36 using namespace testing::ext;
37 namespace {
38 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
39 constexpr int32_t POINTER_ID { 0 };
40 constexpr int32_t DRAG_NUM_ONE { 1 };
41 constexpr int32_t SHADOW_NUM_ONE { 1 };
42 constexpr int32_t PIXEL_MAP_WIDTH { 3 };
43 constexpr int32_t PIXEL_MAP_HEIGHT { 3 };
44 constexpr int32_t WINDOW_ID { -1 };
45 constexpr int32_t READ_OK { 1 };
46 constexpr uint32_t DEFAULT_ICON_COLOR { 0xFF };
47 const std::string FILTER_INFO { "Undefined filter info" };
48 const std::string UD_KEY { "Unified data key" };
49 const std::string EXTRA_INFO { "Undefined extra info" };
50 const std::string CURVE_NAME { "cubic-bezier" };
51 constexpr int32_t FOREGROUND_COLOR_IN { 0x33FF0000 };
52 constexpr int32_t DISPLAY_ID { 0 };
53 constexpr int32_t DISPLAY_X { 50 };
54 constexpr int32_t DISPLAY_Y { 50 };
55 constexpr int32_t INT32_BYTE { 4 };
56 int32_t g_shadowinfoX { 0 };
57 int32_t g_shadowinfoY { 0 };
58 constexpr int32_t ANIMATION_DURATION { 500 };
59 constexpr int32_t MAX_PIXEL_MAP_WIDTH { 600 };
60 constexpr int32_t MAX_PIXEL_MAP_HEIGHT { 600 };
61 constexpr bool HAS_CANCELED_ANIMATION { true };
62 constexpr bool HAS_CUSTOM_ANIMATION { true };
63 Intention g_intention { Intention::DRAG };
64 std::shared_ptr<ContextService> g_context { nullptr };
65 std::shared_ptr<IntentionService> g_intentionService { nullptr };
66 std::shared_ptr<IntentionService> g_intentionServiceNullptr { nullptr };
67 IContext *g_contextNullptr { nullptr };
68 } // namespace
69 
PostSyncTask(DTaskCallback callback)70 int32_t MockDelegateTasks::PostSyncTask(DTaskCallback callback)
71 {
72     return callback();
73 }
74 
PostAsyncTask(DTaskCallback callback)75 int32_t MockDelegateTasks::PostAsyncTask(DTaskCallback callback)
76 {
77     return callback();
78 }
79 
GetInstance()80 ContextService* ContextService::GetInstance()
81 {
82     static std::once_flag flag;
83     std::call_once(flag, [&]() {
84         g_context = std::make_shared<ContextService>();
85     });
86     return g_context.get();
87 }
88 
ContextService()89 ContextService::ContextService()
90 {
91     input_ = std::make_unique<InputAdapter>();
92     pluginMgr_ = std::make_unique<PluginManager>(this);
93     dsoftbus_ = std::make_unique<DSoftbusAdapter>();
94 }
95 
GetDelegateTasks()96 IDelegateTasks& ContextService::GetDelegateTasks()
97 {
98     return delegateTasks_;
99 }
100 
GetDeviceManager()101 IDeviceManager& ContextService::GetDeviceManager()
102 {
103     return devMgr_;
104 }
105 
GetTimerManager()106 ITimerManager& ContextService::GetTimerManager()
107 {
108     return timerMgr_;
109 }
110 
GetDragManager()111 IDragManager& ContextService::GetDragManager()
112 {
113     return dragMgr_;
114 }
115 
GetSocketSessionManager()116 ISocketSessionManager& ContextService::GetSocketSessionManager()
117 {
118     return socketSessionMgr_;
119 }
120 
GetPluginManager()121 IPluginManager& ContextService::GetPluginManager()
122 {
123     return *pluginMgr_;
124 }
125 
GetInput()126 IInputAdapter& ContextService::GetInput()
127 {
128     return *input_;
129 }
130 
GetDSoftbus()131 IDSoftbusAdapter& ContextService::GetDSoftbus()
132 {
133     return *dsoftbus_;
134 }
135 
SetUpTestCase()136 void IntentionServiceTest::SetUpTestCase()
137 {
138     g_intentionService = std::make_shared<IntentionService>(ContextService::GetInstance());
139     g_intentionServiceNullptr = std::make_shared<IntentionService>(g_contextNullptr);
140 }
141 
TearDownTestCase()142 void IntentionServiceTest::TearDownTestCase()
143 {
144     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
145     g_intentionServiceNullptr = nullptr;
146 }
147 
SetUp()148 void IntentionServiceTest::SetUp() {}
149 
TearDown()150 void IntentionServiceTest::TearDown() {}
151 
CreatePixelMap(int32_t width,int32_t height)152 std::shared_ptr<Media::PixelMap> IntentionServiceTest::CreatePixelMap(int32_t width, int32_t height)
153 {
154     CALL_DEBUG_ENTER;
155     if (width <= 0 || width > MAX_PIXEL_MAP_WIDTH || height <= 0 || height > MAX_PIXEL_MAP_HEIGHT) {
156         FI_HILOGE("invalid, height:%{public}d, width:%{public}d", height, width);
157         return nullptr;
158     }
159     Media::InitializationOptions opts;
160     opts.size.width = width;
161     opts.size.height = height;
162     opts.pixelFormat = Media::PixelFormat::BGRA_8888;
163     opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
164     opts.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE;
165 
166     int32_t colorLen = width * height;
167     uint32_t *pixelColors = new (std::nothrow) uint32_t[BUFF_SIZE];
168     CHKPP(pixelColors);
169     int32_t colorByteCount = colorLen * INT32_BYTE;
170     errno_t ret = memset_s(pixelColors, BUFF_SIZE, DEFAULT_ICON_COLOR, colorByteCount);
171     if (ret != EOK) {
172         FI_HILOGE("memset_s failed");
173         delete[] pixelColors;
174         return nullptr;
175     }
176     std::shared_ptr<Media::PixelMap> pixelMap = Media::PixelMap::Create(pixelColors, colorLen, opts);
177     if (pixelMap == nullptr) {
178         FI_HILOGE("Create pixelMap failed");
179         delete[] pixelColors;
180         return nullptr;
181     }
182     delete[] pixelColors;
183     return pixelMap;
184 }
185 
CreateDragData(int32_t sourceType,int32_t pointerId,int32_t dragNum,bool hasCoordinateCorrected,int32_t shadowNum)186 std::optional<DragData> IntentionServiceTest::CreateDragData(int32_t sourceType,
187     int32_t pointerId, int32_t dragNum, bool hasCoordinateCorrected, int32_t shadowNum)
188 {
189     CALL_DEBUG_ENTER;
190     DragData dragData;
191     for (int32_t i = 0; i < shadowNum; i++) {
192         std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT);
193         if (pixelMap == nullptr) {
194             FI_HILOGE("pixelMap nullptr");
195             return std::nullopt;
196         }
197         dragData.shadowInfos.push_back({ pixelMap, g_shadowinfoX, g_shadowinfoY });
198     }
199     dragData.buffer = std::vector<uint8_t>(MAX_BUFFER_SIZE, 0);
200     dragData.extraInfo = FILTER_INFO;
201     dragData.udKey = UD_KEY;
202     dragData.sourceType = sourceType;
203     dragData.extraInfo = EXTRA_INFO;
204     dragData.displayId = DISPLAY_ID;
205     dragData.pointerId = pointerId;
206     dragData.dragNum = dragNum;
207     dragData.displayX = DISPLAY_X;
208     dragData.displayY = DISPLAY_Y;
209     dragData.hasCoordinateCorrected = hasCoordinateCorrected;
210     dragData.hasCanceledAnimation = HAS_CANCELED_ANIMATION;
211     return dragData;
212 }
213 
214 class TestStartDragListener : public IStartDragListener {
215 public:
TestStartDragListener(std::function<void (const DragNotifyMsg &)> function)216     explicit TestStartDragListener(std::function<void(const DragNotifyMsg&)> function) : function_(function) { }
OnDragEndMessage(const DragNotifyMsg & msg)217     void OnDragEndMessage(const DragNotifyMsg &msg) override
218     {
219         FI_HILOGD("DisplayX:%{public}d, displayY:%{public}d, targetPid:%{public}d, result:%{public}d",
220             msg.displayX, msg.displayY, msg.targetPid, static_cast<int32_t>(msg.result));
221         if (function_ != nullptr) {
222             function_(msg);
223         }
224         FI_HILOGD("Test OnDragEndMessage");
225     }
226 
OnHideIconMessage()227     void OnHideIconMessage() override
228     {
229         FI_HILOGD("Test OnHideIconMessage");
230     }
231 private:
232     std::function<void(const DragNotifyMsg&)> function_;
233 };
234 
235 class DragListenerTest : public IDragListener {
236 public:
DragListenerTest()237     DragListenerTest() {}
DragListenerTest(const std::string & name)238     explicit DragListenerTest(const std::string& name) : moduleName_(name) {}
OnDragMessage(DragState state)239     void OnDragMessage(DragState state) override
240     {
241         if (moduleName_.empty()) {
242             moduleName_ = std::string("DragListenerTest");
243         }
244         FI_HILOGD("%{public}s, state:%{public}s", moduleName_.c_str(), PrintDragMessage(state).c_str());
245     }
246 private:
PrintDragMessage(DragState state)247     std::string PrintDragMessage(DragState state)
248     {
249         std::string type = "unknow";
250         const std::map<DragState, std::string> stateType = {
251             { DragState::ERROR, "error"},
252             { DragState::START, "start"},
253             { DragState::STOP, "stop"},
254             { DragState::CANCEL, "cancel"}
255         };
256         auto item = stateType.find(state);
257         if (item != stateType.end()) {
258             type = item->second;
259         }
260         return type;
261     }
262 private:
263     std::string moduleName_;
264 };
265 
AssignToAnimation(PreviewAnimation & animation)266 void IntentionServiceTest::AssignToAnimation(PreviewAnimation &animation)
267 {
268     animation.duration = ANIMATION_DURATION;
269     animation.curveName = CURVE_NAME;
270     animation.curve = { 0.33, 0, 0.67, 1 };
271 }
272 
273 /**
274  * @tc.name: IntentionServiceTest_1
275  * @tc.desc: Test Enable
276  * @tc.type: FUNC
277  * @tc.require:
278  */
279 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Enable001, TestSize.Level0)
280 {
281     CALL_TEST_DEBUG;
282     MessageParcel dataParcel;
283     MessageParcel replyParcel;
284     int32_t ret = g_intentionService->Enable(g_intention, dataParcel, replyParcel);
285     EXPECT_EQ(ret, RET_ERR);
286 }
287 
288 /**
289  * @tc.name: IntentionServiceTest2
290  * @tc.desc: Test Disable
291  * @tc.type: FUNC
292  * @tc.require:
293  */
294 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Disable001, TestSize.Level0)
295 {
296     CALL_TEST_DEBUG;
297     MessageParcel replyParcel;
298     MessageParcel dataParcel;
299     int32_t ret = g_intentionService->Disable(g_intention, dataParcel, replyParcel);
300     EXPECT_EQ(ret, RET_ERR);
301 }
302 
303 /**
304  * @tc.name: IntentionServiceTest3
305  * @tc.desc: Test Start
306  * @tc.type: FUNC
307  * @tc.require:
308  */
309 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Start001, TestSize.Level0)
310 {
311     CALL_TEST_DEBUG;
312     std::optional<DragData> dragData = CreateDragData(
313         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
314     MessageParcel replyParcel;
315     MessageParcel dataParcel;
316 
317     int32_t ret = g_intentionService->Start(g_intention, dataParcel, replyParcel);
318     EXPECT_EQ(ret, RET_ERR);
319 }
320 
321 /**
322  * @tc.name: IntentionServiceTest_Stop001
323  * @tc.desc: Test Stop
324  * @tc.type: FUNC
325  * @tc.require:
326  */
327 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Stop001, TestSize.Level0)
328 {
329     CALL_TEST_DEBUG;
330     MessageParcel replyParcel;
331     MessageParcel dataParcel;
332     int32_t ret = g_intentionService->Stop(g_intention, dataParcel, replyParcel);
333     EXPECT_EQ(ret, RET_ERR);
334 }
335 
336 /**
337  * @tc.name: IntentionServiceTest_Stop002
338  * @tc.desc: Test Stop
339  * @tc.type: FUNC
340  * @tc.require:
341  */
342 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Stop002, TestSize.Level0)
343 {
344     CALL_TEST_DEBUG;
345     auto env = ContextService::GetInstance();
346     ASSERT_NE(env, nullptr);
347     MessageParcel replyParcel;
348     MessageParcel dataParcel;
349     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
350     env->dragMgr_.dragState_ = DragState::START;
351     StopDragParam param { dropResult };
352 
353     int32_t ret = param.Marshalling(dataParcel);
354     EXPECT_EQ(ret, READ_OK);
355     ret = g_intentionService->Stop(g_intention, dataParcel, replyParcel);
356     EXPECT_EQ(ret, RET_OK);
357     env->dragMgr_.dragState_ = DragState::STOP;
358 }
359 
360 /**
361  * @tc.name: IntentionServiceTest_Stop003
362  * @tc.desc: Test Stop
363  * @tc.type: FUNC
364  * @tc.require:
365  */
366 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Stop003, TestSize.Level0)
367 {
368     CALL_TEST_DEBUG;
369     auto env = ContextService::GetInstance();
370     ASSERT_NE(env, nullptr);
371     MessageParcel dataParcel;
372     MessageParcel replyParcel;
373     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
374     env->dragMgr_.dragState_ = DragState::START;
375     StopDragParam param { dropResult };
376 
377     int32_t ret = param.Marshalling(dataParcel);
378     EXPECT_EQ(ret, READ_OK);
379     ret = g_intentionServiceNullptr->Stop(g_intention, dataParcel, replyParcel);
380     EXPECT_EQ(ret, RET_ERR);
381     env->dragMgr_.dragState_ = DragState::STOP;
382 }
383 
384 /**
385  * @tc.name: IntentionServiceTest5
386  * @tc.desc: Test AddWatch
387  * @tc.type: FUNC
388  * @tc.require:
389  */
390 HWTEST_F(IntentionServiceTest, IntentionServiceTest_AddWatch001, TestSize.Level0)
391 {
392     CALL_TEST_DEBUG;
393     int32_t ret = RET_ERR;
394     MessageParcel replyParcel;
395     MessageParcel dataParcel;
396     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
397         DragRequestID::ADD_DRAG_LISTENER, DragRequestID::ADD_SUBSCRIPT_LISTENER};
398     for (const auto& dragRequestID : dragRequestIDs) {
399         ret = g_intentionService->AddWatch(g_intention, dragRequestID, dataParcel, replyParcel);
400         EXPECT_EQ(ret, RET_ERR);
401     }
402 }
403 
404 /**
405  * @tc.name: IntentionServiceTest6
406  * @tc.desc: Test RemoveWatch
407  * @tc.type: FUNC
408  * @tc.require:
409  */
410 HWTEST_F(IntentionServiceTest, IntentionServiceTest_RemoveWatch001, TestSize.Level0)
411 {
412     CALL_TEST_DEBUG;
413     MessageParcel replyParcel;
414     MessageParcel dataParcel;
415     int32_t ret = RET_ERR;
416     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
417         DragRequestID::ADD_DRAG_LISTENER, DragRequestID::ADD_SUBSCRIPT_LISTENER};
418     for (const auto& dragRequestID : dragRequestIDs) {
419         ret = g_intentionService->RemoveWatch(g_intention, dragRequestID, dataParcel, replyParcel);
420         EXPECT_EQ(ret, RET_ERR);
421     }
422 }
423 
424 /**
425  * @tc.name: IntentionServiceTest_Control001
426  * @tc.desc: Test Control
427  * @tc.type: FUNC
428  * @tc.require:
429  */
430 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Control001, TestSize.Level0)
431 {
432     CALL_TEST_DEBUG;
433     int32_t ret = RET_ERR;
434     MessageParcel dataParcel;
435     MessageParcel replyParcel;
436     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
437         DragRequestID::ADD_PRIVILEGE, DragRequestID::ENTER_TEXT_EDITOR_AREA};
438     for (const auto& dragRequestID : dragRequestIDs) {
439         ret = g_intentionService->Control(g_intention, dragRequestID, dataParcel, replyParcel);
440         EXPECT_EQ(ret, RET_ERR);
441     }
442 }
443 
444 /**
445  * @tc.name: IntentionServiceTest_SetParam001
446  * @tc.desc: Test SetParam
447  * @tc.type: FUNC
448  * @tc.require:
449  */
450 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam001, TestSize.Level0)
451 {
452     CALL_TEST_DEBUG;
453     MessageParcel replyParcel;
454     MessageParcel dataParcel;
455     int32_t ret = RET_ERR;
456     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
457         DragRequestID::SET_DRAG_WINDOW_VISIBLE, DragRequestID::UPDATE_DRAG_STYLE,
458         DragRequestID::UPDATE_SHADOW_PIC, DragRequestID::UPDATE_PREVIEW_STYLE,
459         DragRequestID::UPDATE_PREVIEW_STYLE_WITH_ANIMATION};
460     for (const auto& dragRequestID : dragRequestIDs) {
461         ret = g_intentionService->SetParam(g_intention, dragRequestID, dataParcel, replyParcel);
462         EXPECT_EQ(ret, RET_ERR);
463     }
464 }
465 
466 /**
467  * @tc.name: IntentionServiceTest_SetParam002
468  * @tc.desc: Test SetParam
469  * @tc.type: FUNC
470  * @tc.require:
471  */
472 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam002, TestSize.Level0)
473 {
474     CALL_TEST_DEBUG;
475     MessageParcel replyParcel;
476     MessageParcel dataParcel;
477     int32_t ret = g_intentionService->SetParam(g_intention, DragRequestID::SET_DRAG_WINDOW_VISIBLE,
478         dataParcel, replyParcel);
479     EXPECT_EQ(ret, RET_ERR);
480 }
481 
482 /**
483  * @tc.name: IntentionServiceTest_SetParam003
484  * @tc.desc: Test SetParam
485  * @tc.type: FUNC
486  * @tc.require:
487  */
488 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam003, TestSize.Level0)
489 {
490     CALL_TEST_DEBUG;
491     MessageParcel replyParcel;
492     MessageParcel dataParcel;
493     int32_t ret = g_intentionService->SetParam(g_intention, DragRequestID::UPDATE_DRAG_STYLE,
494         dataParcel, replyParcel);
495     EXPECT_EQ(ret, RET_ERR);
496 }
497 
498 /**
499  * @tc.name: IntentionServiceTest_SetParam004
500  * @tc.desc: Test SetParam
501  * @tc.type: FUNC
502  * @tc.require:
503  */
504 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam004, TestSize.Level0)
505 {
506     CALL_TEST_DEBUG;
507     MessageParcel replyParcel;
508     MessageParcel dataParcel;
509     int32_t ret = g_intentionService->SetParam(g_intention, DragRequestID::UPDATE_SHADOW_PIC,
510         dataParcel, replyParcel);
511     EXPECT_EQ(ret, RET_ERR);
512 }
513 
514 /**
515  * @tc.name: IntentionServiceTest_SetParam005
516  * @tc.desc: Test SetParam
517  * @tc.type: FUNC
518  * @tc.require:
519  */
520 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam005, TestSize.Level0)
521 {
522     CALL_TEST_DEBUG;
523     MessageParcel replyParcel;
524     MessageParcel dataParcel;
525     int32_t ret = g_intentionService->SetParam(g_intention, DragRequestID::UPDATE_PREVIEW_STYLE,
526         dataParcel, replyParcel);
527     EXPECT_EQ(ret, RET_ERR);
528 }
529 
530 /**
531  * @tc.name: IntentionServiceTest_SetParam006
532  * @tc.desc: Test SetParam
533  * @tc.type: FUNC
534  * @tc.require:
535  */
536 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam006, TestSize.Level0)
537 {
538     CALL_TEST_DEBUG;
539     MessageParcel replyParcel;
540     MessageParcel dataParcel;
541     int32_t ret = g_intentionService->SetParam(g_intention, DragRequestID::UPDATE_PREVIEW_STYLE_WITH_ANIMATION,
542         dataParcel, replyParcel);
543     EXPECT_EQ(ret, RET_ERR);
544 }
545 
546 /**
547  * @tc.name: IntentionServiceTest_SetParam007
548  * @tc.desc: Test SetParam
549  * @tc.type: FUNC
550  * @tc.require:
551  */
552 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam007, TestSize.Level0)
553 {
554     CALL_TEST_DEBUG;
555     MessageParcel replyParcel;
556     MessageParcel dataParcel;
557     int32_t ret = g_intentionService->SetParam(g_intention, DragRequestID::ENTER_TEXT_EDITOR_AREA,
558         dataParcel, replyParcel);
559     EXPECT_EQ(ret, RET_ERR);
560 }
561 
562 /**
563  * @tc.name: IntentionServiceTest_SetParam008
564  * @tc.desc: Test SetParam
565  * @tc.type: FUNC
566  * @tc.require:
567  */
568 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam008, TestSize.Level0)
569 {
570     CALL_TEST_DEBUG;
571     auto env = ContextService::GetInstance();
572     ASSERT_NE(env, nullptr);
573     std::optional<DragData> dragData = CreateDragData(
574         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
575     MessageParcel replyParcel;
576     MessageParcel dataParcel;
577     env->dragMgr_.dragState_ = DragState::START;
578     SetDragWindowVisibleParam param { true, true };
579     int32_t ret = param.Marshalling(dataParcel);
580     EXPECT_EQ(ret, READ_OK);
581     ret = g_intentionService->SetParam(Intention::DRAG, DragRequestID::SET_DRAG_WINDOW_VISIBLE,
582         dataParcel, replyParcel);
583     EXPECT_EQ(ret, RET_OK);
584     env->dragMgr_.dragState_ = DragState::STOP;
585     DRAG_DATA_MGR.dragData_ = {};
586 }
587 
588 /**
589  * @tc.name: IntentionServiceTest_SetParam009
590  * @tc.desc: Test SetParam
591  * @tc.type: FUNC
592  * @tc.require:
593  */
594 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam009, TestSize.Level0)
595 {
596     CALL_TEST_DEBUG;
597     auto env = ContextService::GetInstance();
598     ASSERT_NE(env, nullptr);
599     MessageParcel dataParcel;
600     MessageParcel replyParcel;
601     env->dragMgr_.dragState_ = DragState::START;
602     std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT);
603     ASSERT_NE(pixelMap, nullptr);
604     ShadowInfo shadowInfo = { pixelMap, 0, 0 };
605     std::string extraInfo;
606     UpdateShadowPicParam param { shadowInfo };
607     bool ret = param.Marshalling(dataParcel);;
608     EXPECT_EQ(ret, READ_OK);
609     ret = g_intentionService->SetParam(g_intention, DragRequestID::UPDATE_SHADOW_PIC,
610         dataParcel, replyParcel);
611     EXPECT_TRUE(ret);
612     env->dragMgr_.dragState_ = DragState::STOP;
613 }
614 
615 /**
616  * @tc.name: IntentionServiceTest_SetParam010
617  * @tc.desc: Test SetParam
618  * @tc.type: FUNC
619  * @tc.require:
620  */
621 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam010, TestSize.Level0)
622 {
623     CALL_TEST_DEBUG;
624     auto env = ContextService::GetInstance();
625     ASSERT_NE(env, nullptr);
626     MessageParcel dataParcel;
627     MessageParcel replyParcel;
628     env->dragMgr_.dragState_ = DragState::START;
629     PreviewStyle previewStyleIn;
630     previewStyleIn.types = { PreviewType::FOREGROUND_COLOR };
631     previewStyleIn.foregroundColor = FOREGROUND_COLOR_IN;
632     UpdatePreviewStyleParam param { previewStyleIn };
633     bool ret = param.Marshalling(dataParcel);;
634     EXPECT_EQ(ret, READ_OK);
635     ret = g_intentionService->SetParam(g_intention, DragRequestID::UPDATE_PREVIEW_STYLE,
636         dataParcel, replyParcel);
637     EXPECT_TRUE(ret);
638     env->dragMgr_.dragState_ = DragState::STOP;
639 }
640 
641 /**
642  * @tc.name: IntentionServiceTest_SetParam011
643  * @tc.desc: Test SetParam
644  * @tc.type: FUNC
645  * @tc.require:
646  */
647 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam011, TestSize.Level0)
648 {
649     CALL_TEST_DEBUG;
650     auto env = ContextService::GetInstance();
651     ASSERT_NE(env, nullptr);
652     MessageParcel dataParcel;
653     MessageParcel replyParcel;
654     env->dragMgr_.dragState_ = DragState::START;
655     PreviewStyle previewStyleIn;
656     previewStyleIn.types = { PreviewType::FOREGROUND_COLOR };
657     previewStyleIn.foregroundColor = FOREGROUND_COLOR_IN;
658     PreviewAnimation animationOut;
659     AssignToAnimation(animationOut);
660     UpdatePreviewAnimationParam param { previewStyleIn, animationOut };
661     bool ret = param.Marshalling(dataParcel);;
662     EXPECT_EQ(ret, READ_OK);
663     ret = g_intentionService->SetParam(Intention::DRAG, DragRequestID::UPDATE_PREVIEW_STYLE_WITH_ANIMATION,
664         dataParcel, replyParcel);
665     EXPECT_FALSE(ret);
666     env->dragMgr_.dragState_ = DragState::STOP;
667 }
668 
669 /**
670  * @tc.name: IntentionServiceTest_SetParam012
671  * @tc.desc: Test SetParam
672  * @tc.type: FUNC
673  * @tc.require:
674  */
675 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetParam012, TestSize.Level0)
676 {
677     CALL_TEST_DEBUG;
678     MessageParcel replyParcel;
679     MessageParcel dataParcel;
680     EnterTextEditorAreaParam param { true };
681     bool ret = param.Marshalling(dataParcel);;
682     EXPECT_EQ(ret, READ_OK);
683     ret = g_intentionService->SetParam(g_intention, DragRequestID::ENTER_TEXT_EDITOR_AREA, dataParcel, replyParcel);
684     EXPECT_EQ(ret, READ_OK);
685 }
686 
687 /**
688  * @tc.name: IntentionServiceTest_GetParam001
689  * @tc.desc: Test GetParam
690  * @tc.type: FUNC
691  * @tc.require:
692  */
693 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam001, TestSize.Level0)
694 {
695     CALL_TEST_DEBUG;
696     int32_t ret = RET_ERR;
697     MessageParcel replyParcel;
698     MessageParcel dataParcel;
699     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
700         DragRequestID::GET_DRAG_TARGET_PID, DragRequestID::GET_UDKEY,
701         DragRequestID::GET_SHADOW_OFFSET, DragRequestID::GET_DRAG_DATA,
702         DragRequestID::GET_DRAG_STATE, DragRequestID::GET_DRAG_SUMMARY,
703         DragRequestID::GET_DRAG_ACTION, DragRequestID::GET_EXTRA_INFO};
704     for (const auto& dragRequestID : dragRequestIDs) {
705         if (dragRequestID == DragRequestID::UNKNOWN_DRAG_ACTION ||
706             dragRequestID == DragRequestID::GET_UDKEY ||
707             dragRequestID == DragRequestID::GET_DRAG_DATA ||
708             dragRequestID == DragRequestID::GET_DRAG_SUMMARY ||
709             dragRequestID == DragRequestID::GET_DRAG_ACTION||
710             dragRequestID == DragRequestID::GET_EXTRA_INFO) {
711                 ret = g_intentionService->GetParam(Intention::DRAG, dragRequestID, dataParcel, replyParcel);
712                 if (ret == RET_OK) {
713                     GTEST_LOG_(INFO) << "dragRequestID: " << dragRequestID;
714                 }
715                 EXPECT_EQ(ret, RET_ERR);
716         } else {
717             ret = g_intentionService->GetParam(Intention::DRAG, dragRequestID, dataParcel, replyParcel);
718             EXPECT_EQ(ret, RET_OK);
719         }
720     }
721 }
722 
723 /**
724  * @tc.name: IntentionServiceTest_GetParam002
725  * @tc.desc: Test GetParam
726  * @tc.type: FUNC
727  * @tc.require:
728  */
729 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam002, TestSize.Level0)
730 {
731     CALL_TEST_DEBUG;
732     MessageParcel replyParcel;
733     MessageParcel dataParcel;
734     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_TARGET_PID,
735         dataParcel, replyParcel);
736     EXPECT_EQ(ret, RET_OK);
737 }
738 
739 /**
740  * @tc.name: IntentionServiceTest_GetParam003
741  * @tc.desc: Test GetParam
742  * @tc.type: FUNC
743  * @tc.require:
744  */
745 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam003, TestSize.Level0)
746 {
747     CALL_TEST_DEBUG;
748     std::optional<DragData> dragData = CreateDragData(
749         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
750     DRAG_DATA_MGR.Init(dragData.value());
751     MessageParcel replyParcel;
752     MessageParcel dataParcel;
753     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_UDKEY,
754         dataParcel, replyParcel);
755     EXPECT_EQ(ret, RET_OK);
756     DRAG_DATA_MGR.dragData_ = {};
757 }
758 
759 /**
760  * @tc.name: IntentionServiceTest_GetParam004
761  * @tc.desc: Test GetParam
762  * @tc.type: FUNC
763  * @tc.require:
764  */
765 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam004, TestSize.Level0)
766 {
767     CALL_TEST_DEBUG;
768     MessageParcel replyParcel;
769     MessageParcel dataParcel;
770     int32_t ret = g_intentionService->GetParam(g_intention, DragRequestID::GET_SHADOW_OFFSET,
771         dataParcel, replyParcel);
772     EXPECT_EQ(ret, RET_ERR);
773 }
774 
775 /**
776  * @tc.name: IntentionServiceTest_GetParam005
777  * @tc.desc: Test GetParam
778  * @tc.type: FUNC
779  * @tc.require:
780  */
781 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam005, TestSize.Level0)
782 {
783     CALL_TEST_DEBUG;
784     MessageParcel replyParcel;
785     MessageParcel dataParcel;
786     int32_t ret = g_intentionService->GetParam(g_intention, DragRequestID::GET_DRAG_DATA,
787         dataParcel, replyParcel);
788     EXPECT_EQ(ret, RET_ERR);
789 }
790 
791 /**
792  * @tc.name: IntentionServiceTest_GetParam006
793  * @tc.desc: Test GetParam
794  * @tc.type: FUNC
795  * @tc.require:
796  */
797 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam006, TestSize.Level0)
798 {
799     CALL_TEST_DEBUG;
800     MessageParcel replyParcel;
801     MessageParcel dataParcel;
802     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_STATE,
803         dataParcel, replyParcel);
804     EXPECT_EQ(ret, RET_OK);
805 }
806 
807 /**
808  * @tc.name: IntentionServiceTest_GetParam007
809  * @tc.desc: Test GetParam
810  * @tc.type: FUNC
811  * @tc.require:
812  */
813 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam007, TestSize.Level0)
814 {
815     CALL_TEST_DEBUG;
816     MessageParcel replyParcel;
817     MessageParcel dataParcel;
818     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_SUMMARY,
819         dataParcel, replyParcel);
820     EXPECT_EQ(ret, RET_ERR);
821 }
822 
823 /**
824  * @tc.name: IntentionServiceTest_GetParam008
825  * @tc.desc: Test GetParam
826  * @tc.type: FUNC
827  * @tc.require:
828  */
829 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam008, TestSize.Level0)
830 {
831     CALL_TEST_DEBUG;
832     MessageParcel replyParcel;
833     MessageParcel dataParcel;
834     int32_t ret = g_intentionService->GetParam(g_intention, DragRequestID::GET_DRAG_ACTION,
835         dataParcel, replyParcel);
836     EXPECT_EQ(ret, RET_ERR);
837 }
838 
839 /**
840  * @tc.name: IntentionServiceTest_GetParam009
841  * @tc.desc: Test GetParam
842  * @tc.type: FUNC
843  * @tc.require:
844  */
845 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam009, TestSize.Level0)
846 {
847     CALL_TEST_DEBUG;
848     MessageParcel replyParcel;
849     MessageParcel dataParcel;
850     int32_t ret = g_intentionService->GetParam(g_intention, DragRequestID::GET_EXTRA_INFO, dataParcel, replyParcel);
851     EXPECT_EQ(ret, RET_ERR);
852 }
853 
854 /**
855  * @tc.name: IntentionServiceTest_GetParam010
856  * @tc.desc: Test GetParam
857  * @tc.type: FUNC
858  * @tc.require:
859  */
860 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam010, TestSize.Level0)
861 {
862     CALL_TEST_DEBUG;
863     MessageParcel replyParcel;
864     MessageParcel dataParcel;
865     int32_t ret = g_intentionService->GetParam(g_intention, DragRequestID::GET_UDKEY, dataParcel, replyParcel);
866     EXPECT_EQ(ret, RET_ERR);
867 }
868 
869 /**
870  * @tc.name: IntentionServiceTest_GetParam011
871  * @tc.desc: Test GetParam
872  * @tc.type: FUNC
873  * @tc.require:
874  */
875 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam011, TestSize.Level0)
876 {
877     CALL_TEST_DEBUG;
878     std::optional<DragData> dragData = CreateDragData(
879         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
880     DRAG_DATA_MGR.Init(dragData.value());
881     MessageParcel replyParcel;
882     MessageParcel dataParcel;
883     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_SHADOW_OFFSET,
884         dataParcel, replyParcel);
885     EXPECT_EQ(ret, RET_OK);
886     DRAG_DATA_MGR.dragData_ = {};
887 }
888 
889 /**
890  * @tc.name: IntentionServiceTest_GetParam012
891  * @tc.desc: Test GetParam
892  * @tc.type: FUNC
893  * @tc.require:
894  */
895 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam012, TestSize.Level0)
896 {
897     CALL_TEST_DEBUG;
898     std::optional<DragData> dragData = CreateDragData(
899         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
900     DRAG_DATA_MGR.Init(dragData.value());
901     MessageParcel replyParcel;
902     MessageParcel dataParcel;
903     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_EXTRA_INFO,
904         dataParcel, replyParcel);
905     EXPECT_EQ(ret, RET_OK);
906     DRAG_DATA_MGR.dragData_ = {};
907 }
908 
909 /**
910  * @tc.name: IntentionServiceTest_GetParam013
911  * @tc.desc: Test GetParam
912  * @tc.type: FUNC
913  * @tc.require:
914  */
915 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam013, TestSize.Level0)
916 {
917     CALL_TEST_DEBUG;
918     auto env = ContextService::GetInstance();
919     ASSERT_NE(env, nullptr);
920     MessageParcel dataParcel;
921     MessageParcel replyParcel;
922     env->dragMgr_.dragState_ = DragState::START;
923     UpdateDragStyleParam param { DragCursorStyle::COPY, -1 };
924     bool ret = param.Marshalling(dataParcel);
925     EXPECT_EQ(ret, READ_OK);
926     ret = g_intentionService->GetParam(g_intention, DragRequestID::UPDATE_DRAG_STYLE, dataParcel, replyParcel);
927     EXPECT_TRUE(ret);
928     env->dragMgr_.dragState_ = DragState::STOP;
929 }
930 
931 /**
932  * @tc.name: IntentionServiceTest_GetParam014
933  * @tc.desc: Test GetParam
934  * @tc.type: FUNC
935  * @tc.require:
936  */
937 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam014, TestSize.Level0)
938 {
939     CALL_TEST_DEBUG;
940     auto env = ContextService::GetInstance();
941     ASSERT_NE(env, nullptr);
942     MessageParcel dataParcel;
943     MessageParcel replyParcel;
944     env->dragMgr_.dragState_ = DragState::START;
945     GetDragTargetPidReply targetPidReply { IPCSkeleton::GetCallingPid() };
946     bool ret = targetPidReply.Marshalling(dataParcel);
947     EXPECT_EQ(ret, READ_OK);
948     ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_TARGET_PID, dataParcel, replyParcel);
949     EXPECT_FALSE(ret);
950     env->dragMgr_.dragState_ = DragState::STOP;
951 }
952 
953 /**
954  * @tc.name: IntentionServiceTest_GetParam015
955  * @tc.desc: Test GetParam
956  * @tc.type: FUNC
957  * @tc.require:
958  */
959 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam015, TestSize.Level0)
960 {
961     CALL_TEST_DEBUG;
962     auto env = ContextService::GetInstance();
963     ASSERT_NE(env, nullptr);
964     std::optional<DragData> dragData = CreateDragData(
965         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
966     env->dragMgr_.dragState_ = DragState::START;
967     MessageParcel replyParcel;
968     MessageParcel dataParcel;
969     DRAG_DATA_MGR.Init(dragData.value());
970     int32_t ret = g_intentionService->GetParam(g_intention, DragRequestID::GET_DRAG_DATA, dataParcel, replyParcel);
971     EXPECT_EQ(ret, RET_OK);
972     DRAG_DATA_MGR.dragData_ = {};
973     ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_DATA, dataParcel, replyParcel);
974     EXPECT_EQ(ret, RET_ERR);
975     env->dragMgr_.dragState_ = DragState::STOP;
976 }
977 
978 /**
979  * @tc.name: IntentionServiceTest_GetParam016
980  * @tc.desc: Test GetParam
981  * @tc.type: FUNC
982  * @tc.require:
983  */
984 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam016, TestSize.Level0)
985 {
986     CALL_TEST_DEBUG;
987     auto env = ContextService::GetInstance();
988     ASSERT_NE(env, nullptr);
989     env->dragMgr_.dragState_ = DragState::ERROR;
990     MessageParcel replyParcel;
991     MessageParcel dataParcel;
992     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_STATE,
993         dataParcel, replyParcel);
994     EXPECT_EQ(ret, RET_ERR);
995     env->dragMgr_.dragState_ = DragState::START;
996     ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_STATE, dataParcel, replyParcel);
997     EXPECT_EQ(ret, RET_OK);
998     env->dragMgr_.dragState_ = DragState::STOP;
999 }
1000 
1001 /**
1002  * @tc.name: IntentionServiceTest_GetParam017
1003  * @tc.desc: Test GetParam
1004  * @tc.type: FUNC
1005  * @tc.require:
1006  */
1007 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam017, TestSize.Level0)
1008 {
1009     CALL_TEST_DEBUG;
1010     auto env = ContextService::GetInstance();
1011     ASSERT_NE(env, nullptr);
1012     env->dragMgr_.dragState_ = DragState::ERROR;
1013     MessageParcel replyParcel;
1014     MessageParcel dataParcel;
1015     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_ACTION,
1016         dataParcel, replyParcel);
1017     EXPECT_EQ(ret, RET_ERR);
1018     env->dragMgr_.dragState_ = DragState::START;
1019     ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_DRAG_ACTION, dataParcel, replyParcel);
1020     EXPECT_EQ(ret, RET_OK);
1021     env->dragMgr_.dragState_ = DragState::STOP;
1022 }
1023 
1024 /**
1025  * @tc.name: IntentionServiceTest_GetParam018
1026  * @tc.desc: Test GetParam
1027  * @tc.type: FUNC
1028  * @tc.require:
1029  */
1030 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetParam018, TestSize.Level0)
1031 {
1032     CALL_TEST_DEBUG;
1033     auto env = ContextService::GetInstance();
1034     ASSERT_NE(env, nullptr);
1035     std::optional<DragData> dragData = CreateDragData(
1036         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
1037     MessageParcel replyParcel;
1038     MessageParcel dataParcel;
1039     DRAG_DATA_MGR.Init(dragData.value());
1040     int32_t ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_EXTRA_INFO,
1041         dataParcel, replyParcel);
1042     EXPECT_EQ(ret, RET_OK);
1043     DRAG_DATA_MGR.dragData_ = {};
1044     ret = g_intentionService->GetParam(Intention::DRAG, DragRequestID::GET_EXTRA_INFO, dataParcel, replyParcel);
1045     EXPECT_EQ(ret, RET_ERR);
1046 }
1047 } // namespace DeviceStatus
1048 } // namespace Msdp
1049 } // namespace OHOS