• 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 
16 #include <functional>
17 #include <gtest/gtest.h>
18 #define private public
19 #define protected public
20 #include "advanced_notification_service_ability.h"
21 #include "notification_preferences.h"
22 #include "distributed_device_manager.h"
23 
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Notification {
28 const int ANS_CLONE_ERROR = -1;
29 class AdvancedNotificationServiceAbilityTest : public testing::Test {
30 public:
SetUpTestCase()31     static void SetUpTestCase() {};
TearDownTestCase()32     static void TearDownTestCase() {};
SetUp()33     void SetUp() {};
TearDown()34     void TearDown() {};
35 };
36 
37 /**
38  * @tc.number    : AdvancedNotificationServiceAbilityTest_00100
39  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0100
40  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
41  */
42 HWTEST_F(
43     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00100, Function | SmallTest | Level1)
44 {
45     int32_t systemAbilityId = 1;
46     bool runOnCreate = true;
47     AdvancedNotificationServiceAbility(systemAbilityId, runOnCreate);
48 }
49 
50 /**
51  * @tc.number    : AdvancedNotificationServiceAbilityTest_00200
52  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0200
53  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
54  */
55 HWTEST_F(
56     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00200, Function | SmallTest | Level1)
57 {
58     int32_t systemAbilityId = 1;
59     bool runOnCreate = true;
60     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
61     test.OnStart();
62 }
63 
64 /**
65  * @tc.number    : AdvancedNotificationServiceAbilityTest_00300
66  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0300
67  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
68  */
69 HWTEST_F(
70     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00300, Function | SmallTest | Level1)
71 {
72     int32_t systemAbilityId = 1;
73     bool runOnCreate = true;
74     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
75     test.OnStop();
76     test.OnStart();
77 }
78 
79 /**
80  * @tc.number    : AdvancedNotificationServiceAbilityTest_00400
81  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0400
82  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
83  */
84 HWTEST_F(
85     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00400, Function | SmallTest | Level1)
86 {
87     int32_t systemAbilityId = 1;
88     bool runOnCreate = true;
89     std::string extension = "backup";
90     MessageParcel data;
91     MessageParcel reply;
92     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
93     ErrCode ret = test.OnExtension(extension, data, reply);
94     EXPECT_EQ(ret, 0);
95 }
96 
97 /**
98  * @tc.number    : AdvancedNotificationServiceAbilityTest_00500
99  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0500
100  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
101  */
102 HWTEST_F(
103     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00500, Function | SmallTest | Level1)
104 {
105     int32_t systemAbilityId = 1;
106     bool runOnCreate = true;
107     std::string extension = "restore";
108     MessageParcel data;
109     MessageParcel reply;
110     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
111     test.OnStart();
112     ErrCode ret = test.OnExtension(extension, data, reply);
113     EXPECT_EQ(ret, (int)ANS_CLONE_ERROR);
114 }
115 
116 /**
117  * @tc.number    : AdvancedNotificationServiceAbilityTest_00600
118  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0600
119  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
120  */
121 HWTEST_F(
122     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00600, Function | SmallTest | Level1)
123 {
124     int32_t systemAbilityId = 1;
125     bool runOnCreate = true;
126     std::string deviceId = "deviceId";
127     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
128     test.OnAddSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, deviceId);
129     EXPECT_EQ(test.isDatashaReready_, true);
130 }
131 
132 /**
133  * @tc.number    : AdvancedNotificationServiceAbilityTest_00700
134  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0700
135  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
136  */
137 HWTEST_F(
138     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00700, Function | SmallTest | Level1)
139 {
140     int32_t systemAbilityId = 1;
141     bool runOnCreate = true;
142     std::string deviceId = "deviceId";
143     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
144     test.OnAddSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, deviceId);
145     test.OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, deviceId);
146     test.OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, deviceId);
147     EXPECT_EQ(test.isDatashaReready_, true);
148 }
149 
150 /**
151  * @tc.number    : AdvancedNotificationServiceAbilityTest_00800
152  * @tc.name      : ANS_AdvancedNotificationServiceAbility_0800
153  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
154  */
155 HWTEST_F(
156     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00800, Function | SmallTest | Level1)
157 {
158     int32_t systemAbilityId = 1;
159     bool runOnCreate = true;
160     std::string deviceId = "deviceId";
161     std::string oldKey = "enabledNotificationDistributed-test-88-aaa";
162     NotificationPreferences::GetInstance()->SetKvToDb(oldKey, "1", 0);
163     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
164     test.OnAddSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, deviceId);
165     std::this_thread::sleep_for(std::chrono::seconds(1));
166     std::string version;
167     NotificationPreferences::GetInstance()->GetKvFromDb("tableVersion", version, 0);
168     ASSERT_EQ(version, "1");
169 }
170 
171 /**
172  * @tc.number    : AdvancedNotificationServiceAbilityTest_00900
173  * @tc.name      : ANS_AdvancedNotificationServiceAbility_00900
174  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
175  */
176 HWTEST_F(
177     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_00900, Function | SmallTest | Level1)
178 {
179     int32_t systemAbilityId = 1;
180     bool runOnCreate = true;
181     std::string deviceId = "deviceId";
182     std::string extension = "other";
183     MessageParcel data;
184     MessageParcel reply;
185     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
186     ErrCode ret = test.OnExtension(extension, data, reply);
187     EXPECT_EQ(ret, (int)ERR_OK);
188 }
189 
190 /**
191  * @tc.number    : AdvancedNotificationServiceAbilityTest_01000
192  * @tc.name      : ANS_AdvancedNotificationServiceAbility_01000
193  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
194  */
195 HWTEST_F(
196     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_01000, Function | SmallTest | Level1)
197 {
198     int32_t systemAbilityId = 1;
199     bool runOnCreate = true;
200     std::string deviceId = "deviceId";
201     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
202     EventFwk::Want want;
203     EventFwk::CommonEventData data;
204     data.SetWant(want.SetAction("usual.event.DATA_SHARE_READY"));
205     test.OnReceiveEvent(data);
206     EXPECT_EQ(test.isDatashaReready_, true);
207 }
208 
209 #ifdef ALL_SCENARIO_COLLABORATION
210 /**
211  * @tc.number    : AdvancedNotificationServiceAbilityTest_02000
212  * @tc.name      : ANS_AdvancedNotificationServiceAbility_02000
213  * @tc.desc      : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate
214  */
215 HWTEST_F(
216     AdvancedNotificationServiceAbilityTest, AdvancedNotificationServiceAbilityTest_02000, Function | SmallTest | Level1)
217 {
218     int32_t systemAbilityId = 1;
219     bool runOnCreate = true;
220     std::string deviceId = "deviceId";
221     AdvancedNotificationServiceAbility test(systemAbilityId, runOnCreate);
222     test.OnAddSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, deviceId);
223 
224     ASSERT_NE(DistributedDeviceManager::GetInstance().stateCallback_, nullptr);
225 }
226 #endif
227 }  // namespace Notification
228 }  // namespace OHOS
229