• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     uint32_t code = INVALID_CODE;
62     MessageParcel data;
63     MessageParcel reply;
64     MessageOption option;
65     dtbabilitymgrStub_->funcsMap_[INVALID_CODE] = nullptr;
66     data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN);
67     int32_t result = dtbabilitymgrStub_->OnRemoteRequest(code, data, reply, option);
68     EXPECT_EQ(result, ERR_NULL_OBJECT);
69     DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_001 end" << std::endl;
70 }
71 
72 /**
73  * @tc.name: OnRemoteRequest_002
74  * @tc.desc: test OnRemoteRequest with distributedFunc is nullptr
75  * @tc.type: FUNC
76  * @tc.require: I64FU7
77  */
78 HWTEST_F(DistributedAbilityManagerStubTest, OnRemoteRequest_002, TestSize.Level3)
79 {
80     DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_002 start" << std::endl;
81     MessageParcel data;
82     MessageParcel reply;
83     MessageOption option;
84     data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN);
85     int32_t result = dtbabilitymgrStub_->OnRemoteRequest(INVALID_CODE, data, reply, option);
86     EXPECT_EQ(result, REQUEST_CODE_ERR);
87     DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_002 end" << std::endl;
88 }
89 
90 /**
91  * @tc.name: RegisterInner_001
92  * @tc.desc: test RegisterInner with continuationExtraParams is nullptr
93  * @tc.type: FUNC
94  * @tc.require: I64FU7
95  */
96 HWTEST_F(DistributedAbilityManagerStubTest, RegisterInner_001, TestSize.Level3)
97 {
98     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_001 start" << std::endl;
99     MessageParcel data;
100     MessageParcel reply;
101     data.WriteInt32(VALUE_OBJECT);
102     int32_t result = dtbabilitymgrStub_->RegisterInner(data, reply);
103     EXPECT_EQ(result, ERR_NULL_OBJECT);
104     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_001 end" << std::endl;
105 }
106 
107 /**
108  * @tc.name: RegisterInner_002
109  * @tc.desc: test RegisterInner
110  * @tc.type: FUNC
111  * @tc.require: I64FU7
112  */
113 HWTEST_F(DistributedAbilityManagerStubTest, RegisterInner_002, TestSize.Level3)
114 {
115     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_002 start" << std::endl;
116     MessageParcel data;
117     MessageParcel reply;
118     data.WriteInt32(VALUE_NULL);
119     int32_t result = dtbabilitymgrStub_->RegisterInner(data, reply);
120     EXPECT_EQ(result, ERR_NONE);
121     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_002 end" << std::endl;
122 }
123 
124 /**
125  * @tc.name: RegisterDeviceSelectionCallbackInner_001
126  * @tc.desc: test RegisterDeviceSelectionCallbackInner with cbType is empty
127  * @tc.type: FUNC
128  * @tc.require: I64FU7
129  */
130 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_001, TestSize.Level3)
131 {
132     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 start" << std::endl;
133     MessageParcel data;
134     MessageParcel reply;
135     int32_t token = 0;
136     data.WriteInt32(token);
137     std::string cbType = "";
138     data.WriteString(cbType);
139     int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
140     EXPECT_EQ(result, ERR_NULL_OBJECT);
141     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 end" << std::endl;
142 }
143 
144 /**
145  * @tc.name: RegisterDeviceSelectionCallbackInner_002
146  * @tc.desc: test RegisterDeviceSelectionCallbackInner with notifier is nullptr
147  * @tc.type: FUNC
148  * @tc.require: I64FU7
149  */
150 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_002, TestSize.Level3)
151 {
152     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 start" << std::endl;
153     MessageParcel data;
154     MessageParcel reply;
155     int32_t token = 0;
156     data.WriteInt32(token);
157     std::string cbType = "mockType";
158     data.WriteString(cbType);
159     int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
160     EXPECT_EQ(result, ERR_NULL_OBJECT);
161     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 end" << std::endl;
162 }
163 
164 /**
165  * @tc.name: UnregisterDeviceSelectionCallbackInner_001
166  * @tc.desc: test UnregisterDeviceSelectionCallbackInner with cbType is empty
167  * @tc.type: FUNC
168  * @tc.require: I64FU7
169  */
170 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterDeviceSelectionCallbackInner_001, TestSize.Level3)
171 {
172     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 start" << std::endl;
173     MessageParcel data;
174     MessageParcel reply;
175     int32_t token = 0;
176     data.WriteInt32(token);
177     std::string cbType = "";
178     data.WriteString(cbType);
179     int32_t result = dtbabilitymgrStub_->UnregisterDeviceSelectionCallbackInner(data, reply);
180     EXPECT_EQ(result, ERR_NULL_OBJECT);
181     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 end" << std::endl;
182 }
183 
184 /**
185  * @tc.name: UnregisterDeviceSelectionCallbackInner_002
186  * @tc.desc: test UnregisterDeviceSelectionCallbackInner with cbType is empty
187  * @tc.type: FUNC
188  * @tc.require: I64FU7
189  */
190 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterDeviceSelectionCallbackInner_002, TestSize.Level3)
191 {
192     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_002 start" << std::endl;
193     MessageParcel data;
194     MessageParcel reply;
195     int32_t token = 0;
196     data.WriteInt32(token);
197     std::string cbType = "12345";
198     data.WriteString(cbType);
199     int32_t result = dtbabilitymgrStub_->UnregisterDeviceSelectionCallbackInner(data, reply);
200     EXPECT_EQ(result, ERR_NONE);
201     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_002 end" << std::endl;
202 }
203 
204 /**
205  * @tc.name: StartDeviceManagerInner_001
206  * @tc.desc: test StartDeviceManagerInner with continuationExtraParams is nullptr
207  * @tc.type: FUNC
208  * @tc.require: I64FU7
209  */
210 HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_001, TestSize.Level3)
211 {
212     DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 start" << std::endl;
213     MessageParcel data;
214     MessageParcel reply;
215     int32_t token = 0;
216     data.WriteInt32(token);
217     int32_t flag = VALUE_OBJECT;
218     data.WriteInt32(flag);
219     int32_t result = dtbabilitymgrStub_->StartDeviceManagerInner(data, reply);
220     EXPECT_EQ(result, ERR_NULL_OBJECT);
221     DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 end" << std::endl;
222 }
223 
224 /**
225  * @tc.name: StartDeviceManagerInner_002
226  * @tc.desc: test StartDeviceManagerInner with continuationExtraParams is nullptr
227  * @tc.type: FUNC
228  * @tc.require: I64FU7
229  */
230 HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_002, TestSize.Level3)
231 {
232     DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 start" << std::endl;
233     MessageParcel data;
234     MessageParcel reply;
235     int32_t token = 0;
236     data.WriteInt32(token);
237     int32_t flag = VALUE_NULL;
238     data.WriteInt32(flag);
239     int32_t result = dtbabilitymgrStub_->StartDeviceManagerInner(data, reply);
240     EXPECT_EQ(result, ERR_NONE);
241     DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_002 end" << std::endl;
242 }
243 
244 /**
245  * @tc.name: UnregisterInner_001
246  * @tc.desc: test UnregisterInner
247  * @tc.type: FUNC
248  * @tc.require: I64FU7
249  */
250 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterInner_001, TestSize.Level3)
251 {
252     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterInner_001 start" << std::endl;
253     MessageParcel data;
254     MessageParcel reply;
255     data.WriteInt32(VALUE_OBJECT);
256     int32_t result = dtbabilitymgrStub_->UnregisterInner(data, reply);
257     EXPECT_EQ(result, ERR_NONE);
258     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterInner_001 end" << std::endl;
259 }
260 
261 /**
262  * @tc.name: UpdateConnectStatusInner_001
263  * @tc.desc: test UpdateConnectStatusInner
264  * @tc.type: FUNC
265  * @tc.require: I64FU7
266  */
267 HWTEST_F(DistributedAbilityManagerStubTest, UpdateConnectStatusInner_001, TestSize.Level3)
268 {
269     DTEST_LOG << "DistributedAbilityManagerStubTest UpdateConnectStatusInner_001 start" << std::endl;
270     MessageParcel data;
271     MessageParcel reply;
272     std::string deviceId = "12345";
273     data.WriteInt32(VALUE_OBJECT);
274     data.WriteString(deviceId);
275     int32_t result = dtbabilitymgrStub_->UpdateConnectStatusInner(data, reply);
276     EXPECT_EQ(result, ERR_NONE);
277     DTEST_LOG << "DistributedAbilityManagerStubTest UpdateConnectStatusInner_001 end" << std::endl;
278 }
279 }
280 }