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: RegisterDeviceSelectionCallbackInner_001
109 * @tc.desc: test RegisterDeviceSelectionCallbackInner with cbType is empty
110 * @tc.type: FUNC
111 * @tc.require: I64FU7
112 */
113 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_001, TestSize.Level3)
114 {
115 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 start" << std::endl;
116 MessageParcel data;
117 MessageParcel reply;
118 int32_t token = 0;
119 data.WriteInt32(token);
120 std::string cbType = "";
121 data.WriteString(cbType);
122 int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
123 EXPECT_EQ(result, ERR_NULL_OBJECT);
124 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 end" << std::endl;
125 }
126
127 /**
128 * @tc.name: RegisterDeviceSelectionCallbackInner_002
129 * @tc.desc: test RegisterDeviceSelectionCallbackInner with notifier is nullptr
130 * @tc.type: FUNC
131 * @tc.require: I64FU7
132 */
133 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_002, TestSize.Level3)
134 {
135 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 start" << std::endl;
136 MessageParcel data;
137 MessageParcel reply;
138 int32_t token = 0;
139 data.WriteInt32(token);
140 std::string cbType = "mockType";
141 data.WriteString(cbType);
142 int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
143 EXPECT_EQ(result, ERR_NULL_OBJECT);
144 DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 end" << std::endl;
145 }
146
147 /**
148 * @tc.name: UnregisterDeviceSelectionCallbackInner_001
149 * @tc.desc: test UnregisterDeviceSelectionCallbackInner with cbType is empty
150 * @tc.type: FUNC
151 * @tc.require: I64FU7
152 */
153 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterDeviceSelectionCallbackInner_001, TestSize.Level3)
154 {
155 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 start" << std::endl;
156 MessageParcel data;
157 MessageParcel reply;
158 int32_t token = 0;
159 data.WriteInt32(token);
160 std::string cbType = "";
161 data.WriteString(cbType);
162 int32_t result = dtbabilitymgrStub_->UnregisterDeviceSelectionCallbackInner(data, reply);
163 EXPECT_EQ(result, ERR_NULL_OBJECT);
164 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 end" << std::endl;
165 }
166
167 /**
168 * @tc.name: UnregisterDeviceSelectionCallbackInner_002
169 * @tc.desc: test UnregisterDeviceSelectionCallbackInner with cbType is empty
170 * @tc.type: FUNC
171 * @tc.require: I64FU7
172 */
173 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterDeviceSelectionCallbackInner_002, TestSize.Level3)
174 {
175 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_002 start" << std::endl;
176 MessageParcel data;
177 MessageParcel reply;
178 int32_t token = 0;
179 data.WriteInt32(token);
180 std::string cbType = "12345";
181 data.WriteString(cbType);
182 int32_t result = dtbabilitymgrStub_->UnregisterDeviceSelectionCallbackInner(data, reply);
183 EXPECT_EQ(result, ERR_NONE);
184 DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_002 end" << std::endl;
185 }
186
187 /**
188 * @tc.name: StartDeviceManagerInner_001
189 * @tc.desc: test StartDeviceManagerInner with continuationExtraParams is nullptr
190 * @tc.type: FUNC
191 * @tc.require: I64FU7
192 */
193 HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_001, TestSize.Level3)
194 {
195 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 start" << std::endl;
196 MessageParcel data;
197 MessageParcel reply;
198 int32_t token = 0;
199 data.WriteInt32(token);
200 int32_t flag = VALUE_OBJECT;
201 data.WriteInt32(flag);
202 int32_t result = dtbabilitymgrStub_->StartDeviceManagerInner(data, reply);
203 EXPECT_EQ(result, ERR_NULL_OBJECT);
204 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 end" << std::endl;
205 }
206
207 /**
208 * @tc.name: StartDeviceManagerInner_002
209 * @tc.desc: test StartDeviceManagerInner with continuationExtraParams is nullptr
210 * @tc.type: FUNC
211 * @tc.require: I64FU7
212 */
213 HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_002, TestSize.Level3)
214 {
215 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 start" << std::endl;
216 MessageParcel data;
217 MessageParcel reply;
218 int32_t token = 0;
219 data.WriteInt32(token);
220 int32_t flag = VALUE_NULL;
221 data.WriteInt32(flag);
222 int32_t result = dtbabilitymgrStub_->StartDeviceManagerInner(data, reply);
223 EXPECT_EQ(result, ERR_NONE);
224 DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_002 end" << std::endl;
225 }
226 }
227 }