• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ans_inner_errors.h"
19 #include "ans_manager_proxy.h"
20 #include "advanced_notification_service.h"
21 #include "if_system_ability_manager.h"
22 #include "iservice_registry.h"
23 #include "notification_helper.h"
24 #include "remote_native_token.h"
25 #include "system_ability_definition.h"
26 
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace Notification {
30 static sptr<ISystemAbilityManager> systemAbilityManager =
31     SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
32 const int32_t CALLING_UID = 9998;
33 const int32_t USERID = 100;
34 
35 class AnsInnerKitsModuleSettingTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp();
40     void TearDown();
41 };
42 
SetUpTestCase()43 void AnsInnerKitsModuleSettingTest::SetUpTestCase()
44 {
45     RemoteNativeToken::SetNativeToken();
46     sptr<AdvancedNotificationService> service = OHOS::Notification::AdvancedNotificationService::GetInstance();
47     OHOS::ISystemAbilityManager::SAExtraProp saExtraProp;
48     systemAbilityManager->AddSystemAbility(OHOS::ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, service, saExtraProp);
49 }
50 
TearDownTestCase()51 void AnsInnerKitsModuleSettingTest::TearDownTestCase()
52 {}
53 
SetUp()54 void AnsInnerKitsModuleSettingTest::SetUp()
55 {}
56 
TearDown()57 void AnsInnerKitsModuleSettingTest::TearDown()
58 {}
59 
60 /**
61  * @tc.number    : ANS_Interface_MT_NotificationSetting_00100
62  * @tc.name      : NotificationSetting_00100
63  * @tc.desc      : Set a specified application to show badge, get the specified application can show badge.
64  * @tc.expected  : Set a specified application to show badge success, get the specified application can show badge.
65  */
66 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00100, Function | MediumTest | Level1)
67 {
68     NotificationBundleOption bundleOption;
69     bundleOption.SetBundleName("bundlename");
70     bundleOption.SetUid(CALLING_UID);
71     GTEST_LOG_(INFO) << "BundleOption is:"<<bundleOption.Dump();
72     EXPECT_EQ(0, NotificationHelper::SetShowBadgeEnabledForBundle(bundleOption, true));
73     bool enabled = false;
74     EXPECT_EQ(0, NotificationHelper::GetShowBadgeEnabledForBundle(bundleOption, enabled));
75     EXPECT_EQ(true, enabled);
76     EXPECT_EQ("bundlename", bundleOption.GetBundleName());
77     EXPECT_EQ(CALLING_UID, bundleOption.GetUid());
78 }
79 
80 /**
81  * @tc.number    : ANS_Interface_MT_NotificationSetting_00200
82  * @tc.name      : NotificationSetting_00100
83  * @tc.desc      : Set a specified application do not show badge, get the specified application can not show badge.
84  * @tc.expected  : Set a specified application do not show badge success, get the specified application can not show
85  *                 badge.
86  */
87 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00200, Function | MediumTest | Level1)
88 {
89     NotificationBundleOption bundleOption("bundlename", CALLING_UID);
90     EXPECT_EQ(0, NotificationHelper::SetShowBadgeEnabledForBundle(bundleOption, false));
91     bool enabled = false;
92     EXPECT_EQ(0, NotificationHelper::GetShowBadgeEnabledForBundle(bundleOption, enabled));
93     EXPECT_EQ(false, enabled);
94     EXPECT_EQ("bundlename", bundleOption.GetBundleName());
95     EXPECT_EQ(CALLING_UID, bundleOption.GetUid());
96 }
97 
98 /**
99  * @tc.number    : ANS_Interface_MT_NotificationSetting_00300
100  * @tc.name      : NotificationSetting_00300
101  * @tc.desc      : Set a specified application can publish notification, get the specified application can publish
102  *                 notification.
103  * @tc.expected  : Set a specified application can publish notification success, get the specified application can
104  *                 publish notification.
105  */
106 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00300, Function | MediumTest | Level1)
107 {
108     NotificationBundleOption bundleOption("bundlename", CALLING_UID);
109     std::string deviceId;
110     EXPECT_EQ(0, NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(bundleOption, deviceId, true));
111     bool enabled = false;
112     EXPECT_EQ(0, NotificationHelper::IsAllowedNotify(bundleOption, enabled));
113     EXPECT_EQ(true, enabled);
114     EXPECT_EQ("bundlename", bundleOption.GetBundleName());
115     EXPECT_EQ(CALLING_UID, bundleOption.GetUid());
116 }
117 
118 /**
119  * @tc.number    : ANS_Interface_MT_NotificationSetting_00400
120  * @tc.name      : NotificationSetting_00400
121  * @tc.desc      : Set a specified application do not publish notification, get the specified application can not
122  *                 publish notification.
123  * @tc.expected  : Set a specified application do not publish notification success, get the specified application can
124  *                 not publish notification.
125  */
126 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00400, Function | MediumTest | Level1)
127 {
128     NotificationBundleOption bundleOption("bundlename", CALLING_UID);
129     std::string deviceId;
130     EXPECT_EQ(0, NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(bundleOption, deviceId, false));
131     bool enabled = false;
132     EXPECT_EQ(0, NotificationHelper::IsAllowedNotify(bundleOption, enabled));
133     EXPECT_EQ(false, enabled);
134     EXPECT_EQ("bundlename", bundleOption.GetBundleName());
135     EXPECT_EQ(CALLING_UID, bundleOption.GetUid());
136 }
137 
138 /**
139  * @tc.number    : ANS_Interface_MT_NotificationSetting_00500
140  * @tc.name      : NotificationSetting_00500
141  * @tc.desc      : If the template configuration file does not exist, query whether the template exists.
142  * @tc.expected  : Query return failed.
143  */
144 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00500, Function | MediumTest | Level1)
145 {
146     std::string templateName("downloadTemplate");
147     bool support = false;
148     EXPECT_EQ(0, NotificationHelper::IsSupportTemplate(templateName, support));
149     EXPECT_EQ(true, support);
150 }
151 
152 /**
153  * @tc.number    : ANS_Interface_MT_NotificationSetting_00700
154  * @tc.name      : NotificationSetting_00700
155  * @tc.desc      : The template does not exist in the system, query whether the template exists.
156  * @tc.expected  : Query return failed.
157  */
158 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00700, Function | MediumTest | Level1)
159 {
160     std::string templateName("downloadTemplate_1");
161     bool support = false;
162     EXPECT_EQ(0, NotificationHelper::IsSupportTemplate(templateName, support));
163     EXPECT_EQ(false, support);
164 }
165 
166 /**
167  * @tc.number    : ANS_Interface_MT_NotificationSetting_00800
168  * @tc.name      : NotificationSetting_00800
169  * @tc.desc      : Set whether to sync notifications to devices that do not have the app installed.
170  * @tc.expected  : Set true, get true.
171  */
172 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00800, Function | MediumTest | Level1)
173 {
174     NotificationBundleOption bundleOption("bundlename", CALLING_UID);
175     EXPECT_EQ(0, NotificationHelper::SetSyncNotificationEnabledWithoutApp(USERID, true));
176     bool enabled = false;
177     EXPECT_EQ(0, NotificationHelper::GetSyncNotificationEnabledWithoutApp(USERID, enabled));
178     EXPECT_EQ(true, enabled);
179 }
180 
181 /**
182  * @tc.number    : ANS_Interface_MT_NotificationSetting_00900
183  * @tc.name      : NotificationSetting_00900
184  * @tc.desc      : Set a specified application do not show badge, get the specified application can not show badge.
185  * @tc.expected  : Set false, get false.
186  */
187 HWTEST_F(AnsInnerKitsModuleSettingTest, ANS_Interface_MT_NotificationSetting_00900, Function | MediumTest | Level1)
188 {
189     NotificationBundleOption bundleOption("bundlename", CALLING_UID);
190     EXPECT_EQ(0, NotificationHelper::SetSyncNotificationEnabledWithoutApp(USERID, false));
191     bool enabled = true;
192     EXPECT_EQ(0, NotificationHelper::GetSyncNotificationEnabledWithoutApp(USERID, enabled));
193     EXPECT_EQ(false, enabled);
194 }
195 }  // namespace Notification
196 }  // namespace OHOS