• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "cooperate_out_test.h"
16 
17 #include "cooperate_context.h"
18 #include "cooperate_free.h"
19 #include "cooperate_in.h"
20 #include "cooperate_out.h"
21 #include "ddm_adapter.h"
22 #include "device.h"
23 #include "dsoftbus_adapter.h"
24 #include "i_device.h"
25 #include "i_cooperate_state.h"
26 #include "input_adapter.h"
27 #include "ipc_skeleton.h"
28 #include "mouse_location.h"
29 #include "socket_session.h"
30 #include "state_machine.h"
31 
32 namespace OHOS {
33 namespace Msdp {
34 namespace DeviceStatus {
35 using namespace testing::ext;
36 using namespace Cooperate;
37 namespace {
38 const std::string TEST_DEV_NODE { "/dev/input/TestDeviceNode" };
39 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
40 constexpr int32_t HOTAREA_500 { 500 };
41 constexpr int32_t HOTAREA_NEGATIVE_500 { -500 };
42 constexpr int32_t HOTAREA_NEGATIVE_200 { -200 };
43 constexpr int32_t HOTAREA_250 { 250 };
44 constexpr int32_t HOTAREA_200 { 200 };
45 constexpr int32_t HOTAREA_150 { 150 };
46 constexpr int32_t HOTAREA_50 { 50 };
47 std::shared_ptr<Context> g_context { nullptr };
48 std::shared_ptr<Context> g_contextOne { nullptr };
49 std::shared_ptr<HotplugObserver> g_observer { nullptr };
50 ContextService *g_instance = nullptr;
51 IContext *g_icontext { nullptr };
52 std::shared_ptr<SocketSession> g_session { nullptr };
53 DelegateTasks g_delegateTasks;
54 DeviceManager g_devMgr;
55 TimerManager g_timerMgr;
56 DragManager g_dragMgr;
57 SocketSessionManager g_socketSessionMgr;
58 std::unique_ptr<IDDMAdapter> g_ddm { nullptr };
59 std::unique_ptr<IInputAdapter> g_input { nullptr };
60 std::unique_ptr<IPluginManager> g_pluginMgr { nullptr };
61 std::unique_ptr<IDSoftbusAdapter> g_dsoftbus { nullptr };
62 std::shared_ptr<Cooperate::StateMachine> g_stateMachine { nullptr };
63 const std::string LOCAL_NETWORKID { "testLocalNetworkId" };
64 const std::string REMOTE_NETWORKID { "testRemoteNetworkId" };
65 } // namespace
66 
ContextService()67 ContextService::ContextService()
68 {
69 }
70 
~ContextService()71 ContextService::~ContextService()
72 {
73 }
74 
GetDelegateTasks()75 IDelegateTasks& ContextService::GetDelegateTasks()
76 {
77     return g_delegateTasks;
78 }
79 
GetDeviceManager()80 IDeviceManager& ContextService::GetDeviceManager()
81 {
82     return g_devMgr;
83 }
84 
GetTimerManager()85 ITimerManager& ContextService::GetTimerManager()
86 {
87     return g_timerMgr;
88 }
89 
GetDragManager()90 IDragManager& ContextService::GetDragManager()
91 {
92     return g_dragMgr;
93 }
94 
GetInstance()95 ContextService* ContextService::GetInstance()
96 {
97     static std::once_flag flag;
98     std::call_once(flag, [&]() {
99         ContextService *cooContext = new (std::nothrow) ContextService();
100         CHKPL(cooContext);
101         g_instance = cooContext;
102     });
103     return g_instance;
104 }
105 
GetSocketSessionManager()106 ISocketSessionManager& ContextService::GetSocketSessionManager()
107 {
108     return g_socketSessionMgr;
109 }
110 
GetDDM()111 IDDMAdapter& ContextService::GetDDM()
112 {
113     return *g_ddm;
114 }
115 
GetPluginManager()116 IPluginManager& ContextService::GetPluginManager()
117 {
118     return *g_pluginMgr;
119 }
120 
GetInput()121 IInputAdapter& ContextService::GetInput()
122 {
123     return *g_input;
124 }
125 
GetDSoftbus()126 IDSoftbusAdapter& ContextService::GetDSoftbus()
127 {
128     return *g_dsoftbus;
129 }
130 
NotifyCooperate()131 void CooperateOutTest::NotifyCooperate()
132 {
133     int32_t errCode { static_cast<int32_t>(CoordinationErrCode::COORDINATION_OK) };
134     EventManager::CooperateStateNotice cooperateStateNotice{IPCSkeleton::GetCallingPid(),
135         MessageId::COORDINATION_MESSAGE, 1, true, errCode};
136     g_contextOne->eventMgr_.NotifyCooperateState(cooperateStateNotice);
137     g_context->eventMgr_.NotifyCooperateState(cooperateStateNotice);
138     g_socketSessionMgr.AddSession(g_session);
139     g_context->eventMgr_.NotifyCooperateState(cooperateStateNotice);
140     g_context->eventMgr_.GetCooperateState(cooperateStateNotice);
141 }
142 
CheckInHot()143 void CooperateOutTest::CheckInHot()
144 {
145     g_context->hotArea_.displayX_ = 0;
146     g_context->hotArea_.height_ = HOTAREA_500;
147     g_context->hotArea_.displayY_ = HOTAREA_250;
148     g_context->hotArea_.CheckInHotArea();
149     g_context->hotArea_.width_ = HOTAREA_200;
150     g_context->hotArea_.displayX_ = HOTAREA_150;
151     g_context->hotArea_.height_ = HOTAREA_500;
152     g_context->hotArea_.displayY_ = HOTAREA_250;
153     g_context->hotArea_.CheckInHotArea();
154     g_context->hotArea_.displayY_ = HOTAREA_50;
155     g_context->hotArea_.width_ = HOTAREA_500;
156     g_context->hotArea_.displayX_ = HOTAREA_250;
157     g_context->hotArea_.CheckInHotArea();
158     g_context->hotArea_.height_ = HOTAREA_500;
159     g_context->hotArea_.displayY_ = HOTAREA_500;
160     g_context->hotArea_.width_ = HOTAREA_500;
161     g_context->hotArea_.displayX_ = HOTAREA_250;
162     g_context->hotArea_.CheckInHotArea();
163     g_context->hotArea_.height_ = HOTAREA_500;
164     g_context->hotArea_.displayY_ = HOTAREA_NEGATIVE_500;
165     g_context->hotArea_.width_ = HOTAREA_500;
166     g_context->hotArea_.displayX_ = HOTAREA_NEGATIVE_200;
167     g_context->hotArea_.CheckInHotArea();
168 }
169 
SetUpTestCase()170 void CooperateOutTest::SetUpTestCase() {}
171 
SetUp()172 void CooperateOutTest::SetUp()
173 {
174     g_ddm = std::make_unique<DDMAdapter>();
175     g_input = std::make_unique<InputAdapter>();
176     g_dsoftbus = std::make_unique<DSoftbusAdapter>();
177     g_contextOne = std::make_shared<Context>(g_icontext);
178     auto env = ContextService::GetInstance();
179     g_context = std::make_shared<Context>(env);
180     int32_t moduleType = 1;
181     int32_t tokenType = 1;
182     int32_t uid = IPCSkeleton::GetCallingUid();
183     int32_t pid = IPCSkeleton::GetCallingPid();
184     int32_t sockFds[2] { -1, -1 };
185     g_session = std::make_shared<SocketSession>("test", moduleType, tokenType, sockFds[0], uid, pid);
186 }
187 
TearDown()188 void CooperateOutTest::TearDown()
189 {
190     g_context = nullptr;
191     g_contextOne = nullptr;
192     g_session = nullptr;
193     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
194 }
195 
OnThreeStates(const CooperateEvent & event)196 void CooperateOutTest::OnThreeStates(const CooperateEvent &event)
197 {
198     auto env = ContextService::GetInstance();
199     Context cooperateContext(env);
200     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
201     g_stateMachine->current_ = CooperateState::COOPERATE_STATE_OUT;
202     g_stateMachine->OnEvent(cooperateContext, event);
203     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
204     g_stateMachine->current_ = CooperateState::COOPERATE_STATE_IN;
205     g_stateMachine->OnEvent(cooperateContext, event);
206     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
207     g_stateMachine->current_ = CooperateState::COOPERATE_STATE_FREE;
208     g_stateMachine->OnEvent(cooperateContext, event);
209     std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
210 }
211 
212 class CooperateObserver final : public ICooperateObserver {
213 public:
214     CooperateObserver() = default;
215     virtual ~CooperateObserver() = default;
216 
IsAllowCooperate()217     virtual bool IsAllowCooperate()
218     {
219         return true;
220     }
OnStartCooperate(StartCooperateData & data)221     virtual void OnStartCooperate(StartCooperateData &data) {}
OnRemoteStartCooperate(RemoteStartCooperateData & data)222     virtual void OnRemoteStartCooperate(RemoteStartCooperateData &data) {}
OnStopCooperate(const std::string & remoteNetworkId)223     virtual void OnStopCooperate(const std::string &remoteNetworkId) {}
OnTransitionOut(const std::string & remoteNetworkId,const CooperateInfo & cooperateInfo)224     virtual void OnTransitionOut(const std::string &remoteNetworkId, const CooperateInfo &cooperateInfo) {}
OnTransitionIn(const std::string & remoteNetworkId,const CooperateInfo & cooperateInfo)225     virtual void OnTransitionIn(const std::string &remoteNetworkId, const CooperateInfo &cooperateInfo) {}
OnBack(const std::string & remoteNetworkId,const CooperateInfo & cooperateInfo)226     virtual void OnBack(const std::string &remoteNetworkId, const CooperateInfo &cooperateInfo) {}
OnRelay(const std::string & remoteNetworkId,const CooperateInfo & cooperateInfo)227     virtual void OnRelay(const std::string &remoteNetworkId, const CooperateInfo &cooperateInfo) {}
OnReset()228     virtual void OnReset() {}
CloseDistributedFileConnection(const std::string & remoteNetworkId)229     virtual void CloseDistributedFileConnection(const std::string &remoteNetworkId) {}
230 };
231 
232 /**
233  * @tc.name: CooperateOutTest001
234  * @tc.desc: Test OnRelay in the CooperateOut class
235  * @tc.type: FUNC
236  * @tc.require:
237  */
238 HWTEST_F(CooperateOutTest, CooperateOutTest001, TestSize.Level1)
239 {
240     CALL_TEST_DEBUG;
241     bool normal = false;
242     CooperateEvent event(
243         CooperateEventType::DSOFTBUS_RELAY_COOPERATE,
244         DSoftbusRelayCooperate {
245             .networkId = REMOTE_NETWORKID,
246             .normal = normal,
247         });
248     auto env = ContextService::GetInstance();
249     ASSERT_NE(env, nullptr);
250     Context cooperateContext(env);
251     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
252     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
253     ASSERT_NE(stateOut.initial_, nullptr);
254     stateOut.initial_->OnRelay(cooperateContext, event);
255     cooperateContext.remoteNetworkId_ = REMOTE_NETWORKID;
256     stateOut.initial_->OnRelay(cooperateContext, event);
257     bool ret = g_context->mouseLocation_.HasLocalListener();
258     EXPECT_FALSE(ret);
259 }
260 
261 /**
262  * @tc.name: CooperateOutTest002
263  * @tc.desc: Test OnComeBack in the CooperateOut class
264  * @tc.type: FUNC
265  * @tc.require:
266  */
267 HWTEST_F(CooperateOutTest, CooperateOutTest002, TestSize.Level1)
268 {
269     CALL_TEST_DEBUG;
270     auto cursorpos = g_context->NormalizedCursorPosition();
271     CooperateEvent comeBackEvent(
272         CooperateEventType::DSOFTBUS_COME_BACK,
273         DSoftbusComeBack {
274             .originNetworkId = LOCAL_NETWORKID,
275             .success = true,
276             .cursorPos = cursorpos,
277         });
278     auto env = ContextService::GetInstance();
279     ASSERT_NE(env, nullptr);
280     Context cooperateContext(env);
281     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
282     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
283     ASSERT_NE(stateOut.initial_, nullptr);
284     cooperateContext.remoteNetworkId_ = REMOTE_NETWORKID;
285     stateOut.initial_->OnComeBack(cooperateContext, comeBackEvent);
286     cooperateContext.remoteNetworkId_ = LOCAL_NETWORKID;
287     stateOut.initial_->OnComeBack(cooperateContext, comeBackEvent);
288     bool ret = g_context->mouseLocation_.HasLocalListener();
289     EXPECT_FALSE(ret);
290 }
291 
292 /**
293  * @tc.name: CooperateOutTest003
294  * @tc.desc: Test OnRemoteStart
295  * @tc.type: FUNC
296  * @tc.require:
297  */
298 HWTEST_F(CooperateOutTest, CooperateOutTest003, TestSize.Level1)
299 {
300     CALL_TEST_DEBUG;
301     std::string localNetworkId = g_context->dsoftbus_.GetLocalNetworkId();
302     CooperateEvent bothLocalEvent(
303         CooperateEventType::DSOFTBUS_START_COOPERATE,
304         DSoftbusStartCooperate {
305             .networkId = localNetworkId
306         });
307     auto env = ContextService::GetInstance();
308     ASSERT_NE(env, nullptr);
309     Context cooperateContext(env);
310     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
311     cooperateContext.remoteNetworkId_ = localNetworkId;
312     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
313     ASSERT_NE(stateOut.initial_, nullptr);
314     stateOut.initial_->OnRemoteStart(cooperateContext, bothLocalEvent);
315     CooperateEvent bothLocalEventStop(
316         CooperateEventType::DSOFTBUS_STOP_COOPERATE,
317         DDMBoardOnlineEvent {
318             .networkId = localNetworkId
319         });
320     stateOut.initial_->OnRemoteStop(cooperateContext, bothLocalEventStop);
321     bool ret = g_context->mouseLocation_.HasLocalListener();
322     EXPECT_FALSE(ret);
323 }
324 
325 /**
326  * @tc.name: CooperateOutTest005
327  * @tc.desc: Test cooperate plugin
328  * @tc.type: FUNC
329  * @tc.require:
330  */
331 HWTEST_F(CooperateOutTest, CooperateOutTest005, TestSize.Level1)
332 {
333     CALL_TEST_DEBUG;
334     auto env = ContextService::GetInstance();
335     ASSERT_NE(env, nullptr);
336     Context cooperateContext(env);
337     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
338     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
339     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
340     ASSERT_NE(relay, nullptr);
341     cooperateContext.remoteNetworkId_ = REMOTE_NETWORKID;
342     int32_t testErrCode = 0;
343     CooperateEvent event (
344         CooperateEventType::DSOFTBUS_SESSION_OPENED,
345         DDMBoardOnlineEvent {
346             .networkId = REMOTE_NETWORKID,
347             .normal = true,
348             .errCode = testErrCode,
349     });
350     g_stateMachine->isCooperateEnable_ = true;
351     g_stateMachine->current_ = CooperateState::COOPERATE_STATE_OUT;
352     ASSERT_NO_FATAL_FAILURE(relay->OnBoardOffline(cooperateContext, event));
353 }
354 
355 /**
356  * @tc.name: CooperateOutTest006
357  * @tc.desc: Test cooperate plugin
358  * @tc.type: FUNC
359  * @tc.require:
360  */
361 HWTEST_F(CooperateOutTest, CooperateOutTest006, TestSize.Level1)
362 {
363     CALL_TEST_DEBUG;
364     auto env = ContextService::GetInstance();
365     ASSERT_NE(env, nullptr);
366     Context cooperateContext(env);
367     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
368     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
369     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
370     ASSERT_NE(relay, nullptr);
371     cooperateContext.remoteNetworkId_ = REMOTE_NETWORKID;
372     int32_t testErrCode = 0;
373     CooperateEvent event (
374         CooperateEventType::DSOFTBUS_SESSION_OPENED,
375         DDMBoardOnlineEvent {
376             .networkId = REMOTE_NETWORKID,
377             .normal = false,
378             .errCode = testErrCode,
379     });
380     g_stateMachine->isCooperateEnable_ = true;
381     g_stateMachine->current_ = CooperateState::COOPERATE_STATE_OUT;
382     ASSERT_NO_FATAL_FAILURE(relay->OnSwitchChanged(cooperateContext, event));
383 }
384 
385 /**
386  * @tc.name: CooperateOutTest007
387  * @tc.desc: Test cooperate plugin
388  * @tc.type: FUNC
389  * @tc.require:
390  */
391 HWTEST_F(CooperateOutTest, CooperateOutTest007, TestSize.Level1)
392 {
393     CALL_TEST_DEBUG;
394     auto env = ContextService::GetInstance();
395     ASSERT_NE(env, nullptr);
396     Context cooperateContext(env);
397     StopCooperateEvent stopEvent {
398         .pid = IPCSkeleton::GetCallingPid(),
399         .userData = 1,
400         .isUnchained = false,
401     };
402     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
403     Cooperate::CooperateOut cooperateOut(*g_stateMachine, env);
404     ASSERT_NO_FATAL_FAILURE(cooperateOut.UnchainConnections(cooperateContext, stopEvent));
405 }
406 
407 /**
408  * @tc.name: CooperateOutTest008
409  * @tc.desc: Test cooperate plugin
410  * @tc.type: FUNC
411  * @tc.require:
412  */
413 HWTEST_F(CooperateOutTest, CooperateOutTest008, TestSize.Level1)
414 {
415     CALL_TEST_DEBUG;
416     CooperateEvent event(
417         CooperateEventType::WITH_OPTIONS_START,
418         StartWithOptionsEvent{
419             .errCode = std::make_shared<std::promise<int32_t>>(),
420     });
421     auto env = ContextService::GetInstance();
422     ASSERT_NE(env, nullptr);
423     Context cooperateContext(env);
424     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
425     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
426     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
427     ASSERT_NE(relay, nullptr);
428     relay->OnStartWithOptions(cooperateContext, event);
429     bool ret = g_context->mouseLocation_.HasLocalListener();
430     EXPECT_FALSE(ret);
431 }
432 
433 /**
434  * @tc.name: CooperateOutTest009
435  * @tc.desc: Test cooperate plugin
436  * @tc.type: FUNC
437  * @tc.require:
438  */
439 HWTEST_F(CooperateOutTest, CooperateOutTest009, TestSize.Level1)
440 {
441     CALL_TEST_DEBUG;
442     CooperateEvent event(
443         CooperateEventType::DSOFTBUS_COOPERATE_WITH_OPTIONS,
444         DSoftbusCooperateOptions{
445             .networkId = "test",
446     });
447     auto env = ContextService::GetInstance();
448     ASSERT_NE(env, nullptr);
449     Context cooperateContext(env);
450     StartCooperateEvent startEvent {IPCSkeleton::GetCallingPid(), 1, "testtrue", 1,
451         std::make_shared<std::promise<int32_t>>(),
452     };
453     cooperateContext.StartCooperate(startEvent);
454     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
455     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
456     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
457     ASSERT_NE(relay, nullptr);
458     relay->OnRemoteStartWithOptions(cooperateContext, event);
459     bool ret = g_context->mouseLocation_.HasLocalListener();
460     EXPECT_FALSE(ret);
461 }
462 
463 /**
464  * @tc.name: CooperateOutTest010
465  * @tc.desc: Test cooperate plugin
466  * @tc.type: FUNC
467  * @tc.require:
468  */
469 HWTEST_F(CooperateOutTest, CooperateOutTest010, TestSize.Level1)
470 {
471     CALL_TEST_DEBUG;
472     CooperateEvent event(
473         CooperateEventType::DSOFTBUS_COOPERATE_WITH_OPTIONS,
474         DSoftbusCooperateOptions{
475             .networkId = "test",
476     });
477     auto env = ContextService::GetInstance();
478     ASSERT_NE(env, nullptr);
479     Context cooperateContext(env);
480     StartCooperateEvent startEvent {IPCSkeleton::GetCallingPid(), 1, "test", 1,
481         std::make_shared<std::promise<int32_t>>(),
482     };
483     cooperateContext.StartCooperate(startEvent);
484     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
485     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
486     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
487     ASSERT_NE(relay, nullptr);
488     relay->OnRemoteStartWithOptions(cooperateContext, event);
489     bool ret = g_context->mouseLocation_.HasLocalListener();
490     EXPECT_FALSE(ret);
491 }
492 
493 /**
494  * @tc.name: CooperateOutTest011
495  * @tc.desc: Test cooperate plugin
496  * @tc.type: FUNC
497  * @tc.require:
498  */
499 HWTEST_F(CooperateOutTest, CooperateOutTest011, TestSize.Level1)
500 {
501     CALL_TEST_DEBUG;
502     auto env = ContextService::GetInstance();
503     ASSERT_NE(env, nullptr);
504     Context cooperateContext(env);
505     CooperateEvent event(
506         CooperateEventType::DSOFTBUS_COOPERATE_WITH_OPTIONS,
507         DSoftbusCooperateOptions{
508             .networkId = cooperateContext.Local(),
509     });
510     StartCooperateEvent startEvent {IPCSkeleton::GetCallingPid(), 1, "test", 1,
511         std::make_shared<std::promise<int32_t>>(),
512     };
513     cooperateContext.StartCooperate(startEvent);
514     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
515     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
516     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
517     ASSERT_NE(relay, nullptr);
518     relay->OnRemoteStartWithOptions(cooperateContext, event);
519     bool ret = g_context->mouseLocation_.HasLocalListener();
520     EXPECT_FALSE(ret);
521 }
522 
523 /**
524  * @tc.name: CooperateOutTest012
525  * @tc.desc: Test cooperate plugin
526  * @tc.type: FUNC
527  * @tc.require:
528  */
529 HWTEST_F(CooperateOutTest, CooperateOutTest012, TestSize.Level1)
530 {
531     CALL_TEST_DEBUG;
532     CooperateEvent event(
533         CooperateEventType::DSOFTBUS_COME_BACK_WITH_OPTIONS,
534         DSoftbusCooperateOptions{
535             .networkId = "test",
536     });
537     auto env = ContextService::GetInstance();
538     ASSERT_NE(env, nullptr);
539     Context cooperateContext(env);
540     StartCooperateEvent startEvent {IPCSkeleton::GetCallingPid(), 1, "testtrue", 1,
541         std::make_shared<std::promise<int32_t>>(),
542     };
543     cooperateContext.StartCooperate(startEvent);
544     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
545     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
546     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
547     ASSERT_NE(relay, nullptr);
548     relay->OnComeBackWithOptions(cooperateContext, event);
549     bool ret = g_context->mouseLocation_.HasLocalListener();
550     EXPECT_FALSE(ret);
551 }
552 
553 /**
554  * @tc.name: CooperateOutTest013
555  * @tc.desc: Test cooperate plugin
556  * @tc.type: FUNC
557  * @tc.require:
558  */
559 HWTEST_F(CooperateOutTest, CooperateOutTest013, TestSize.Level1)
560 {
561     CALL_TEST_DEBUG;
562     CooperateEvent event(
563         CooperateEventType::DSOFTBUS_COME_BACK_WITH_OPTIONS,
564         DSoftbusCooperateOptions{
565             .networkId = "test",
566     });
567     auto env = ContextService::GetInstance();
568     ASSERT_NE(env, nullptr);
569     Context cooperateContext(env);
570     StartCooperateEvent startEvent {IPCSkeleton::GetCallingPid(), 1, "test", 1,
571         std::make_shared<std::promise<int32_t>>(),
572     };
573     cooperateContext.StartCooperate(startEvent);
574     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
575     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
576     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
577     ASSERT_NE(relay, nullptr);
578     relay->OnComeBackWithOptions(cooperateContext, event);
579     bool ret = g_context->mouseLocation_.HasLocalListener();
580     EXPECT_FALSE(ret);
581 }
582 
583 /**
584  * @tc.name: CooperateOutTest014
585  * @tc.desc: Test cooperate plugin
586  * @tc.type: FUNC
587  * @tc.require:
588  */
589 HWTEST_F(CooperateOutTest, CooperateOutTest014, TestSize.Level1)
590 {
591     CALL_TEST_DEBUG;
592     CooperateEvent event(
593         CooperateEventType::DSOFTBUS_RELAY_COOPERATE_WITHOPTIONS,
594         DSoftbusRelayCooperate{
595             .networkId = "test",
596     });
597     auto env = ContextService::GetInstance();
598     ASSERT_NE(env, nullptr);
599     Context cooperateContext(env);
600     StartCooperateEvent startEvent {IPCSkeleton::GetCallingPid(), 1, "test", 1,
601         std::make_shared<std::promise<int32_t>>(),
602     };
603     cooperateContext.StartCooperate(startEvent);
604     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
605     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
606     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
607     ASSERT_NE(relay, nullptr);
608     relay->OnRelayWithOptions(cooperateContext, event);
609     bool ret = g_context->mouseLocation_.HasLocalListener();
610     EXPECT_FALSE(ret);
611 }
612 
613 /**
614  * @tc.name: CooperateOutTest015
615  * @tc.desc: Test cooperate plugin
616  * @tc.type: FUNC
617  * @tc.require:
618  */
619 HWTEST_F(CooperateOutTest, CooperateOutTest015, TestSize.Level1)
620 {
621     CALL_TEST_DEBUG;
622     CooperateEvent event(
623         CooperateEventType::DSOFTBUS_RELAY_COOPERATE_WITHOPTIONS,
624         DSoftbusRelayCooperate{
625             .networkId = "test",
626     });
627     auto env = ContextService::GetInstance();
628     ASSERT_NE(env, nullptr);
629     Context cooperateContext(env);
630     StartCooperateEvent startEvent {IPCSkeleton::GetCallingPid(), 1, "test", 1,
631         std::make_shared<std::promise<int32_t>>(),
632     };
633     cooperateContext.StartCooperate(startEvent);
634     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
635     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
636     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
637     ASSERT_NE(relay, nullptr);
638     relay->OnRelayWithOptions(cooperateContext, event);
639     bool ret = g_context->mouseLocation_.HasLocalListener();
640     EXPECT_FALSE(ret);
641 }
642 
643 /**
644  * @tc.name: CooperateOutTest016
645  * @tc.desc: Test cooperate plugin
646  * @tc.type: FUNC
647  * @tc.require:
648  */
649 HWTEST_F(CooperateOutTest, CooperateOutTest016, TestSize.Level1)
650 {
651     CALL_TEST_DEBUG;
652     CooperateEvent event(
653         CooperateEventType::DSOFTBUS_RELAY_COOPERATE_WITHOPTIONS,
654         StartWithOptionsEvent{
655             .errCode = std::make_shared<std::promise<int32_t>>(),
656     });
657     auto env = ContextService::GetInstance();
658     ASSERT_NE(env, nullptr);
659     Context cooperateContext(env);
660     g_stateMachine = std::make_shared<Cooperate::StateMachine>(env);
661     Cooperate::CooperateOut stateOut(*g_stateMachine, env);
662     auto relay = std::make_shared<Cooperate::CooperateOut::Initial>(stateOut);
663     ASSERT_NE(relay, nullptr);
664     relay->OnProgressWithOptions(cooperateContext, event);
665     bool ret = g_context->mouseLocation_.HasLocalListener();
666     EXPECT_FALSE(ret);
667 }
668 } // namespace DeviceStatus
669 } // namespace Msdp
670 } // namespace OHOS