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
16 #include <thread>
17 #include "gtest/gtest.h"
18
19 #define private public
20
21 #include "advanced_notification_service.h"
22 #include "advanced_datashare_helper.h"
23 #include "notification_check_request.h"
24 #include "notification_constant.h"
25
26 #include "ans_ut_constant.h"
27 #include "mock_ipc_skeleton.h"
28 #include "mock_bundle_mgr.h"
29 #include "mock_accesstoken_kit.h"
30
31 using namespace testing::ext;
32 using namespace OHOS::Security::AccessToken;
33
34 namespace OHOS {
35 namespace Notification {
36
37 class AdvancedNotificationDistMgrServiceTest : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 void SetUp();
42 void TearDown();
43
44 private:
45 static sptr<AdvancedNotificationService> advancedNotificationService_;
46 };
47
48 sptr<AdvancedNotificationService> AdvancedNotificationDistMgrServiceTest::advancedNotificationService_ = nullptr;
49
SetUpTestCase()50 void AdvancedNotificationDistMgrServiceTest::SetUpTestCase() {}
51
TearDownTestCase()52 void AdvancedNotificationDistMgrServiceTest::TearDownTestCase() {}
53
SetUp()54 void AdvancedNotificationDistMgrServiceTest::SetUp()
55 {
56 GTEST_LOG_(INFO) << "SetUp start";
57
58 advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService();
59
60 GTEST_LOG_(INFO) << "SetUp end";
61 }
62
TearDown()63 void AdvancedNotificationDistMgrServiceTest::TearDown()
64 {
65 advancedNotificationService_ = nullptr;
66 GTEST_LOG_(INFO) << "TearDown";
67 }
68
69 /**
70 * @tc.name: SetDistributedEnabledBySlot_100
71 * @tc.desc: Test SetDistributedEnabledBySlot when caller is not subsystem or system app.
72 * @tc.type: FUNC
73 * @tc.require: issue
74 */
75 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetDistributedEnabledBySlot_100, Function | SmallTest | Level1)
76 {
77 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
78 MockIsSystemApp(false);
79 int32_t slotTypeInt = 5;
80 std::string deviceType = "";
81 bool enabled = false;
82 auto ret = advancedNotificationService_->SetDistributedEnabledBySlot(slotTypeInt, deviceType, enabled);
83
84 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
85 }
86
87 /**
88 * @tc.name: IsDistributedEnabledBySlot_100
89 * @tc.desc: Test IsDistributedEnabledBySlot when caller is not subsystem or system app.
90 * @tc.type: FUNC
91 * @tc.require: issue
92 */
93 HWTEST_F(AdvancedNotificationDistMgrServiceTest, IsDistributedEnabledBySlot_100, Function | SmallTest | Level1)
94 {
95 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
96 MockIsSystemApp(false);
97 int32_t slotTypeInt = 5;
98 std::string deviceType = "";
99 bool enabled = false;
100
101 auto ret = advancedNotificationService_->IsDistributedEnabledBySlot(slotTypeInt, deviceType, enabled);
102
103 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
104 }
105
106 /**
107 * @tc.name: IsDistributedEnabledBySlot_200
108 * @tc.desc: Test IsDistributedEnabledBySlot when caller has no permission.
109 * @tc.type: FUNC
110 * @tc.require: issue
111 */
112 HWTEST_F(AdvancedNotificationDistMgrServiceTest, IsDistributedEnabledBySlot_200, Function | SmallTest | Level1)
113 {
114 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE);
115 MockIsVerfyPermisson(false);
116 int32_t slotTypeInt = 5;
117 std::string deviceType = "";
118 bool enabled = false;
119
120 auto ret = advancedNotificationService_->IsDistributedEnabledBySlot(slotTypeInt, deviceType, enabled);
121
122 ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
123 }
124
125 /**
126 * @tc.name: IsDistributedEnabledBySlot_300
127 * @tc.desc: Test IsDistributedEnabledBySlot when succeed to call.
128 * @tc.type: FUNC
129 * @tc.require: issue
130 */
131 HWTEST_F(AdvancedNotificationDistMgrServiceTest, IsDistributedEnabledBySlot_300, Function | SmallTest | Level1)
132 {
133 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE);
134 MockIsVerfyPermisson(true);
135 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
136 int32_t slotTypeInt = 5;
137 std::string deviceType = "testType";
138 bool enabled = false;
139
140 auto ret = advancedNotificationService_->IsDistributedEnabledBySlot(slotTypeInt, deviceType, enabled);
141
142 ASSERT_EQ(ret, (int)ERR_OK);
143 }
144
145 /**
146 * @tc.name: GetTargetDeviceStatus_100
147 * @tc.desc: Test GetTargetDeviceStatus when caller is not subsystem.
148 * @tc.type: FUNC
149 * @tc.require: issue
150 */
151 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetTargetDeviceStatus_100, Function | SmallTest | Level1)
152 {
153 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_INVALID);
154 std::string deviceType = "testType";
155 int32_t status = 5;
156
157 auto ret = advancedNotificationService_->GetTargetDeviceStatus(deviceType, status);
158
159 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
160 }
161
162 /**
163 * @tc.name: DistributeOperationParamCheck_100
164 * @tc.desc: Test DistributeOperationParamCheck when caller is not subsystem or system app.
165 * @tc.type: FUNC
166 * @tc.require: issue
167 */
168 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperationParamCheck_100, Function | SmallTest | Level1)
169 {
170 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
171 MockIsSystemApp(false);
172 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
173 operationInfo->SetHashCode("testHashCode");
174 sptr<IAnsOperationCallback> callback = nullptr;
175
176 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
177
178 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
179 }
180
181 /**
182 * @tc.name: DistributeOperationParamCheck_200
183 * @tc.desc: Test DistributeOperationParamCheck when invalid operationType.
184 * @tc.type: FUNC
185 * @tc.require: issue
186 */
187 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperationParamCheck_200, Function | SmallTest | Level1)
188 {
189 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
190 operationInfo->SetHashCode("hashCode");
191 operationInfo->SetOperationType(static_cast<OperationType>(5));
192 sptr<IAnsOperationCallback> callback = nullptr;
193 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
194 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
195 }
196
197 /**
198 * @tc.name: DistributeOperation_100
199 * @tc.desc: Test DistributeOperation when notificationSvrQueue_ is nullptr.
200 * @tc.type: FUNC
201 * @tc.require: issue
202 */
203 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_100, Function | SmallTest | Level1)
204 {
205 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
206 MockIsSystemApp(true);
207 MockIsVerfyPermisson(true);
208 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
209 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
210 operationInfo->SetHashCode("testHashCode");
211 sptr<IAnsOperationCallback> callback = nullptr;
212 advancedNotificationService_->notificationSvrQueue_ = nullptr;
213
214 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
215
216 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
217 }
218
219 /**
220 * @tc.name: DistributeOperation_200
221 * @tc.desc: Test DistributeOperation when notificationList_ is empty.
222 * @tc.type: FUNC
223 * @tc.require: issue
224 */
225 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_200, Function | SmallTest | Level1)
226 {
227 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
228 MockIsSystemApp(true);
229 MockIsVerfyPermisson(true);
230 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
231 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
232 operationInfo->SetHashCode("testHashCode");
233 operationInfo->SetOperationType(OperationType::DISTRIBUTE_OPERATION_REPLY);
234 sptr<IAnsOperationCallback> callback = nullptr;
235
236 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
237
238 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
239 }
240
241 /**
242 * @tc.name: DistributeOperation_300
243 * @tc.desc: Test DistributeOperation when operationInfo's hashcode is not satisfied.
244 * @tc.type: FUNC
245 * @tc.require: issue
246 */
247 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_300, Function | SmallTest | Level1)
248 {
249 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
250 MockIsSystemApp(true);
251 MockIsVerfyPermisson(true);
252 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
253 sptr<NotificationBundleOption> bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
254 sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
255 auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
256 advancedNotificationService_->AddToNotificationList(record);
257 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
258 operationInfo->SetHashCode("testHashCode");
259 operationInfo->SetOperationType(OperationType::DISTRIBUTE_OPERATION_REPLY);
260 sptr<IAnsOperationCallback> callback = nullptr;
261
262 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
263
264 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
265 }
266
267 /**
268 * @tc.name: DistributeOperation_400
269 * @tc.desc: Test DistributeOperation ERR_OK.
270 * @tc.type: FUNC
271 * @tc.require: issue
272 */
273 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_400, Function | SmallTest | Level1)
274 {
275 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
276 MockIsSystemApp(true);
277 MockIsVerfyPermisson(true);
278 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
279 sptr<NotificationBundleOption> bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
280 sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
281 request->SetDistributedCollaborate(true);
282 auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
283 advancedNotificationService_->DeleteAll();
284 advancedNotificationService_->AddToNotificationList(record);
285 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
286 operationInfo->SetHashCode(record->notification->GetKey());
287 operationInfo->SetOperationType(OperationType::DISTRIBUTE_OPERATION_REPLY);
288 sptr<IAnsOperationCallback> callback = nullptr;
289 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
290 ASSERT_EQ(ret, (int)ERR_OK);
291 }
292
293 /**
294 * @tc.name: DistributeOperation_500
295 * @tc.desc: Test DistributeOperation when record's NotificationRequestPoint is nullptr.
296 * @tc.type: FUNC
297 * @tc.require: issue
298 */
299 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_500, Function | SmallTest | Level1)
300 {
301 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
302 MockIsSystemApp(true);
303 MockIsVerfyPermisson(true);
304 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
305 sptr<NotificationBundleOption> bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
306 std::shared_ptr<NotificationRecord> record = std::make_shared<NotificationRecord>();
307 record->notification = new (std::nothrow) Notification(nullptr);
308 advancedNotificationService_->DeleteAll();
309 advancedNotificationService_->AddToNotificationList(record);
310 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
311 operationInfo->SetHashCode(record->notification->GetKey());
312 operationInfo->SetOperationType(OperationType::DISTRIBUTE_OPERATION_REPLY);
313 sptr<IAnsOperationCallback> callback = nullptr;
314 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
315 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
316 }
317
318 /**
319 * @tc.name: DistributeOperation_600
320 * @tc.desc: Test DistributeOperation when record's distributedCollaborate_ is false.
321 * @tc.type: FUNC
322 * @tc.require: issue
323 */
324 HWTEST_F(AdvancedNotificationDistMgrServiceTest, DistributeOperation_600, Function | SmallTest | Level1)
325 {
326 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
327 MockIsSystemApp(true);
328 MockIsVerfyPermisson(true);
329 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
330 sptr<NotificationBundleOption> bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
331 sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
332 request->SetDistributedCollaborate(false);
333 auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
334 advancedNotificationService_->DeleteAll();
335 advancedNotificationService_->AddToNotificationList(record);
336 sptr<NotificationOperationInfo> operationInfo = new (std::nothrow) NotificationOperationInfo();
337 operationInfo->SetHashCode(record->notification->GetKey());
338 operationInfo->SetOperationType(OperationType::DISTRIBUTE_OPERATION_REPLY);
339 sptr<IAnsOperationCallback> callback = nullptr;
340 auto ret = advancedNotificationService_->DistributeOperation(operationInfo, callback);
341 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
342 }
343
344 /**
345 * @tc.name: SetTargetDeviceStatus_100
346 * @tc.desc: Test SetTargetDeviceStatus when caller is not subsystem or system app.
347 * @tc.type: FUNC
348 * @tc.require: issue
349 */
350 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceStatus_100, Function | SmallTest | Level1)
351 {
352 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
353 MockIsSystemApp(false);
354 const std::string deviceType = "testDeviceType";
355 uint32_t status = 0;
356 const std::string deviceId = "testDeviceId";
357
358 auto ret = advancedNotificationService_->SetTargetDeviceStatus(deviceType, status, deviceId);
359
360 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
361 }
362
363 /**
364 * @tc.name: SetTargetDeviceStatus_200
365 * @tc.desc: Test SetTargetDeviceStatus when deviceType is empty.
366 * @tc.type: FUNC
367 * @tc.require: issue
368 */
369 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceStatus_200, Function | SmallTest | Level1)
370 {
371 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
372 MockIsSystemApp(false);
373 const std::string deviceType = "";
374 uint32_t status = 0;
375 uint32_t controlFlag = 0;
376 const std::string deviceId = "testDeviceId";
377 int32_t userId = 100;
378
379 auto ret = advancedNotificationService_->SetTargetDeviceStatus(deviceType, status, controlFlag, deviceId, userId);
380
381 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
382 }
383
384 /**
385 * @tc.name: SetTargetDeviceStatus_300
386 * @tc.desc: Test SetTargetDeviceStatus when caller is not subsystem or system app.
387 * @tc.type: FUNC
388 * @tc.require: issue
389 */
390 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceStatus_300, Function | SmallTest | Level1)
391 {
392 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
393 MockIsSystemApp(false);
394 const std::string deviceType = NotificationConstant::PAD_DEVICE_TYPE;
395 uint32_t status = 0;
396 uint32_t controlFlag = 0;
397 const std::string deviceId = "testDeviceId";
398 int32_t userId = 100;
399
400 auto ret = advancedNotificationService_->SetTargetDeviceStatus(deviceType, status, controlFlag, deviceId, userId);
401
402 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
403 }
404
405 /**
406 * @tc.name: SetTargetDeviceStatus_400
407 * @tc.desc: Test SetTargetDeviceStatus when caller has no permission.
408 * @tc.type: FUNC
409 * @tc.require: issue
410 */
411 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceStatus_400, Function | SmallTest | Level1)
412 {
413 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
414 MockIsSystemApp(true);
415 MockIsVerfyPermisson(false);
416 const std::string deviceType = NotificationConstant::PAD_DEVICE_TYPE;
417 uint32_t status = 0;
418 uint32_t controlFlag = 0;
419 const std::string deviceId = "testDeviceId";
420 int32_t userId = 100;
421
422 auto ret = advancedNotificationService_->SetTargetDeviceStatus(deviceType, status, controlFlag, deviceId, userId);
423
424 ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
425 }
426
427 /**
428 * @tc.name: SetTargetDeviceStatus_500
429 * @tc.desc: Test SetTargetDeviceStatus when deviceType is pad.
430 * @tc.type: FUNC
431 * @tc.require: issue
432 */
433 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceStatus_500, Function | SmallTest | Level1)
434 {
435 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
436 MockIsSystemApp(true);
437 MockIsVerfyPermisson(true);
438 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
439 const std::string deviceType = NotificationConstant::PAD_DEVICE_TYPE;
440 uint32_t status = 0;
441 uint32_t controlFlag = 0;
442 const std::string deviceId = "testDeviceId";
443 int32_t userId = 100;
444
445 auto ret = advancedNotificationService_->SetTargetDeviceStatus(deviceType, status, controlFlag, deviceId, userId);
446
447 ASSERT_EQ(ret, (int)ERR_OK);
448 }
449
450 /**
451 * @tc.name: SetTargetDeviceStatus_600
452 * @tc.desc: Test SetTargetDeviceStatus when deviceType is not pad and pc.
453 * @tc.type: FUNC
454 * @tc.require: issue
455 */
456 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceStatus_600, Function | SmallTest | Level1)
457 {
458 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
459 MockIsSystemApp(true);
460 MockIsVerfyPermisson(true);
461 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
462 const std::string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE;
463 uint32_t status = 0;
464 uint32_t controlFlag = 0;
465 const std::string deviceId = "testDeviceId";
466 int32_t userId = 100;
467
468 auto ret = advancedNotificationService_->SetTargetDeviceStatus(deviceType, status, controlFlag, deviceId, userId);
469
470 ASSERT_EQ(ret, (int)ERR_OK);
471 }
472
473 /**
474 * @tc.name: SetTargetDeviceBundleList_100
475 * @tc.desc: Test SetTargetDeviceBundleList when caller is not subsystem.
476 * @tc.type: FUNC
477 * @tc.require: issue
478 */
479 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceBundleList_100, Function | SmallTest | Level1)
480 {
481 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_INVALID);
482 const std::string deviceType = "";
483 const std::string deviceId = "";
484 int operatorType = 0;
485 const std::vector<std::string> labelList;
486 const std::vector<std::string> bundleList;
487
488 auto ret = advancedNotificationService_->SetTargetDeviceBundleList(deviceType, deviceId, operatorType,
489 bundleList, labelList);
490
491 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
492 }
493
494 /**
495 * @tc.name: SetTargetDeviceBundleList_200
496 * @tc.desc: Test SetTargetDeviceBundleList when caller has no permission.
497 * @tc.type: FUNC
498 * @tc.require: issue
499 */
500 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceBundleList_200, Function | SmallTest | Level1)
501 {
502 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE);
503 MockIsVerfyPermisson(false);
504 const std::string deviceType = "";
505 const std::string deviceId = "";
506 int operatorType = 0;
507 const std::vector<std::string> labelList;
508 const std::vector<std::string> bundleList;
509
510 auto ret = advancedNotificationService_->SetTargetDeviceBundleList(deviceType, deviceId, operatorType,
511 bundleList, labelList);
512
513 ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
514 }
515
516 /**
517 * @tc.name: SetTargetDeviceBundleList_300
518 * @tc.desc: Test SetTargetDeviceBundleList when caller has invalid parameters.
519 * @tc.type: FUNC
520 * @tc.require: issue
521 */
522 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceBundleList_300, Function | SmallTest | Level1)
523 {
524 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE);
525 MockIsVerfyPermisson(true);
526 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
527 const std::string deviceType = "";
528 const std::string deviceId = "";
529 int operatorType = 0;
530 const std::vector<std::string> labelList;
531 const std::vector<std::string> bundleList;
532
533 auto ret = advancedNotificationService_->SetTargetDeviceBundleList(deviceType, deviceId, operatorType,
534 bundleList, labelList);
535
536 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
537 }
538
539 /**
540 * @tc.name: GetMutilDeviceStatus_100
541 * @tc.desc: Test GetMutilDeviceStatus when caller is not subsystem.
542 * @tc.type: FUNC
543 * @tc.require: issue
544 */
545 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetMutilDeviceStatus_100, Function | SmallTest | Level1)
546 {
547 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_INVALID);
548 const std::string deviceType = "pad";
549 uint32_t flag = 3;
550 int32_t userId;
551 std::string deviceId = "";
552
553 auto ret = advancedNotificationService_->GetMutilDeviceStatus(deviceType, flag, deviceId, userId);
554 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
555 }
556
557 /**
558 * @tc.name: GetTargetDeviceBundleList_100
559 * @tc.desc: Test GetTargetDeviceBundleList when caller is not subsystem.
560 * @tc.type: FUNC
561 * @tc.require: issue
562 */
563 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetTargetDeviceBundleList_100, Function | SmallTest | Level1)
564 {
565 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_INVALID);
566 const std::string deviceType = "pad";
567 const std::string deviceId = "id";
568 std::vector<std::string> bundles;
569 std::vector<std::string> labels;
570 auto ret = advancedNotificationService_->GetTargetDeviceBundleList(deviceType, deviceId, bundles, labels);
571 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
572 }
573
574 /**
575 * @tc.name: SetTargetDeviceSwitch_100
576 * @tc.desc: Test SetTargetDeviceSwitch when caller is not subsystem.
577 * @tc.type: FUNC
578 * @tc.require: issue
579 */
580 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceSwitch_100, Function | SmallTest | Level1)
581 {
582 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_INVALID);
583 const std::string deviceType = "";
584 const std::string deviceId = "";
585 bool notificaitonEnable = false;
586 bool liveViewEnable = false;
587
588 auto ret = advancedNotificationService_->SetTargetDeviceSwitch(
589 deviceType, deviceId, notificaitonEnable, liveViewEnable);
590
591 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
592 }
593
594 /**
595 * @tc.name: SetTargetDeviceSwitch_200
596 * @tc.desc: Test SetTargetDeviceSwitch when caller has no permission.
597 * @tc.type: FUNC
598 * @tc.require: issue
599 */
600 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceSwitch_200, Function | SmallTest | Level1)
601 {
602 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE);
603 MockIsVerfyPermisson(false);
604 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
605 const std::string deviceType = "";
606 const std::string deviceId = "";
607 bool notificaitonEnable = false;
608 bool liveViewEnable = false;
609
610 auto ret = advancedNotificationService_->SetTargetDeviceSwitch(
611 deviceType, deviceId, notificaitonEnable, liveViewEnable);
612
613 ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
614 }
615
616 /**
617 * @tc.name: SetTargetDeviceSwitch_300
618 * @tc.desc: Test SetTargetDeviceSwitch when caller has invalid parameters.
619 * @tc.type: FUNC
620 * @tc.require: issue
621 */
622 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetTargetDeviceSwitch_300, Function | SmallTest | Level1)
623 {
624 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE);
625 MockIsVerfyPermisson(true);
626 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
627 const std::string deviceType = "";
628 const std::string deviceId = "";
629 bool notificaitonEnable = false;
630 bool liveViewEnable = false;
631
632 auto ret = advancedNotificationService_->SetTargetDeviceSwitch(
633 deviceType, deviceId, notificaitonEnable, liveViewEnable);
634
635 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
636 }
637
638 /**
639 * @tc.name: GetAllDistribuedEnabledBundles_100
640 * @tc.desc: Test GetAllDistribuedEnabledBundles when caller has no permission.
641 * @tc.type: FUNC
642 * @tc.require: issue
643 */
644 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetAllDistribuedEnabledBundles_100, Function | SmallTest | Level1)
645 {
646 MockIsVerfyPermisson(false);
647 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
648 const std::string deviceType = "";
649 std::vector<NotificationBundleOption> bundleOptions;
650
651 auto ret = advancedNotificationService_->GetAllDistribuedEnabledBundles(deviceType, bundleOptions);
652
653 ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
654 }
655
656 /**
657 * @tc.name: GetAllDistribuedEnabledBundles_200
658 * @tc.desc: Test GetAllDistribuedEnabledBundles when notificationSvrQueue_ is nullptr.
659 * @tc.type: FUNC
660 * @tc.require: issue
661 */
662 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetAllDistribuedEnabledBundles_200, Function | SmallTest | Level1)
663 {
664 MockIsVerfyPermisson(true);
665 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
666 const std::string deviceType = "";
667 std::vector<NotificationBundleOption> bundleOptions;
668 advancedNotificationService_->notificationSvrQueue_ = nullptr;
669
670 auto ret = advancedNotificationService_->GetAllDistribuedEnabledBundles(deviceType, bundleOptions);
671
672 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
673 }
674
675 /**
676 * @tc.name: GetAllDistribuedEnabledBundles_300
677 * @tc.desc: Test GetAllDistribuedEnabledBundles when caller has invalid parameters.
678 * @tc.type: FUNC
679 * @tc.require: issue
680 */
681 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetAllDistribuedEnabledBundles_300, Function | SmallTest | Level1)
682 {
683 MockIsVerfyPermisson(true);
684 IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN);
685 const std::string deviceType = "";
686 std::vector<NotificationBundleOption> bundleOptions;
687
688 auto ret = advancedNotificationService_->GetAllDistribuedEnabledBundles(deviceType, bundleOptions);
689
690 ASSERT_EQ(ret, (int)ERR_OK);
691 }
692
693 /**
694 * @tc.name: SetDistributedEnabledByBundle_100
695 * @tc.desc: Test SetDistributedEnabledByBundle when caller has invalid parameters.
696 * @tc.type: FUNC
697 * @tc.require: issue
698 */
699 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetDistributedEnabledByBundle_100, Function | SmallTest | Level1)
700 {
701 const std::string deviceType = "";
702 bool enabled = false;
703 sptr<NotificationBundleOption> bundleOption = nullptr;
704
705 auto ret = advancedNotificationService_->SetDistributedEnabledByBundle(bundleOption, deviceType, enabled);
706
707 ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
708 }
709
710 /**
711 * @tc.name: SetDistributedEnabled_100
712 * @tc.desc: Test SetDistributedEnabled when caller is not subsystem or system app.
713 * @tc.type: FUNC
714 * @tc.require: issue
715 */
716 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetDistributedEnabled_100, Function | SmallTest | Level1)
717 {
718 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
719 MockIsSystemApp(false);
720 const std::string deviceType = NotificationConstant::PAD_DEVICE_TYPE;
721 bool enabled = 0;
722
723 auto ret = advancedNotificationService_->SetDistributedEnabled(deviceType, enabled);
724
725 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
726 }
727
728 /**
729 * @tc.name: SetDistributedEnabled_200
730 * @tc.desc: Test SetDistributedEnabled when succeed to call.
731 * @tc.type: FUNC
732 * @tc.require: issue
733 */
734 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetDistributedEnabled_200, Function | SmallTest | Level1)
735 {
736 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
737 MockIsSystemApp(true);
738 const std::string deviceType = NotificationConstant::PAD_DEVICE_TYPE;
739 bool enabled = 0;
740
741 auto ret = advancedNotificationService_->SetDistributedEnabled(deviceType, enabled);
742
743 ASSERT_EQ(ret, (int)ERR_OK);
744 }
745
746 /**
747 * @tc.name: IsDistributedEnabled_100
748 * @tc.desc: Test IsDistributedEnabled when caller is not subsystem or system app.
749 * @tc.type: FUNC
750 * @tc.require: issue
751 */
752 HWTEST_F(AdvancedNotificationDistMgrServiceTest, IsDistributedEnabled_100, Function | SmallTest | Level1)
753 {
754 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
755 MockIsSystemApp(false);
756 const std::string deviceType = NotificationConstant::PAD_DEVICE_TYPE;
757 bool enabled = 0;
758
759 auto ret = advancedNotificationService_->IsDistributedEnabled(deviceType, enabled);
760
761 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
762 }
763
764 /**
765 * @tc.name: IsDistributedEnabled_200
766 * @tc.desc: Test IsDistributedEnabled when succeed to call.
767 * @tc.type: FUNC
768 * @tc.require: issue
769 */
770 HWTEST_F(AdvancedNotificationDistMgrServiceTest, IsDistributedEnabled_200, Function | SmallTest | Level1)
771 {
772 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
773 MockIsSystemApp(true);
774 const std::string deviceType = NotificationConstant::PAD_DEVICE_TYPE;
775 bool enabled = 0;
776
777 auto ret = advancedNotificationService_->IsDistributedEnabled(deviceType, enabled);
778
779 ASSERT_EQ(ret, (int)ERR_OK);
780 }
781
782 /**
783 * @tc.name: GetDistributedAbility_100
784 * @tc.desc: Test GetDistributedAbility when caller is not subsystem or system app.
785 * @tc.type: FUNC
786 * @tc.require: issue
787 */
788 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetDistributedAbility_100, Function | SmallTest | Level1)
789 {
790 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
791 MockIsSystemApp(false);
792 int32_t abilityId = 0;
793
794 auto ret = advancedNotificationService_->GetDistributedAbility(abilityId);
795
796 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
797 }
798
799 /**
800 * @tc.name: GetDistributedAuthStatus_100
801 * @tc.desc: Test GetDistributedAuthStatus when caller is not subsystem or system app.
802 * @tc.type: FUNC
803 * @tc.require: issue
804 */
805 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetDistributedAuthStatus_100, Function | SmallTest | Level1)
806 {
807 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
808 MockIsSystemApp(false);
809 const std::string deviceType = "";
810 const std::string deviceId = "";
811 int32_t userId = 100;
812 bool isAuth = false;
813
814 auto ret = advancedNotificationService_->GetDistributedAuthStatus(deviceType, deviceId, userId, isAuth);
815
816 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
817 }
818
819 /**
820 * @tc.name: GetDistributedAuthStatus_200
821 * @tc.desc: Test GetDistributedAuthStatus when succeed to call.
822 * @tc.type: FUNC
823 * @tc.require: issue
824 */
825 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetDistributedAuthStatus_200, Function | SmallTest | Level1)
826 {
827 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
828 MockIsSystemApp(true);
829 const std::string deviceType = "";
830 const std::string deviceId = "";
831 int32_t userId = 100;
832 bool isAuth = false;
833
834 auto ret = advancedNotificationService_->GetDistributedAuthStatus(deviceType, deviceId, userId, isAuth);
835
836 ASSERT_EQ(ret, (int)ERR_OK);
837 }
838
839 /**
840 * @tc.name: SetDistributedAuthStatus_100
841 * @tc.desc: Test SetDistributedAuthStatus when caller is not subsystem or system app.
842 * @tc.type: FUNC
843 * @tc.require: issue
844 */
845 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetDistributedAuthStatus_100, Function | SmallTest | Level1)
846 {
847 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
848 MockIsSystemApp(false);
849 const std::string deviceType = "";
850 const std::string deviceId = "";
851 int32_t userId = 100;
852 bool isAuth = false;
853
854 auto ret = advancedNotificationService_->SetDistributedAuthStatus(deviceType, deviceId, userId, isAuth);
855
856 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
857 }
858
859 /**
860 * @tc.name: SetDistributedAuthStatus_200
861 * @tc.desc: Test SetDistributedAuthStatus when succeed to call.
862 * @tc.type: FUNC
863 * @tc.require: issue
864 */
865 HWTEST_F(AdvancedNotificationDistMgrServiceTest, SetDistributedAuthStatus_200, Function | SmallTest | Level1)
866 {
867 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
868 MockIsSystemApp(true);
869 const std::string deviceType = "";
870 const std::string deviceId = "";
871 int32_t userId = 100;
872 bool isAuth = false;
873
874 auto ret = advancedNotificationService_->SetDistributedAuthStatus(deviceType, deviceId, userId, isAuth);
875
876 ASSERT_EQ(ret, (int)ERR_OK);
877 }
878
879 /**
880 * @tc.name: GetDistributedDevicelist_0100
881 * @tc.desc: Test GetDistributedDevicelist.
882 * @tc.type: FUNC
883 */
884 HWTEST_F(AdvancedNotificationDistMgrServiceTest, GetDistributedDevicelist_0100, Function | SmallTest | Level1)
885 {
886 MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
887 MockIsSystemApp(false);
888 std::vector<std::string> deviceTypes;
889 auto ret = advancedNotificationService_->GetDistributedDevicelist(deviceTypes);
890 ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
891 }
892 } // namespace Notification
893 } // namespace OHOS
894