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