• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define BUFF_SIZE 100
17 #include "intention_service_test.h"
18 
19 #include "ddm_adapter.h"
20 #include "drag_data_manager.h"
21 #include "drag_server.h"
22 #include "dsoftbus_adapter.h"
23 #include "fi_log.h"
24 #include "input_adapter.h"
25 #include "intention_service.h"
26 #include "interaction_manager.h"
27 #include "ipc_skeleton.h"
28 #include "plugin_manager.h"
29 
30 #undef LOG_TAG
31 #define LOG_TAG "IntentionServiceTest"
32 
33 namespace OHOS {
34 namespace Msdp {
35 namespace DeviceStatus {
36 using namespace testing::ext;
37 namespace {
38 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
39 constexpr int32_t PIXEL_MAP_WIDTH { 3 };
40 constexpr int32_t PIXEL_MAP_HEIGHT { 3 };
41 constexpr int32_t WINDOW_ID { -1 };
42 constexpr uint32_t DEFAULT_ICON_COLOR { 0xFF };
43 const std::string FILTER_INFO { "Undefined filter info" };
44 const std::string UD_KEY { "Unified data key" };
45 const std::string EXTRA_INFO { "Undefined extra info" };
46 const std::string CURVE_NAME { "cubic-bezier" };
47 constexpr int32_t DISPLAY_ID { 0 };
48 constexpr int32_t DISPLAY_X { 50 };
49 constexpr int32_t DISPLAY_Y { 50 };
50 constexpr int32_t INT32_BYTE { 4 };
51 int32_t g_shadowinfoX { 0 };
52 int32_t g_shadowinfoY { 0 };
53 constexpr int32_t ANIMATION_DURATION { 500 };
54 constexpr int32_t MAX_PIXEL_MAP_WIDTH { 600 };
55 constexpr int32_t MAX_PIXEL_MAP_HEIGHT { 600 };
56 constexpr bool HAS_CANCELED_ANIMATION { true };
57 constexpr bool HAS_CUSTOM_ANIMATION { true };
58 std::shared_ptr<ContextService> g_context { nullptr };
59 std::shared_ptr<IntentionService> g_intentionService { nullptr };
60 std::shared_ptr<IntentionService> g_intentionServiceNullptr { nullptr };
61 sptr<IRemoteDevStaCallback> stationaryCallback_;
62 IContext *g_contextNullptr { nullptr };
63 DragManager g_dragMgr;
64 int32_t PERMISSION_EXCEPTION { 201 };
65 constexpr int32_t RET_NO_SUPPORT = 801;
66 constexpr float DOUBLEPIMAX = 6.3F;
67 } // namespace
68 
PostSyncTask(DTaskCallback callback)69 int32_t MockDelegateTasks::PostSyncTask(DTaskCallback callback)
70 {
71     return callback();
72 }
73 
PostAsyncTask(DTaskCallback callback)74 int32_t MockDelegateTasks::PostAsyncTask(DTaskCallback callback)
75 {
76     return callback();
77 }
78 
GetInstance()79 ContextService* ContextService::GetInstance()
80 {
81     static std::once_flag flag;
82     std::call_once(flag, [&]() {
83         g_context = std::make_shared<ContextService>();
84     });
85     return g_context.get();
86 }
87 
ContextService()88 ContextService::ContextService()
89 {
90     ddm_ = std::make_unique<DDMAdapter>();
91     input_ = std::make_unique<InputAdapter>();
92     pluginMgr_ = std::make_unique<PluginManager>(this);
93     dsoftbus_ = std::make_unique<DSoftbusAdapter>();
94 }
95 
GetDelegateTasks()96 IDelegateTasks& ContextService::GetDelegateTasks()
97 {
98     return delegateTasks_;
99 }
100 
GetDeviceManager()101 IDeviceManager& ContextService::GetDeviceManager()
102 {
103     return devMgr_;
104 }
105 
GetTimerManager()106 ITimerManager& ContextService::GetTimerManager()
107 {
108     return timerMgr_;
109 }
110 
GetDragManager()111 IDragManager& ContextService::GetDragManager()
112 {
113     return g_dragMgr;
114 }
115 
GetSocketSessionManager()116 ISocketSessionManager& ContextService::GetSocketSessionManager()
117 {
118     return socketSessionMgr_;
119 }
120 
GetDDM()121 IDDMAdapter& ContextService::GetDDM()
122 {
123     return *ddm_;
124 }
125 
GetPluginManager()126 IPluginManager& ContextService::GetPluginManager()
127 {
128     return *pluginMgr_;
129 }
130 
GetInput()131 IInputAdapter& ContextService::GetInput()
132 {
133     return *input_;
134 }
135 
GetDSoftbus()136 IDSoftbusAdapter& ContextService::GetDSoftbus()
137 {
138     return *dsoftbus_;
139 }
140 
SetUpTestCase()141 void IntentionServiceTest::SetUpTestCase()
142 {
143     g_intentionService = std::make_shared<IntentionService>(ContextService::GetInstance());
144     g_intentionServiceNullptr = std::make_shared<IntentionService>(g_contextNullptr);
145 }
146 
TearDownTestCase()147 void IntentionServiceTest::TearDownTestCase()
148 {
149     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
150     g_intentionServiceNullptr = nullptr;
151 }
152 
SetUp()153 void IntentionServiceTest::SetUp()
154 {
155     stationaryCallback_ = new (std::nothrow) TestDevStaCallback();
156 }
157 
TearDown()158 void IntentionServiceTest::TearDown() {}
159 
CreatePixelMap(int32_t width,int32_t height)160 std::shared_ptr<Media::PixelMap> IntentionServiceTest::CreatePixelMap(int32_t width, int32_t height)
161 {
162     CALL_DEBUG_ENTER;
163     if (width <= 0 || width > MAX_PIXEL_MAP_WIDTH || height <= 0 || height > MAX_PIXEL_MAP_HEIGHT) {
164         FI_HILOGE("invalid, height:%{public}d, width:%{public}d", height, width);
165         return nullptr;
166     }
167     Media::InitializationOptions opts;
168     opts.size.width = width;
169     opts.size.height = height;
170     opts.pixelFormat = Media::PixelFormat::BGRA_8888;
171     opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
172     opts.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE;
173 
174     int32_t colorLen = width * height;
175     uint32_t *pixelColors = new (std::nothrow) uint32_t[BUFF_SIZE];
176     CHKPP(pixelColors);
177     int32_t colorByteCount = colorLen * INT32_BYTE;
178     errno_t ret = memset_s(pixelColors, BUFF_SIZE, DEFAULT_ICON_COLOR, colorByteCount);
179     if (ret != EOK) {
180         FI_HILOGE("memset_s failed");
181         delete[] pixelColors;
182         return nullptr;
183     }
184     std::shared_ptr<Media::PixelMap> pixelMap = Media::PixelMap::Create(pixelColors, colorLen, opts);
185     if (pixelMap == nullptr) {
186         FI_HILOGE("Create pixelMap failed");
187         delete[] pixelColors;
188         return nullptr;
189     }
190     delete[] pixelColors;
191     return pixelMap;
192 }
193 
CreateDragData(int32_t sourceType,int32_t pointerId,int32_t dragNum,bool hasCoordinateCorrected,int32_t shadowNum)194 std::optional<DragData> IntentionServiceTest::CreateDragData(int32_t sourceType,
195     int32_t pointerId, int32_t dragNum, bool hasCoordinateCorrected, int32_t shadowNum)
196 {
197     CALL_DEBUG_ENTER;
198     DragData dragData;
199     for (int32_t i = 0; i < shadowNum; i++) {
200         std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT);
201         if (pixelMap == nullptr) {
202             FI_HILOGE("pixelMap nullptr");
203             return std::nullopt;
204         }
205         dragData.shadowInfos.push_back({ pixelMap, g_shadowinfoX, g_shadowinfoY });
206     }
207     dragData.buffer = std::vector<uint8_t>(MAX_BUFFER_SIZE, 0);
208     dragData.extraInfo = FILTER_INFO;
209     dragData.udKey = UD_KEY;
210     dragData.sourceType = sourceType;
211     dragData.extraInfo = EXTRA_INFO;
212     dragData.displayId = DISPLAY_ID;
213     dragData.pointerId = pointerId;
214     dragData.dragNum = dragNum;
215     dragData.displayX = DISPLAY_X;
216     dragData.displayY = DISPLAY_Y;
217     dragData.hasCoordinateCorrected = hasCoordinateCorrected;
218     dragData.hasCanceledAnimation = HAS_CANCELED_ANIMATION;
219     return dragData;
220 }
221 
222 class TestStartDragListener : public IStartDragListener {
223 public:
TestStartDragListener(std::function<void (const DragNotifyMsg &)> function)224     explicit TestStartDragListener(std::function<void(const DragNotifyMsg&)> function) : function_(function) { }
OnDragEndMessage(const DragNotifyMsg & msg)225     void OnDragEndMessage(const DragNotifyMsg &msg) override
226     {
227         FI_HILOGD("DisplayX:%{public}d, displayY:%{public}d, targetPid:%{public}d, result:%{public}d",
228             msg.displayX, msg.displayY, msg.targetPid, static_cast<int32_t>(msg.result));
229         if (function_ != nullptr) {
230             function_(msg);
231         }
232         FI_HILOGD("Test OnDragEndMessage");
233     }
234 
OnHideIconMessage()235     void OnHideIconMessage() override
236     {
237         FI_HILOGD("Test OnHideIconMessage");
238     }
239 private:
240     std::function<void(const DragNotifyMsg&)> function_;
241 };
242 
243 class DragListenerTest : public IDragListener {
244 public:
DragListenerTest()245     DragListenerTest() {}
DragListenerTest(const std::string & name)246     explicit DragListenerTest(const std::string& name) : moduleName_(name) {}
OnDragMessage(DragState state)247     void OnDragMessage(DragState state) override
248     {
249         if (moduleName_.empty()) {
250             moduleName_ = std::string("DragListenerTest");
251         }
252         FI_HILOGD("%{public}s, state:%{public}s", moduleName_.c_str(), PrintDragMessage(state).c_str());
253     }
254 private:
PrintDragMessage(DragState state)255     std::string PrintDragMessage(DragState state)
256     {
257         std::string type = "unknow";
258         const std::map<DragState, std::string> stateType = {
259             { DragState::ERROR, "error"},
260             { DragState::START, "start"},
261             { DragState::STOP, "stop"},
262             { DragState::CANCEL, "cancel"}
263         };
264         auto item = stateType.find(state);
265         if (item != stateType.end()) {
266             type = item->second;
267         }
268         return type;
269     }
270 private:
271     std::string moduleName_;
272 };
273 
AssignToAnimation(PreviewAnimation & animation)274 void IntentionServiceTest::AssignToAnimation(PreviewAnimation &animation)
275 {
276     animation.duration = ANIMATION_DURATION;
277     animation.curveName = CURVE_NAME;
278     animation.curve = { 0.33, 0, 0.67, 1 };
279 }
280 
281 /**
282  * @tc.name: IntentionServiceTest_1
283  * @tc.desc: Test Socket
284  * @tc.type: FUNC
285  * @tc.require:
286  */
287 HWTEST_F(IntentionServiceTest, IntentionServiceTest_Socket001, TestSize.Level0)
288 {
289     CALL_TEST_DEBUG;
290     auto programName = GetProgramName();
291     int32_t socketFd { -1 };
292     int32_t tokenType { -1 };
293     int32_t ret = g_intentionService->Socket(programName, CONNECT_MODULE_TYPE_FI_CLIENT, socketFd, tokenType);
294     EXPECT_EQ(ret, RET_ERR);
295 }
296 
297 /**
298  * @tc.name: IntentionServiceTest2
299  * @tc.desc: Test EnableCooperate
300  * @tc.type: FUNC
301  * @tc.require:
302  */
303 HWTEST_F(IntentionServiceTest, IntentionServiceTest_EnableCooperate001, TestSize.Level0)
304 {
305     CALL_TEST_DEBUG;
306     int32_t userData = 0;
307     ErrCode ret = g_intentionService->EnableCooperate(userData);
308     EXPECT_EQ(ret, PERMISSION_EXCEPTION);
309 }
310 
311 
312 /**
313  * @tc.name: IntentionServiceTest3
314  * @tc.desc: Test DisableCooperate
315  * @tc.type: FUNC
316  * @tc.require:
317  */
318 HWTEST_F(IntentionServiceTest, IntentionServiceTest_DisableCooperate001, TestSize.Level0)
319 {
320     CALL_TEST_DEBUG;
321     int32_t userData = 0;
322     ErrCode ret = g_intentionService->DisableCooperate(userData);
323     EXPECT_EQ(ret, PERMISSION_EXCEPTION);
324 }
325 /**
326  * @tc.name: IntentionServiceTest4
327  * @tc.desc: Test StartCooperate
328  * @tc.type: FUNC
329  * @tc.require:
330  */
331 HWTEST_F(IntentionServiceTest, IntentionServiceTest_StartCooperate001, TestSize.Level0)
332 {
333     CALL_TEST_DEBUG;
334     std::string remoteNetworkId = "networkId";
335     int32_t userData = 0;
336     int32_t startDeviceId = 0;
337     bool isCheckPermission = true;
338     ErrCode ret = g_intentionService->StartCooperate(remoteNetworkId, userData, startDeviceId, isCheckPermission);
339     EXPECT_EQ(ret, PERMISSION_EXCEPTION);
340 }
341 
342 /**
343  * @tc.name: IntentionServiceTest_StartCooperateWithOptions001
344  * @tc.desc: Test StartCooperate
345  * @tc.type: FUNC
346  * @tc.require:
347  */
348 HWTEST_F(IntentionServiceTest, IntentionServiceTest_StartCooperateWithOptions001, TestSize.Level0)
349 {
350     CALL_TEST_DEBUG;
351     std::string remoteNetworkId = "networkId";
352     int32_t userData = 0;
353     int32_t startDeviceId = 0;
354     bool isCheckPermission = true;
355     CooperateOptions options {
356             .displayX = 500,
357             .displayY = 500,
358             .displayId = 1
359     };
360     SequenceableCooperateOptions sequenceableCooperateOptions(options);
361     ErrCode ret = g_intentionService->StartCooperateWithOptions(remoteNetworkId, userData, startDeviceId,
362         isCheckPermission, sequenceableCooperateOptions);
363     EXPECT_EQ(ret, PERMISSION_EXCEPTION);
364 }
365 
366 /**
367  * @tc.name: IntentionServiceTest5
368  * @tc.desc: Test RegisterCooperateListener
369  * @tc.type: FUNC
370  * @tc.require:
371  */
372 HWTEST_F(IntentionServiceTest, IntentionServiceTest_RegisterCooperateListener001, TestSize.Level0)
373 {
374     CALL_TEST_DEBUG;
375     ErrCode ret = g_intentionService->RegisterCooperateListener();
376     EXPECT_EQ(ret, PERMISSION_EXCEPTION);
377 }
378 
379 /**
380  * @tc.name: IntentionServiceTest6
381  * @tc.desc: Test UnregisterCooperateListener
382  * @tc.type: FUNC
383  * @tc.require:
384  */
385 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UnregisterCooperateListener001, TestSize.Level0)
386 {
387     CALL_TEST_DEBUG;
388     ErrCode ret = g_intentionService->UnregisterCooperateListener();
389     EXPECT_EQ(ret, PERMISSION_EXCEPTION);
390 }
391 
392 /**
393  * @tc.name: IntentionServiceTest7
394  * @tc.desc: Test RegisterHotAreaListener
395  * @tc.type: FUNC
396  * @tc.require:
397  */
398 HWTEST_F(IntentionServiceTest, IntentionServiceTest_RegisterHotAreaListener001, TestSize.Level0)
399 {
400     CALL_TEST_DEBUG;
401     int32_t userData = 0;
402     bool isCheckPermission = true;
403     ErrCode ret = g_intentionServiceNullptr->RegisterHotAreaListener(userData, isCheckPermission);
404     EXPECT_EQ(ret, RET_ERR);
405 }
406 /**
407  * @tc.name: IntentionServiceTest8
408  * @tc.desc: Test UnregisterHotAreaListener
409  * @tc.type: FUNC
410  * @tc.require:
411  */
412 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UnregisterHotAreaListener001, TestSize.Level0)
413 {
414     CALL_TEST_DEBUG;
415     ErrCode ret = g_intentionServiceNullptr->UnregisterHotAreaListener();
416     EXPECT_EQ(ret, RET_ERR);
417 }
418 
419 /**
420  * @tc.name: IntentionServiceTest9
421  * @tc.desc: Test RegisterMouseEventListener
422  * @tc.type: FUNC
423  * @tc.require:
424  */
425 HWTEST_F(IntentionServiceTest, IntentionServiceTest_RegisterMouseEventListener001, TestSize.Level0)
426 {
427     CALL_TEST_DEBUG;
428     std::string networkId = "networkId";
429     ErrCode ret = g_intentionServiceNullptr->RegisterMouseEventListener(networkId);
430     EXPECT_EQ(ret, RET_ERR);
431 }
432 
433 /**
434  * @tc.name: IntentionServiceTest10
435  * @tc.desc: Test UnregisterMouseEventListener
436  * @tc.type: FUNC
437  * @tc.require:
438  */
439 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UnregisterMouseEventListener001, TestSize.Level0)
440 {
441     CALL_TEST_DEBUG;
442     std::string networkId = "networkId";
443     ErrCode ret = g_intentionServiceNullptr->UnregisterMouseEventListener(networkId);
444     EXPECT_EQ(ret, RET_ERR);
445 }
446 
447 /**
448  * @tc.name: IntentionServiceTest11
449  * @tc.desc: Test GetCooperateStateSync
450  * @tc.type: FUNC
451  * @tc.require:
452  */
453 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetCooperateStateSync001, TestSize.Level0)
454 {
455     CALL_TEST_DEBUG;
456     std::string udid = "udid";
457     bool state = true;
458     ErrCode ret = g_intentionServiceNullptr->GetCooperateStateSync(udid, state);
459     EXPECT_EQ(ret, RET_ERR);
460 }
461 
462 /**
463  * @tc.name: IntentionServiceTest12
464  * @tc.desc: Test GetCooperateStateAsync
465  * @tc.type: FUNC
466  * @tc.require:
467  */
468 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetCooperateStateAsync001, TestSize.Level0)
469 {
470     CALL_TEST_DEBUG;
471     std::string networkId = "networkId";
472     int32_t userData = 0;
473     bool isCheckPermission = true;
474     ErrCode ret = g_intentionServiceNullptr->GetCooperateStateAsync(networkId, userData, isCheckPermission);
475     EXPECT_EQ(ret, RET_ERR);
476 }
477 
478 /**
479  * @tc.name: IntentionServiceTest13
480  * @tc.desc: Test SetDamplingCoefficient
481  * @tc.type: FUNC
482  * @tc.require:
483  */
484 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetDamplingCoefficient001, TestSize.Level0)
485 {
486     CALL_TEST_DEBUG;
487     uint32_t direction = 0;
488     double coefficient = 0;
489     ErrCode ret = g_intentionServiceNullptr->RegisterHotAreaListener(direction, coefficient);
490     EXPECT_EQ(ret, RET_ERR);
491 }
492 
493 /**
494  * @tc.name: IntentionServiceTest14
495  * @tc.desc: Test StartDrag
496  * @tc.type: FUNC
497  * @tc.require:
498  */
499 HWTEST_F(IntentionServiceTest, IntentionServiceTest_StartDrag001, TestSize.Level0)
500 {
501     CALL_TEST_DEBUG;
502     DragData dragData;
503     SequenceableDragData sequenceableDragData(dragData);
504     ErrCode ret = g_intentionServiceNullptr->StartDrag(sequenceableDragData);
505     EXPECT_EQ(ret, RET_ERR);
506 }
507 
508 /**
509  * @tc.name: IntentionServiceTest15
510  * @tc.desc: Test StopDrag
511  * @tc.type: FUNC
512  * @tc.require:
513  */
514 HWTEST_F(IntentionServiceTest, IntentionServiceTest_StopDrag001, TestSize.Level0)
515 {
516     CALL_TEST_DEBUG;
517     DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
518     SequenceableDragResult sequenceableDragResult(dropResult);
519     ErrCode ret = g_intentionServiceNullptr->StopDrag(sequenceableDragResult);
520     EXPECT_EQ(ret, RET_ERR);
521 }
522 
523 /**
524  * @tc.name: IntentionServiceTest16
525  * @tc.desc: Test AddDraglistener
526  * @tc.type: FUNC
527  * @tc.require:
528  */
529 HWTEST_F(IntentionServiceTest, IntentionServiceTest_AddDraglistener001, TestSize.Level0)
530 {
531     CALL_TEST_DEBUG;
532     bool isJsCaller = true;
533     ErrCode ret = g_intentionServiceNullptr->AddDraglistener(isJsCaller);
534     EXPECT_EQ(ret, RET_ERR);
535 }
536 
537 /**
538  * @tc.name: IntentionServiceTest17
539  * @tc.desc: Test RemoveDraglistener
540  * @tc.type: FUNC
541  * @tc.require:
542  */
543 HWTEST_F(IntentionServiceTest, IntentionServiceTest_RemoveDraglistener001, TestSize.Level0)
544 {
545     CALL_TEST_DEBUG;
546     bool isJsCaller = true;
547     ErrCode ret = g_intentionServiceNullptr->RemoveDraglistener(isJsCaller);
548     EXPECT_EQ(ret, RET_ERR);
549 }
550 
551 /**
552  * @tc.name: IntentionServiceTest18
553  * @tc.desc: Test AddSubscriptListener
554  * @tc.type: FUNC
555  * @tc.require:
556  */
557 HWTEST_F(IntentionServiceTest, IntentionServiceTest_AddSubscriptListener001, TestSize.Level0)
558 {
559     CALL_TEST_DEBUG;
560     ErrCode ret = g_intentionServiceNullptr->AddSubscriptListener();
561     EXPECT_EQ(ret, RET_ERR);
562 }
563 
564 /**
565  * @tc.name: IntentionServiceTest19
566  * @tc.desc: Test RemoveSubscriptListener
567  * @tc.type: FUNC
568  * @tc.require:
569  */
570 HWTEST_F(IntentionServiceTest, IntentionServiceTest_RemoveSubscriptListener001, TestSize.Level0)
571 {
572     CALL_TEST_DEBUG;
573     ErrCode ret = g_intentionServiceNullptr->RemoveSubscriptListener();
574     EXPECT_EQ(ret, RET_ERR);
575 }
576 
577 /**
578  * @tc.name: IntentionServiceTest20
579  * @tc.desc: Test SetDragWindowVisible
580  * @tc.type: FUNC
581  * @tc.require:
582  */
583 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetDragWindowVisible001, TestSize.Level0)
584 {
585     CALL_TEST_DEBUG;
586     DragVisibleParam dragVisibleParam;
587     SequenceableDragVisible sequenceableDragVisible(dragVisibleParam);
588     ErrCode ret = g_intentionServiceNullptr->SetDragWindowVisible(sequenceableDragVisible);
589     EXPECT_EQ(ret, RET_ERR);
590 }
591 
592 /**
593  * @tc.name: IntentionServiceTest21
594  * @tc.desc: Test UpdateDragStyle
595  * @tc.type: FUNC
596  * @tc.require:
597  */
598 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UpdateDragStyle001, TestSize.Level0)
599 {
600     CALL_TEST_DEBUG;
601     int32_t style = 0;
602     int32_t eventId = 0;
603     ErrCode ret = g_intentionServiceNullptr->UpdateDragStyle(style, eventId);
604     EXPECT_EQ(ret, RET_ERR);
605 }
606 
607 /**
608  * @tc.name: IntentionServiceTest22
609  * @tc.desc: Test UpdateShadowPic
610  * @tc.type: FUNC
611  * @tc.require:
612  */
613 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UpdateShadowPic001, TestSize.Level0)
614 {
615     CALL_TEST_DEBUG;
616     std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT);
617     ErrCode ret = g_intentionServiceNullptr->UpdateShadowPic(pixelMap, 0, 0);
618     EXPECT_EQ(ret, RET_ERR);
619 }
620 
621 /**
622  * @tc.name: IntentionServiceTest23
623  * @tc.desc: Test GetDragTargetPid
624  * @tc.type: FUNC
625  * @tc.require:
626  */
627 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDragTargetPid001, TestSize.Level0)
628 {
629     CALL_TEST_DEBUG;
630     int32_t targetPid = 0;
631     ErrCode ret = g_intentionServiceNullptr->GetDragTargetPid(targetPid);
632     EXPECT_EQ(ret, RET_ERR);
633 }
634 
635 /**
636  * @tc.name: IntentionServiceTest24
637  * @tc.desc: GetUdKey
638  * @tc.type: FUNC
639  * @tc.require:
640  */
641 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetUdKey001, TestSize.Level0)
642 {
643     CALL_TEST_DEBUG;
644     std::string udKey = "udkey";
645     ErrCode ret = g_intentionServiceNullptr->GetUdKey(udKey);
646     EXPECT_EQ(ret, RET_ERR);
647 }
648 
649 /**
650  * @tc.name: IntentionServiceTest25
651  * @tc.desc: Test GetShadowOffset
652  * @tc.type: FUNC
653  * @tc.require:
654  */
655 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetShadowOffset001, TestSize.Level0)
656 {
657     CALL_TEST_DEBUG;
658     int32_t offsetX = 1;
659     int32_t offsetY = 1;
660     int32_t width = 1;
661     int32_t height = 1;
662     ErrCode ret = g_intentionServiceNullptr->GetShadowOffset(offsetX, offsetY, width, height);
663     EXPECT_EQ(ret, RET_ERR);
664 }
665 
666 /**
667  * @tc.name: IntentionServiceTest26
668  * @tc.desc: Test GetDragData
669  * @tc.type: FUNC
670  * @tc.require:
671  */
672 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDragData001, TestSize.Level0)
673 {
674     CALL_TEST_DEBUG;
675     DragData dragData;
676     SequenceableDragData sequenceableDragData(dragData);
677     ErrCode ret = g_intentionServiceNullptr->GetDragData(sequenceableDragData);
678     EXPECT_EQ(ret, RET_ERR);
679 }
680 
681 /**
682  * @tc.name: IntentionServiceTest27
683  * @tc.desc: Test UpdatePreviewStyle
684  * @tc.type: FUNC
685  * @tc.require:
686  */
687 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UpdatePreviewStyle001, TestSize.Level0)
688 {
689     CALL_TEST_DEBUG;
690     PreviewStyle previewStyle;
691     SequenceablePreviewStyle sequenceablePreviewStyle(previewStyle);
692     ErrCode ret = g_intentionServiceNullptr->UpdatePreviewStyle(sequenceablePreviewStyle);
693     EXPECT_EQ(ret, RET_ERR);
694 }
695 
696 /**
697  * @tc.name: IntentionServiceTest28
698  * @tc.desc: Test UpdatePreviewStyleWithAnimation
699  * @tc.type: FUNC
700  * @tc.require:
701  */
702 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UpdatePreviewStyleWithAnimation001, TestSize.Level0)
703 {
704     CALL_TEST_DEBUG;
705     PreviewStyle previewStyle;
706     PreviewAnimation previewAnimation;
707     SequenceablePreviewAnimation sequenceablePreviewAnimation(previewStyle, previewAnimation);
708     ErrCode ret = g_intentionServiceNullptr->UpdatePreviewStyleWithAnimation(sequenceablePreviewAnimation);
709     EXPECT_EQ(ret, RET_ERR);
710 }
711 
712 /**
713  * @tc.name: IntentionServiceTest29
714  * @tc.desc: Test RotateDragWindowSync
715  * @tc.type: FUNC
716  * @tc.require:
717  */
718 HWTEST_F(IntentionServiceTest, IntentionServiceTest_RotateDragWindowSync001, TestSize.Level0)
719 {
720     CALL_TEST_DEBUG;
721     std::shared_ptr<Rosen::RSTransaction> rsTransaction { nullptr };
722     SequenceableRotateWindow sequenceableRotateWindow(rsTransaction);
723     ErrCode ret = g_intentionServiceNullptr->RotateDragWindowSync(sequenceableRotateWindow);
724     EXPECT_EQ(ret, RET_ERR);
725 }
726 
727 /**
728  * @tc.name: IntentionServiceTest30
729  * @tc.desc: Test SetDragWindowScreenId
730  * @tc.type: FUNC
731  * @tc.require:
732  */
733 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetDragWindowScreenId001, TestSize.Level0)
734 {
735     CALL_TEST_DEBUG;
736     ErrCode ret = g_intentionServiceNullptr->SetDragWindowScreenId(0, 0);
737     EXPECT_EQ(ret, RET_ERR);
738 }
739 
740 /**
741  * @tc.name: IntentionServiceTest31
742  * @tc.desc: Test GetDragSummary
743  * @tc.type: FUNC
744  * @tc.require:
745  */
746 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDragSummary001, TestSize.Level0)
747 {
748     CALL_TEST_DEBUG;
749     std::map<std::string, int64_t> summarys;
750     bool isJsCaller = true;
751     ErrCode ret = g_intentionServiceNullptr->GetDragSummary(summarys, isJsCaller);
752     EXPECT_EQ(ret, RET_ERR);
753 }
754 
755 /**
756  * @tc.name: IntentionServiceTest32
757  * @tc.desc: Test SetDragSwitchState
758  * @tc.type: FUNC
759  * @tc.require:
760  */
761 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetDragSwitchState001, TestSize.Level0)
762 {
763     CALL_TEST_DEBUG;
764     bool enable = true;
765     bool isJsCaller = true;
766     ErrCode ret = g_intentionServiceNullptr->SetDragSwitchState(enable, isJsCaller);
767     EXPECT_EQ(ret, RET_ERR);
768 }
769 
770 /**
771  * @tc.name: IntentionServiceTest33
772  * @tc.desc: Test SetAppDragSwitchState
773  * @tc.type: FUNC
774  * @tc.require:
775  */
776 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetAppDragSwitchState001, TestSize.Level0)
777 {
778     CALL_TEST_DEBUG;
779     bool enable = true;
780     std::string pkgName = "pkg";
781     bool isJsCaller = true;
782     ErrCode ret = g_intentionServiceNullptr->SetAppDragSwitchState(enable, pkgName, isJsCaller);
783     EXPECT_EQ(ret, RET_ERR);
784 }
785 
786 /**
787  * @tc.name: IntentionServiceTest34
788  * @tc.desc: Test GetDragState
789  * @tc.type: FUNC
790  * @tc.require:
791  */
792 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDragState001, TestSize.Level0)
793 {
794     CALL_TEST_DEBUG;
795     int32_t dragState = 0;
796     ErrCode ret = g_intentionServiceNullptr->GetDragState(dragState);
797     EXPECT_EQ(ret, RET_ERR);
798 }
799 
800 /**
801  * @tc.name: IntentionServiceTest35
802  * @tc.desc: Test EnableUpperCenterMode
803  * @tc.type: FUNC
804  * @tc.require:
805  */
806 HWTEST_F(IntentionServiceTest, IntentionServiceTest_EnableUpperCenterMode001, TestSize.Level0)
807 {
808     CALL_TEST_DEBUG;
809     bool enable = true;
810     ErrCode ret = g_intentionServiceNullptr->EnableUpperCenterMode(enable);
811     EXPECT_EQ(ret, RET_ERR);
812 }
813 
814 /**
815  * @tc.name: IntentionServiceTest36
816  * @tc.desc: Test GetDragAction
817  * @tc.type: FUNC
818  * @tc.require:
819  */
820 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDragAction001, TestSize.Level0)
821 {
822     CALL_TEST_DEBUG;
823     int32_t dragAction = 0;
824     ErrCode ret = g_intentionServiceNullptr->GetDragAction(dragAction);
825     EXPECT_EQ(ret, RET_ERR);
826 }
827 
828 /**
829  * @tc.name: IntentionServiceTest37
830  * @tc.desc: Test GetExtraInfo
831  * @tc.type: FUNC
832  * @tc.require:
833  */
834 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetExtraInfo001, TestSize.Level0)
835 {
836     CALL_TEST_DEBUG;
837     std::string extraInfo = "extraInfo";
838     ErrCode ret = g_intentionServiceNullptr->GetExtraInfo(extraInfo);
839     EXPECT_EQ(ret, RET_ERR);
840 }
841 
842 /**
843  * @tc.name: IntentionServiceTest38
844  * @tc.desc: Test AddPrivilege
845  * @tc.type: FUNC
846  * @tc.require:
847  */
848 HWTEST_F(IntentionServiceTest, IntentionServiceTest_AddPrivilege001, TestSize.Level0)
849 {
850     CALL_TEST_DEBUG;
851     ErrCode ret = g_intentionServiceNullptr->AddPrivilege();
852     EXPECT_EQ(ret, RET_ERR);
853 }
854 
855 /**
856  * @tc.name: IntentionServiceTest39
857  * @tc.desc: Test EraseMouseIcon
858  * @tc.type: FUNC
859  * @tc.require:
860  */
861 HWTEST_F(IntentionServiceTest, IntentionServiceTest_EraseMouseIcon001, TestSize.Level0)
862 {
863     CALL_TEST_DEBUG;
864     ErrCode ret = g_intentionServiceNullptr->EraseMouseIcon();
865     EXPECT_EQ(ret, RET_ERR);
866 }
867 
868 /**
869  * @tc.name: IntentionServiceTest40
870  * @tc.desc: Test SetMouseDragMonitorState
871  * @tc.type: FUNC
872  * @tc.require:
873  */
874 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetMouseDragMonitorState001, TestSize.Level0)
875 {
876     CALL_TEST_DEBUG;
877     bool state = true;
878     ErrCode ret = g_intentionServiceNullptr->SetMouseDragMonitorState(state);
879     EXPECT_EQ(ret, RET_ERR);
880 }
881 
882 /**
883  * @tc.name: IntentionServiceTest41
884  * @tc.desc: Test SetDraggableState
885  * @tc.type: FUNC
886  * @tc.require:
887  */
888 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetDraggableState001, TestSize.Level0)
889 {
890     CALL_TEST_DEBUG;
891     bool state = true;
892     ErrCode ret = g_intentionServiceNullptr->SetDraggableState(state);
893     EXPECT_EQ(ret, RET_ERR);
894 }
895 
896 /**
897  * @tc.name: IntentionServiceTest42
898  * @tc.desc: Test GetAppDragSwitchState
899  * @tc.type: FUNC
900  * @tc.require:
901  */
902 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetAppDragSwitchState001, TestSize.Level0)
903 {
904     CALL_TEST_DEBUG;
905     bool state = true;
906     ErrCode ret = g_intentionServiceNullptr->GetAppDragSwitchState(state);
907     EXPECT_EQ(ret, RET_ERR);
908 }
909 
910 /**
911  * @tc.name: IntentionServiceTest43
912  * @tc.desc: Test SetDraggableStateAsync
913  * @tc.type: FUNC
914  * @tc.require:
915  */
916 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SetDraggableStateAsync001, TestSize.Level0)
917 {
918     CALL_TEST_DEBUG;
919     bool state = true;
920     int64_t downTime = 6;
921     ErrCode ret = g_intentionServiceNullptr->SetDraggableStateAsync(state, downTime);
922     EXPECT_EQ(ret, RET_ERR);
923 }
924 
925 /**
926  * @tc.name: IntentionServiceTest44
927  * @tc.desc: Test GetDragBundleInfo
928  * @tc.type: FUNC
929  * @tc.require:
930  */
931 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDragBundleInfo001, TestSize.Level0)
932 {
933     CALL_TEST_DEBUG;
934     std::string bundleName = {"name"};
935     bool state = true;
936     ErrCode ret = g_intentionServiceNullptr->GetDragBundleInfo(bundleName, state);
937     EXPECT_EQ(ret, RET_ERR);
938     ret = g_intentionServiceNullptr->GetDragBundleInfo(bundleName, state);
939     EXPECT_EQ(ret, RET_ERR);
940 }
941 /**
942  * @tc.name: IntentionServiceTest45
943  * @tc.desc: Test SubscribeStationaryCallback
944  * @tc.desc: Test GetDragBundleInfo
945  * @tc.type: FUNC
946  * @tc.require:
947  */
948 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SubscribeStationary001, TestSize.Level0)
949 {
950     CALL_TEST_DEBUG;
951     int32_t type = Type::TYPE_STILL;
952     int32_t event = ActivityEvent::ENTER;
953     int32_t reportTime = ReportLatencyNs::MIDDLE;
954     ErrCode ret = g_intentionService->SubscribeStationaryCallback(type, event, reportTime, stationaryCallback_);
955     EXPECT_EQ(ret, RET_OK);
956 }
957 
958 /**
959  * @tc.name: IntentionServiceTest46
960  * @tc.desc: Test UnsubscribeStationaryCallback
961  * @tc.type: FUNC
962  * @tc.require:
963  */
964 HWTEST_F(IntentionServiceTest, IntentionServiceTest_UnsubscribeStationary001, TestSize.Level0)
965 {
966     CALL_TEST_DEBUG;
967     int32_t type = Type::TYPE_STILL;
968     int32_t event = ActivityEvent::ENTER;
969     ErrCode ret = g_intentionService->UnsubscribeStationaryCallback(type, event, stationaryCallback_);
970     EXPECT_EQ(ret, RET_OK);
971 }
972 
973 /**
974  * @tc.name: IntentionServiceTest47
975  * @tc.desc: Test GetDeviceStatusData
976  * @tc.type: FUNC
977  * @tc.require:
978  */
979 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDeviceStatusData001, TestSize.Level0)
980 {
981     CALL_TEST_DEBUG;
982     int32_t type = Type::TYPE_STILL;
983     int32_t retType = 0;
984     int32_t retValue = 0;
985     int32_t ret = g_intentionService->GetDeviceStatusData(type, retType, retValue);
986     EXPECT_EQ(ret, RET_OK);
987 }
988 
989 /**
990  * @tc.name: IntentionServiceTest48
991  * @tc.desc: Test GetDevicePostureDataSync
992  * @tc.type: FUNC
993  * @tc.require:
994  */
995 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDevicePostureDataSync001, TestSize.Level0)
996 {
997     CALL_TEST_DEBUG;
998     DevicePostureData data;
999     SequenceablePostureData seqData(data);
1000     ErrCode ret = g_intentionService->GetDevicePostureDataSync(seqData);
1001     EXPECT_TRUE(ret == RET_NO_SUPPORT || ret == RET_OK);
1002     data = seqData.GetPostureData();
1003     EXPECT_TRUE(data.rollRad >= 0 && data.rollRad <= DOUBLEPIMAX && data.pitchRad >= 0 &&
1004         data.pitchRad <= DOUBLEPIMAX && data.yawRad >= 0 && data.yawRad <= DOUBLEPIMAX);
1005 }
1006 
1007 /**
1008  * @tc.name: IntentionServiceTest49
1009  * @tc.desc: Test GetPageContent
1010  * @tc.type: FUNC
1011  * @tc.require:
1012  */
1013 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetPageContent001, TestSize.Level0)
1014 {
1015     CALL_TEST_DEBUG;
1016     OnScreen::SequenceablePageContent content;
1017     OnScreen::SequenceableContentOption option;
1018     ErrCode ret = g_intentionService->GetPageContent(option, content);
1019     EXPECT_TRUE(ret >= RET_ERR);
1020 }
1021 
1022 /**
1023  * @tc.name: IntentionServiceTest50
1024  * @tc.desc: Test SendControlEvent
1025  * @tc.type: FUNC
1026  * @tc.require:
1027  */
1028 HWTEST_F(IntentionServiceTest, IntentionServiceTest_SendControlEvent001, TestSize.Level0)
1029 {
1030     CALL_TEST_DEBUG;
1031     OnScreen::SequenceableControlEvent event;
1032     event.controlEvent_.eventType = OnScreen::EventType::SCROLL_TO_HOOK;
1033     ErrCode ret = g_intentionService->SendControlEvent(event);
1034     EXPECT_TRUE(ret >= RET_ERR);
1035 }
1036 
1037 /**
1038  * @tc.name: IntentionServiceTest_GetDragSummaryInfo
1039  * @tc.desc: Test GetDragSummaryInfo
1040  * @tc.type: FUNC
1041  * @tc.require:
1042  */
1043 HWTEST_F(IntentionServiceTest, IntentionServiceTest_GetDragSummaryInfo, TestSize.Level1)
1044 {
1045     CALL_TEST_DEBUG;
1046     g_dragMgr.dragState_ = DragState::START;
1047     DragSummaryInfo dragSummaryInfo;
1048     SequenceableDragSummaryInfo sequenceableDragSummaryInfo(dragSummaryInfo);
1049     bool ret = g_intentionService->GetDragSummaryInfo(sequenceableDragSummaryInfo);
1050     EXPECT_EQ(ret, RET_OK);
1051     g_dragMgr.dragState_ = DragState::STOP;
1052     ErrCode errCode = g_intentionService->GetDragSummaryInfo(sequenceableDragSummaryInfo);
1053     EXPECT_EQ(errCode, RET_ERR);
1054 }
1055 } // namespace DeviceStatus
1056 } // namespace Msdp
1057 } // namespace OHOS