• 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 
16 #include "dscreen_source_stub_test.h"
17 
18 #include <memory>
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace DistributedHardware {
SetUpTestCase(void)25 void DScreenSourceStubTest::SetUpTestCase(void)
26 {
27 }
28 
TearDownTestCase(void)29 void DScreenSourceStubTest::TearDownTestCase(void)
30 {
31 }
32 
SetUp(void)33 void DScreenSourceStubTest::SetUp(void)
34 {
35 }
36 
TearDown(void)37 void DScreenSourceStubTest::TearDown(void)
38 {
39 }
40 
InitSource(const std::string & params,const sptr<IDScreenSourceCallback> & callback)41 int32_t DScreenSourceStubTest::TestDScreenSourceStub::InitSource(const std::string &params,
42     const sptr<IDScreenSourceCallback> &callback)
43 {
44     (void)params;
45     (void)callback;
46     return DH_SUCCESS;
47 }
48 
ReleaseSource()49 int32_t DScreenSourceStubTest::TestDScreenSourceStub::ReleaseSource()
50 {
51     return DH_SUCCESS;
52 }
53 
RegisterDistributedHardware(const std::string & devId,const std::string & dhId,const EnableParam & param,const std::string & reqId)54 int32_t DScreenSourceStubTest::TestDScreenSourceStub::RegisterDistributedHardware(const std::string &devId,
55     const std::string &dhId, const EnableParam &param, const std::string &reqId)
56 {
57     (void)devId;
58     (void)dhId;
59     (void)param;
60     (void)reqId;
61     return DH_SUCCESS;
62 }
63 
UnregisterDistributedHardware(const std::string & devId,const std::string & dhId,const std::string & reqId)64 int32_t DScreenSourceStubTest::TestDScreenSourceStub::UnregisterDistributedHardware(const std::string &devId,
65     const std::string &dhId, const std::string &reqId)
66 {
67     (void)devId;
68     (void)dhId;
69     (void)reqId;
70     return DH_SUCCESS;
71 }
72 
ConfigDistributedHardware(const std::string & devId,const std::string & dhId,const std::string & key,const std::string & value)73 int32_t DScreenSourceStubTest::TestDScreenSourceStub::ConfigDistributedHardware(const std::string &devId,
74     const std::string &dhId, const std::string &key, const std::string &value)
75 {
76     (void)devId;
77     (void)dhId;
78     (void)key;
79     (void)value;
80     return DH_SUCCESS;
81 }
82 
DScreenNotify(const std::string & devId,int32_t eventCode,const std::string & eventContent)83 void DScreenSourceStubTest::TestDScreenSourceStub::DScreenNotify(const std::string &devId, int32_t eventCode,
84     const std::string &eventContent)
85 {
86     devId_ = devId;
87     eventCode_ = eventCode;
88     eventContent_ = eventContent;
89 }
90 
91 /**
92  * @tc.name: InitSource_001
93  * @tc.desc: Invoke the InitSource ipc interface.
94  * @tc.type: FUNC
95  * @tc.require: Issue Number
96  */
97 HWTEST_F(DScreenSourceStubTest, InitSource_001, TestSize.Level1)
98 {
99     sptr<IRemoteObject> sourceStubPtr = new TestDScreenSourceStub();
100     DScreenSourceProxy sourceProxy(sourceStubPtr);
101 
102     sptr<DScreenSourceCallback> callback;
103     int32_t ret = sourceProxy.InitSource("", callback);
104     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
105 
106     ret = sourceProxy.InitSource("params000", callback);
107     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
108 
109     callback = new DScreenSourceCallback();
110     ret = sourceProxy.InitSource("params000", callback);
111     EXPECT_EQ(DH_SUCCESS, ret);
112 }
113 
114 /**
115  * @tc.name: ReleaseSource_001
116  * @tc.desc: Invoke the ReleaseSource ipc interface.
117  * @tc.type: FUNC
118  * @tc.require: Issue Number
119  */
120 HWTEST_F(DScreenSourceStubTest, ReleaseSource_001, TestSize.Level1)
121 {
122     sptr<IRemoteObject> sourceStubPtr = new TestDScreenSourceStub();
123     DScreenSourceProxy sourceProxy(sourceStubPtr);
124     int32_t ret = sourceProxy.ReleaseSource();
125     EXPECT_EQ(DH_SUCCESS, ret);
126 }
127 
128 /**
129  * @tc.name: RegisterDistributedHardware_001
130  * @tc.desc: Invoke the RegisterDistributedHardware ipc interface.
131  * @tc.type: FUNC
132  * @tc.require: Issue Number
133  */
134 HWTEST_F(DScreenSourceStubTest, RegisterDistributedHardware_001, TestSize.Level1)
135 {
136     sptr<IRemoteObject> sourceStubPtr = new TestDScreenSourceStub();
137     DScreenSourceProxy sourceProxy(sourceStubPtr);
138 
139     EnableParam param;
140     param.version = "";
141     param.attrs = "";
142     int32_t ret = sourceProxy.RegisterDistributedHardware("", "dhId000", param, "reqId000");
143     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
144 
145     std::string devId = R"(dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
146         Id000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
147         hId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000)";
148     ret = sourceProxy.RegisterDistributedHardware(devId, "dhId000", param, "reqId000");
149     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
150 
151     ret = sourceProxy.RegisterDistributedHardware("devId000", "", param, "reqId000");
152     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
153 
154     ret = sourceProxy.RegisterDistributedHardware("devId000", devId, param, "reqId000");
155     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
156 
157     ret = sourceProxy.RegisterDistributedHardware("devId000", "dhId000", param, "");
158     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
159 
160     ret = sourceProxy.RegisterDistributedHardware("devId000", "dhId000", param, devId);
161     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
162 
163     ret = sourceProxy.RegisterDistributedHardware("devId000", "dhId000", param, "reqId000");
164     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
165 
166     param.version = "1";
167     ret = sourceProxy.RegisterDistributedHardware("devId000", "dhId000", param, "reqId000");
168     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
169 
170     param.attrs = "attrs";
171     ret = sourceProxy.RegisterDistributedHardware("devId000", "dhId000", param, "reqId000");
172     EXPECT_EQ(DH_SUCCESS, ret);
173 }
174 
175 /**
176  * @tc.name: UnregisterDistributedHardware_001
177  * @tc.desc: Invoke the UnregisterDistributedHardware ipc interface.
178  * @tc.type: FUNC
179  * @tc.require: Issue Number
180  */
181 HWTEST_F(DScreenSourceStubTest, UnregisterDistributedHardware_001, TestSize.Level1)
182 {
183     sptr<IRemoteObject> sourceStubPtr = new TestDScreenSourceStub();
184     DScreenSourceProxy sourceProxy(sourceStubPtr);
185 
186     int32_t ret = sourceProxy.UnregisterDistributedHardware("", "dhId000", "reqId000");
187     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
188 
189     std::string devId = R"(dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
190         Id000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
191         hId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000)";
192     ret = sourceProxy.UnregisterDistributedHardware(devId, "dhId000", "reqId000");
193     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
194 
195     ret = sourceProxy.UnregisterDistributedHardware("devId000", "", "reqId000");
196     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
197 
198     ret = sourceProxy.UnregisterDistributedHardware("devId000", devId, "reqId000");
199     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
200 
201     ret = sourceProxy.UnregisterDistributedHardware("devId000", "dhId000", "");
202     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
203 
204     ret = sourceProxy.UnregisterDistributedHardware("devId000", "dhId000", devId);
205     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
206 
207     ret = sourceProxy.UnregisterDistributedHardware("devId000", "dhId000", "reqId000");
208     EXPECT_EQ(DH_SUCCESS, ret);
209 }
210 
211 /**
212  * @tc.name: ConfigDistributedHardware_001
213  * @tc.desc: Invoke the ConfigDistributedHardware ipc interface.
214  * @tc.type: FUNC
215  * @tc.require: Issue Number
216  */
217 HWTEST_F(DScreenSourceStubTest, ConfigDistributedHardware_001, TestSize.Level1)
218 {
219     sptr<IRemoteObject> sourceStubPtr = new TestDScreenSourceStub();
220     DScreenSourceProxy sourceProxy(sourceStubPtr);
221 
222     int32_t ret = sourceProxy.ConfigDistributedHardware("", "dhId000", "key000", "value000");
223     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
224 
225     std::string devId = R"(dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
226         Id000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
227         hId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000)";
228     ret = sourceProxy.ConfigDistributedHardware(devId, "dhId000", "key000", "value000");
229     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
230 
231     ret = sourceProxy.ConfigDistributedHardware("devId000", "", "key000", "value000");
232     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
233 
234     ret = sourceProxy.ConfigDistributedHardware("devId000", devId, "key000", "value000");
235     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
236 
237     ret = sourceProxy.ConfigDistributedHardware("devId000", "dhId000", "", "value000");
238     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
239 
240     ret = sourceProxy.ConfigDistributedHardware("devId000", "dhId000", "key000", "");
241     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
242 
243     ret = sourceProxy.ConfigDistributedHardware("devId000", "dhId000", "key000", "value000");
244     EXPECT_EQ(DH_SUCCESS, ret);
245 }
246 
247 /**
248  * @tc.name: DScreenNotify_001
249  * @tc.desc: Invoke the DScreenNotify ipc interface.
250  * @tc.type: FUNC
251  * @tc.require: Issue Number
252  */
253 HWTEST_F(DScreenSourceStubTest, DScreenNotify_001, TestSize.Level1)
254 {
255     sptr<IRemoteObject> sourceStubPtr = new TestDScreenSourceStub();
256     DScreenSourceProxy sourceProxy(sourceStubPtr);
257 
258     sourceProxy.DScreenNotify("", 0, "eventContent000");
259 
260     std::string longString = R"(dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
261         Id000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000d
262         hId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000dhId000)";
263     sourceProxy.DScreenNotify(longString, 0, "eventContent000");
264 
265     sourceProxy.DScreenNotify("devId000", 0, "");
266 
267     std::string devId = "devId000";
268     int32_t eventCode = 0;
269     std::string eventContent = "eventContent000";
270     sourceProxy.DScreenNotify(devId, eventCode, eventContent);
271     EXPECT_STREQ(devId.c_str(), ((sptr<TestDScreenSourceStub> &)sourceStubPtr)->devId_.c_str());
272     EXPECT_EQ(eventCode, ((sptr<TestDScreenSourceStub> &)sourceStubPtr)->eventCode_);
273     EXPECT_STREQ(eventContent.c_str(), ((sptr<TestDScreenSourceStub> &)sourceStubPtr)->eventContent_.c_str());
274 }
275 }
276 }