1 /*
2 * Copyright (c) 2024-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
16 #include <memory>
17
18 #include "accesstoken_kit.h"
19 #include "gtest/gtest.h"
20 #include "ipc_skeleton.h"
21
22 #include "cooperate_server.h"
23 #include "cooperate_server_test.h"
24 #include "fi_log.h"
25 #include "nativetoken_kit.h"
26 #include "test_context.h"
27 #include "token_setproc.h"
28
29 #undef LOG_TAG
30 #define LOG_TAG "CooperateServerTest"
31
32 namespace OHOS {
33 namespace Msdp {
34 namespace DeviceStatus {
35 using namespace testing::ext;
36 namespace {
37 int32_t g_userData { 1 };
38 uint64_t g_tokenID1 { 5 };
39 const std::string COOPERATE_ACCESS_PERMISSION { "ohos.permission.COOPERATE_MANAGER" };
40 std::mutex g_lockSetToken;
41 uint64_t g_shellTokenId = 0;
42 static constexpr int32_t DEFAULT_API_VERSION = 12;
43 static MockHapToken* g_mock = nullptr;
44 constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
45 } // namespace
SetTestEvironment(uint64_t shellTokenId)46 void SetTestEvironment(uint64_t shellTokenId)
47 {
48 std::lock_guard<std::mutex> lock(g_lockSetToken);
49 g_shellTokenId = shellTokenId;
50 }
51
ResetTestEvironment()52 void ResetTestEvironment()
53 {
54 std::lock_guard<std::mutex> lock(g_lockSetToken);
55 g_shellTokenId = 0;
56 }
57
GetShellTokenId()58 uint64_t GetShellTokenId()
59 {
60 std::lock_guard<std::mutex> lock(g_lockSetToken);
61 return g_shellTokenId;
62 }
63
GetNativeTokenIdFromProcess(const std::string & process)64 uint64_t GetNativeTokenIdFromProcess(const std::string &process)
65 {
66 uint64_t selfTokenId = GetSelfTokenID();
67 EXPECT_EQ(0, SetSelfTokenID(GetShellTokenId()));
68
69 std::string dumpInfo;
70 Security::AccessToken::AtmToolsParamInfo info;
71 info.processName = process;
72 Security::AccessToken::AccessTokenKit::DumpTokenInfo(info, dumpInfo);
73 size_t pos = dumpInfo.find("\"tokenID\": ");
74 if (pos == std::string::npos) {
75 FI_HILOGE("tokenid not find");
76 return 0;
77 }
78 pos += std::string("\"tokenID\": ").length();
79 std::string numStr;
80 while (pos < dumpInfo.length() && std::isdigit(dumpInfo[pos])) {
81 numStr += dumpInfo[pos];
82 ++pos;
83 }
84 EXPECT_EQ(0, SetSelfTokenID(selfTokenId));
85
86 std::istringstream iss(numStr);
87 Security::AccessToken::AccessTokenID tokenID;
88 iss >> tokenID;
89 return tokenID;
90 }
91
AllocTestHapToken(const Security::AccessToken::HapInfoParams & hapInfo,Security::AccessToken::HapPolicyParams & hapPolicy,Security::AccessToken::AccessTokenIDEx & tokenIdEx)92 int32_t AllocTestHapToken(const Security::AccessToken::HapInfoParams& hapInfo,
93 Security::AccessToken::HapPolicyParams& hapPolicy, Security::AccessToken::AccessTokenIDEx& tokenIdEx)
94 {
95 uint64_t selfTokenId = GetSelfTokenID();
96 for (auto& permissionStateFull : hapPolicy.permStateList) {
97 Security::AccessToken::PermissionDef permDefResult;
98 if (Security::AccessToken::AccessTokenKit::GetDefPermission(permissionStateFull.permissionName, permDefResult)
99 != Security::AccessToken::RET_SUCCESS) {
100 continue;
101 }
102 if (permDefResult.availableLevel > hapPolicy.apl) {
103 hapPolicy.aclRequestedList.emplace_back(permissionStateFull.permissionName);
104 }
105 }
106 if (GetNativeTokenIdFromProcess("foundation") == selfTokenId) {
107 return Security::AccessToken::AccessTokenKit::InitHapToken(hapInfo, hapPolicy, tokenIdEx);
108 }
109
110 MockNativeToken mock("foundation");
111 int32_t ret = Security::AccessToken::AccessTokenKit::InitHapToken(hapInfo, hapPolicy, tokenIdEx);
112
113 // restore
114 EXPECT_EQ(0, SetSelfTokenID(selfTokenId));
115
116 return ret;
117 }
118
DeleteTestHapToken(Security::AccessToken::AccessTokenID tokenID)119 int32_t DeleteTestHapToken(Security::AccessToken::AccessTokenID tokenID)
120 {
121 uint64_t selfTokenId = GetSelfTokenID();
122 if (GetNativeTokenIdFromProcess("foundation") == selfTokenId) {
123 return Security::AccessToken::AccessTokenKit::DeleteToken(tokenID);
124 }
125
126 MockNativeToken mock("foundation");
127
128 int32_t ret = Security::AccessToken::AccessTokenKit::DeleteToken(tokenID);
129
130 EXPECT_EQ(0, SetSelfTokenID(selfTokenId));
131 return ret;
132 }
133
MockNativeToken(const std::string & process)134 MockNativeToken::MockNativeToken(const std::string& process)
135 {
136 selfToken_ = GetSelfTokenID();
137 uint32_t tokenId = GetNativeTokenIdFromProcess(process);
138 FI_HILOGI("selfToken_:%{public}" PRId64 ", tokenId:%{public}u", selfToken_, tokenId);
139 SetSelfTokenID(tokenId);
140 }
141
~MockNativeToken()142 MockNativeToken::~MockNativeToken()
143 {
144 SetSelfTokenID(selfToken_);
145 }
146
MockHapToken(const std::string & bundle,const std::vector<std::string> & reqPerm,bool isSystemApp)147 MockHapToken::MockHapToken(
148 const std::string& bundle, const std::vector<std::string>& reqPerm, bool isSystemApp)
149 {
150 selfToken_ = GetSelfTokenID();
151 Security::AccessToken::HapInfoParams infoParams = {
152 .userID = 0,
153 .bundleName = bundle,
154 .instIndex = 0,
155 .appIDDesc = "AccessTokenTestAppID",
156 .apiVersion = DEFAULT_API_VERSION,
157 .isSystemApp = isSystemApp,
158 .appDistributionType = "",
159 };
160
161 Security::AccessToken::HapPolicyParams policyParams = {
162 .apl = Security::AccessToken::APL_NORMAL,
163 .domain = "accesstoken_test_domain",
164 };
165 for (size_t i = 0; i < reqPerm.size(); ++i) {
166 Security::AccessToken::PermissionDef permDefResult;
167 if (Security::AccessToken::AccessTokenKit::GetDefPermission(reqPerm[i], permDefResult)
168 != Security::AccessToken::RET_SUCCESS) {
169 continue;
170 }
171 Security::AccessToken::PermissionStateFull permState = {
172 .permissionName = reqPerm[i],
173 .isGeneral = true,
174 .resDeviceID = {"local3"},
175 .grantStatus = {Security::AccessToken::PermissionState::PERMISSION_DENIED},
176 .grantFlags = {Security::AccessToken::PermissionFlag::PERMISSION_DEFAULT_FLAG}
177 };
178 policyParams.permStateList.emplace_back(permState);
179 if (permDefResult.availableLevel > policyParams.apl) {
180 policyParams.aclRequestedList.emplace_back(reqPerm[i]);
181 }
182 }
183
184 Security::AccessToken::AccessTokenIDEx tokenIdEx = {0};
185 EXPECT_EQ(Security::AccessToken::RET_SUCCESS, AllocTestHapToken(infoParams, policyParams, tokenIdEx));
186 mockToken_= tokenIdEx.tokenIdExStruct.tokenID;
187 EXPECT_NE(mockToken_, Security::AccessToken::INVALID_TOKENID);
188 EXPECT_EQ(0, SetSelfTokenID(tokenIdEx.tokenIDEx));
189 }
190
~MockHapToken()191 MockHapToken::~MockHapToken()
192 {
193 if (mockToken_ != Security::AccessToken::INVALID_TOKENID) {
194 EXPECT_EQ(0, DeleteTestHapToken(mockToken_));
195 }
196 EXPECT_EQ(0, SetSelfTokenID(selfToken_));
197 }
198
CooperateServerTest()199 CooperateServerTest::CooperateServerTest()
200 {
201 context_ = std::make_shared<TestContext>();
202 cooperateServer_ = std::make_shared<CooperateServer>(context_.get());
203 }
204
SetUp()205 void CooperateServerTest::SetUp()
206 {}
207
TearDown()208 void CooperateServerTest::TearDown()
209 {}
210
SetUpTestCase()211 void CooperateServerTest::SetUpTestCase()
212 {
213 std::vector<std::string> reqPerm;
214 reqPerm.emplace_back(COOPERATE_ACCESS_PERMISSION);
215 g_mock = new (std::nothrow) MockHapToken("MouseLocationListenerTest", reqPerm, true);
216 CHKPV(g_mock);
217 FI_HILOGI("SetUpTestCase ok.");
218 }
219
TearDownTestCase()220 void CooperateServerTest::TearDownTestCase()
221 {
222 std::lock_guard<std::mutex> lock(g_lockSetToken);
223 g_shellTokenId = 0;
224 if (g_mock != nullptr) {
225 delete g_mock;
226 g_mock = nullptr;
227 }
228 std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
229 }
230
231 /**
232 * @tc.name: EnableTest1
233 * @tc.desc: Test func named enable
234 * @tc.type: FUNC
235 * @tc.require:
236 */
237 HWTEST_F(CooperateServerTest, EnableTest1, TestSize.Level0)
238 {
239 CALL_TEST_DEBUG;
240 CallingContext context {
241 .intention = intention_,
242 .tokenId = IPCSkeleton::GetCallingTokenID(),
243 .uid = IPCSkeleton::GetCallingUid(),
244 .pid = IPCSkeleton::GetCallingPid(),
245 };
246 ASSERT_NO_FATAL_FAILURE(cooperateServer_->EnableCooperate(context, g_userData));
247 context_->GetPluginManager().UnloadCooperate();
248 }
249
250 /**
251 * @tc.name: EnableTest2
252 * @tc.desc: Test func named enable
253 * @tc.type: FUNC
254 * @tc.require:
255 */
256 HWTEST_F(CooperateServerTest, EnableTest2, TestSize.Level0)
257 {
258 CALL_TEST_DEBUG;
259 CallingContext context {
260 .intention = intention_,
261 .tokenId = g_tokenID1,
262 .uid = IPCSkeleton::GetCallingUid(),
263 .pid = IPCSkeleton::GetCallingPid(),
264 };
265 ASSERT_NO_FATAL_FAILURE(cooperateServer_->EnableCooperate(context, g_userData));
266 context_->GetPluginManager().UnloadCooperate();
267 }
268
269 /**
270 * @tc.name: DisableTest1
271 * @tc.desc: Test func named disable
272 * @tc.type: FUNC
273 * @tc.require:
274 */
275 HWTEST_F(CooperateServerTest, DisableTest1, TestSize.Level0)
276 {
277 CALL_TEST_DEBUG;
278 CallingContext context {
279 .intention = intention_,
280 .tokenId = IPCSkeleton::GetCallingTokenID(),
281 .uid = IPCSkeleton::GetCallingUid(),
282 .pid = IPCSkeleton::GetCallingPid(),
283 };
284 ASSERT_NO_FATAL_FAILURE(cooperateServer_->DisableCooperate(context, g_userData));
285 context_->GetPluginManager().UnloadCooperate();
286 }
287
288 /**
289 * @tc.name: DisableTest2
290 * @tc.desc: Test func named disable
291 * @tc.type: FUNC
292 * @tc.require:
293 */
294 HWTEST_F(CooperateServerTest, DisableTest2, TestSize.Level0)
295 {
296 CALL_TEST_DEBUG;
297 CallingContext context {
298 .intention = intention_,
299 .tokenId = g_tokenID1,
300 .uid = IPCSkeleton::GetCallingUid(),
301 .pid = IPCSkeleton::GetCallingPid(),
302 };
303 ASSERT_NO_FATAL_FAILURE(cooperateServer_->DisableCooperate(context, g_userData));
304 context_->GetPluginManager().UnloadCooperate();
305 }
306
307 /**
308 * @tc.name: StartTest1
309 * @tc.desc: Test func named start
310 * @tc.type: FUNC
311 * @tc.require:
312 */
313 HWTEST_F(CooperateServerTest, StartTest1, TestSize.Level0)
314 {
315 CALL_TEST_DEBUG;
316 CallingContext context {
317 .intention = intention_,
318 .tokenId = IPCSkeleton::GetCallingTokenID(),
319 .uid = IPCSkeleton::GetCallingUid(),
320 .pid = IPCSkeleton::GetCallingPid(),
321 };
322 std::string networkId = "networkId";
323 int32_t startDeviceId = 0;
324 bool isCheckPermission = true;
325 ASSERT_NO_FATAL_FAILURE(cooperateServer_->StartCooperate(context,
326 networkId, g_userData, startDeviceId, isCheckPermission));
327 context_->GetPluginManager().UnloadCooperate();
328 }
329
330 /**
331 * @tc.name: StartTest2
332 * @tc.desc: Test func named start
333 * @tc.type: FUNC
334 * @tc.require:
335 */
336 HWTEST_F(CooperateServerTest, StartTest2, TestSize.Level0)
337 {
338 CALL_TEST_DEBUG;
339 CallingContext context {
340 .intention = intention_,
341 .tokenId = g_tokenID1,
342 .uid = IPCSkeleton::GetCallingUid(),
343 .pid = IPCSkeleton::GetCallingPid(),
344 };
345 std::string networkId = "networkId";
346 int32_t startDeviceId = 0;
347 bool isCheckPermission = true;
348 ASSERT_NO_FATAL_FAILURE(cooperateServer_->StartCooperate(context,
349 networkId, g_userData, startDeviceId, isCheckPermission));
350 context_->GetPluginManager().UnloadCooperate();
351 }
352
353 /**
354 * @tc.name: StartWithOptionsTest1
355 * @tc.desc: Test func named start
356 * @tc.type: FUNC
357 * @tc.require:
358 */
359 HWTEST_F(CooperateServerTest, StartWithOptionsTest1, TestSize.Level0)
360 {
361 CALL_TEST_DEBUG;
362 CallingContext context {
363 .intention = intention_,
364 .tokenId = IPCSkeleton::GetCallingTokenID(),
365 .uid = IPCSkeleton::GetCallingUid(),
366 .pid = IPCSkeleton::GetCallingPid(),
367 };
368 std::string networkId = "networkId";
369 int32_t startDeviceId = 0;
370 CooperateOptions options {
371 .displayX = 500,
372 .displayY = 500,
373 .displayId = 1
374 };
375 ASSERT_NO_FATAL_FAILURE(cooperateServer_->StartCooperateWithOptions(context,
376 networkId, g_userData, startDeviceId, options));
377 context_->GetPluginManager().UnloadCooperate();
378 }
379
380 /**
381 * @tc.name: StopCooperateTest1
382 * @tc.desc: Test func named stop
383 * @tc.type: FUNC
384 * @tc.require:
385 */
386 HWTEST_F(CooperateServerTest, StopCooperateTest1, TestSize.Level0)
387 {
388 CALL_TEST_DEBUG;
389 CallingContext context {
390 .intention = intention_,
391 .tokenId = IPCSkeleton::GetCallingTokenID(),
392 .uid = IPCSkeleton::GetCallingUid(),
393 .pid = IPCSkeleton::GetCallingPid(),
394 };
395 bool isUnchained = true;
396 bool isCheckPermission = true;
397 ASSERT_NO_FATAL_FAILURE(cooperateServer_->StopCooperate(context, g_userData, isUnchained, isCheckPermission));
398 context_->GetPluginManager().UnloadCooperate();
399 }
400
401 /**
402 * @tc.name: StopCooperateTest2
403 * @tc.desc: Test func named stop
404 * @tc.type: FUNC
405 * @tc.require:
406 */
407 HWTEST_F(CooperateServerTest, StopCooperateTest2, TestSize.Level0)
408 {
409 CALL_TEST_DEBUG;
410 CallingContext context {
411 .intention = intention_,
412 .tokenId = g_tokenID1,
413 .uid = IPCSkeleton::GetCallingUid(),
414 .pid = IPCSkeleton::GetCallingPid(),
415 };
416 bool isUnchained = true;
417 bool isCheckPermission = true;
418 ASSERT_NO_FATAL_FAILURE(cooperateServer_->StopCooperate(context, g_userData, isUnchained, isCheckPermission));
419 context_->GetPluginManager().UnloadCooperate();
420 }
421
422 /**
423 * @tc.name: RegisterCooperateListenerTest1
424 * @tc.desc: Test func named stop
425 * @tc.type: FUNC
426 * @tc.require:
427 */
428 HWTEST_F(CooperateServerTest, RegisterCooperateListenerTest1, TestSize.Level0)
429 {
430 CALL_TEST_DEBUG;
431 CallingContext context {
432 .intention = intention_,
433 .tokenId = IPCSkeleton::GetCallingTokenID(),
434 .uid = IPCSkeleton::GetCallingUid(),
435 .pid = IPCSkeleton::GetCallingPid(),
436 };
437 ASSERT_NO_FATAL_FAILURE(cooperateServer_->RegisterCooperateListener(context));
438 context_->GetPluginManager().UnloadCooperate();
439 }
440
441 /**
442 * @tc.name: RegisterCooperateListenerTest2
443 * @tc.desc: Test func named stop
444 * @tc.type: FUNC
445 * @tc.require:
446 */
447 HWTEST_F(CooperateServerTest, RegisterCooperateListenerTest2, TestSize.Level0)
448 {
449 CALL_TEST_DEBUG;
450 CallingContext context {
451 .intention = intention_,
452 .tokenId = g_tokenID1,
453 .uid = IPCSkeleton::GetCallingUid(),
454 .pid = IPCSkeleton::GetCallingPid(),
455 };
456 ASSERT_NO_FATAL_FAILURE(cooperateServer_->RegisterCooperateListener(context));
457 context_->GetPluginManager().UnloadCooperate();
458 }
459 /**
460 * @tc.name: UnregisterCooperateListenerTest1
461 * @tc.desc: Test func named stop
462 * @tc.type: FUNC
463 * @tc.require:
464 */
465 HWTEST_F(CooperateServerTest, UnregisterCooperateListenerTest1, TestSize.Level0)
466 {
467 CALL_TEST_DEBUG;
468 CallingContext context {
469 .intention = intention_,
470 .tokenId = IPCSkeleton::GetCallingTokenID(),
471 .uid = IPCSkeleton::GetCallingUid(),
472 .pid = IPCSkeleton::GetCallingPid(),
473 };
474 ASSERT_NO_FATAL_FAILURE(cooperateServer_->UnregisterCooperateListener(context));
475 context_->GetPluginManager().UnloadCooperate();
476 }
477
478 /**
479 * @tc.name: UnregisterCooperateListenerTest2
480 * @tc.desc: Test func named stop
481 * @tc.type: FUNC
482 * @tc.require:
483 */
484 HWTEST_F(CooperateServerTest, UnregisterCooperateListenerTest2, TestSize.Level0)
485 {
486 CALL_TEST_DEBUG;
487 CallingContext context {
488 .intention = intention_,
489 .tokenId = g_tokenID1,
490 .uid = IPCSkeleton::GetCallingUid(),
491 .pid = IPCSkeleton::GetCallingPid(),
492 };
493 ASSERT_NO_FATAL_FAILURE(cooperateServer_->UnregisterCooperateListener(context));
494 context_->GetPluginManager().UnloadCooperate();
495 }
496
497 /**
498 * @tc.name: RegisterHotAreaListenerTest1
499 * @tc.desc: Test func named stop
500 * @tc.type: FUNC
501 * @tc.require:
502 */
503 HWTEST_F(CooperateServerTest, RegisterHotAreaListenerTest1, TestSize.Level0)
504 {
505 CALL_TEST_DEBUG;
506 CallingContext context {
507 .intention = intention_,
508 .tokenId = IPCSkeleton::GetCallingTokenID(),
509 .uid = IPCSkeleton::GetCallingUid(),
510 .pid = IPCSkeleton::GetCallingPid(),
511 };
512 bool isCheckPermission = true;
513 ASSERT_NO_FATAL_FAILURE(cooperateServer_->RegisterHotAreaListener(context, g_userData, isCheckPermission));
514 context_->GetPluginManager().UnloadCooperate();
515 }
516
517 /**
518 * @tc.name: RegisterHotAreaListenerTest2
519 * @tc.desc: Test func named stop
520 * @tc.type: FUNC
521 * @tc.require:
522 */
523 HWTEST_F(CooperateServerTest, RegisterHotAreaListenerTest2, TestSize.Level0)
524 {
525 CALL_TEST_DEBUG;
526 CallingContext context {
527 .intention = intention_,
528 .tokenId = g_tokenID1,
529 .uid = IPCSkeleton::GetCallingUid(),
530 .pid = IPCSkeleton::GetCallingPid(),
531 };
532 bool isCheckPermission = true;
533 ASSERT_NO_FATAL_FAILURE(cooperateServer_->RegisterHotAreaListener(context, g_userData, isCheckPermission));
534 context_->GetPluginManager().UnloadCooperate();
535 }
536
537 /**
538 * @tc.name: UnregisterHotAreaListenerTest1
539 * @tc.desc: Test func named stop
540 * @tc.type: FUNC
541 * @tc.require:
542 */
543 HWTEST_F(CooperateServerTest, UnregisterHotAreaListenerTest1, TestSize.Level0)
544 {
545 CALL_TEST_DEBUG;
546 CallingContext context {
547 .intention = intention_,
548 .tokenId = IPCSkeleton::GetCallingTokenID(),
549 .uid = IPCSkeleton::GetCallingUid(),
550 .pid = IPCSkeleton::GetCallingPid(),
551 };
552 ASSERT_NO_FATAL_FAILURE(cooperateServer_->UnregisterHotAreaListener(context));
553 context_->GetPluginManager().UnloadCooperate();
554 }
555
556 /**
557 * @tc.name: UnregisterHotAreaListenerTest2
558 * @tc.desc: Test func named stop
559 * @tc.type: FUNC
560 * @tc.require:
561 */
562 HWTEST_F(CooperateServerTest, UnregisterHotAreaListenerTest2, TestSize.Level0)
563 {
564 CALL_TEST_DEBUG;
565 CallingContext context {
566 .intention = intention_,
567 .tokenId = g_tokenID1,
568 .uid = IPCSkeleton::GetCallingUid(),
569 .pid = IPCSkeleton::GetCallingPid(),
570 };
571 ASSERT_NO_FATAL_FAILURE(cooperateServer_->UnregisterHotAreaListener(context));
572 context_->GetPluginManager().UnloadCooperate();
573 }
574
575 /**
576 * @tc.name: RegisterMouseEventListenerTest1
577 * @tc.desc: Test func named stop
578 * @tc.type: FUNC
579 * @tc.require:
580 */
581 HWTEST_F(CooperateServerTest, RegisterMouseEventListenerTest1, TestSize.Level0)
582 {
583 CALL_TEST_DEBUG;
584 CallingContext context {
585 .intention = intention_,
586 .tokenId = IPCSkeleton::GetCallingTokenID(),
587 .uid = IPCSkeleton::GetCallingUid(),
588 .pid = IPCSkeleton::GetCallingPid(),
589 };
590 std::string networkId = "networkId";
591 ASSERT_NO_FATAL_FAILURE(cooperateServer_->RegisterMouseEventListener(context, networkId));
592 context_->GetPluginManager().UnloadCooperate();
593 }
594
595 /**
596 * @tc.name: RegisterMouseEventListenerTest2
597 * @tc.desc: Test func named stop
598 * @tc.type: FUNC
599 * @tc.require:
600 */
601 HWTEST_F(CooperateServerTest, RegisterMouseEventListenerTest2, TestSize.Level0)
602 {
603 CALL_TEST_DEBUG;
604 CallingContext context {
605 .intention = intention_,
606 .tokenId = g_tokenID1,
607 .uid = IPCSkeleton::GetCallingUid(),
608 .pid = IPCSkeleton::GetCallingPid(),
609 };
610 std::string networkId = "networkId";
611 ASSERT_NO_FATAL_FAILURE(cooperateServer_->RegisterMouseEventListener(context, networkId));
612 context_->GetPluginManager().UnloadCooperate();
613 }
614
615 /**
616 * @tc.name: UnregisterMouseEventListenerTest1
617 * @tc.desc: Test func named stop
618 * @tc.type: FUNC
619 * @tc.require:
620 */
621 HWTEST_F(CooperateServerTest, UnregisterMouseEventListenerTest1, TestSize.Level0)
622 {
623 CALL_TEST_DEBUG;
624 CallingContext context {
625 .intention = intention_,
626 .tokenId = IPCSkeleton::GetCallingTokenID(),
627 .uid = IPCSkeleton::GetCallingUid(),
628 .pid = IPCSkeleton::GetCallingPid(),
629 };
630 std::string networkId = "networkId";
631 ASSERT_NO_FATAL_FAILURE(cooperateServer_->UnregisterMouseEventListener(context, networkId));
632 context_->GetPluginManager().UnloadCooperate();
633 }
634
635 /**
636 * @tc.name: UnregisterMouseEventListenerTest2
637 * @tc.desc: Test func named stop
638 * @tc.type: FUNC
639 * @tc.require:
640 */
641 HWTEST_F(CooperateServerTest, UnregisterMouseEventListenerTest2, TestSize.Level0)
642 {
643 CALL_TEST_DEBUG;
644 CallingContext context {
645 .intention = intention_,
646 .tokenId = g_tokenID1,
647 .uid = IPCSkeleton::GetCallingUid(),
648 .pid = IPCSkeleton::GetCallingPid(),
649 };
650 std::string networkId = "networkId";
651 ASSERT_NO_FATAL_FAILURE(cooperateServer_->UnregisterMouseEventListener(context, networkId));
652 context_->GetPluginManager().UnloadCooperate();
653 }
654
655 /**
656 * @tc.name: GetCooperateStateSyncTest1
657 * @tc.desc: Test func named stop
658 * @tc.type: FUNC
659 * @tc.require:
660 */
661 HWTEST_F(CooperateServerTest, GetCooperateStateSyncTest1, TestSize.Level0)
662 {
663 CALL_TEST_DEBUG;
664 CallingContext context {
665 .intention = intention_,
666 .tokenId = IPCSkeleton::GetCallingTokenID(),
667 .uid = IPCSkeleton::GetCallingUid(),
668 .pid = IPCSkeleton::GetCallingPid(),
669 };
670 std::string udid = "udid";
671 bool state = true;
672 ASSERT_NO_FATAL_FAILURE(cooperateServer_->GetCooperateStateSync(context, udid, state));
673 context_->GetPluginManager().UnloadCooperate();
674 }
675
676 /**
677 * @tc.name: GetCooperateStateSyncTest2
678 * @tc.desc: Test func named stop
679 * @tc.type: FUNC
680 * @tc.require:
681 */
682 HWTEST_F(CooperateServerTest, GetCooperateStateSyncTest2, TestSize.Level0)
683 {
684 CALL_TEST_DEBUG;
685 CallingContext context {
686 .intention = intention_,
687 .tokenId = g_tokenID1,
688 .uid = IPCSkeleton::GetCallingUid(),
689 .pid = IPCSkeleton::GetCallingPid(),
690 };
691 std::string udid = "udid";
692 bool state = true;
693 ASSERT_NO_FATAL_FAILURE(cooperateServer_->GetCooperateStateSync(context, udid, state));
694 context_->GetPluginManager().UnloadCooperate();
695 }
696
697 /**
698 * @tc.name: GetCooperateStateAsyncTest1
699 * @tc.desc: Test func named stop
700 * @tc.type: FUNC
701 * @tc.require:
702 */
703 HWTEST_F(CooperateServerTest, GetCooperateStateAsyncTest1, TestSize.Level0)
704 {
705 CALL_TEST_DEBUG;
706 CallingContext context {
707 .intention = intention_,
708 .tokenId = IPCSkeleton::GetCallingTokenID(),
709 .uid = IPCSkeleton::GetCallingUid(),
710 .pid = IPCSkeleton::GetCallingPid(),
711 };
712 std::string networkId = "networkId";
713 bool isCheckPermission = true;
714 ASSERT_NO_FATAL_FAILURE(cooperateServer_->GetCooperateStateAsync(context,
715 networkId, g_userData, isCheckPermission));
716 context_->GetPluginManager().UnloadCooperate();
717 }
718
719 /**
720 * @tc.name: GetCooperateStateAsyncTest2
721 * @tc.desc: Test func named stop
722 * @tc.type: FUNC
723 * @tc.require:
724 */
725 HWTEST_F(CooperateServerTest, GetCooperateStateAsyncTest2, TestSize.Level0)
726 {
727 CALL_TEST_DEBUG;
728 CallingContext context {
729 .intention = intention_,
730 .tokenId = g_tokenID1,
731 .uid = IPCSkeleton::GetCallingUid(),
732 .pid = IPCSkeleton::GetCallingPid(),
733 };
734 std::string networkId = "networkId";
735 bool isCheckPermission = true;
736 ASSERT_NO_FATAL_FAILURE(cooperateServer_->GetCooperateStateAsync(context,
737 networkId, g_userData, isCheckPermission));
738 context_->GetPluginManager().UnloadCooperate();
739 }
740
741 /**
742 * @tc.name: SetDamplingCoefficientTest1
743 * @tc.desc: Test func named SetDamplingCoefficient
744 * @tc.type: FUNC
745 * @tc.require:
746 */
747 HWTEST_F(CooperateServerTest, SetDamplingCoefficientTest1, TestSize.Level0)
748 {
749 CALL_TEST_DEBUG;
750 CallingContext context {
751 .intention = intention_,
752 .tokenId = IPCSkeleton::GetCallingTokenID(),
753 .uid = IPCSkeleton::GetCallingUid(),
754 .pid = IPCSkeleton::GetCallingPid(),
755 };
756 uint32_t direction = 0;
757 double coefficient = 0;
758 ASSERT_NO_FATAL_FAILURE(cooperateServer_->SetDamplingCoefficient(context, direction, coefficient));
759 context_->GetPluginManager().UnloadCooperate();
760 }
761
762 /**
763 * @tc.name: SetDamplingCoefficientTest2
764 * @tc.desc: Test func named SetDamplingCoefficient
765 * @tc.type: FUNC
766 * @tc.require:
767 */
768 HWTEST_F(CooperateServerTest, SetDamplingCoefficientTest2, TestSize.Level0)
769 {
770 CALL_TEST_DEBUG;
771 CallingContext context {
772 .intention = intention_,
773 .tokenId = g_tokenID1,
774 .uid = IPCSkeleton::GetCallingUid(),
775 .pid = IPCSkeleton::GetCallingPid(),
776 };
777 uint32_t direction = 0;
778 double coefficient = 0;
779 ASSERT_NO_FATAL_FAILURE(cooperateServer_->SetDamplingCoefficient(context, direction, coefficient));
780 context_->GetPluginManager().UnloadCooperate();
781 }
782 } // namespace DeviceStatus
783 } // namespace Msdp
784 } // namespace OHOS