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 "drag_server_test.h"
18 
19 #include "devicestatus_service.h"
20 #include "drag_data_manager.h"
21 #include "drag_params.h"
22 #include "drag_server.h"
23 #include "interaction_manager.h"
24 #include "ipc_skeleton.h"
25 #include "singleton.h"
26 #include "tunnel_client.h"
27 #include "accesstoken_kit.h"
28 #include "nativetoken_kit.h"
29 #include "token_setproc.h"
30 
31 namespace OHOS {
32 namespace Msdp {
33 namespace DeviceStatus {
34 using namespace testing::ext;
35 namespace {
36 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
37 constexpr int32_t POINTER_ID { 0 };
38 constexpr int32_t DRAG_NUM_ONE { 1 };
39 constexpr int32_t SHADOW_NUM_ONE { 1 };
40 constexpr int32_t PIXEL_MAP_WIDTH { 3 };
41 constexpr int32_t PIXEL_MAP_HEIGHT { 3 };
42 constexpr int32_t WINDOW_ID { -1 };
43 constexpr int32_t READ_OK { 1 };
44 constexpr uint32_t DEFAULT_ICON_COLOR { 0xFF };
45 const std::string FILTER_INFO { "Undefined filter info" };
46 const std::string UD_KEY { "Unified data key" };
47 const std::string EXTRA_INFO { "Undefined extra info" };
48 const std::string CURVE_NAME { "cubic-bezier" };
49 constexpr int32_t FOREGROUND_COLOR_IN { 0x33FF0000 };
50 constexpr int32_t DISPLAY_ID { 0 };
51 constexpr int32_t DISPLAY_X { 50 };
52 constexpr int32_t DISPLAY_Y { 50 };
53 constexpr int32_t INT32_BYTE { 4 };
54 int32_t g_shadowinfo_x { 0 };
55 int32_t g_shadowinfo_y { 0 };
56 ContextService *g_instance = nullptr;
57 DelegateTasks g_delegateTasks;
58 DeviceManager g_devMgr;
59 TimerManager g_timerMgr;
60 DragManager g_dragMgr;
61 DragClient g_dragClient;
62 SocketSessionManager g_socketSessionMgr;
63 std::unique_ptr<IInputAdapter> g_input { nullptr };
64 std::unique_ptr<IPluginManager> g_pluginMgr { nullptr };
65 std::unique_ptr<IDSoftbusAdapter> g_dsoftbus { nullptr };
66 constexpr int32_t ANIMATION_DURATION { 500 };
67 constexpr int32_t MAX_PIXEL_MAP_WIDTH { 600 };
68 constexpr int32_t MAX_PIXEL_MAP_HEIGHT { 600 };
69 constexpr bool HAS_CANCELED_ANIMATION { true };
70 constexpr bool HAS_CUSTOM_ANIMATION { true };
71 Intention g_intention { Intention::UNKNOWN_INTENTION };
72 std::shared_ptr<DragServer> g_dragServer { nullptr };
73 std::shared_ptr<DragServer> g_dragServerOne { nullptr };
74 IContext *g_context { nullptr };
75 IContext *g_contextOne { nullptr };
76 std::shared_ptr<TunnelClient> g_tunnel { nullptr };
77 Security::AccessToken::HapInfoParams g_testInfoParms = {
78     .userID = 1,
79     .bundleName = "drag_server_test",
80     .instIndex = 0,
81     .appIDDesc = "test"
82 };
83 
84 Security::AccessToken::HapPolicyParams g_testPolicyPrams = {
85     .apl = Security::AccessToken::APL_NORMAL,
86     .domain = "test.domain",
87     .permList = {},
88     .permStateList = {}
89 };
90 } // namespace
91 
ContextService()92 ContextService::ContextService()
93 {
94 }
95 
~ContextService()96 ContextService::~ContextService()
97 {
98 }
99 
GetDelegateTasks()100 IDelegateTasks& ContextService::GetDelegateTasks()
101 {
102     return g_delegateTasks;
103 }
104 
GetDeviceManager()105 IDeviceManager& ContextService::GetDeviceManager()
106 {
107     return g_devMgr;
108 }
109 
GetTimerManager()110 ITimerManager& ContextService::GetTimerManager()
111 {
112     return g_timerMgr;
113 }
114 
GetDragManager()115 IDragManager& ContextService::GetDragManager()
116 {
117     return g_dragMgr;
118 }
119 
GetInstance()120 ContextService* ContextService::GetInstance()
121 {
122     static std::once_flag flag;
123     std::call_once(flag, [&]() {
124         ContextService *cooContext = new (std::nothrow) ContextService();
125         CHKPL(cooContext);
126         g_instance = cooContext;
127     });
128     return g_instance;
129 }
130 
GetSocketSessionManager()131 ISocketSessionManager& ContextService::GetSocketSessionManager()
132 {
133     return g_socketSessionMgr;
134 }
135 
GetPluginManager()136 IPluginManager& ContextService::GetPluginManager()
137 {
138     return *g_pluginMgr;
139 }
140 
GetInput()141 IInputAdapter& ContextService::GetInput()
142 {
143     return *g_input;
144 }
145 
GetDSoftbus()146 IDSoftbusAdapter& ContextService::GetDSoftbus()
147 {
148     return *g_dsoftbus;
149 }
150 
SetUpTestCase()151 void DragServerTest::SetUpTestCase() {}
152 
SetUp()153 void DragServerTest::SetUp()
154 {
155     g_context = ContextService::GetInstance();
156     g_dragServer = std::make_shared<DragServer>(g_context);
157     g_dragServerOne = std::make_shared<DragServer>(g_contextOne);
158     g_tunnel = std::make_shared<TunnelClient>();
159 }
160 
TearDown()161 void DragServerTest::TearDown()
162 {
163     g_dragServer = nullptr;
164     g_context = nullptr;
165     g_tunnel = nullptr;
166     g_dragServerOne = nullptr;
167     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
168 }
169 
CreatePixelMap(int32_t width,int32_t height)170 std::shared_ptr<Media::PixelMap> DragServerTest::CreatePixelMap(int32_t width, int32_t height)
171 {
172     CALL_DEBUG_ENTER;
173     if (width <= 0 || width > MAX_PIXEL_MAP_WIDTH || height <= 0 || height > MAX_PIXEL_MAP_HEIGHT) {
174         FI_HILOGE("invalid, height:%{public}d, width:%{public}d", height, width);
175         return nullptr;
176     }
177     Media::InitializationOptions opts;
178     opts.size.width = width;
179     opts.size.height = height;
180     opts.pixelFormat = Media::PixelFormat::BGRA_8888;
181     opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
182     opts.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE;
183 
184     int32_t colorLen = width * height;
185     uint32_t *pixelColors = new (std::nothrow) uint32_t[BUFF_SIZE];
186     CHKPP(pixelColors);
187     int32_t colorByteCount = colorLen * INT32_BYTE;
188     errno_t ret = memset_s(pixelColors, BUFF_SIZE, DEFAULT_ICON_COLOR, colorByteCount);
189     if (ret != EOK) {
190         FI_HILOGE("memset_s failed");
191         delete[] pixelColors;
192         return nullptr;
193     }
194     std::shared_ptr<Media::PixelMap> pixelMap = Media::PixelMap::Create(pixelColors, colorLen, opts);
195     if (pixelMap == nullptr) {
196         FI_HILOGE("Create pixelMap failed");
197         delete[] pixelColors;
198         return nullptr;
199     }
200     delete[] pixelColors;
201     return pixelMap;
202 }
203 
CreateDragData(int32_t sourceType,int32_t pointerId,int32_t dragNum,bool hasCoordinateCorrected,int32_t shadowNum)204 std::optional<DragData> DragServerTest::CreateDragData(int32_t sourceType,
205     int32_t pointerId, int32_t dragNum, bool hasCoordinateCorrected, int32_t shadowNum)
206 {
207     CALL_DEBUG_ENTER;
208     DragData dragData;
209     for (int32_t i = 0; i < shadowNum; i++) {
210         std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT);
211         if (pixelMap == nullptr) {
212             FI_HILOGE("pixelMap nullptr");
213             return std::nullopt;
214         }
215         dragData.shadowInfos.push_back({ pixelMap, g_shadowinfo_x, g_shadowinfo_y });
216     }
217     dragData.buffer = std::vector<uint8_t>(MAX_BUFFER_SIZE, 0);
218     dragData.extraInfo = FILTER_INFO;
219     dragData.udKey = UD_KEY;
220     dragData.sourceType = sourceType;
221     dragData.extraInfo = EXTRA_INFO;
222     dragData.displayId = DISPLAY_ID;
223     dragData.pointerId = pointerId;
224     dragData.dragNum = dragNum;
225     dragData.displayX = DISPLAY_X;
226     dragData.displayY = DISPLAY_Y;
227     dragData.hasCoordinateCorrected = hasCoordinateCorrected;
228     dragData.hasCanceledAnimation = HAS_CANCELED_ANIMATION;
229     return dragData;
230 }
231 
NativeTokenGet()232 uint64_t NativeTokenGet()
233 {
234     uint64_t tokenId;
235     NativeTokenInfoParams infoInstance = {
236         .dcapsNum = 0,
237         .permsNum = 0,
238         .aclsNum = 0,
239         .dcaps = nullptr,
240         .perms = nullptr,
241         .acls = nullptr,
242         .aplStr = "system_basic",
243     };
244 
245     infoInstance.processName = " DragServerTest";
246     tokenId = GetAccessTokenId(&infoInstance);
247     SetSelfTokenID(tokenId);
248     OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
249     return tokenId;
250 }
251 class TestStartDragListener : public IStartDragListener {
252 public:
TestStartDragListener(std::function<void (const DragNotifyMsg &)> function)253     explicit TestStartDragListener(std::function<void(const DragNotifyMsg&)> function) : function_(function) { }
OnDragEndMessage(const DragNotifyMsg & msg)254     void OnDragEndMessage(const DragNotifyMsg &msg) override
255     {
256         FI_HILOGD("DisplayX:%{public}d, displayY:%{public}d, targetPid:%{public}d, result:%{public}d",
257             msg.displayX, msg.displayY, msg.targetPid, static_cast<int32_t>(msg.result));
258         if (function_ != nullptr) {
259             function_(msg);
260         }
261         FI_HILOGD("Test OnDragEndMessage");
262     }
263 
OnHideIconMessage()264     void OnHideIconMessage() override
265     {
266         FI_HILOGD("Test OnHideIconMessage");
267     }
268 private:
269     std::function<void(const DragNotifyMsg&)> function_;
270 };
271 
272 class DragListenerTest : public IDragListener {
273 public:
DragListenerTest()274     DragListenerTest() {}
DragListenerTest(const std::string & name)275     explicit DragListenerTest(const std::string& name) : moduleName_(name) {}
OnDragMessage(DragState state)276     void OnDragMessage(DragState state) override
277     {
278         if (moduleName_.empty()) {
279             moduleName_ = std::string("DragListenerTest");
280         }
281         FI_HILOGD("%{public}s, state:%{public}s", moduleName_.c_str(), PrintDragMessage(state).c_str());
282     }
283 private:
PrintDragMessage(DragState state)284     std::string PrintDragMessage(DragState state)
285     {
286         std::string type = "unknow";
287         const std::map<DragState, std::string> stateType = {
288             { DragState::ERROR, "error"},
289             { DragState::START, "start"},
290             { DragState::STOP, "stop"},
291             { DragState::CANCEL, "cancel"}
292         };
293         auto item = stateType.find(state);
294         if (item != stateType.end()) {
295             type = item->second;
296         }
297         return type;
298     }
299 private:
300     std::string moduleName_;
301 };
302 
AssignToAnimation(PreviewAnimation & animation)303 void DragServerTest::AssignToAnimation(PreviewAnimation &animation)
304 {
305     animation.duration = ANIMATION_DURATION;
306     animation.curveName = CURVE_NAME;
307     animation.curve = { 0.33, 0, 0.67, 1 };
308 }
309 
310 /**
311  * @tc.name: DragServerTest1
312  * @tc.desc: Drag Drawing
313  * @tc.type: FUNC
314  * @tc.require:
315  */
316 HWTEST_F(DragServerTest, DragServerTest1, TestSize.Level0)
317 {
318     CALL_TEST_DEBUG;
319     CallingContext context {
320         .intention = g_intention,
321         .tokenId = IPCSkeleton::GetCallingTokenID(),
322         .uid = IPCSkeleton::GetCallingUid(),
323         .pid = IPCSkeleton::GetCallingPid(),
324     };
325     MessageParcel datas;
326     MessageParcel reply;
327     int32_t ret = g_dragServer->Enable(context, datas, reply);
328     EXPECT_EQ(ret, RET_ERR);
329 }
330 
331 /**
332  * @tc.name: DragServerTest2
333  * @tc.desc: Drag Drawing
334  * @tc.type: FUNC
335  * @tc.require:
336  */
337 HWTEST_F(DragServerTest, DragServerTest2, TestSize.Level0)
338 {
339     CALL_TEST_DEBUG;
340     CallingContext context {
341         .intention = g_intention,
342         .tokenId = IPCSkeleton::GetCallingTokenID(),
343         .uid = IPCSkeleton::GetCallingUid(),
344         .pid = IPCSkeleton::GetCallingPid(),
345     };
346     MessageParcel reply;
347     MessageParcel datas;
348     int32_t ret = g_dragServer->Disable(context, datas, reply);
349     EXPECT_EQ(ret, RET_ERR);
350 }
351 
352 /**
353  * @tc.name: DragServerTest3
354  * @tc.desc: Drag Drawing
355  * @tc.type: FUNC
356  * @tc.require:
357  */
358 HWTEST_F(DragServerTest, DragServerTest3, TestSize.Level0)
359 {
360     CALL_TEST_DEBUG;
361     std::optional<DragData> dragData = CreateDragData(
362         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
363     CallingContext context {
364         .intention = g_intention,
365         .tokenId = IPCSkeleton::GetCallingTokenID(),
366         .uid = IPCSkeleton::GetCallingUid(),
367         .pid = IPCSkeleton::GetCallingPid(),
368     };
369     MessageParcel reply;
370     MessageParcel datas;
371     int32_t ret = g_dragServer->Start(context, datas, reply);
372     EXPECT_EQ(ret, RET_ERR);
373 }
374 
375 /**
376  * @tc.name: DragServerTest4
377  * @tc.desc: Drag Drawing
378  * @tc.type: FUNC
379  * @tc.require:
380  */
381 HWTEST_F(DragServerTest, DragServerTest4, TestSize.Level0)
382 {
383     CALL_TEST_DEBUG;
384     CallingContext context {
385         .intention = g_intention,
386         .tokenId = IPCSkeleton::GetCallingTokenID(),
387         .uid = IPCSkeleton::GetCallingUid(),
388         .pid = IPCSkeleton::GetCallingPid(),
389     };
390     MessageParcel reply;
391     MessageParcel datas;
392     int32_t ret = g_dragServer->Stop(context, datas, reply);
393     EXPECT_EQ(ret, RET_ERR);
394 }
395 
396 /**
397  * @tc.name: DragServerTest5
398  * @tc.desc: Drag Drawing
399  * @tc.type: FUNC
400  * @tc.require:
401  */
402 HWTEST_F(DragServerTest, DragServerTest5, TestSize.Level0)
403 {
404     CALL_TEST_DEBUG;
405     CallingContext context {
406         .intention = g_intention,
407         .tokenId = IPCSkeleton::GetCallingTokenID(),
408         .uid = IPCSkeleton::GetCallingUid(),
409         .pid = IPCSkeleton::GetCallingPid(),
410     };
411     int32_t ret = -1;
412     MessageParcel reply;
413     MessageParcel datas;
414     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
415         DragRequestID::ADD_DRAG_LISTENER, DragRequestID::ADD_SUBSCRIPT_LISTENER};
416     for (const auto& dragRequestID : dragRequestIDs) {
417         GTEST_LOG_(INFO) << "dragRequestID: " << dragRequestID;
418         ret = g_dragServer->AddWatch(context, dragRequestID, datas, reply);
419         EXPECT_EQ(ret, RET_ERR);
420     }
421 }
422 
423 /**
424  * @tc.name: DragServerTest6
425  * @tc.desc: Drag Drawing
426  * @tc.type: FUNC
427  * @tc.require:
428  */
429 HWTEST_F(DragServerTest, DragServerTest6, TestSize.Level0)
430 {
431     CALL_TEST_DEBUG;
432     CallingContext context {
433         .intention = g_intention,
434         .tokenId = IPCSkeleton::GetCallingTokenID(),
435         .uid = IPCSkeleton::GetCallingUid(),
436         .pid = IPCSkeleton::GetCallingPid(),
437     };
438     MessageParcel reply;
439     MessageParcel datas;
440     int32_t ret = -1;
441     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
442         DragRequestID::REMOVE_DRAG_LISTENER, DragRequestID::REMOVE_SUBSCRIPT_LISTENER};
443     for (const auto& dragRequestID : dragRequestIDs) {
444         GTEST_LOG_(INFO) << "dragRequestID: " << dragRequestID;
445         ret = g_dragServer->RemoveWatch(context, dragRequestID, datas, reply);
446         EXPECT_EQ(ret, RET_ERR);
447     }
448 }
449 
450 /**
451  * @tc.name: DragServerTest7
452  * @tc.desc: Drag Drawing
453  * @tc.type: FUNC
454  * @tc.require:
455  */
456 HWTEST_F(DragServerTest, DragServerTest7, TestSize.Level0)
457 {
458     CALL_TEST_DEBUG;
459     CallingContext context {
460         .intention = g_intention,
461         .tokenId = IPCSkeleton::GetCallingTokenID(),
462         .uid = IPCSkeleton::GetCallingUid(),
463         .pid = IPCSkeleton::GetCallingPid(),
464     };
465     MessageParcel reply;
466     MessageParcel datas;
467     int32_t ret = -1;
468     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
469         DragRequestID::SET_DRAG_WINDOW_VISIBLE, DragRequestID::UPDATE_DRAG_STYLE,
470         DragRequestID::UPDATE_SHADOW_PIC, DragRequestID::UPDATE_PREVIEW_STYLE,
471         DragRequestID::UPDATE_PREVIEW_STYLE_WITH_ANIMATION, DragRequestID::SET_DRAG_WINDOW_SCREEN_ID};
472     for (const auto& dragRequestID : dragRequestIDs) {
473         GTEST_LOG_(INFO) << "dragRequestID: " << dragRequestID;
474         ret = g_dragServer->SetParam(context, dragRequestID, datas, reply);
475         EXPECT_EQ(ret, RET_ERR);
476     }
477 }
478 
479 /**
480  * @tc.name: DragServerTest8
481  * @tc.desc: Drag Drawing
482  * @tc.type: FUNC
483  * @tc.require:
484  */
485 HWTEST_F(DragServerTest, DragServerTest8, TestSize.Level0)
486 {
487     CALL_TEST_DEBUG;
488     int32_t ret = -1;
489     CallingContext context {
490         .intention = g_intention,
491         .tokenId = IPCSkeleton::GetCallingTokenID(),
492         .uid = IPCSkeleton::GetCallingUid(),
493         .pid = IPCSkeleton::GetCallingPid(),
494     };
495     MessageParcel reply;
496     MessageParcel datas;
497     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
498         DragRequestID::GET_DRAG_TARGET_PID, DragRequestID::GET_UDKEY,
499         DragRequestID::GET_SHADOW_OFFSET, DragRequestID::GET_DRAG_DATA,
500         DragRequestID::GET_DRAG_STATE, DragRequestID::GET_DRAG_SUMMARY,
501         DragRequestID::GET_DRAG_ACTION, DragRequestID::GET_EXTRA_INFO};
502     for (const auto& dragRequestID : dragRequestIDs) {
503         GTEST_LOG_(INFO) << "dragRequestID: " << dragRequestID;
504         if (dragRequestID == DragRequestID::UNKNOWN_DRAG_ACTION ||
505             dragRequestID == DragRequestID::GET_UDKEY ||
506             dragRequestID == DragRequestID::GET_SHADOW_OFFSET ||
507             dragRequestID == DragRequestID::GET_DRAG_SUMMARY ||
508             dragRequestID == DragRequestID::GET_DRAG_DATA ||
509             dragRequestID == DragRequestID::GET_DRAG_ACTION||
510             dragRequestID == DragRequestID::GET_EXTRA_INFO) {
511                 ret = g_dragServer->GetParam(context, dragRequestID, datas, reply);
512                 EXPECT_EQ(ret, RET_ERR);
513         } else {
514             ret = g_dragServer->GetParam(context, dragRequestID, datas, reply);
515             EXPECT_EQ(ret, RET_OK);
516         }
517     }
518 }
519 
520 /**
521  * @tc.name: DragServerTest9
522  * @tc.desc: Drag Drawing
523  * @tc.type: FUNC
524  * @tc.require:
525  */
526 HWTEST_F(DragServerTest, DragServerTest9, TestSize.Level0)
527 {
528     CALL_TEST_DEBUG;
529     int32_t ret = -1;
530     CallingContext context {
531         .intention = g_intention,
532         .tokenId = IPCSkeleton::GetCallingTokenID(),
533         .uid = IPCSkeleton::GetCallingUid(),
534         .pid = IPCSkeleton::GetCallingPid(),
535     };
536     MessageParcel datas;
537     MessageParcel reply;
538     std::vector<DragRequestID> dragRequestIDs = {DragRequestID::UNKNOWN_DRAG_ACTION,
539         DragRequestID::ADD_PRIVILEGE, DragRequestID::ENTER_TEXT_EDITOR_AREA,
540         DragRequestID::ROTATE_DRAG_WINDOW_SYNC, DragRequestID::ERASE_MOUSE_ICON,
541         DragRequestID::SET_MOUSE_DRAG_MONITOR_STATE};
542     for (const auto& dragRequestID : dragRequestIDs) {
543         GTEST_LOG_(INFO) << "dragRequestID: " << dragRequestID;
544         ret = g_dragServer->Control(context, dragRequestID, datas, reply);
545         EXPECT_EQ(ret, RET_ERR);
546     }
547 }
548 
549 /**
550  * @tc.name: DragServerTest10
551  * @tc.desc: Drag Drawing
552  * @tc.type: FUNC
553  * @tc.require:
554  */
555 HWTEST_F(DragServerTest, DragServerTest10, TestSize.Level0)
556 {
557     CALL_TEST_DEBUG;
558     CallingContext context {
559         .intention = g_intention,
560         .tokenId = IPCSkeleton::GetCallingTokenID(),
561         .uid = IPCSkeleton::GetCallingUid(),
562         .pid = IPCSkeleton::GetCallingPid(),
563     };
564     MessageParcel reply;
565     MessageParcel datas;
566     int32_t ret = g_dragServer->SetDragWindowVisible(context, datas, reply);
567     EXPECT_EQ(ret, RET_ERR);
568 }
569 
570 /**
571  * @tc.name: DragServerTest11
572  * @tc.desc: Drag Drawing
573  * @tc.type: FUNC
574  * @tc.require:
575  */
576 HWTEST_F(DragServerTest, DragServerTest11, TestSize.Level0)
577 {
578     CALL_TEST_DEBUG;
579     CallingContext context {
580         .intention = g_intention,
581         .tokenId = IPCSkeleton::GetCallingTokenID(),
582         .uid = IPCSkeleton::GetCallingUid(),
583         .pid = IPCSkeleton::GetCallingPid(),
584     };
585     MessageParcel reply;
586     MessageParcel datas;
587     int32_t ret = g_dragServer->UpdateDragStyle(context, datas, reply);
588     EXPECT_EQ(ret, RET_ERR);
589 }
590 
591 /**
592  * @tc.name: DragServerTest12
593  * @tc.desc: Drag Drawing
594  * @tc.type: FUNC
595  * @tc.require:
596  */
597 HWTEST_F(DragServerTest, DragServerTest12, TestSize.Level0)
598 {
599     CALL_TEST_DEBUG;
600     CallingContext context {
601         .intention = g_intention,
602         .tokenId = IPCSkeleton::GetCallingTokenID(),
603         .uid = IPCSkeleton::GetCallingUid(),
604         .pid = IPCSkeleton::GetCallingPid(),
605     };
606     MessageParcel reply;
607     MessageParcel datas;
608     int32_t ret = g_dragServer->UpdateShadowPic(context, datas, reply);
609     EXPECT_EQ(ret, RET_ERR);
610 }
611 
612 /**
613  * @tc.name: DragServerTest13
614  * @tc.desc: Drag Drawing
615  * @tc.type: FUNC
616  * @tc.require:
617  */
618 HWTEST_F(DragServerTest, DragServerTest13, TestSize.Level0)
619 {
620     CALL_TEST_DEBUG;
621     CallingContext context {
622         .intention = g_intention,
623         .tokenId = IPCSkeleton::GetCallingTokenID(),
624         .uid = IPCSkeleton::GetCallingUid(),
625         .pid = IPCSkeleton::GetCallingPid(),
626     };
627     MessageParcel reply;
628     MessageParcel datas;
629     int32_t ret = g_dragServer->UpdatePreviewStyle(context, datas, reply);
630     EXPECT_EQ(ret, RET_ERR);
631 }
632 
633 /**
634  * @tc.name: DragServerTest14
635  * @tc.desc: Drag Drawing
636  * @tc.type: FUNC
637  * @tc.require:
638  */
639 HWTEST_F(DragServerTest, DragServerTest14, TestSize.Level0)
640 {
641     CALL_TEST_DEBUG;
642     CallingContext context {
643         .intention = g_intention,
644         .tokenId = IPCSkeleton::GetCallingTokenID(),
645         .uid = IPCSkeleton::GetCallingUid(),
646         .pid = IPCSkeleton::GetCallingPid(),
647     };
648     MessageParcel reply;
649     MessageParcel datas;
650     int32_t ret = g_dragServer->UpdatePreviewAnimation(context, datas, reply);
651     EXPECT_EQ(ret, RET_ERR);
652 }
653 
654 /**
655  * @tc.name: DragServerTest15
656  * @tc.desc: Drag Drawing
657  * @tc.type: FUNC
658  * @tc.require:
659  */
660 HWTEST_F(DragServerTest, DragServerTest15, TestSize.Level0)
661 {
662     CALL_TEST_DEBUG;
663     CallingContext context {
664         .intention = g_intention,
665         .tokenId = IPCSkeleton::GetCallingTokenID(),
666         .uid = IPCSkeleton::GetCallingUid(),
667         .pid = IPCSkeleton::GetCallingPid(),
668     };
669     MessageParcel reply;
670     MessageParcel datas;
671     int32_t ret = g_dragServer->GetDragTargetPid(context, datas, reply);
672     EXPECT_EQ(ret, RET_OK);
673 }
674 
675 /**
676  * @tc.name: DragServerTest16
677  * @tc.desc: Drag Drawing
678  * @tc.type: FUNC
679  * @tc.require:
680  */
681 HWTEST_F(DragServerTest, DragServerTest16, TestSize.Level0)
682 {
683     CALL_TEST_DEBUG;
684     std::optional<DragData> dragData = CreateDragData(
685         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
686     CallingContext context {
687         .intention = g_intention,
688         .tokenId = IPCSkeleton::GetCallingTokenID(),
689         .uid = IPCSkeleton::GetCallingUid(),
690         .pid = IPCSkeleton::GetCallingPid(),
691     };
692     DRAG_DATA_MGR.Init(dragData.value());
693     MessageParcel reply;
694     MessageParcel datas;
695     int32_t ret = g_dragServer->GetUdKey(context, datas, reply);
696     EXPECT_EQ(ret, RET_OK);
697     DRAG_DATA_MGR.dragData_ = {};
698 }
699 
700 /**
701  * @tc.name: DragServerTest17
702  * @tc.desc: Drag Drawing
703  * @tc.type: FUNC
704  * @tc.require:
705  */
706 HWTEST_F(DragServerTest, DragServerTest17, TestSize.Level0)
707 {
708     CALL_TEST_DEBUG;
709     CallingContext context {
710         .intention = g_intention,
711         .tokenId = IPCSkeleton::GetCallingTokenID(),
712         .uid = IPCSkeleton::GetCallingUid(),
713         .pid = IPCSkeleton::GetCallingPid(),
714     };
715     MessageParcel reply;
716     MessageParcel datas;
717     int32_t ret = g_dragServer->GetShadowOffset(context, datas, reply);
718     EXPECT_EQ(ret, RET_ERR);
719 }
720 
721 /**
722  * @tc.name: DragServerTest18
723  * @tc.desc: Drag Drawing
724  * @tc.type: FUNC
725  * @tc.require:
726  */
727 HWTEST_F(DragServerTest, DragServerTest18, TestSize.Level0)
728 {
729     CALL_TEST_DEBUG;
730     CallingContext context {
731         .intention = g_intention,
732         .tokenId = IPCSkeleton::GetCallingTokenID(),
733         .uid = IPCSkeleton::GetCallingUid(),
734         .pid = IPCSkeleton::GetCallingPid(),
735     };
736     MessageParcel reply;
737     MessageParcel datas;
738     int32_t ret = g_dragServer->GetDragData(context, datas, reply);
739     EXPECT_EQ(ret, RET_ERR);
740 }
741 
742 /**
743  * @tc.name: DragServerTest19
744  * @tc.desc: Drag Drawing
745  * @tc.type: FUNC
746  * @tc.require:
747  */
748 HWTEST_F(DragServerTest, DragServerTest19, TestSize.Level0)
749 {
750     CALL_TEST_DEBUG;
751     CallingContext context {
752         .intention = g_intention,
753         .tokenId = IPCSkeleton::GetCallingTokenID(),
754         .uid = IPCSkeleton::GetCallingUid(),
755         .pid = IPCSkeleton::GetCallingPid(),
756     };
757     MessageParcel reply;
758     MessageParcel datas;
759     int32_t ret = g_dragServer->GetDragState(context, datas, reply);
760     EXPECT_EQ(ret, RET_OK);
761 }
762 
763 /**
764  * @tc.name: DragServerTest20
765  * @tc.desc: Drag Drawing
766  * @tc.type: FUNC
767  * @tc.require:
768  */
769 HWTEST_F(DragServerTest, DragServerTest20, TestSize.Level0)
770 {
771     CALL_TEST_DEBUG;
772     CallingContext context {
773         .intention = g_intention,
774         .tokenId = IPCSkeleton::GetCallingTokenID(),
775         .uid = IPCSkeleton::GetCallingUid(),
776         .pid = IPCSkeleton::GetCallingPid(),
777     };
778     MessageParcel reply;
779     MessageParcel datas;
780     int32_t ret = g_dragServer->GetDragSummary(context, datas, reply);
781     EXPECT_EQ(ret, RET_ERR);
782 }
783 
784 /**
785  * @tc.name: DragServerTest21
786  * @tc.desc: Drag Drawing
787  * @tc.type: FUNC
788  * @tc.require:
789  */
790 HWTEST_F(DragServerTest, DragServerTest21, TestSize.Level0)
791 {
792     CALL_TEST_DEBUG;
793     CallingContext context {
794         .intention = g_intention,
795         .tokenId = IPCSkeleton::GetCallingTokenID(),
796         .uid = IPCSkeleton::GetCallingUid(),
797         .pid = IPCSkeleton::GetCallingPid(),
798     };
799     MessageParcel reply;
800     MessageParcel datas;
801     int32_t ret = g_dragServer->GetDragAction(context, datas, reply);
802     EXPECT_EQ(ret, RET_ERR);
803 }
804 
805 /**
806  * @tc.name: DragServerTest22
807  * @tc.desc: Drag Drawing
808  * @tc.type: FUNC
809  * @tc.require:
810  */
811 HWTEST_F(DragServerTest, DragServerTest22, TestSize.Level0)
812 {
813     CALL_TEST_DEBUG;
814     CallingContext context {
815         .intention = g_intention,
816         .tokenId = IPCSkeleton::GetCallingTokenID(),
817         .uid = IPCSkeleton::GetCallingUid(),
818         .pid = IPCSkeleton::GetCallingPid(),
819     };
820     MessageParcel reply;
821     MessageParcel datas;
822     int32_t ret = g_dragServer->GetExtraInfo(context, datas, reply);
823     EXPECT_EQ(ret, RET_ERR);
824 }
825 
826 /**
827  * @tc.name: DragServerTest23
828  * @tc.desc: Drag Drawing
829  * @tc.type: FUNC
830  * @tc.require:
831  */
832 HWTEST_F(DragServerTest, DragServerTest23, TestSize.Level0)
833 {
834     CALL_TEST_DEBUG;
835     CallingContext context {
836         .intention = g_intention,
837         .tokenId = IPCSkeleton::GetCallingTokenID(),
838         .uid = IPCSkeleton::GetCallingUid(),
839         .pid = IPCSkeleton::GetCallingPid(),
840     };
841     MessageParcel reply;
842     MessageParcel datas;
843     int32_t ret = g_dragServer->EnterTextEditorArea(context, datas, reply);
844     EXPECT_EQ(ret, RET_ERR);
845 }
846 
847 /**
848  * @tc.name: DragServerTest24
849  * @tc.desc: Drag Drawing
850  * @tc.type: FUNC
851  * @tc.require:
852  */
853 HWTEST_F(DragServerTest, DragServerTest24, TestSize.Level0)
854 {
855     CALL_TEST_DEBUG;
856     CallingContext context {
857         .intention = g_intention,
858         .tokenId = IPCSkeleton::GetCallingTokenID(),
859         .uid = IPCSkeleton::GetCallingUid(),
860         .pid = IPCSkeleton::GetCallingPid(),
861     };
862     MessageParcel reply;
863     MessageParcel datas;
864     int32_t ret = g_dragServer->GetUdKey(context, datas, reply);
865     EXPECT_EQ(ret, RET_ERR);
866 }
867 
868 /**
869  * @tc.name: DragServerTest25
870  * @tc.desc: Drag Drawing
871  * @tc.type: FUNC
872  * @tc.require:
873  */
874 HWTEST_F(DragServerTest, DragServerTest25, TestSize.Level0)
875 {
876     CALL_TEST_DEBUG;
877     std::optional<DragData> dragData = CreateDragData(
878         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
879     CallingContext context {
880         .intention = g_intention,
881         .tokenId = IPCSkeleton::GetCallingTokenID(),
882         .uid = IPCSkeleton::GetCallingUid(),
883         .pid = IPCSkeleton::GetCallingPid(),
884     };
885     DRAG_DATA_MGR.Init(dragData.value());
886     MessageParcel reply;
887     MessageParcel datas;
888     int32_t ret = g_dragServer->GetShadowOffset(context, datas, reply);
889     EXPECT_EQ(ret, RET_OK);
890     DRAG_DATA_MGR.dragData_ = {};
891 }
892 
893 /**
894  * @tc.name: DragServerTest26
895  * @tc.desc: Drag Drawing
896  * @tc.type: FUNC
897  * @tc.require:
898  */
899 HWTEST_F(DragServerTest, DragServerTest26, TestSize.Level0)
900 {
901     CALL_TEST_DEBUG;
902     std::optional<DragData> dragData = CreateDragData(
903         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
904     CallingContext context {
905         .intention = g_intention,
906         .tokenId = IPCSkeleton::GetCallingTokenID(),
907         .uid = IPCSkeleton::GetCallingUid(),
908         .pid = IPCSkeleton::GetCallingPid(),
909     };
910     DRAG_DATA_MGR.Init(dragData.value());
911     MessageParcel reply;
912     MessageParcel datas;
913     int32_t ret = g_dragServer->GetExtraInfo(context, datas, reply);
914     EXPECT_EQ(ret, RET_OK);
915     DRAG_DATA_MGR.dragData_ = {};
916 }
917 
918 /**
919  * @tc.name: DragServerTest27
920  * @tc.desc: Drag Drawing
921  * @tc.type: FUNC
922  * @tc.require:
923  */
924 HWTEST_F(DragServerTest, DragServerTest27, TestSize.Level0)
925 {
926     CALL_TEST_DEBUG;
927     std::optional<DragData> dragData = CreateDragData(
928         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
929     CallingContext context {
930         .intention = g_intention,
931         .tokenId = IPCSkeleton::GetCallingTokenID(),
932         .uid = IPCSkeleton::GetCallingUid(),
933         .pid = IPCSkeleton::GetCallingPid(),
934     };
935 
936     MessageParcel reply;
937     MessageParcel datas;
938     g_dragMgr.dragState_ = DragState::START;
939     SetDragWindowVisibleParam param { true, true };
940     int32_t ret = param.Marshalling(datas);
941     EXPECT_EQ(ret, READ_OK);
942     ret = g_dragServer->SetDragWindowVisible(context, datas, reply);
943     EXPECT_EQ(ret, RET_OK);
944     g_dragMgr.dragState_  = DragState::STOP;
945     DRAG_DATA_MGR.dragData_ = {};
946 }
947 
948 /**
949  * @tc.name: DragServerTest28
950  * @tc.desc: Drag Drawing
951  * @tc.type: FUNC
952  * @tc.require:
953  */
954 HWTEST_F(DragServerTest, DragServerTest28, TestSize.Level0)
955 {
956     CALL_TEST_DEBUG;
957     CallingContext context {
958         .intention = g_intention,
959         .tokenId = IPCSkeleton::GetCallingTokenID(),
960         .uid = IPCSkeleton::GetCallingUid(),
961         .pid = IPCSkeleton::GetCallingPid(),
962     };
963     MessageParcel reply;
964     MessageParcel datas;
965     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
966     g_dragMgr.dragState_ = DragState::START;
967     StopDragParam param { dropResult };
968 
969     int32_t ret = param.Marshalling(datas);
970     EXPECT_EQ(ret, READ_OK);
971     ret = g_dragServer->Stop(context, datas, reply);
972     EXPECT_EQ(ret, RET_OK);
973     g_dragMgr.dragState_ = DragState::STOP;
974 }
975 
976 /**
977  * @tc.name: DragServerTest29
978  * @tc.desc: Drag Drawing
979  * @tc.type: FUNC
980  * @tc.require:
981  */
982 HWTEST_F(DragServerTest, DragServerTest29, TestSize.Level0)
983 {
984     CALL_TEST_DEBUG;
985     CallingContext context {
986         .intention = g_intention,
987         .tokenId = IPCSkeleton::GetCallingTokenID(),
988         .uid = IPCSkeleton::GetCallingUid(),
989         .pid = IPCSkeleton::GetCallingPid(),
990     };
991     MessageParcel datas;
992     MessageParcel reply;
993     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
994     g_dragMgr.dragState_ = DragState::START;
995     StopDragParam param { dropResult };
996 
997     int32_t ret = param.Marshalling(datas);
998     EXPECT_EQ(ret, READ_OK);
999     ret = g_dragServerOne->Stop(context, datas, reply);
1000     EXPECT_EQ(ret, RET_ERR);
1001     g_dragMgr.dragState_ = DragState::STOP;
1002 }
1003 
1004 /**
1005  * @tc.name: DragServerTest30
1006  * @tc.desc: Drag Drawing
1007  * @tc.type: FUNC
1008  * @tc.require:
1009  */
1010 HWTEST_F(DragServerTest, DragServerTest30, TestSize.Level0)
1011 {
1012     CALL_TEST_DEBUG;
1013     CallingContext context {
1014         .intention = g_intention,
1015         .tokenId = IPCSkeleton::GetCallingTokenID(),
1016         .uid = IPCSkeleton::GetCallingUid(),
1017         .pid = IPCSkeleton::GetCallingPid(),
1018     };
1019     MessageParcel datas;
1020     MessageParcel reply;
1021     g_dragMgr.dragState_ = DragState::START;
1022     UpdateDragStyleParam param { DragCursorStyle::COPY, -1 };
1023     bool ret = param.Marshalling(datas);
1024     EXPECT_EQ(ret, READ_OK);
1025     ret = g_dragServer->UpdateDragStyle(context, datas, reply);
1026     EXPECT_TRUE(ret);
1027     g_dragMgr.dragState_ = DragState::STOP;
1028 }
1029 
1030 /**
1031  * @tc.name: DragServerTest31
1032  * @tc.desc: Drag Drawing
1033  * @tc.type: FUNC
1034  * @tc.require:
1035  */
1036 HWTEST_F(DragServerTest, DragServerTest31, TestSize.Level0)
1037 {
1038     CALL_TEST_DEBUG;
1039     CallingContext context {
1040         .intention = g_intention,
1041         .tokenId = IPCSkeleton::GetCallingTokenID(),
1042         .uid = IPCSkeleton::GetCallingUid(),
1043         .pid = IPCSkeleton::GetCallingPid(),
1044     };
1045     MessageParcel datas;
1046     MessageParcel reply;
1047     g_dragMgr.dragState_ = DragState::START;
1048     std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT);
1049     ASSERT_NE(pixelMap, nullptr);
1050     ShadowInfo shadowInfo = { pixelMap, 0, 0 };
1051     std::string extraInfo;
1052     UpdateShadowPicParam param { shadowInfo };
1053     bool ret = param.Marshalling(datas);;
1054     EXPECT_EQ(ret, READ_OK);
1055     ret = g_dragServer->UpdateShadowPic(context, datas, reply);
1056     EXPECT_TRUE(ret);
1057     g_dragMgr.dragState_ = DragState::STOP;
1058 }
1059 
1060 /**
1061  * @tc.name: DragServerTest32
1062  * @tc.desc: Drag Drawing
1063  * @tc.type: FUNC
1064  * @tc.require:
1065  */
1066 HWTEST_F(DragServerTest, DragServerTest32, TestSize.Level0)
1067 {
1068     CALL_TEST_DEBUG;
1069     CallingContext context {
1070         .intention = g_intention,
1071         .tokenId = IPCSkeleton::GetCallingTokenID(),
1072         .uid = IPCSkeleton::GetCallingUid(),
1073         .pid = IPCSkeleton::GetCallingPid(),
1074     };
1075     MessageParcel datas;
1076     MessageParcel reply;
1077     g_dragMgr.dragState_ = DragState::START;
1078     PreviewStyle previewStyleIn;
1079     previewStyleIn.types = { PreviewType::FOREGROUND_COLOR };
1080     previewStyleIn.foregroundColor = FOREGROUND_COLOR_IN;
1081     UpdatePreviewStyleParam param { previewStyleIn };
1082     bool ret = param.Marshalling(datas);;
1083     EXPECT_EQ(ret, READ_OK);
1084     ret = g_dragServer->UpdatePreviewStyle(context, datas, reply);
1085     EXPECT_TRUE(ret);
1086     g_dragMgr.dragState_ = DragState::STOP;
1087 }
1088 
1089 /**
1090  * @tc.name: DragServerTest33
1091  * @tc.desc: Drag Drawing
1092  * @tc.type: FUNC
1093  * @tc.require:
1094  */
1095 HWTEST_F(DragServerTest, DragServerTest33, TestSize.Level0)
1096 {
1097     CALL_TEST_DEBUG;
1098     CallingContext context {
1099         .intention = g_intention,
1100         .tokenId = IPCSkeleton::GetCallingTokenID(),
1101         .uid = IPCSkeleton::GetCallingUid(),
1102         .pid = IPCSkeleton::GetCallingPid(),
1103     };
1104     MessageParcel datas;
1105     MessageParcel reply;
1106     g_dragMgr.dragState_ = DragState::START;
1107     PreviewStyle previewStyleIn;
1108     previewStyleIn.types = { PreviewType::FOREGROUND_COLOR };
1109     previewStyleIn.foregroundColor = FOREGROUND_COLOR_IN;
1110     PreviewAnimation animationOut;
1111     AssignToAnimation(animationOut);
1112     UpdatePreviewAnimationParam param { previewStyleIn, animationOut };
1113     bool ret = param.Marshalling(datas);;
1114     EXPECT_EQ(ret, READ_OK);
1115     ret = g_dragServer->UpdatePreviewAnimation(context, datas, reply);
1116     EXPECT_FALSE(ret);
1117     g_dragMgr.dragState_ = DragState::STOP;
1118 }
1119 
1120 /**
1121  * @tc.name: DragServerTest34
1122  * @tc.desc: Drag Drawing
1123  * @tc.type: FUNC
1124  * @tc.require:
1125  */
1126 HWTEST_F(DragServerTest, DragServerTest34, TestSize.Level0)
1127 {
1128     CALL_TEST_DEBUG;
1129     CallingContext context {
1130         .intention = g_intention,
1131         .tokenId = IPCSkeleton::GetCallingTokenID(),
1132         .uid = IPCSkeleton::GetCallingUid(),
1133         .pid = IPCSkeleton::GetCallingPid(),
1134     };
1135     MessageParcel datas;
1136     MessageParcel reply;
1137     g_dragMgr.dragState_ = DragState::START;
1138     GetDragTargetPidReply targetPidReply { IPCSkeleton::GetCallingPid() };
1139     bool ret = targetPidReply.Marshalling(datas);
1140     EXPECT_EQ(ret, READ_OK);
1141     ret = g_dragServer->GetDragTargetPid(context, datas, reply);
1142     EXPECT_FALSE(ret);
1143     g_dragMgr.dragState_ = DragState::STOP;
1144 }
1145 
1146 /**
1147  * @tc.name: DragServerTest35
1148  * @tc.desc: Drag Drawing
1149  * @tc.type: FUNC
1150  * @tc.require:
1151  */
1152 HWTEST_F(DragServerTest, DragServerTest35, TestSize.Level0)
1153 {
1154     CALL_TEST_DEBUG;
1155     CallingContext context {
1156         .intention = g_intention,
1157         .tokenId = IPCSkeleton::GetCallingTokenID(),
1158         .uid = IPCSkeleton::GetCallingUid(),
1159         .pid = IPCSkeleton::GetCallingPid(),
1160     };
1161     std::optional<DragData> dragData = CreateDragData(
1162         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
1163     g_dragMgr.dragState_ = DragState::START;
1164     MessageParcel reply;
1165     MessageParcel datas;
1166     DRAG_DATA_MGR.Init(dragData.value());
1167     int32_t ret = g_dragServer->GetDragData(context, datas, reply);
1168     EXPECT_EQ(ret, RET_OK);
1169     DRAG_DATA_MGR.dragData_ = {};
1170     ret = g_dragServer->GetDragData(context, datas, reply);
1171     EXPECT_EQ(ret, RET_ERR);
1172     g_dragMgr.dragState_ = DragState::STOP;
1173 }
1174 
1175 /**
1176  * @tc.name: DragServerTest36
1177  * @tc.desc: Drag Drawing
1178  * @tc.type: FUNC
1179  * @tc.require:
1180  */
1181 HWTEST_F(DragServerTest, DragServerTest36, TestSize.Level0)
1182 {
1183     CALL_TEST_DEBUG;
1184     CallingContext context {
1185         .intention = g_intention,
1186         .tokenId = IPCSkeleton::GetCallingTokenID(),
1187         .uid = IPCSkeleton::GetCallingUid(),
1188         .pid = IPCSkeleton::GetCallingPid(),
1189     };
1190     g_dragMgr.dragState_ = DragState::ERROR;
1191     MessageParcel reply;
1192     MessageParcel datas;
1193     int32_t ret = g_dragServer->GetDragState(context, datas, reply);
1194     EXPECT_EQ(ret, RET_ERR);
1195     g_dragMgr.dragState_ = DragState::START;
1196     ret = g_dragServer->GetDragState(context, datas, reply);
1197     EXPECT_EQ(ret, RET_OK);
1198     g_dragMgr.dragState_ = DragState::STOP;
1199 }
1200 
1201 /**
1202  * @tc.name: DragServerTest37
1203  * @tc.desc: Drag Drawing
1204  * @tc.type: FUNC
1205  * @tc.require:
1206  */
1207 HWTEST_F(DragServerTest, DragServerTest37, TestSize.Level0)
1208 {
1209     CALL_TEST_DEBUG;
1210     CallingContext context {
1211         .intention = g_intention,
1212         .tokenId = IPCSkeleton::GetCallingTokenID(),
1213         .uid = IPCSkeleton::GetCallingUid(),
1214         .pid = IPCSkeleton::GetCallingPid(),
1215     };
1216     g_dragMgr.dragState_ = DragState::ERROR;
1217     MessageParcel reply;
1218     MessageParcel datas;
1219     int32_t ret = g_dragServer->GetDragAction(context, datas, reply);
1220     EXPECT_EQ(ret, RET_ERR);
1221     g_dragMgr.dragState_ = DragState::START;
1222     ret = g_dragServer->GetDragAction(context, datas, reply);
1223     EXPECT_EQ(ret, RET_OK);
1224     g_dragMgr.dragState_ = DragState::STOP;
1225 }
1226 
1227 /**
1228  * @tc.name: DragServerTest38
1229  * @tc.desc: Drag Drawing
1230  * @tc.type: FUNC
1231  * @tc.require:
1232  */
1233 HWTEST_F(DragServerTest, DragServerTest38, TestSize.Level0)
1234 {
1235     CALL_TEST_DEBUG;
1236     std::optional<DragData> dragData = CreateDragData(
1237         MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE);
1238     CallingContext context {
1239         .intention = g_intention,
1240         .tokenId = IPCSkeleton::GetCallingTokenID(),
1241         .uid = IPCSkeleton::GetCallingUid(),
1242         .pid = IPCSkeleton::GetCallingPid(),
1243     };
1244     MessageParcel reply;
1245     MessageParcel datas;
1246     DRAG_DATA_MGR.Init(dragData.value());
1247     int32_t ret = g_dragServer->GetExtraInfo(context, datas, reply);
1248     EXPECT_EQ(ret, RET_OK);
1249     DRAG_DATA_MGR.dragData_ = {};
1250     ret = g_dragServer->GetExtraInfo(context, datas, reply);
1251     EXPECT_EQ(ret, RET_ERR);
1252 }
1253 
1254 /**
1255  * @tc.name: DragServerTest39
1256  * @tc.desc: Drag Drawing
1257  * @tc.type: FUNC
1258  * @tc.require:
1259  */
1260 HWTEST_F(DragServerTest, DragServerTest39, TestSize.Level0)
1261 {
1262     CALL_TEST_DEBUG;
1263     g_dragServer->GetPackageName(IPCSkeleton::GetCallingTokenID());
1264     g_dragServer->GetPackageName(-1);
1265     CallingContext context {
1266         .intention = g_intention,
1267         .tokenId = IPCSkeleton::GetCallingTokenID(),
1268         .uid = IPCSkeleton::GetCallingUid(),
1269         .pid = IPCSkeleton::GetCallingPid(),
1270     };
1271     MessageParcel reply;
1272     MessageParcel datas;
1273     EnterTextEditorAreaParam param { true };
1274     bool ret = param.Marshalling(datas);;
1275     EXPECT_EQ(ret, READ_OK);
1276     ret = g_dragServer->EnterTextEditorArea(context, datas, reply);
1277     EXPECT_EQ(ret, READ_OK);
1278 }
1279 
1280 /**
1281  * @tc.name: DragServerTest40
1282  * @tc.desc: Drag Drawing
1283  * @tc.type: FUNC
1284  * @tc.require:
1285  */
1286 HWTEST_F(DragServerTest, DragServerTest40, TestSize.Level0)
1287 {
1288     CALL_TEST_DEBUG;
1289     bool ret = DRAG_DATA_MGR.GetDragWindowVisible();
1290     EXPECT_FALSE(ret);
1291 }
1292 
1293 /**
1294  * @tc.name: DragServerTest42
1295  * @tc.desc: Drag Drawing
1296  * @tc.type: FUNC
1297  * @tc.require:
1298  */
1299 HWTEST_F(DragServerTest, DragServerTest42, TestSize.Level0)
1300 {
1301     CALL_TEST_DEBUG;
1302     DRAG_DATA_MGR.SetTextEditorAreaFlag(true);
1303     DRAG_DATA_MGR.SetPixelMapLocation({1, 1});
1304     bool ret = DRAG_DATA_MGR.GetCoordinateCorrected();
1305     EXPECT_FALSE(ret);
1306 }
1307 
1308 /**
1309  * @tc.name: DragServerTest43
1310  * @tc.desc: Drag Drawing
1311  * @tc.type: FUNC
1312  * @tc.require:
1313  */
1314 HWTEST_F(DragServerTest, DragServerTest43, TestSize.Level0)
1315 {
1316     CALL_TEST_DEBUG;
1317     DRAG_DATA_MGR.initialPixelMapLocation_ = {1, 1};
1318     DRAG_DATA_MGR.SetInitialPixelMapLocation(DRAG_DATA_MGR.GetInitialPixelMapLocation());
1319     DRAG_DATA_MGR.SetDragOriginDpi(1);
1320     bool ret = DRAG_DATA_MGR.GetTextEditorAreaFlag();
1321     EXPECT_TRUE(ret);
1322 }
1323 
1324 /**
1325  * @tc.name: DragServerTest44
1326  * @tc.desc: Drag Drawing
1327  * @tc.type: FUNC
1328  * @tc.require:
1329  */
1330 HWTEST_F(DragServerTest, DragServerTest44, TestSize.Level0)
1331 {
1332     CALL_TEST_DEBUG;
1333     CallingContext context {
1334         .intention = g_intention,
1335         .tokenId = IPCSkeleton::GetCallingTokenID(),
1336         .uid = IPCSkeleton::GetCallingUid(),
1337         .pid = IPCSkeleton::GetCallingPid(),
1338     };
1339     MessageParcel reply;
1340     MessageParcel datas;
1341     int32_t ret = g_dragServer->Start(context, datas, reply);
1342     EXPECT_EQ(ret, RET_ERR);
1343 }
1344 
1345 /**
1346  * @tc.name: DragServerTest45
1347  * @tc.desc: Drag Drawing
1348  * @tc.type: FUNC
1349  * @tc.require:
1350  */
1351 HWTEST_F(DragServerTest, DragServerTest45, TestSize.Level0)
1352 {
1353     CALL_TEST_DEBUG;
1354     CallingContext context {
1355         .intention = g_intention,
1356         .tokenId = IPCSkeleton::GetCallingTokenID(),
1357         .uid = IPCSkeleton::GetCallingUid(),
1358         .pid = IPCSkeleton::GetCallingPid(),
1359     };
1360     MessageParcel reply;
1361     MessageParcel datas;
1362     bool ret = g_dragServer->IsSystemServiceCalling(context);
1363     EXPECT_TRUE(ret);
1364 }
1365 
1366 /**
1367  * @tc.name: DragServerTest46
1368  * @tc.desc: Drag Drawing
1369  * @tc.type: FUNC
1370  * @tc.require:
1371  */
1372 HWTEST_F(DragServerTest, DragServerTest46, TestSize.Level0)
1373 {
1374     CALL_TEST_DEBUG;
1375     CallingContext context {
1376         .intention = g_intention,
1377         .tokenId = IPCSkeleton::GetCallingTokenID(),
1378         .uid = IPCSkeleton::GetCallingUid(),
1379         .pid = IPCSkeleton::GetCallingPid(),
1380     };
1381     MessageParcel reply;
1382     MessageParcel datas;
1383     int32_t ret = g_dragServer->RotateDragWindowSync(context, datas, reply);
1384     EXPECT_EQ(ret, RET_ERR);
1385 }
1386 
1387 /**
1388  * @tc.name: DragServerTest47
1389  * @tc.desc: Drag Drawing
1390  * @tc.type: FUNC
1391  * @tc.require:
1392  */
1393 HWTEST_F(DragServerTest, DragServerTest47, TestSize.Level0)
1394 {
1395     CALL_TEST_DEBUG;
1396     CallingContext context {
1397         .intention = g_intention,
1398         .tokenId = IPCSkeleton::GetCallingTokenID(),
1399         .uid = IPCSkeleton::GetCallingUid(),
1400         .pid = IPCSkeleton::GetCallingPid(),
1401     };
1402     MessageParcel reply;
1403     MessageParcel datas;
1404     int32_t ret = g_dragServer->SetDragWindowScreenId(context, datas, reply);
1405     EXPECT_EQ(ret, RET_ERR);
1406 }
1407 
1408 /**
1409  * @tc.name: DragClientTest48
1410  * @tc.desc: Drag Drawing
1411  * @tc.type: FUNC
1412  * @tc.require:
1413  */
1414 HWTEST_F(DragServerTest, DragClientTest48, TestSize.Level0)
1415 {
1416     CALL_TEST_DEBUG;
1417     uint16_t displayId = 0;
1418     uint64_t screenId = 0;
1419     int32_t ret = g_dragClient.SetDragWindowScreenId(*g_tunnel, displayId, screenId);
1420     EXPECT_EQ(ret, RET_OK);
1421 }
1422 
1423 /**
1424  * @tc.name: DragClientTest49
1425  * @tc.desc: Drag Drawing
1426  * @tc.type: FUNC
1427  * @tc.require:
1428  */
1429 HWTEST_F(DragServerTest, DragClientTest49, TestSize.Level0)
1430 {
1431     CALL_TEST_DEBUG;
1432     std::shared_ptr<StreamClient> g_streamClient { nullptr };
1433     NetPacket packet(MessageId::DRAG_NOTIFY_RESULT);
1434     int32_t ret = g_dragClient.OnNotifyHideIcon(*g_streamClient, packet);
1435     EXPECT_EQ(ret, RET_ERR);
1436 }
1437 
1438 /**
1439  * @tc.name: DragClientTest50
1440  * @tc.desc: Drag Drawing
1441  * @tc.type: FUNC
1442  * @tc.require:
1443  */
1444 HWTEST_F(DragServerTest, DragClientTest50, TestSize.Level0)
1445 {
1446     CALL_TEST_DEBUG;
1447     std::shared_ptr<StreamClient> g_streamClient { nullptr };
1448     NetPacket packet(MessageId::DRAG_NOTIFY_RESULT);
__anon3f8f639d0302(const DragNotifyMsg& msg) 1449     auto dragEndHandler = [](const DragNotifyMsg& msg) {
1450         FI_HILOGI("TEST");
1451     };
1452     g_dragClient.startDragListener_ = std::make_shared<TestStartDragListener>(dragEndHandler);
1453     int32_t ret = g_dragClient.OnNotifyHideIcon(*g_streamClient, packet);
1454     EXPECT_EQ(ret, RET_OK);
1455 }
1456 
1457 /**
1458  * @tc.name: DragClientTest51
1459  * @tc.desc: Drag Drawing
1460  * @tc.type: FUNC
1461  * @tc.require:
1462  */
1463 HWTEST_F(DragServerTest, DragClientTest51, TestSize.Level0)
1464 {
1465     CALL_TEST_DEBUG;
1466     std::shared_ptr<StreamClient> g_streamClient { nullptr };
1467     NetPacket packet(MessageId::DRAG_NOTIFY_RESULT);
1468     int32_t ret = g_dragClient.OnDragStyleChangedMessage(*g_streamClient, packet);
1469     EXPECT_EQ(ret, RET_ERR);
1470 }
1471 
1472 /**
1473  * @tc.name: DragServerTest48
1474  * @tc.desc: Drag Drawing
1475  * @tc.type: FUNC
1476  * @tc.require:
1477  */
1478 HWTEST_F(DragServerTest, DragServerTest48, TestSize.Level0)
1479 {
1480     CALL_TEST_DEBUG;
1481     uint64_t g_tokenId = NativeTokenGet();
1482     EXPECT_EQ(g_tokenId, IPCSkeleton::GetCallingTokenID());
1483     CallingContext context {
1484         .intention = g_intention,
1485         .tokenId = IPCSkeleton::GetCallingTokenID(),
1486         .uid = IPCSkeleton::GetCallingUid(),
1487         .pid = IPCSkeleton::GetCallingPid(),
1488     };
1489     MessageParcel reply;
1490     MessageParcel datas;
1491     g_dragServer->GetPackageName(IPCSkeleton::GetCallingTokenID());
1492     bool ret = g_dragServer->IsSystemHAPCalling(context);
1493     EXPECT_TRUE(ret);
1494     OHOS::Security::AccessToken::AccessTokenKit::DeleteToken(g_tokenId);
1495 }
1496 
1497 /**
1498  * @tc.name: DragServerTest49
1499  * @tc.desc: Drag Drawing
1500  * @tc.type: FUNC
1501  * @tc.require:
1502  */
1503 HWTEST_F(DragServerTest, DragServerTest49, TestSize.Level0)
1504 {
1505     CALL_TEST_DEBUG;
1506     Security::AccessToken::AccessTokenIDEx tokenIdEx = {0};
1507     tokenIdEx = Security::AccessToken::AccessTokenKit::AllocHapToken(g_testInfoParms, g_testPolicyPrams);
1508     EXPECT_EQ(0, SetSelfTokenID(tokenIdEx.tokenIdExStruct.tokenID));
1509     auto g_tokenId1 = tokenIdEx.tokenIdExStruct.tokenID;
1510     CallingContext context {
1511         .intention = g_intention,
1512         .tokenId = g_tokenId1,
1513         .uid = IPCSkeleton::GetCallingUid(),
1514         .pid = IPCSkeleton::GetCallingPid(),
1515     };
1516     MessageParcel reply;
1517     MessageParcel datas;
1518     g_dragServer->GetPackageName(g_tokenId1);
1519     bool ret = g_dragServer->IsSystemHAPCalling(context);
1520     EXPECT_FALSE(ret);
1521 }
1522 } // namespace DeviceStatus
1523 } // namespace Msdp
1524 } // namespace OHOS
1525