1 /*
2 * Copyright (c) 2022 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 #define private public
17 #include "distributed_sched_service.h"
18 #undef private
19 #include "distributed_sched_uid_test.h"
20 #include "distributed_sched_util.h"
21 #define private public
22 #include "mission/distributed_sched_mission_manager.h"
23 #undef private
24 #include "test_log.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::AAFwk;
29 using namespace OHOS::AppExecFwk;
30
31 namespace OHOS {
32 namespace DistributedSchedule {
33 namespace {
34 const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
35 const std::u16string MOCK_INVALID_DESCRIPTOR = u"invalid descriptor";
36 constexpr const char* FOUNDATION_PROCESS_NAME = "foundation";
37 constexpr int32_t CAllING_UID = 10001;
38 const char *PERMS[] = {
39 "ohos.permission.DISTRIBUTED_DATASYNC"
40 };
41 }
42
SetUpTestCase()43 void DistributedSchedUidTest::SetUpTestCase()
44 {
45 DTEST_LOG << "DistributedSchedUidTest::SetUpTestCase" << std::endl;
46 setuid(CAllING_UID);
47 }
48
TearDownTestCase()49 void DistributedSchedUidTest::TearDownTestCase()
50 {
51 DTEST_LOG << "DistributedSchedUidTest::TearDownTestCase" << std::endl;
52 }
53
TearDown()54 void DistributedSchedUidTest::TearDown()
55 {
56 DTEST_LOG << "DistributedSchedUidTest::TearDown" << std::endl;
57 distributedSchedStub_ = nullptr;
58 }
59
SetUp()60 void DistributedSchedUidTest::SetUp()
61 {
62 DTEST_LOG << "DistributedSchedUidTest::SetUp" << std::endl;
63 distributedSchedStub_ = new DistributedSchedService();
64 DistributedSchedUtil::MockProcessAndPermission(FOUNDATION_PROCESS_NAME, PERMS, 1);
65 }
66
67 /**
68 * @tc.name: StartAbilityFromRemoteInner_001
69 * @tc.desc: check StartAbilityFromRemoteInner
70 * @tc.type: FUNC
71 */
72 HWTEST_F(DistributedSchedUidTest, StartAbilityFromRemoteInner_001, TestSize.Level3)
73 {
74 DTEST_LOG << "DistributedSchedUidTest StartAbilityFromRemoteInner_001 begin" << std::endl;
75 MessageParcel data;
76 MessageParcel reply;
77
78 int32_t result = distributedSchedStub_->StartAbilityFromRemoteInner(data, reply);
79 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
80 DTEST_LOG << "DistributedSchedUidTest StartAbilityFromRemoteInner_001 end" << std::endl;
81 }
82
83 /**
84 * @tc.name: SendResultFromRemoteInner_001
85 * @tc.desc: check SendResultFromRemoteInner
86 * @tc.type: FUNC
87 */
88 HWTEST_F(DistributedSchedUidTest, SendResultFromRemoteInner_001, TestSize.Level3)
89 {
90 DTEST_LOG << "DistributedSchedUidTest SendResultFromRemoteInner_001 begin" << std::endl;
91 MessageParcel data;
92 MessageParcel reply;
93
94 int32_t result = distributedSchedStub_->SendResultFromRemoteInner(data, reply);
95 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
96 DTEST_LOG << "DistributedSchedUidTest SendResultFromRemoteInner_001 end" << std::endl;
97 }
98
99 /**
100 * @tc.name: NotifyContinuationResultFromRemoteInner_001
101 * @tc.desc: check NotifyContinuationResultFromRemoteInner
102 * @tc.type: FUNC
103 */
104 HWTEST_F(DistributedSchedUidTest, NotifyContinuationResultFromRemoteInner_001, TestSize.Level3)
105 {
106 DTEST_LOG << "DistributedSchedUidTest NotifyContinuationResultFromRemoteInner_001 begin" << std::endl;
107 MessageParcel data;
108 MessageParcel reply;
109
110 int32_t result = distributedSchedStub_->NotifyContinuationResultFromRemoteInner(data, reply);
111 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
112 DTEST_LOG << "DistributedSchedUidTest NotifyContinuationResultFromRemoteInner_001 end" << std::endl;
113 }
114
115 /**
116 * @tc.name: ConnectAbilityFromRemoteInner_001
117 * @tc.desc: check ConnectAbilityFromRemoteInner
118 * @tc.type: FUNC
119 */
120 HWTEST_F(DistributedSchedUidTest, ConnectAbilityFromRemoteInner_001, TestSize.Level3)
121 {
122 DTEST_LOG << "DistributedSchedUidTest ConnectAbilityFromRemoteInner_001 begin" << std::endl;
123 MessageParcel data;
124 MessageParcel reply;
125
126 int32_t result = distributedSchedStub_->ConnectAbilityFromRemoteInner(data, reply);
127 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
128 DTEST_LOG << "DistributedSchedUidTest ConnectAbilityFromRemoteInner_001 end" << std::endl;
129 }
130
131 /**
132 * @tc.name: DisconnectAbilityFromRemoteInner_001
133 * @tc.desc: check DisconnectAbilityFromRemoteInner
134 * @tc.type: FUNC
135 */
136 HWTEST_F(DistributedSchedUidTest, DisconnectAbilityFromRemoteInner_001, TestSize.Level3)
137 {
138 DTEST_LOG << "DistributedSchedUidTest DisconnectAbilityFromRemoteInner_001 begin" << std::endl;
139 MessageParcel data;
140 MessageParcel reply;
141
142 int32_t result = distributedSchedStub_->DisconnectAbilityFromRemoteInner(data, reply);
143 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
144 DTEST_LOG << "DistributedSchedUidTest DisconnectAbilityFromRemoteInner_001 end" << std::endl;
145 }
146
147 /**
148 * @tc.name: NotifyProcessDiedFromRemoteInner_001
149 * @tc.desc: check NotifyProcessDiedFromRemoteInner
150 * @tc.type: FUNC
151 */
152 HWTEST_F(DistributedSchedUidTest, NotifyProcessDiedFromRemoteInner_001, TestSize.Level3)
153 {
154 DTEST_LOG << "DistributedSchedUidTest NotifyProcessDiedFromRemoteInner_001 begin" << std::endl;
155 MessageParcel data;
156 MessageParcel reply;
157
158 int32_t result = distributedSchedStub_->NotifyProcessDiedFromRemoteInner(data, reply);
159 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
160 DTEST_LOG << "DistributedSchedUidTest NotifyProcessDiedFromRemoteInner_001 end" << std::endl;
161 }
162
163 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
164 /**
165 * @tc.name: StartSyncMissionsFromRemoteInner_001
166 * @tc.desc: check StartSyncMissionsFromRemoteInner
167 * @tc.type: FUNC
168 */
169 HWTEST_F(DistributedSchedUidTest, StartSyncMissionsFromRemoteInner_001, TestSize.Level3)
170 {
171 DTEST_LOG << "DistributedSchedUidTest StartSyncMissionsFromRemoteInner_001 begin" << std::endl;
172 MessageParcel data;
173 MessageParcel reply;
174
175 int32_t result = distributedSchedStub_->StartSyncMissionsFromRemoteInner(data, reply);
176 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
177 DTEST_LOG << "DistributedSchedUidTest StartSyncMissionsFromRemoteInner_001 end" << std::endl;
178 }
179
180 /**
181 * @tc.name: StopSyncMissionsFromRemoteInner_001
182 * @tc.desc: check StopSyncMissionsFromRemoteInner
183 * @tc.type: FUNC
184 */
185 HWTEST_F(DistributedSchedUidTest, StopSyncMissionsFromRemoteInner_001, TestSize.Level3)
186 {
187 DTEST_LOG << "DistributedSchedUidTest StopSyncMissionsFromRemoteInner_001 begin" << std::endl;
188 MessageParcel data;
189 MessageParcel reply;
190
191 int32_t result = distributedSchedStub_->StopSyncMissionsFromRemoteInner(data, reply);
192 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
193 DTEST_LOG << "DistributedSchedUidTest StopSyncMissionsFromRemoteInner_001 end" << std::endl;
194 }
195
196 /**
197 * @tc.name: NotifyMissionsChangedFromRemoteInner_001
198 * @tc.desc: check NotifyMissionsChangedFromRemoteInner
199 * @tc.type: FUNC
200 */
201 HWTEST_F(DistributedSchedUidTest, NotifyMissionsChangedFromRemoteInner_001, TestSize.Level3)
202 {
203 DTEST_LOG << "DistributedSchedUidTest NotifyMissionsChangedFromRemoteInner_001 begin" << std::endl;
204 MessageParcel data;
205 MessageParcel reply;
206
207 int32_t result = distributedSchedStub_->NotifyMissionsChangedFromRemoteInner(data, reply);
208 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
209 DTEST_LOG << "DistributedSchedUidTest NotifyMissionsChangedFromRemoteInner_001 end" << std::endl;
210 }
211 #endif
212
213 /**
214 * @tc.name: StartAbilityByCallFromRemoteInner_001
215 * @tc.desc: check StartAbilityByCallFromRemoteInner
216 * @tc.type: FUNC
217 */
218 HWTEST_F(DistributedSchedUidTest, StartAbilityByCallFromRemoteInner_001, TestSize.Level3)
219 {
220 DTEST_LOG << "DistributedSchedUidTest StartAbilityByCallFromRemoteInner_001 begin" << std::endl;
221 MessageParcel data;
222 MessageParcel reply;
223
224 int32_t result = distributedSchedStub_->StartAbilityByCallFromRemoteInner(data, reply);
225 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
226 DTEST_LOG << "DistributedSchedUidTest StartAbilityByCallFromRemoteInner_001 end" << std::endl;
227 }
228
229 /**
230 * @tc.name: ReleaseAbilityFromRemoteInner_001
231 * @tc.desc: check ReleaseAbilityFromRemoteInner
232 * @tc.type: FUNC
233 */
234 HWTEST_F(DistributedSchedUidTest, ReleaseAbilityFromRemoteInner_001, TestSize.Level3)
235 {
236 DTEST_LOG << "DistributedSchedUidTest ReleaseAbilityFromRemoteInner_001 begin" << std::endl;
237 MessageParcel data;
238 MessageParcel reply;
239
240 int32_t result = distributedSchedStub_->ReleaseAbilityFromRemoteInner(data, reply);
241 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
242 DTEST_LOG << "DistributedSchedUidTest ReleaseAbilityFromRemoteInner_001 end" << std::endl;
243 }
244
245 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
246 /**
247 * @tc.name: StartShareFormFromRemoteInner_001
248 * @tc.desc: check StartShareFormFromRemoteInner
249 * @tc.type: FUNC
250 */
251 HWTEST_F(DistributedSchedUidTest, StartShareFormFromRemoteInner_001, TestSize.Level3)
252 {
253 DTEST_LOG << "DistributedSchedUidTest StartShareFormFromRemoteInner_001 begin" << std::endl;
254 MessageParcel data;
255 MessageParcel reply;
256
257 int32_t result = distributedSchedStub_->StartShareFormFromRemoteInner(data, reply);
258 EXPECT_EQ(result, ERR_NONE);
259 DTEST_LOG << "DistributedSchedUidTest StartShareFormFromRemoteInner_001 end" << std::endl;
260 }
261 #endif
262
263 /**
264 * @tc.name: GetDistributedComponentListInner_001
265 * @tc.desc: check GetDistributedComponentListInner
266 * @tc.type: FUNC
267 */
268 HWTEST_F(DistributedSchedUidTest, GetDistributedComponentListInner_001, TestSize.Level3)
269 {
270 DTEST_LOG << "DistributedSchedUidTest GetDistributedComponentListInner_001 begin" << std::endl;
271 MessageParcel data;
272 MessageParcel reply;
273
274 int32_t result = distributedSchedStub_->GetDistributedComponentListInner(data, reply);
275 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
276 DTEST_LOG << "DistributedSchedUidTest GetDistributedComponentListInner_001 end" << std::endl;
277 }
278
279 /**
280 * @tc.name: StartFreeInstallFromRemoteInner_001
281 * @tc.desc: check StartFreeInstallFromRemoteInner
282 * @tc.type: FUNC
283 */
284 HWTEST_F(DistributedSchedUidTest, StartFreeInstallFromRemoteInner_001, TestSize.Level3)
285 {
286 DTEST_LOG << "DistributedSchedUidTest StartFreeInstallFromRemoteInner_001 begin" << std::endl;
287 MessageParcel data;
288 MessageParcel reply;
289
290 int32_t result = distributedSchedStub_->StartFreeInstallFromRemoteInner(data, reply);
291 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
292 DTEST_LOG << "DistributedSchedUidTest StartFreeInstallFromRemoteInner_001 end" << std::endl;
293 }
294
295 /**
296 * @tc.name: NotifyCompleteFreeInstallFromRemoteInner_001
297 * @tc.desc: check NotifyCompleteFreeInstallFromRemoteInner
298 * @tc.type: FUNC
299 */
300 HWTEST_F(DistributedSchedUidTest, NotifyCompleteFreeInstallFromRemoteInner_001, TestSize.Level3)
301 {
302 DTEST_LOG << "DistributedSchedUidTest NotifyCompleteFreeInstallFromRemoteInner_001 begin" << std::endl;
303 MessageParcel data;
304 MessageParcel reply;
305
306 int32_t result = distributedSchedStub_->NotifyCompleteFreeInstallFromRemoteInner(data, reply);
307 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
308 DTEST_LOG << "DistributedSchedUidTest NotifyCompleteFreeInstallFromRemoteInner_001 end" << std::endl;
309 }
310 }
311 }