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