• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 DISTRIBUTED_SCHED_SA_ID = 1401;
27 constexpr int32_t INVALID_CODE = 123456;
28 const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
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(DISTRIBUTED_SCHED_SA_ID, true);
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     uint32_t code = INVALID_CODE;
82     MessageParcel data;
83     MessageParcel reply;
84     MessageOption option;
85     dtbabilitymgrStub_->distributedFuncMap_[INVALID_CODE] = nullptr;
86     data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN);
87     int32_t result = dtbabilitymgrStub_->OnRemoteRequest(code, data, reply, option);
88     EXPECT_EQ(result, ERR_NULL_OBJECT);
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     MessageParcel data;
102     MessageParcel reply;
103     data.WriteInt32(VALUE_OBJECT);
104     int32_t result = dtbabilitymgrStub_->RegisterInner(data, reply);
105     EXPECT_EQ(result, ERR_NULL_OBJECT);
106     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterInner_001 end" << std::endl;
107 }
108 
109 /**
110  * @tc.name: RegisterDeviceSelectionCallbackInner_001
111  * @tc.desc: test RegisterDeviceSelectionCallbackInner with cbType is empty
112  * @tc.type: FUNC
113  * @tc.require: I64FU7
114  */
115 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_001, TestSize.Level3)
116 {
117     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 start" << std::endl;
118     MessageParcel data;
119     MessageParcel reply;
120     int32_t token = 0;
121     data.WriteInt32(token);
122     std::string cbType = "";
123     data.WriteString(cbType);
124     int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
125     EXPECT_EQ(result, ERR_NULL_OBJECT);
126     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_001 end" << std::endl;
127 }
128 
129 /**
130  * @tc.name: RegisterDeviceSelectionCallbackInner_002
131  * @tc.desc: test RegisterDeviceSelectionCallbackInner with notifier is nullptr
132  * @tc.type: FUNC
133  * @tc.require: I64FU7
134  */
135 HWTEST_F(DistributedAbilityManagerStubTest, RegisterDeviceSelectionCallbackInner_002, TestSize.Level3)
136 {
137     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 start" << std::endl;
138     MessageParcel data;
139     MessageParcel reply;
140     int32_t token = 0;
141     data.WriteInt32(token);
142     std::string cbType = "mockType";
143     data.WriteString(cbType);
144     int32_t result = dtbabilitymgrStub_->RegisterDeviceSelectionCallbackInner(data, reply);
145     EXPECT_EQ(result, ERR_NULL_OBJECT);
146     DTEST_LOG << "DistributedAbilityManagerStubTest RegisterDeviceSelectionCallbackInner_002 end" << std::endl;
147 }
148 
149 /**
150  * @tc.name: UnregisterDeviceSelectionCallbackInner_001
151  * @tc.desc: test UnregisterDeviceSelectionCallbackInner with cbType is empty
152  * @tc.type: FUNC
153  * @tc.require: I64FU7
154  */
155 HWTEST_F(DistributedAbilityManagerStubTest, UnregisterDeviceSelectionCallbackInner_001, TestSize.Level3)
156 {
157     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 start" << std::endl;
158     MessageParcel data;
159     MessageParcel reply;
160     int32_t token = 0;
161     data.WriteInt32(token);
162     std::string cbType = "";
163     data.WriteString(cbType);
164     int32_t result = dtbabilitymgrStub_->UnregisterDeviceSelectionCallbackInner(data, reply);
165     EXPECT_EQ(result, ERR_NULL_OBJECT);
166     DTEST_LOG << "DistributedAbilityManagerStubTest UnregisterDeviceSelectionCallbackInner_001 end" << std::endl;
167 }
168 
169 /**
170  * @tc.name: StartDeviceManagerInner_001
171  * @tc.desc: test StartDeviceManagerInner with continuationExtraParams is nullptr
172  * @tc.type: FUNC
173  * @tc.require: I64FU7
174  */
175 HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_001, TestSize.Level3)
176 {
177     DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 start" << std::endl;
178     MessageParcel data;
179     MessageParcel reply;
180     int32_t token = 0;
181     data.WriteInt32(token);
182     int32_t flag = VALUE_OBJECT;
183     data.WriteInt32(flag);
184     int32_t result = dtbabilitymgrStub_->StartDeviceManagerInner(data, reply);
185     EXPECT_EQ(result, ERR_NULL_OBJECT);
186     DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 end" << std::endl;
187 }
188 
189 /**
190  * @tc.name: GetDistributedComponentListInner_001
191  * @tc.desc: test GetDistributedComponentListInner with interfaceToken is empty
192  * @tc.type: FUNC
193  * @tc.require: I64FU7
194  */
195 HWTEST_F(DistributedAbilityManagerStubTest, GetDistributedComponentListInner_001, TestSize.Level3)
196 {
197     DTEST_LOG << "DistributedAbilityManagerStubTest GetDistributedComponentListInner_001 start" << std::endl;
198     MessageParcel data;
199     MessageParcel reply;
200     MessageOption option;
201     int32_t result = dtbabilitymgrStub_->GetDistributedComponentListInner(data, reply, option);
202     EXPECT_EQ(result, DMS_PERMISSION_DENIED);
203     DTEST_LOG << "DistributedAbilityManagerStubTest GetDistributedComponentListInner_001 end" << std::endl;
204 }
205 }
206 }