1 /*
2  * Copyright (c) 2021 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 <gtest/gtest.h>
16 #include <functional>
17 
18 #define private public
19 #include "advanced_notification_service.h"
20 #undef private
21 #include "ans_const_define.h"
22 #include "ans_inner_errors.h"
23 #include "ans_manager_proxy.h"
24 #include "if_system_ability_manager.h"
25 #include "iservice_registry.h"
26 #include "notification_helper.h"
27 #include "remote_native_token.h"
28 #include "system_ability_definition.h"
29 #include "accesstoken_kit.h"
30 
31 using namespace testing::ext;
32 using namespace OHOS::Security::AccessToken;
33 
34 namespace OHOS {
35 namespace Notification {
36 extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet);
37 extern void MockIsSystemApp(bool isSystemApp);
38 
39 const int32_t SLEEP_TIME = 1;
40 static sptr<ISystemAbilityManager> systemAbilityManager =
41     SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
42 
43 class AnsInnerKitsModuleSlotTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47     void SetUp();
48     void TearDown();
49 
50     static sptr<AdvancedNotificationService> service_;
51 };
52 
53 sptr<AdvancedNotificationService> AnsInnerKitsModuleSlotTest::service_;
SetUpTestCase()54 void AnsInnerKitsModuleSlotTest::SetUpTestCase()
55 {
56     RemoteNativeToken::SetNativeToken("ans_innerkits_module_slot_test");
57     service_ = OHOS::Notification::AdvancedNotificationService::GetInstance();
58     OHOS::ISystemAbilityManager::SAExtraProp saExtraProp;
59     systemAbilityManager->AddSystemAbility(OHOS::ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, service_, saExtraProp);
60 }
61 
TearDownTestCase()62 void AnsInnerKitsModuleSlotTest::TearDownTestCase()
63 {
64     if (service_ != nullptr) {
65         service_->SelfClean();
66     }
67 }
68 
SetUp()69 void AnsInnerKitsModuleSlotTest::SetUp()
70 {
71     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
72     MockIsSystemApp(true);
73     NotificationHelper::RemoveAllSlots();
74 }
75 
TearDown()76 void AnsInnerKitsModuleSlotTest::TearDown()
77 {}
78 
79 /**
80  * @tc.number    : ANS_Interface_MT_NotificationSlot_00100
81  * @tc.name      : NotificationSlot_00100
82  * @tc.desc      : Add notification slot(type is SOCIAL_COMMUNICATION), get notification slot and remove notification
83  * slot.
84  * @tc.expected  : Add notification slot success, get notification slot correctly and remove notification slot success.
85  */
86 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00100, Function | MediumTest | Level1)
87 {
88     NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION);
89     slot.SetEnableLight(true);
90     slot.SetDescription("description");
91     slot.SetLedLightColor(0);
92     slot.SetLevel(NotificationSlot::NotificationLevel::LEVEL_LOW);
93     slot.SetSound(Uri("."));
94     std::vector<int64_t> style;
95     style.push_back(0);
96     slot.SetVibrationStyle(style);
97     slot.EnableBypassDnd(true);
98     slot.EnableBadge(true);
99     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
100     sleep(SLEEP_TIME);
101 
102     sptr<NotificationSlot> spSlot(new NotificationSlot());
103     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot));
104     EXPECT_NE(nullptr, spSlot);
105     GTEST_LOG_(INFO) << "after get slot dump slot information:" << spSlot->Dump();
106     EXPECT_EQ(true, spSlot->CanEnableLight());
107     EXPECT_EQ(true, spSlot->CanVibrate());
108     EXPECT_EQ("description", spSlot->GetDescription());
109     EXPECT_EQ("SOCIAL_COMMUNICATION", spSlot->GetId());
110     EXPECT_EQ(0, spSlot->GetLedLightColor());
111     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel());
112     EXPECT_EQ(NotificationConstant::SOCIAL_COMMUNICATION, spSlot->GetType());
113     EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, spSlot->GetLockScreenVisibleness());
114     EXPECT_EQ("SOCIAL_COMMUNICATION", spSlot->GetName());
115     EXPECT_EQ(Uri("."), spSlot->GetSound());
116     for (auto it : spSlot->GetVibrationStyle()) {
117         EXPECT_EQ(0, it);
118     }
119     EXPECT_EQ(Uri("."), spSlot->GetSound());
120     EXPECT_EQ(true, spSlot->IsEnableBypassDnd());
121     EXPECT_EQ(true, spSlot->IsShowBadge());
122     EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION));
123     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot));
124 }
125 
126 /**
127  * @tc.number    : ANS_Interface_MT_NotificationSlot_00200
128  * @tc.name      : NotificationSlot_00200
129  * @tc.desc      : Add notification slot(type is SERVICE_REMINDER), get notification slot and remove notification slot.
130  * @tc.expected  : Add notification slot success, get notification slot correctly and remove notification slot success.
131  */
132 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00200, Function | MediumTest | Level1)
133 {
134     NotificationSlot slot(NotificationConstant::SERVICE_REMINDER);
135     slot.SetEnableLight(true);
136     slot.SetDescription("description");
137     slot.SetLedLightColor(0);
138     slot.SetLevel(NotificationSlot::NotificationLevel::LEVEL_LOW);
139     slot.SetSound(Uri("."));
140     std::vector<int64_t> style;
141     style.push_back(0);
142     slot.SetVibrationStyle(style);
143     slot.EnableBypassDnd(true);
144     slot.EnableBadge(true);
145     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
146     sleep(SLEEP_TIME);
147     sptr<NotificationSlot> spSlot(new NotificationSlot());
148     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SERVICE_REMINDER, spSlot));
149 
150     EXPECT_NE(nullptr, spSlot);
151     EXPECT_EQ(true, spSlot->CanEnableLight());
152     EXPECT_EQ(true, spSlot->CanVibrate());
153     EXPECT_EQ("description", spSlot->GetDescription());
154     EXPECT_EQ("SERVICE_REMINDER", spSlot->GetId());
155     EXPECT_EQ(0, spSlot->GetLedLightColor());
156     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel());
157     EXPECT_EQ(NotificationConstant::SERVICE_REMINDER, spSlot->GetType());
158     EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, spSlot->GetLockScreenVisibleness());
159     EXPECT_EQ("SERVICE_REMINDER", spSlot->GetName());
160     EXPECT_EQ(Uri("."), spSlot->GetSound());
161     for (auto it : spSlot->GetVibrationStyle()) {
162         EXPECT_EQ(0, it);
163     }
164     EXPECT_EQ(Uri("."), spSlot->GetSound());
165     EXPECT_EQ(true, spSlot->IsEnableBypassDnd());
166     EXPECT_EQ(true, spSlot->IsShowBadge());
167     EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::SERVICE_REMINDER));
168     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SERVICE_REMINDER, spSlot));
169 }
170 
171 /**
172  * @tc.number    : ANS_Interface_MT_NotificationSlot_00300
173  * @tc.name      : NotificationSlot_00300
174  * @tc.desc      : Add notification slot(type is CONTENT_INFORMATION), get notification slot and remove notification
175  * slot.
176  * @tc.expected  : Add notification slot success, get notification slot correctly and remove notification slot success.
177  */
178 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00300, Function | MediumTest | Level1)
179 {
180     NotificationSlot slot(NotificationConstant::CONTENT_INFORMATION);
181     slot.SetEnableLight(true);
182     slot.SetDescription("description");
183     slot.SetLedLightColor(0);
184     slot.SetLevel(NotificationSlot::NotificationLevel::LEVEL_LOW);
185     slot.SetSound(Uri("."));
186     std::vector<int64_t> style;
187     style.push_back(0);
188     slot.SetVibrationStyle(style);
189     slot.EnableBypassDnd(true);
190     slot.EnableBadge(true);
191     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
192     sleep(SLEEP_TIME);
193     sptr<NotificationSlot> spSlot(new NotificationSlot());
194     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::CONTENT_INFORMATION, spSlot));
195 
196     EXPECT_NE(nullptr, spSlot);
197     EXPECT_EQ(true, spSlot->CanEnableLight());
198     EXPECT_EQ(true, spSlot->CanVibrate());
199     EXPECT_EQ("description", spSlot->GetDescription());
200     EXPECT_EQ("CONTENT_INFORMATION", spSlot->GetId());
201     EXPECT_EQ(0, spSlot->GetLedLightColor());
202     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel());
203     EXPECT_EQ(NotificationConstant::CONTENT_INFORMATION, spSlot->GetType());
204     EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness());
205     EXPECT_EQ("CONTENT_INFORMATION", spSlot->GetName());
206     EXPECT_EQ(Uri("."), spSlot->GetSound());
207     for (auto it : spSlot->GetVibrationStyle()) {
208         EXPECT_EQ(0, it);
209     }
210     EXPECT_EQ(Uri("."), spSlot->GetSound());
211     EXPECT_EQ(true, spSlot->IsEnableBypassDnd());
212     EXPECT_EQ(true, spSlot->IsShowBadge());
213     EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::CONTENT_INFORMATION));
214     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::CONTENT_INFORMATION, spSlot));
215 }
216 
217 /**
218  * @tc.number    : ANS_Interface_MT_NotificationSlot_00400
219  * @tc.name      : NotificationSlot_00400
220  * @tc.desc      : Add notification slot(type is OTHER), get notification slot and remove notification slot.
221  * @tc.expected  : Add notification slot success, get notification slot correctly and remove notification slot success.
222  */
223 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00400, Function | MediumTest | Level1)
224 {
225     NotificationSlot slot(NotificationConstant::OTHER);
226     slot.SetEnableLight(true);
227     slot.SetDescription("description");
228     slot.SetLedLightColor(0);
229     slot.SetLevel(NotificationSlot::NotificationLevel::LEVEL_LOW);
230     slot.SetSound(Uri("."));
231     std::vector<int64_t> style;
232     style.push_back(0);
233     slot.SetVibrationStyle(style);
234     slot.EnableBypassDnd(true);
235     slot.EnableBadge(true);
236     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
237     sleep(SLEEP_TIME);
238     sptr<NotificationSlot> spSlot(new NotificationSlot());
239     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot));
240 
241     EXPECT_NE(nullptr, spSlot);
242     EXPECT_EQ(true, spSlot->CanEnableLight());
243     EXPECT_EQ(true, spSlot->CanVibrate());
244     EXPECT_EQ("description", spSlot->GetDescription());
245     EXPECT_EQ("OTHER", spSlot->GetId());
246     EXPECT_EQ(0, spSlot->GetLedLightColor());
247     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel());
248     EXPECT_EQ(NotificationConstant::OTHER, spSlot->GetType());
249     EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness());
250     EXPECT_EQ("OTHER", spSlot->GetName());
251     EXPECT_EQ(Uri("."), spSlot->GetSound());
252     for (auto it : spSlot->GetVibrationStyle()) {
253         EXPECT_EQ(0, it);
254     }
255     EXPECT_EQ(Uri("."), spSlot->GetSound());
256     EXPECT_EQ(true, spSlot->IsEnableBypassDnd());
257     EXPECT_EQ(true, spSlot->IsShowBadge());
258     EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::OTHER));
259     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot));
260 }
261 
262 /**
263  * @tc.number    : ANS_Interface_MT_NotificationSlot_00500
264  * @tc.name      : NotificationSlot_00500
265  * @tc.desc      : Add notification slot(type is OTHER), slot set description character length exceed 1000
266  *                 characters, get notification slot and remove notification slot.
267  * @tc.expected  : Add notification slot success, get notification slot correctly and remove notification slot success.
268  */
269 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00500, Function | MediumTest | Level1)
270 {
271     NotificationSlot slot(NotificationConstant::OTHER);
272     slot.SetEnableLight(true);
273     std::string description(2000, 'c');
274     slot.SetDescription(description);
275     slot.SetLedLightColor(0);
276     slot.SetLevel(NotificationSlot::NotificationLevel::LEVEL_LOW);
277     slot.SetSound(Uri("."));
278     std::vector<int64_t> style;
279     style.push_back(0);
280     slot.SetVibrationStyle(style);
281     slot.EnableBypassDnd(true);
282     slot.EnableBadge(true);
283     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
284     sleep(SLEEP_TIME);
285     sptr<NotificationSlot> spSlot(new NotificationSlot());
286     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot));
287 
288     EXPECT_NE(nullptr, spSlot);
289     GTEST_LOG_(INFO) << "get slot is:" << spSlot->Dump();
290     EXPECT_EQ(true, spSlot->CanEnableLight());
291     EXPECT_EQ(true, spSlot->CanVibrate());
292     std::string expecteDescription(1000, 'c');
293     EXPECT_EQ(expecteDescription, spSlot->GetDescription());
294     EXPECT_EQ("OTHER", spSlot->GetId());
295     EXPECT_EQ(0, spSlot->GetLedLightColor());
296     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel());
297     EXPECT_EQ(NotificationConstant::OTHER, spSlot->GetType());
298     EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness());
299     EXPECT_EQ("OTHER", spSlot->GetName());
300     EXPECT_EQ(Uri("."), spSlot->GetSound());
301     for (auto it : spSlot->GetVibrationStyle()) {
302         EXPECT_EQ(0, it);
303     }
304     EXPECT_EQ(Uri("."), spSlot->GetSound());
305     EXPECT_EQ(true, spSlot->IsEnableBypassDnd());
306     EXPECT_EQ(true, spSlot->IsShowBadge());
307     EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::OTHER));
308     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot));
309 }
310 
311 /**
312  * @tc.number    : ANS_Interface_MT_NotificationSlot_00600
313  * @tc.name      : NotificationSlot_00600
314  * @tc.desc      : Create notification slot(type is SOCIAL_COMMUNICATION), get sound and vibration.
315  * @tc.expected  : Create notification slot success, get sound and vibration success.
316  */
317 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00600, Function | MediumTest | Level1)
318 {
319     NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION);
320     EXPECT_EQ("SOCIAL_COMMUNICATION", slot.GetName());
321     EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, slot.GetLockScreenVisibleness());
322     EXPECT_EQ(DEFAULT_NOTIFICATION_SOUND.ToString(), slot.GetSound().ToString());
323     EXPECT_TRUE(slot.CanVibrate());
324     EXPECT_EQ(DEFAULT_NOTIFICATION_VIBRATION, slot.GetVibrationStyle());
325     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_HIGH, slot.GetLevel());
326 }
327 
328 /**
329  * @tc.number    : ANS_Interface_MT_NotificationSlot_00700
330  * @tc.name      : NotificationSlot_00700
331  * @tc.desc      : Create notification slot(type is SERVICE_REMINDER),  get sound and vibration.
332  * @tc.expected  : Create notification slot success, get sound and vibration success.
333  */
334 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00700, Function | MediumTest | Level1)
335 {
336     NotificationSlot slot(NotificationConstant::SERVICE_REMINDER);
337     EXPECT_EQ("SERVICE_REMINDER", slot.GetName());
338     EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, slot.GetLockScreenVisibleness());
339     EXPECT_EQ(DEFAULT_NOTIFICATION_SOUND.ToString(), slot.GetSound().ToString());
340     EXPECT_TRUE(slot.CanVibrate());
341     EXPECT_EQ(DEFAULT_NOTIFICATION_VIBRATION, slot.GetVibrationStyle());
342     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_DEFAULT, slot.GetLevel());
343 }
344 
345 /**
346  * @tc.number    : ANS_Interface_MT_NotificationSlot_00800
347  * @tc.name      : NotificationSlot_00800
348  * @tc.desc      : Create notification slot(type is CONTENT_INFORMATION), get sound and vibration.
349  * @tc.expected  : Create notification slot success, get sound and vibration success.
350  */
351 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00800, Function | MediumTest | Level1)
352 {
353     NotificationSlot slot(NotificationConstant::CONTENT_INFORMATION);
354     EXPECT_EQ("CONTENT_INFORMATION", slot.GetName());
355     EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, slot.GetLockScreenVisibleness());
356     EXPECT_EQ("", slot.GetSound().ToString());
357     EXPECT_FALSE(slot.CanVibrate());
358     EXPECT_EQ(0U, slot.GetVibrationStyle().size());
359     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_MIN, slot.GetLevel());
360 }
361 
362 /**
363  * @tc.number    : ANS_Interface_MT_NotificationSlot_00900
364  * @tc.name      : NotificationSlot_00900
365  * @tc.desc      : Create notification slot(type is OTHER), get sound and vibration.
366  * @tc.expected  : Create notification slot success, get sound and vibration success.
367  */
368 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00900, Function | MediumTest | Level1)
369 {
370     NotificationSlot slot(NotificationConstant::OTHER);
371     EXPECT_EQ("OTHER", slot.GetName());
372     EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, slot.GetLockScreenVisibleness());
373     EXPECT_EQ("", slot.GetSound().ToString());
374     EXPECT_FALSE(slot.CanVibrate());
375     EXPECT_EQ(0U, slot.GetVibrationStyle().size());
376     EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_MIN, slot.GetLevel());
377 }
378 
379 /**
380  * @tc.number    : ANS_Interface_MT_SetEnabledForBundleSlot_00100
381  * @tc.name      : SetEnabledForBundleSlot_00100
382  * @tc.desc      : Add notification slot(type is SOCIAL_COMMUNICATION), get slot default enable,
383  * set and get slot enable.
384  * @tc.expected  : Add notification slot success, slot default enalbe is true, get is the same as setting.
385  */
386 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00100, Function | MediumTest | Level1)
387 {
388     NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION);
389     slot.SetEnableLight(true);
390     slot.SetDescription("description");
391     slot.SetLedLightColor(0);
392     slot.SetLevel(NotificationSlot::NotificationLevel::LEVEL_LOW);
393     slot.SetSound(Uri("."));
394     std::vector<int64_t> style;
395     style.push_back(0);
396     slot.SetVibrationStyle(style);
397     slot.EnableBypassDnd(true);
398     slot.EnableBadge(true);
399     EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot));
400     sleep(SLEEP_TIME);
401     sptr<NotificationSlot> spSlot(new NotificationSlot());
402     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot));
403     EXPECT_NE(spSlot, nullptr);
404     EXPECT_EQ(spSlot->GetEnable(), true);
405 
406     bool enable = false;
407     NotificationBundleOption bo("bundlename", 1);
408     EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(
409         bo, NotificationConstant::SOCIAL_COMMUNICATION, enable, false));
410     sleep(SLEEP_TIME);
411     EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable));
412     EXPECT_EQ(enable, false);
413 }
414 
415 /**
416  * @tc.number    : ANS_Interface_MT_SetEnabledForBundleSlot_00200
417  * @tc.name      : SetEnabledForBundleSlot_00200
418  * @tc.desc      : Add slot when there is no type slot, add it. (SOCIAL_COMMUNICATION)
419  * @tc.expected  : Set success, and get success.
420  */
421 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00200, Function | MediumTest | Level1)
422 {
423     bool enable = true;
424     NotificationBundleOption bo("bundleName", 1);
425     EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(
426         bo, NotificationConstant::SOCIAL_COMMUNICATION, enable, false));
427     sleep(SLEEP_TIME);
428     enable = false;
429     EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable));
430     EXPECT_EQ(enable, true);
431 
432     sptr<NotificationSlot> spSlot(new NotificationSlot());
433     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot));
434     EXPECT_NE(spSlot, nullptr);
435     EXPECT_EQ(spSlot->GetEnable(), true);
436 }
437 
438 /**
439  * @tc.number    : ANS_Interface_MT_SetEnabledForBundleSlot_00300
440  * @tc.name      : SetEnabledForBundleSlot_00300
441  * @tc.desc      : Add slot when there is no type slot, add it. (SERVICE_REMINDER)
442  * @tc.expected  : Set false, and get false.
443  */
444 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00300, Function | MediumTest | Level1)
445 {
446     bool enable = false;
447     NotificationBundleOption bo("bundleName", 1);
448     EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(
449         bo, NotificationConstant::SERVICE_REMINDER, enable, false));
450     sleep(SLEEP_TIME);
451     enable = true;
452     EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable));
453     EXPECT_EQ(enable, false);
454 
455     sptr<NotificationSlot> spSlot(new NotificationSlot());
456     EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SERVICE_REMINDER, spSlot));
457     EXPECT_NE(spSlot, nullptr);
458     EXPECT_EQ(spSlot->GetEnable(), false);
459 }
460 }  // namespace Notification
461 }  // namespace OHOS
462