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_test_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 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(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     ASSERT_NE(distributedSchedStub_, nullptr);
76     MessageParcel data;
77     MessageParcel reply;
78 
79     int32_t result = distributedSchedStub_->StartAbilityFromRemoteInner(data, reply);
80     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
81     DTEST_LOG << "DistributedSchedUidTest StartAbilityFromRemoteInner_001 end" << std::endl;
82 }
83 
84 /**
85  * @tc.name: SendResultFromRemoteInner_001
86  * @tc.desc: check SendResultFromRemoteInner
87  * @tc.type: FUNC
88  */
89 HWTEST_F(DistributedSchedUidTest, SendResultFromRemoteInner_001, TestSize.Level3)
90 {
91     DTEST_LOG << "DistributedSchedUidTest SendResultFromRemoteInner_001 begin" << std::endl;
92     ASSERT_NE(distributedSchedStub_, nullptr);
93     MessageParcel data;
94     MessageParcel reply;
95 
96     int32_t result = distributedSchedStub_->SendResultFromRemoteInner(data, reply);
97     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
98     DTEST_LOG << "DistributedSchedUidTest SendResultFromRemoteInner_001 end" << std::endl;
99 }
100 
101 /**
102  * @tc.name: NotifyContinuationResultFromRemoteInner_001
103  * @tc.desc: check NotifyContinuationResultFromRemoteInner
104  * @tc.type: FUNC
105  */
106 HWTEST_F(DistributedSchedUidTest, NotifyContinuationResultFromRemoteInner_001, TestSize.Level3)
107 {
108     DTEST_LOG << "DistributedSchedUidTest NotifyContinuationResultFromRemoteInner_001 begin" << std::endl;
109     ASSERT_NE(distributedSchedStub_, nullptr);
110     MessageParcel data;
111     MessageParcel reply;
112 
113     int32_t result = distributedSchedStub_->NotifyContinuationResultFromRemoteInner(data, reply);
114     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
115     DTEST_LOG << "DistributedSchedUidTest NotifyContinuationResultFromRemoteInner_001 end" << std::endl;
116 }
117 
118 /**
119  * @tc.name: ConnectAbilityFromRemoteInner_001
120  * @tc.desc: check ConnectAbilityFromRemoteInner
121  * @tc.type: FUNC
122  */
123 HWTEST_F(DistributedSchedUidTest, ConnectAbilityFromRemoteInner_001, TestSize.Level3)
124 {
125     DTEST_LOG << "DistributedSchedUidTest ConnectAbilityFromRemoteInner_001 begin" << std::endl;
126     ASSERT_NE(distributedSchedStub_, nullptr);
127     MessageParcel data;
128     MessageParcel reply;
129 
130     int32_t result = distributedSchedStub_->ConnectAbilityFromRemoteInner(data, reply);
131     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
132     DTEST_LOG << "DistributedSchedUidTest ConnectAbilityFromRemoteInner_001 end" << std::endl;
133 }
134 
135 /**
136  * @tc.name: DisconnectAbilityFromRemoteInner_001
137  * @tc.desc: check DisconnectAbilityFromRemoteInner
138  * @tc.type: FUNC
139  */
140 HWTEST_F(DistributedSchedUidTest, DisconnectAbilityFromRemoteInner_001, TestSize.Level3)
141 {
142     DTEST_LOG << "DistributedSchedUidTest DisconnectAbilityFromRemoteInner_001 begin" << std::endl;
143     ASSERT_NE(distributedSchedStub_, nullptr);
144     MessageParcel data;
145     MessageParcel reply;
146 
147     int32_t result = distributedSchedStub_->DisconnectAbilityFromRemoteInner(data, reply);
148     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
149     DTEST_LOG << "DistributedSchedUidTest DisconnectAbilityFromRemoteInner_001 end" << std::endl;
150 }
151 
152 /**
153  * @tc.name: NotifyProcessDiedFromRemoteInner_001
154  * @tc.desc: check NotifyProcessDiedFromRemoteInner
155  * @tc.type: FUNC
156  */
157 HWTEST_F(DistributedSchedUidTest, NotifyProcessDiedFromRemoteInner_001, TestSize.Level3)
158 {
159     DTEST_LOG << "DistributedSchedUidTest NotifyProcessDiedFromRemoteInner_001 begin" << std::endl;
160     ASSERT_NE(distributedSchedStub_, nullptr);
161     MessageParcel data;
162     MessageParcel reply;
163 
164     int32_t result = distributedSchedStub_->NotifyProcessDiedFromRemoteInner(data, reply);
165     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
166     DTEST_LOG << "DistributedSchedUidTest NotifyProcessDiedFromRemoteInner_001 end" << std::endl;
167 }
168 
169 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
170 /**
171  * @tc.name: StartSyncMissionsFromRemoteInner_001
172  * @tc.desc: check StartSyncMissionsFromRemoteInner
173  * @tc.type: FUNC
174  */
175 HWTEST_F(DistributedSchedUidTest, StartSyncMissionsFromRemoteInner_001, TestSize.Level3)
176 {
177     DTEST_LOG << "DistributedSchedUidTest StartSyncMissionsFromRemoteInner_001 begin" << std::endl;
178     ASSERT_NE(distributedSchedStub_, nullptr);
179     MessageParcel data;
180     MessageParcel reply;
181 
182     int32_t result = distributedSchedStub_->StartSyncMissionsFromRemoteInner(data, reply);
183     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
184     DTEST_LOG << "DistributedSchedUidTest StartSyncMissionsFromRemoteInner_001 end" << std::endl;
185 }
186 
187 /**
188  * @tc.name: StopSyncMissionsFromRemoteInner_001
189  * @tc.desc: check StopSyncMissionsFromRemoteInner
190  * @tc.type: FUNC
191  */
192 HWTEST_F(DistributedSchedUidTest, StopSyncMissionsFromRemoteInner_001, TestSize.Level3)
193 {
194     DTEST_LOG << "DistributedSchedUidTest StopSyncMissionsFromRemoteInner_001 begin" << std::endl;
195     ASSERT_NE(distributedSchedStub_, nullptr);
196     MessageParcel data;
197     MessageParcel reply;
198 
199     int32_t result = distributedSchedStub_->StopSyncMissionsFromRemoteInner(data, reply);
200     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
201     DTEST_LOG << "DistributedSchedUidTest StopSyncMissionsFromRemoteInner_001 end" << std::endl;
202 }
203 
204 /**
205  * @tc.name: NotifyMissionsChangedFromRemoteInner_001
206  * @tc.desc: check NotifyMissionsChangedFromRemoteInner
207  * @tc.type: FUNC
208  */
209 HWTEST_F(DistributedSchedUidTest, NotifyMissionsChangedFromRemoteInner_001, TestSize.Level3)
210 {
211     DTEST_LOG << "DistributedSchedUidTest NotifyMissionsChangedFromRemoteInner_001 begin" << std::endl;
212     ASSERT_NE(distributedSchedStub_, nullptr);
213     MessageParcel data;
214     MessageParcel reply;
215 
216     int32_t result = distributedSchedStub_->NotifyMissionsChangedFromRemoteInner(data, reply);
217     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
218     DTEST_LOG << "DistributedSchedUidTest NotifyMissionsChangedFromRemoteInner_001 end" << std::endl;
219 }
220 #endif
221 
222 /**
223  * @tc.name: StartAbilityByCallFromRemoteInner_001
224  * @tc.desc: check StartAbilityByCallFromRemoteInner
225  * @tc.type: FUNC
226  */
227 HWTEST_F(DistributedSchedUidTest, StartAbilityByCallFromRemoteInner_001, TestSize.Level3)
228 {
229     DTEST_LOG << "DistributedSchedUidTest StartAbilityByCallFromRemoteInner_001 begin" << std::endl;
230     ASSERT_NE(distributedSchedStub_, nullptr);
231     MessageParcel data;
232     MessageParcel reply;
233 
234     int32_t result = distributedSchedStub_->StartAbilityByCallFromRemoteInner(data, reply);
235     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
236     DTEST_LOG << "DistributedSchedUidTest StartAbilityByCallFromRemoteInner_001 end" << std::endl;
237 }
238 
239 /**
240  * @tc.name: ReleaseAbilityFromRemoteInner_001
241  * @tc.desc: check ReleaseAbilityFromRemoteInner
242  * @tc.type: FUNC
243  */
244 HWTEST_F(DistributedSchedUidTest, ReleaseAbilityFromRemoteInner_001, TestSize.Level3)
245 {
246     DTEST_LOG << "DistributedSchedUidTest ReleaseAbilityFromRemoteInner_001 begin" << std::endl;
247     ASSERT_NE(distributedSchedStub_, nullptr);
248     MessageParcel data;
249     MessageParcel reply;
250 
251     int32_t result = distributedSchedStub_->ReleaseAbilityFromRemoteInner(data, reply);
252     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
253     DTEST_LOG << "DistributedSchedUidTest ReleaseAbilityFromRemoteInner_001 end" << std::endl;
254 }
255 
256 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
257 /**
258  * @tc.name: StartShareFormFromRemoteInner_001
259  * @tc.desc: check StartShareFormFromRemoteInner
260  * @tc.type: FUNC
261  */
262 HWTEST_F(DistributedSchedUidTest, StartShareFormFromRemoteInner_001, TestSize.Level3)
263 {
264     DTEST_LOG << "DistributedSchedUidTest StartShareFormFromRemoteInner_001 begin" << std::endl;
265     ASSERT_NE(distributedSchedStub_, nullptr);
266     MessageParcel data;
267     MessageParcel reply;
268 
269     int32_t result = distributedSchedStub_->StartShareFormFromRemoteInner(data, reply);
270     EXPECT_EQ(result, ERR_NONE);
271     DTEST_LOG << "DistributedSchedUidTest StartShareFormFromRemoteInner_001 end" << std::endl;
272 }
273 #endif
274 
275 /**
276  * @tc.name: GetDistributedComponentListInner_001
277  * @tc.desc: check GetDistributedComponentListInner
278  * @tc.type: FUNC
279  */
280 HWTEST_F(DistributedSchedUidTest, GetDistributedComponentListInner_001, TestSize.Level3)
281 {
282     DTEST_LOG << "DistributedSchedUidTest GetDistributedComponentListInner_001 begin" << std::endl;
283     ASSERT_NE(distributedSchedStub_, nullptr);
284     MessageParcel data;
285     MessageParcel reply;
286 
287     int32_t result = distributedSchedStub_->GetDistributedComponentListInner(data, reply);
288     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
289     DTEST_LOG << "DistributedSchedUidTest GetDistributedComponentListInner_001 end" << std::endl;
290 }
291 
292 /**
293  * @tc.name: StartFreeInstallFromRemoteInner_001
294  * @tc.desc: check StartFreeInstallFromRemoteInner
295  * @tc.type: FUNC
296  */
297 HWTEST_F(DistributedSchedUidTest, StartFreeInstallFromRemoteInner_001, TestSize.Level3)
298 {
299     DTEST_LOG << "DistributedSchedUidTest StartFreeInstallFromRemoteInner_001 begin" << std::endl;
300     ASSERT_NE(distributedSchedStub_, nullptr);
301     MessageParcel data;
302     MessageParcel reply;
303 
304     int32_t result = distributedSchedStub_->StartFreeInstallFromRemoteInner(data, reply);
305     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
306     DTEST_LOG << "DistributedSchedUidTest StartFreeInstallFromRemoteInner_001 end" << std::endl;
307 }
308 
309 /**
310  * @tc.name: NotifyCompleteFreeInstallFromRemoteInner_001
311  * @tc.desc: check NotifyCompleteFreeInstallFromRemoteInner
312  * @tc.type: FUNC
313  */
314 HWTEST_F(DistributedSchedUidTest, NotifyCompleteFreeInstallFromRemoteInner_001, TestSize.Level3)
315 {
316     DTEST_LOG << "DistributedSchedUidTest NotifyCompleteFreeInstallFromRemoteInner_001 begin" << std::endl;
317     ASSERT_NE(distributedSchedStub_, nullptr);
318     MessageParcel data;
319     MessageParcel reply;
320 
321     int32_t result = distributedSchedStub_->NotifyCompleteFreeInstallFromRemoteInner(data, reply);
322     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
323     DTEST_LOG << "DistributedSchedUidTest NotifyCompleteFreeInstallFromRemoteInner_001 end" << std::endl;
324 }
325 }
326 }