1 /*
2 * Copyright (c) 2022-2023 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 "distributed_ability_manager_stub_test.h"
16
17 #include "dtbschedmgr_log.h"
18 #include "test_log.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace DistributedSchedule {
25 namespace {
26 constexpr int32_t REQUEST_CODE_ERR = 305;
27 constexpr int32_t INVALID_CODE = 123456;
28 const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
29 }
30
SetUpTestCase()31 void DistributedAbilityManagerStubTest::SetUpTestCase()
32 {
33 DTEST_LOG << "DistributedAbilityManagerStubTest::SetUpTestCase" << std::endl;
34 }
35
TearDownTestCase()36 void DistributedAbilityManagerStubTest::TearDownTestCase()
37 {
38 DTEST_LOG << "DistributedAbilityManagerStubTest::TearDownTestCase" << std::endl;
39 }
40
SetUp()41 void DistributedAbilityManagerStubTest::SetUp()
42 {
43 dtbabilitymgrStub_ = new DistributedAbilityManagerService();
44 DTEST_LOG << "DistributedAbilityManagerStubTest::SetUp" << std::endl;
45 }
46
TearDown()47 void DistributedAbilityManagerStubTest::TearDown()
48 {
49 DTEST_LOG << "DistributedAbilityManagerStubTest::TearDown" << std::endl;
50 }
51
52 /**
53 * @tc.name: OnRemoteRequest_001
54 * @tc.desc: test OnRemoteRequest with func is nullptr
55 * @tc.type: FUNC
56 * @tc.require: I64FU7
57 */
58 HWTEST_F(DistributedAbilityManagerStubTest, OnRemoteRequest_001, TestSize.Level3)
59 {
60 DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_001 start" << std::endl;
61 ASSERT_NE(nullptr, dtbabilitymgrStub_);
62 uint32_t code = INVALID_CODE;
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option;
66 dtbabilitymgrStub_->funcsMap_[INVALID_CODE] = nullptr;
67 data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN);
68 int32_t result = dtbabilitymgrStub_->OnRemoteRequest(code, data, reply, option);
69 EXPECT_EQ(result, ERR_NULL_OBJECT);
70 DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_001 end" << std::endl;
71 }
72
73 /**
74 * @tc.name: OnRemoteRequest_002
75 * @tc.desc: test OnRemoteRequest with distributedFunc is nullptr
76 * @tc.type: FUNC
77 * @tc.require: I64FU7
78 */
79 HWTEST_F(DistributedAbilityManagerStubTest, OnRemoteRequest_002, TestSize.Level3)
80 {
81 DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_002 start" << std::endl;
82 ASSERT_NE(nullptr, dtbabilitymgrStub_);
83 MessageParcel data;
84 MessageParcel reply;
85 MessageOption option;
86 data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN);
87 int32_t result = dtbabilitymgrStub_->OnRemoteRequest(INVALID_CODE, data, reply, option);
88 EXPECT_EQ(result, REQUEST_CODE_ERR);
89 DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_002 end" << std::endl;
90 }
91
92 /**
93 * @tc.name: RegisterInner_001
94 * @tc.desc: test RegisterInner with continuationExtraParams is nullptr
95 * @tc.type: FUNC
96 * @tc.require: I64FU7
97 */
98 HWTEST_F(DistributedAbilityManagerStubTest, RegisterInner_001, TestSize.Level3)
99 {
100 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_001 start" << std::endl;
101 ASSERT_NE(nullptr, dtbabilitymgrStub_);
102 MessageParcel data;
103 MessageParcel reply;
104 data.WriteInt32(VALUE_OBJECT);
105 int32_t result = dtbabilitymgrStub_->RegisterInner(data, reply);
106 EXPECT_EQ(result, ERR_NULL_OBJECT);
107 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_001 end" << std::endl;
108 }
109
110 /**
111 * @tc.name: RegisterInner_002
112 * @tc.desc: test RegisterInner
113 * @tc.type: FUNC
114 * @tc.require: I64FU7
115 */
116 HWTEST_F(DistributedAbilityManagerStubTest, RegisterInner_002, TestSize.Level3)
117 {
118 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_002 start" << std::endl;
119 ASSERT_NE(nullptr, dtbabilitymgrStub_);
120 MessageParcel data;
121 MessageParcel reply;
122 data.WriteInt32(VALUE_NULL);
123 int32_t result = dtbabilitymgrStub_->RegisterInner(data, reply);
124 EXPECT_EQ(result, ERR_NONE);
125 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_002 end" << std::endl;
126 }
127
128 /**
129 * @tc.name: RegisterDeviceSelectionCallbackInner_001
130 * @tc.desc: test RegisterDeviceSelectionCallbackInner with cbType is empty
131 * @tc.type: FUNC
132 * @tc.require: I64FU7
133 */
134 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_001, TestSize.Level3)
135 {
136 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 start" << std::endl;
137 ASSERT_NE(nullptr, dtbabilitymgrStub_);
138 MessageParcel data;
139 MessageParcel reply;
140 int32_t token = 0;
141 data.WriteInt32(token);
142 std::string cbType = "";
143 data.WriteString(cbType);
144 int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
145 EXPECT_EQ(result, ERR_NULL_OBJECT);
146 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 end" << std::endl;
147 }
148
149 /**
150 * @tc.name: RegisterDeviceSelectionCallbackInner_002
151 * @tc.desc: test RegisterDeviceSelectionCallbackInner with notifier is nullptr
152 * @tc.type: FUNC
153 * @tc.require: I64FU7
154 */
155 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_002, TestSize.Level3)
156 {
157 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 start" << std::endl;
158 ASSERT_NE(nullptr, dtbabilitymgrStub_);
159 MessageParcel data;
160 MessageParcel reply;
161 int32_t token = 0;
162 data.WriteInt32(token);
163 std::string cbType = "mockType";
164 data.WriteString(cbType);
165 int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
166 EXPECT_EQ(result, ERR_NULL_OBJECT);
167 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 end" << std::endl;
168 }
169
170 /**
171 * @tc.name: UnregisterDeviceSelectionCallbackInner_001
172 * @tc.desc: test UnregisterDeviceSelectionCallbackInner with cbType is empty
173 * @tc.type: FUNC
174 * @tc.require: I64FU7
175 */
176 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterDeviceSelectionCallbackInner_001, TestSize.Level3)
177 {
178 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 start" << std::endl;
179 ASSERT_NE(nullptr, dtbabilitymgrStub_);
180 MessageParcel data;
181 MessageParcel reply;
182 int32_t token = 0;
183 data.WriteInt32(token);
184 std::string cbType = "";
185 data.WriteString(cbType);
186 int32_t result = dtbabilitymgrStub_->UnregisterDeviceSelectionCallbackInner(data, reply);
187 EXPECT_EQ(result, ERR_NULL_OBJECT);
188 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 end" << std::endl;
189 }
190
191 /**
192 * @tc.name: UnregisterDeviceSelectionCallbackInner_002
193 * @tc.desc: test UnregisterDeviceSelectionCallbackInner with cbType is empty
194 * @tc.type: FUNC
195 * @tc.require: I64FU7
196 */
197 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterDeviceSelectionCallbackInner_002, TestSize.Level3)
198 {
199 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_002 start" << std::endl;
200 ASSERT_NE(nullptr, dtbabilitymgrStub_);
201 MessageParcel data;
202 MessageParcel reply;
203 int32_t token = 0;
204 data.WriteInt32(token);
205 std::string cbType = "12345";
206 data.WriteString(cbType);
207 int32_t result = dtbabilitymgrStub_->UnregisterDeviceSelectionCallbackInner(data, reply);
208 EXPECT_EQ(result, ERR_NONE);
209 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_002 end" << std::endl;
210 }
211
212 /**
213 * @tc.name: StartDeviceManagerInner_001
214 * @tc.desc: test StartDeviceManagerInner with continuationExtraParams is nullptr
215 * @tc.type: FUNC
216 * @tc.require: I64FU7
217 */
218 HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_001, TestSize.Level3)
219 {
220 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 start" << std::endl;
221 ASSERT_NE(nullptr, dtbabilitymgrStub_);
222 MessageParcel data;
223 MessageParcel reply;
224 int32_t token = 0;
225 data.WriteInt32(token);
226 int32_t flag = VALUE_OBJECT;
227 data.WriteInt32(flag);
228 int32_t result = dtbabilitymgrStub_->StartDeviceManagerInner(data, reply);
229 EXPECT_EQ(result, ERR_NULL_OBJECT);
230 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 end" << std::endl;
231 }
232
233 /**
234 * @tc.name: StartDeviceManagerInner_002
235 * @tc.desc: test StartDeviceManagerInner with continuationExtraParams is nullptr
236 * @tc.type: FUNC
237 * @tc.require: I64FU7
238 */
239 HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_002, TestSize.Level3)
240 {
241 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 start" << std::endl;
242 ASSERT_NE(nullptr, dtbabilitymgrStub_);
243 MessageParcel data;
244 MessageParcel reply;
245 int32_t token = 0;
246 data.WriteInt32(token);
247 int32_t flag = VALUE_NULL;
248 data.WriteInt32(flag);
249 int32_t result = dtbabilitymgrStub_->StartDeviceManagerInner(data, reply);
250 EXPECT_EQ(result, ERR_NONE);
251 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_002 end" << std::endl;
252 }
253
254 /**
255 * @tc.name: UnregisterInner_001
256 * @tc.desc: test UnregisterInner
257 * @tc.type: FUNC
258 * @tc.require: I64FU7
259 */
260 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterInner_001, TestSize.Level3)
261 {
262 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterInner_001 start" << std::endl;
263 ASSERT_NE(nullptr, dtbabilitymgrStub_);
264 MessageParcel data;
265 MessageParcel reply;
266 data.WriteInt32(VALUE_OBJECT);
267 int32_t result = dtbabilitymgrStub_->UnregisterInner(data, reply);
268 EXPECT_EQ(result, ERR_NONE);
269 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterInner_001 end" << std::endl;
270 }
271
272 /**
273 * @tc.name: UpdateConnectStatusInner_001
274 * @tc.desc: test UpdateConnectStatusInner
275 * @tc.type: FUNC
276 * @tc.require: I64FU7
277 */
278 HWTEST_F(DistributedAbilityManagerStubTest, UpdateConnectStatusInner_001, TestSize.Level3)
279 {
280 DTEST_LOG << "DistributedAbilityManagerStubTest UpdateConnectStatusInner_001 start" << std::endl;
281 ASSERT_NE(nullptr, dtbabilitymgrStub_);
282 MessageParcel data;
283 MessageParcel reply;
284 std::string deviceId = "12345";
285 data.WriteInt32(VALUE_OBJECT);
286 data.WriteString(deviceId);
287 int32_t result = dtbabilitymgrStub_->UpdateConnectStatusInner(data, reply);
288 EXPECT_EQ(result, ERR_NONE);
289 DTEST_LOG << "DistributedAbilityManagerStubTest UpdateConnectStatusInner_001 end" << std::endl;
290 }
291 }
292 }