1 /*
2 * Copyright (c) 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
16 #include <gtest/gtest.h>
17
18 #define private public
19 #define protected public
20 #include "array_wrapper.h"
21 #include "base_object.h"
22 #include "bool_wrapper.h"
23 #include "byte_wrapper.h"
24 #include "distributed_want_params.h"
25 #include "distributed_want_params_wrapper.h"
26 #include "double_wrapper.h"
27 #include "float_wrapper.h"
28 #include "int_wrapper.h"
29 #include "long_wrapper.h"
30 #include "short_wrapper.h"
31 #include "string_wrapper.h"
32 #include "test_log.h"
33 #include "zchar_wrapper.h"
34 #undef private
35 #undef protected
36
37 using namespace testing::ext;
38 using namespace OHOS;
39 using namespace AAFwk;
40 using namespace DistributedSchedule;
41 using OHOS::Parcel;
42 class DistributedWantParamsBaseTest : public testing::Test {
43 public:
DistributedWantParamsBaseTest()44 DistributedWantParamsBaseTest()
45 {}
~DistributedWantParamsBaseTest()46 ~DistributedWantParamsBaseTest()
47 {}
48 static void SetUpTestCase(void);
49 static void TearDownTestCase(void);
50 void SetUp();
51 void TearDown();
52 std::shared_ptr<DistributedWantParams> wantParamsIn_ = nullptr;
53 std::shared_ptr<DistributedWantParams> wantParamsOut_ = nullptr;
54 static sptr<DistributedWantParams> distributedWantParams_;
55 };
56
57 sptr<DistributedWantParams> DistributedWantParamsBaseTest::distributedWantParams_;
58
SetUpTestCase(void)59 void DistributedWantParamsBaseTest::SetUpTestCase(void)
60 {
61 distributedWantParams_ = new DistributedWantParams();
62 }
63
TearDownTestCase(void)64 void DistributedWantParamsBaseTest::TearDownTestCase(void)
65 {}
66
SetUp(void)67 void DistributedWantParamsBaseTest::SetUp(void)
68 {
69 wantParamsIn_ = std::make_shared<DistributedWantParams>();
70 wantParamsOut_ = std::make_shared<DistributedWantParams>();
71 }
72
TearDown(void)73 void DistributedWantParamsBaseTest::TearDown(void)
74 {
75 }
76
77 /**
78 * @tc.number: DistributedWantParams_Parcelable_0100
79 * @tc.name: Marshalling/Unmarshalling
80 * @tc.desc: marshalling WantParams, and then check result.
81 */
82 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0100, Function | MediumTest | Level3)
83 {
84 std::string keyStr = "12345667";
85 std::string valueStr = "sdasdfdsffdgfdg";
86 wantParamsIn_->SetParam(keyStr, String::Box(valueStr));
87 Parcel in;
88 if (wantParamsOut_ != nullptr) {
89 wantParamsIn_->Marshalling(in);
90 std::shared_ptr<DistributedWantParams> wantParamsOut_(DistributedWantParams::Unmarshalling(in));
91 EXPECT_EQ(valueStr, String::Unbox(IString::Query(wantParamsOut_->GetParam(keyStr))));
92 }
93 }
94
95 /**
96 * @tc.number: DistributedWantParams_Parcelable_0200
97 * @tc.name: Marshalling/Unmarshalling
98 * @tc.desc: marshalling WantParams, and then check result.
99 */
100 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0200, Function | MediumTest | Level3)
101 {
102 std::string keyStr = "12345667";
103 bool valueBool = true;
104 wantParamsIn_->SetParam(keyStr, Boolean::Box(valueBool));
105
106 Parcel in;
107 if (wantParamsOut_ != nullptr) {
108 wantParamsIn_->Marshalling(in);
109 std::shared_ptr<DistributedWantParams> wantParamsOut_(DistributedWantParams::Unmarshalling(in));
110 EXPECT_EQ(valueBool, Boolean::Unbox(IBoolean::Query(wantParamsOut_->GetParam(keyStr))));
111 }
112 }
113
114 /**
115 * @tc.number: DistributedWantParams_Parcelable_0300
116 * @tc.name: Marshalling/Unmarshalling
117 * @tc.desc: marshalling WantParams, and then check result.
118 */
119 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0300, Function | MediumTest | Level3)
120 {
121 std::string keyStr = "12345667";
122 int valueInteger = 12345;
123 wantParamsIn_->SetParam(keyStr, Integer::Box(valueInteger));
124 Integer::Unbox(IInteger::Query(wantParamsIn_->GetParam(keyStr)));
125
126 Parcel in;
127 wantParamsIn_->Marshalling(in);
128 std::shared_ptr<DistributedWantParams> wantParamsOut_(DistributedWantParams::Unmarshalling(in));
129 if (wantParamsOut_ != nullptr) {
130 int right = Integer::Unbox(IInteger::Query(wantParamsOut_->GetParam(keyStr)));
131 EXPECT_EQ(valueInteger, right);
132 wantParamsOut_ = nullptr;
133 }
134 }
135
136 /**
137 * @tc.number: DistributedWantParams_Parcelable_0400
138 * @tc.name: Marshalling/Unmarshalling
139 * @tc.desc: marshalling WantParams, and then check result.
140 */
141 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0400, Function | MediumTest | Level3)
142 {
143 std::string keyStr = "12345667";
144 long valueLong = 1234567;
145 wantParamsIn_->SetParam(keyStr, Long::Box(valueLong));
146
147 Parcel in;
148 wantParamsIn_->Marshalling(in);
149 std::shared_ptr<DistributedWantParams> wantParamsOut_(DistributedWantParams::Unmarshalling(in));
150 std::string outString(String::Unbox(IString::Query(wantParamsOut_->GetParam(keyStr))));
151 EXPECT_STREQ(std::to_string(valueLong).c_str(), outString.c_str());
152 }
153
154 /**
155 * @tc.number: DistributedWantParams_Parcelable_0600
156 * @tc.name: Marshalling/Unmarshalling
157 * @tc.desc: marshalling nested WantParams, and then check result.
158 */
159 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0600, Function | MediumTest | Level3)
160 {
161 DistributedWantParams wp;
162 wp.SetParam("hello", String::Box("World"));
163 wp.SetParam("welcome", String::Box("NY"));
164
165 DistributedWantParams l1;
166 l1.SetParam("l1", DistributedWantParamWrapper::Box(wp));
167 wantParamsIn_->SetParam("l2", DistributedWantParamWrapper::Box(l1));
168 Parcel in;
169 wantParamsIn_->Marshalling(in);
170 std::shared_ptr<DistributedWantParams> wantParamsOut_(DistributedWantParams::Unmarshalling(in));
171 DistributedWantParams l1Out =
172 DistributedWantParamWrapper::Unbox(IDistributedWantParams::Query(wantParamsOut_->GetParam("l2")));
173 DistributedWantParams wpOut =
174 DistributedWantParamWrapper::Unbox(IDistributedWantParams::Query(l1.GetParam("l1")));
175 std::string hello(String::Unbox(IString::Query(wpOut.GetParam("hello"))));
176 EXPECT_EQ(hello, "World");
177 std::string welcome(String::Unbox(IString::Query(wpOut.GetParam("welcome"))));
178 EXPECT_EQ(welcome, "NY");
179 }
180
181 /**
182 * @tc.number: DistributedWantParams_Parcelable_0700
183 * @tc.name: Marshalling/Unmarshalling
184 * @tc.desc: marshalling array, and then check result.
185 */
186 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0700, Function | MediumTest | Level3)
187 {
188 sptr<AAFwk::IArray> ao = new (std::nothrow) AAFwk::Array(2, AAFwk::g_IID_IString);
189 std::string valueStr0 = "TestValue0";
190 ao->Set(0, String::Box(valueStr0));
191 std::string valueStr1 = "TestValue1";
192 ao->Set(1, String::Box(valueStr1));
193
194 DistributedWantParams l1;
195 l1.SetParam("l1", ao);
196 wantParamsIn_->SetParam("l2", DistributedWantParamWrapper::Box(l1));
197
198 Parcel in;
199 wantParamsIn_->Marshalling(in);
200 std::shared_ptr<DistributedWantParams> wantParamsOut_(DistributedWantParams::Unmarshalling(in));
201 DistributedWantParams l1Out =
202 DistributedWantParamWrapper::Unbox(IDistributedWantParams::Query(wantParamsOut_->GetParam("l2")));
203 IArray *aoOut = IArray::Query(l1Out.GetParam("l1"));
204
205 long size;
206 aoOut->GetLength(size);
207 EXPECT_EQ(size, 2);
208 sptr<IInterface> str0;
209 sptr<IInterface> str1;
210 aoOut->Get(0, str0);
211 aoOut->Get(1, str1);
212
213 EXPECT_EQ(valueStr0, String::Unbox(IString::Query(str0)));
214 EXPECT_EQ(valueStr1, String::Unbox(IString::Query(str1)));
215 }
216
217 /**
218 * @tc.number: DistributedWantParams_GetStringByType_0200
219 * @tc.name: GetStringByType
220 * @tc.desc: Test get bool with invalid type in the WantParam.
221 */
222 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0200, Function | MediumTest | Level3)
223 {
224 const std::string value = "true";
225 sptr<IInterface> boolObj =
226 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BOOLEAN, value);
227 std::string stringVal =
228 DistributedWantParams::GetStringByType(boolObj, DistributedWantParams::VALUE_TYPE_BOOLEAN);
229 EXPECT_EQ(stringVal, "true");
230 }
231
232 /**
233 * @tc.number: DistributedWantParams_GetStringByType_0300
234 * @tc.name: GetStringByType
235 * @tc.desc: Test get string with invalid type in the WantParam.
236 */
237 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0300, Function | MediumTest | Level3)
238 {
239 const std::string value = "string";
240 sptr<IInterface> stringObj =
241 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_STRING, value);
242 std::string stringVal =
243 DistributedWantParams::GetStringByType(stringObj, DistributedWantParams::VALUE_TYPE_STRING);
244 EXPECT_EQ(stringVal, "string");
245 }
246
247 /**
248 * @tc.number: DistributedWantParams_GetStringByType_0400
249 * @tc.name: GetStringByType
250 * @tc.desc: Test get byte with invalid type in the WantParam.
251 */
252 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0400, Function | MediumTest | Level3)
253 {
254 const std::string value = "129";
255 sptr<IInterface> byteObj =
256 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BYTE, value);
257 std::string byteVal = DistributedWantParams::GetStringByType(byteObj, DistributedWantParams::VALUE_TYPE_BYTE);
258 EXPECT_EQ(byteVal, "129");
259 }
260
261 /**
262 * @tc.number: DistributedWantParams_GetStringByType_0500
263 * @tc.name: GetStringByType
264 * @tc.desc: Test get char with invalid type in the WantParam.
265 */
266 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0500, Function | MediumTest | Level3)
267 {
268 const std::string value = "I";
269 sptr<IInterface> charObj =
270 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_CHAR, value);
271 std::string charVal = DistributedWantParams::GetStringByType(charObj, DistributedWantParams::VALUE_TYPE_CHAR);
272 EXPECT_EQ(charVal, "I");
273 }
274
275 /**
276 * @tc.number: DistributedWantParams_GetStringByType_0600
277 * @tc.name: GetStringByType
278 * @tc.desc: Test get short with invalid type in the WantParam.
279 */
280 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0600, Function | MediumTest | Level3)
281 {
282 const std::string value = "123";
283 sptr<IInterface> shortObj =
284 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_SHORT, value);
285 std::string shortVal = DistributedWantParams::GetStringByType(shortObj, DistributedWantParams::VALUE_TYPE_SHORT);
286 EXPECT_EQ(shortVal, "123");
287 }
288
289 /**
290 * @tc.number: DistributedWantParams_GetStringByType_0700
291 * @tc.name: GetStringByType
292 * @tc.desc: Test get int with invalid type in the WantParam.
293 */
294 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0700, Function | MediumTest | Level3)
295 {
296 const std::string value = "-1";
297 sptr<IInterface> intObj = DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_INT, value);
298 std::string intVal = DistributedWantParams::GetStringByType(intObj, DistributedWantParams::VALUE_TYPE_INT);
299 EXPECT_EQ(intVal, "-1");
300 }
301
302 /**
303 * @tc.number: DistributedWantParams_GetStringByType_0800
304 * @tc.name: GetStringByType
305 * @tc.desc: Test get long with invalid type in the WantParam.
306 */
307 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0800, Function | MediumTest | Level3)
308 {
309 const std::string value = "-1";
310 sptr<IInterface> longObj =
311 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_LONG, value);
312 std::string longVal = DistributedWantParams::GetStringByType(longObj, DistributedWantParams::VALUE_TYPE_LONG);
313 EXPECT_EQ(longVal, "-1");
314 }
315
316 /**
317 * @tc.number: DistributedWantParams_GetStringByType_0900
318 * @tc.name: GetStringByType
319 * @tc.desc: Test get float with invalid type in the WantParam.
320 */
321 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_0900, Function | MediumTest | Level3)
322 {
323 const std::string value = "-1.0004";
324 sptr<IInterface> floatObj =
325 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_FLOAT, value);
326 std::string floatVal = DistributedWantParams::GetStringByType(floatObj, DistributedWantParams::VALUE_TYPE_FLOAT);
327 EXPECT_EQ(floatVal, "-1.000400");
328 }
329
330 /**
331 * @tc.number: DistributedWantParams_GetStringByType_1000
332 * @tc.name: GetStringByType
333 * @tc.desc: Test get float with invalid type in the WantParam.
334 */
335 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_1000, Function | MediumTest | Level3)
336 {
337 const std::string value = "-1.00000004";
338 sptr<IInterface> doubleObj =
339 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_DOUBLE, value);
340 std::string doubleVal =
341 DistributedWantParams::GetStringByType(doubleObj, DistributedWantParams::VALUE_TYPE_DOUBLE);
342 EXPECT_EQ(doubleVal, "-1.000000");
343 }
344
345 /**
346 * @tc.number: DistributedWantParams_GetStringByType_1100
347 * @tc.name: GetStringByType
348 * @tc.desc: Test get float with invalid type in the WantParam.
349 */
350 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetStringByType_1100, Function | MediumTest | Level3)
351 {
352 const std::string value = "I5{2,3,5,7,11}";
353 sptr<IInterface> arrayObj =
354 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_ARRAY, value);
355 std::string arrayVal = DistributedWantParams::GetStringByType(arrayObj, DistributedWantParams::VALUE_TYPE_ARRAY);
356 EXPECT_EQ(arrayVal, "I5{2,3,5,7,11}");
357 }
358
359 /**
360 * @tc.number: DistributedWantParams_NewArrayData_0100
361 * @tc.name: NewArrayData
362 * @tc.desc: Test NewArrayData with invalid sptr<IArray> parameter.
363 */
364 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_NewArrayData_0100, Function | MediumTest | Level3)
365 {
366 sptr<AAFwk::IArray> array = new (std::nothrow) AAFwk::Array(0, g_IID_IDistributedWantParams);
367 DistributedWantParams wp;
368 wp.SetParam("param1", array);
369 IArray *iarray = IArray::Query(array);
370 sptr<IArray> destAO = nullptr;
371 bool result = wp.NewArrayData(iarray, destAO);
372 EXPECT_FALSE(result);
373 }
374
375 /**
376 * @tc.number: DistributedWantParams_GetDataType_0100
377 * @tc.name: GetDataType
378 * @tc.desc: Test GetDataType with invalid parameter.
379 */
380 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0100, Function | MediumTest | Level3)
381 {
382 int type = DistributedWantParams::GetDataType(nullptr);
383 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_NULL);
384 }
385
386 /**
387 * @tc.number: DistributedWantParams_GetDataType_0200
388 * @tc.name: GetDataType
389 * @tc.desc: Test GetDataType with bool parameter.
390 */
391 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0200, Function | MediumTest | Level3)
392 {
393 const std::string value = "true";
394 sptr<IInterface> boolObj =
395 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BOOLEAN, value);
396 int type = DistributedWantParams::GetDataType(boolObj);
397 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_BOOLEAN);
398 }
399
400 /**
401 * @tc.number: DistributedWantParams_GetDataType_0300
402 * @tc.name: GetDataType
403 * @tc.desc: Test GetDataType with byte parameter.
404 */
405 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0300, Function | MediumTest | Level3)
406 {
407 const std::string value = "129";
408 sptr<IInterface> byteObj =
409 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BYTE, value);
410 int type = DistributedWantParams::GetDataType(byteObj);
411 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_BYTE);
412 }
413
414 /**
415 * @tc.number: DistributedWantParams_GetDataType_0400
416 * @tc.name: GetDataType
417 * @tc.desc: Test GetDataType with char parameter.
418 */
419 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0400, Function | MediumTest | Level3)
420 {
421 const std::string value = "I";
422 sptr<IInterface> charObj =
423 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_CHAR, value);
424 int type = DistributedWantParams::GetDataType(charObj);
425 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_CHAR);
426 }
427
428 /**
429 * @tc.number: DistributedWantParams_GetDataType_0500
430 * @tc.name: GetDataType
431 * @tc.desc: Test GetDataType with short parameter.
432 */
433 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0500, Function | MediumTest | Level3)
434 {
435 const std::string value = "123";
436 sptr<IInterface> shortObj =
437 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_SHORT, value);
438 int type = DistributedWantParams::GetDataType(shortObj);
439 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_SHORT);
440 }
441
442 /**
443 * @tc.number: DistributedWantParams_GetDataType_0600
444 * @tc.name: GetDataType
445 * @tc.desc: Test GetDataType with int parameter.
446 */
447 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0600, Function | MediumTest | Level3)
448 {
449 const std::string value = "-1";
450 sptr<IInterface> intObj = DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_INT, value);
451 int type = DistributedWantParams::GetDataType(intObj);
452 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_INT);
453 }
454
455 /**
456 * @tc.number: DistributedWantParams_GetDataType_0700
457 * @tc.name: GetDataType
458 * @tc.desc: Test GetDataType with long parameter.
459 */
460 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0700, Function | MediumTest | Level3)
461 {
462 const std::string value = "-1";
463 sptr<IInterface> longObj = DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_LONG, value);
464 int type = DistributedWantParams::GetDataType(longObj);
465 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_LONG);
466 }
467
468 /**
469 * @tc.number: DistributedWantParams_GetDataType_0800
470 * @tc.name: GetDataType
471 * @tc.desc: Test GetDataType with float parameter.
472 */
473 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0800, Function | MediumTest | Level3)
474 {
475 const std::string value = "-1.0004";
476 sptr<IInterface> floatObj =
477 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_FLOAT, value);
478 int type = DistributedWantParams::GetDataType(floatObj);
479 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_FLOAT);
480 }
481
482 /**
483 * @tc.number: DistributedWantParams_GetDataType_0900
484 * @tc.name: GetDataType
485 * @tc.desc: Test GetDataType with double parameter.
486 */
487 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_0900, Function | MediumTest | Level3)
488 {
489 const std::string value = "-1.00000004";
490 sptr<IInterface> doubleObj =
491 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_DOUBLE, value);
492 int type = DistributedWantParams::GetDataType(doubleObj);
493 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_DOUBLE);
494 }
495
496 /**
497 * @tc.number: DistributedWantParams_GetDataType_1000
498 * @tc.name: GetDataType
499 * @tc.desc: Test GetDataType with string parameter.
500 */
501 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_1000, Function | MediumTest | Level3)
502 {
503 const std::string value = "hello";
504 sptr<IInterface> stringObj =
505 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_STRING, value);
506 int type = DistributedWantParams::GetDataType(stringObj);
507 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_STRING);
508 }
509
510 /**
511 * @tc.number: DistributedWantParams_GetDataType_1100
512 * @tc.name: GetDataType
513 * @tc.desc: Test GetDataType with array parameter.
514 */
515 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetDataType_1100, Function | MediumTest | Level3)
516 {
517 const std::string value = "I5{2,3,5,7,11}";
518 sptr<IInterface> interfaceObj =
519 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_ARRAY, value);
520 int type = DistributedWantParams::GetDataType(interfaceObj);
521 EXPECT_EQ(type, DistributedWantParams::VALUE_TYPE_ARRAY);
522 }
523
524 /**
525 * @tc.number: DistributedWantParams_GetInterfaceByType_0100
526 * @tc.name: GetInterfaceByType
527 * @tc.desc: Test GetInterfaceByType with boolean type.
528 */
529 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0100, Function | MediumTest | Level3)
530 {
531 const std::string value = "true";
532 sptr<IInterface> boolObj =
533 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BOOLEAN, value);
534 EXPECT_TRUE(Boolean::Unbox(IBoolean::Query(boolObj)));
535 }
536
537 /**
538 * @tc.number: DistributedWantParams_GetInterfaceByType_0200
539 * @tc.name: GetInterfaceByType
540 * @tc.desc: Test GetInterfaceByType with byte type.
541 */
542 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0200, Function | MediumTest | Level3)
543 {
544 const std::string value = "129";
545 sptr<IInterface> byteObj =
546 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BYTE, value);
547 EXPECT_EQ(Byte::Unbox(IByte::Query(byteObj)), 129);
548 }
549
550 /**
551 * @tc.number: DistributedWantParams_GetInterfaceByType_0300
552 * @tc.name: GetInterfaceByType
553 * @tc.desc: Test GetInterfaceByType with char type.
554 */
555 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0300, Function | MediumTest | Level3)
556 {
557 const std::string value = "I";
558 sptr<IInterface> charObj =
559 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_CHAR, value);
560 EXPECT_EQ(Char::Unbox(IChar::Query(charObj)), 'I');
561 }
562
563 /**
564 * @tc.number: DistributedWantParams_GetInterfaceByType_0400
565 * @tc.name: GetInterfaceByType
566 * @tc.desc: Test GetInterfaceByType with short type.
567 */
568 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0400, Function | MediumTest | Level3)
569 {
570 const std::string value = "123";
571 sptr<IInterface> shortObj =
572 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_SHORT, value);
573 EXPECT_EQ(Short::Unbox(IShort::Query(shortObj)), 123);
574 }
575
576 /**
577 * @tc.number: DistributedWantParams_GetInterfaceByType_0500
578 * @tc.name: GetInterfaceByType
579 * @tc.desc: Test GetInterfaceByType with integer type.
580 */
581 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0500, Function | MediumTest | Level3)
582 {
583 const std::string value = "-1";
584 sptr<IInterface> intObj = DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_INT, value);
585 EXPECT_EQ(Integer::Unbox(IInteger::Query(intObj)), -1);
586 }
587
588 /**
589 * @tc.number: DistributedWantParams_GetInterfaceByType_0600
590 * @tc.name: GetInterfaceByType
591 * @tc.desc: Test GetInterfaceByType with long type.
592 */
593 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0600, Function | MediumTest | Level3)
594 {
595 const std::string value = "-1";
596 sptr<IInterface> longObj =
597 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_LONG, value);
598 EXPECT_EQ(Long::Unbox(ILong::Query(longObj)), -1);
599 }
600
601 /**
602 * @tc.number: DistributedWantParams_GetInterfaceByType_0700
603 * @tc.name: GetInterfaceByType
604 * @tc.desc: Test GetInterfaceByType with float type.
605 */
606 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0700, Function | MediumTest | Level3)
607 {
608 const std::string value = "-1.0004";
609 sptr<IInterface> floatObj =
610 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_FLOAT, value);
611 EXPECT_FLOAT_EQ(Float::Unbox(IFloat::Query(floatObj)), -1.0004);
612 }
613
614 /**
615 * @tc.number: DistributedWantParams_GetInterfaceByType_0800
616 * @tc.name: GetInterfaceByType
617 * @tc.desc: Test GetInterfaceByType with double type.
618 */
619 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0800, Function | MediumTest | Level3)
620 {
621 const std::string value = "-1.00000004";
622 sptr<IInterface> doubleObj =
623 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_DOUBLE, value);
624 EXPECT_DOUBLE_EQ(Double::Unbox(IDouble::Query(doubleObj)), -1.00000004);
625 }
626
627 /**
628 * @tc.number: DistributedWantParams_GetInterfaceByType_0900
629 * @tc.name: GetInterfaceByType
630 * @tc.desc: Test GetInterfaceByType with string type.
631 */
632 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_0900, Function | MediumTest | Level3)
633 {
634 const std::string value = "hello";
635 sptr<IInterface> stringObj =
636 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_STRING, value);
637 EXPECT_EQ(String::Unbox(IString::Query(stringObj)), std::string("hello"));
638 }
639
640 /**
641 * @tc.number: DistributedWantParams_GetInterfaceByType_1000
642 * @tc.name: GetInterfaceByType
643 * @tc.desc: Test GetInterfaceByType with array type.
644 */
645 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_1000, Function | MediumTest | Level3)
646 {
647 const std::string value = "I5{2,3,5,7,11}";
648 sptr<IInterface> interfaceObj =
649 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_ARRAY, value);
650 Array* arrayObj = static_cast<Array *>(IArray::Query(interfaceObj));
651 sptr<IInterface> valueObj;
652 arrayObj->Get(0, valueObj);
653 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 2);
654 arrayObj->Get(1, valueObj);
655 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 3);
656 arrayObj->Get(2, valueObj);
657 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 5);
658 arrayObj->Get(3, valueObj);
659 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 7);
660 arrayObj->Get(4, valueObj);
661 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 11);
662 }
663
664 /**
665 * @tc.number: DistributedWantParams_GetInterfaceByType_1100
666 * @tc.name: GetInterfaceByType
667 * @tc.desc: Test GetInterfaceByType with invalid type.
668 */
669 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_GetInterfaceByType_1100, Function | MediumTest | Level3)
670 {
671 const std::string value = "123";
672 sptr<IInterface> arrayObj =
673 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_NULL, value);
674 EXPECT_EQ(arrayObj, nullptr);
675 }
676
677 /**
678 * @tc.number: DistributedWantParams_CompareInterface_0100
679 * @tc.name: CompareInterface
680 * @tc.desc: Test CompareInterface with bool type.
681 */
682 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0100, Function | MediumTest | Level3)
683 {
684 const std::string value = "true";
685 sptr<IInterface> interfaceObj =
686 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BOOLEAN, value);
687 bool result =
688 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_BOOLEAN);
689 EXPECT_TRUE(result);
690 }
691
692 /**
693 * @tc.number: DistributedWantParams_CompareInterface_0200
694 * @tc.name: CompareInterface
695 * @tc.desc: Test CompareInterface with byte type.
696 */
697 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0200, Function | MediumTest | Level3)
698 {
699 const std::string value = "129";
700 sptr<IInterface> interfaceObj =
701 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_BYTE, value);
702 bool result =
703 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_BYTE);
704 EXPECT_TRUE(result);
705 }
706
707 /**
708 * @tc.number: DistributedWantParams_CompareInterface_0300
709 * @tc.name: CompareInterface
710 * @tc.desc: Test CompareInterface with char type.
711 */
712 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0300, Function | MediumTest | Level3)
713 {
714 const std::string value = "I";
715 sptr<IInterface> interfaceObj =
716 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_CHAR, value);
717 bool result =
718 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_CHAR);
719 EXPECT_TRUE(result);
720 }
721
722 /**
723 * @tc.number: DistributedWantParams_CompareInterface_0400
724 * @tc.name: CompareInterface
725 * @tc.desc: Test CompareInterface with short type.
726 */
727 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0400, Function | MediumTest | Level3)
728 {
729 const std::string value = "123";
730 sptr<IInterface> interfaceObj =
731 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_SHORT, value);
732 bool result =
733 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_SHORT);
734 EXPECT_TRUE(result);
735 }
736
737 /**
738 * @tc.number: DistributedWantParams_CompareInterface_0500
739 * @tc.name: CompareInterface
740 * @tc.desc: Test CompareInterface with integer type.
741 */
742 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0500, Function | MediumTest | Level3)
743 {
744 const std::string value = "-1";
745 sptr<IInterface> interfaceObj =
746 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_INT, value);
747 bool result =
748 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_INT);
749 EXPECT_TRUE(result);
750 }
751
752 /**
753 * @tc.number: DistributedWantParams_CompareInterface_0600
754 * @tc.name: CompareInterface
755 * @tc.desc: Test CompareInterface with long type.
756 */
757 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0600, Function | MediumTest | Level3)
758 {
759 const std::string value = "-1";
760 sptr<IInterface> interfaceObj =
761 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_LONG, value);
762 bool result =
763 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_LONG);
764 EXPECT_TRUE(result);
765 }
766
767 /**
768 * @tc.number: DistributedWantParams_CompareInterface_0700
769 * @tc.name: CompareInterface
770 * @tc.desc: Test CompareInterface with float type.
771 */
772 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0700, Function | MediumTest | Level3)
773 {
774 const std::string value = "-1.0004";
775 sptr<IInterface> interfaceObj =
776 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_FLOAT, value);
777 bool result =
778 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_FLOAT);
779 EXPECT_TRUE(result);
780 }
781
782 /**
783 * @tc.number: DistributedWantParams_CompareInterface_0800
784 * @tc.name: CompareInterface
785 * @tc.desc: Test CompareInterface with double type.
786 */
787 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0800, Function | MediumTest | Level3)
788 {
789 const std::string value = "-1.00000004";
790 sptr<IInterface> interfaceObj =
791 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_DOUBLE, value);
792 bool result =
793 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_DOUBLE);
794 EXPECT_TRUE(result);
795 }
796
797 /**
798 * @tc.number: DistributedWantParams_CompareInterface_0900
799 * @tc.name: CompareInterface
800 * @tc.desc: Test CompareInterface with string type.
801 */
802 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_0900, Function | MediumTest | Level3)
803 {
804 const std::string value = "hello";
805 sptr<IInterface> interfaceObj =
806 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_STRING, value);
807 bool result =
808 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_STRING);
809 EXPECT_TRUE(result);
810 }
811
812 /**
813 * @tc.number: DistributedWantParams_CompareInterface_1000
814 * @tc.name: CompareInterface
815 * @tc.desc: Test CompareInterface with array type.
816 */
817 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_1000, Function | MediumTest | Level3)
818 {
819 const std::string value = "I5{2,3,5,7,11}";
820 sptr<IInterface> interfaceObj =
821 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_ARRAY, value);
822 bool result =
823 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_ARRAY);
824 EXPECT_TRUE(result);
825 }
826
827 /**
828 * @tc.number: DistributedWantParams_WriteArrayToParStr_0100
829 * @tc.name: WriteArrayToParcelString
830 * @tc.desc: Test WriteArrayToParcelString string content.
831 */
832 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParStr_0100, Function | MediumTest | Level3)
833 {
834 Parcel parcel;
835 DistributedWantParams wp;
836 bool result = wp.WriteArrayToParcelString(parcel, nullptr);
837 EXPECT_FALSE(result);
838 }
839
840 /**
841 * @tc.number: DistributedWantParams_WriteArrayToParBo_0100
842 * @tc.name: WriteArrayToParcelBool
843 * @tc.desc: Test WriteArrayToParcelBool bool content.
844 */
845 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParBo_0100, Function | MediumTest | Level3)
846 {
847 Parcel parcel;
848 DistributedWantParams wp;
849 bool result = wp.WriteArrayToParcelBool(parcel, nullptr);
850 EXPECT_FALSE(result);
851 }
852
853 /**
854 * @tc.number: DistributedWantParams_WriteArrayToParBy_0100
855 * @tc.name: WriteArrayToParcelByte
856 * @tc.desc: Test WriteArrayToParcelByte byte content.
857 */
858 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParBy_0100, Function | MediumTest | Level3)
859 {
860 Parcel parcel;
861 DistributedWantParams wp;
862 bool result = wp.WriteArrayToParcelByte(parcel, nullptr);
863 EXPECT_FALSE(result);
864 }
865
866 /**
867 * @tc.number: DistributedWantParams_WriteArrayToParCh_0100
868 * @tc.name: WriteArrayToParcelChar
869 * @tc.desc: Test WriteArrayToParcelChar char content.
870 */
871 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParCh_0100, Function | MediumTest | Level3)
872 {
873 Parcel parcel;
874 DistributedWantParams wp;
875 bool result = wp.WriteArrayToParcelChar(parcel, nullptr);
876 EXPECT_FALSE(result);
877 }
878
879 /**
880 * @tc.number: DistributedWantParams_WriteArrayToParSho_0100
881 * @tc.name: WriteArrayToParcelShort
882 * @tc.desc: Test WriteArrayToParcelShort short content.
883 */
884 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParSho_0100, Function | MediumTest | Level3)
885 {
886 Parcel parcel;
887 DistributedWantParams wp;
888 bool result = wp.WriteArrayToParcelShort(parcel, nullptr);
889 EXPECT_FALSE(result);
890 }
891
892 /**
893 * @tc.number: DistributedWantParams_WriteArrayToParInt_0100
894 * @tc.name: WriteArrayToParcelInt
895 * @tc.desc: Test WriteArrayToParcelInt int content.
896 */
897 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParInt_0100, Function | MediumTest | Level3)
898 {
899 Parcel parcel;
900 DistributedWantParams wp;
901 bool result = wp.WriteArrayToParcelInt(parcel, nullptr);
902 EXPECT_FALSE(result);
903 }
904
905 /**
906 * @tc.number: DistributedWantParams_WriteArrayToParLo_0100
907 * @tc.name: WriteArrayToParcelLong
908 * @tc.desc: Test WriteArrayToParcelLong long content.
909 */
910 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParLo_0100, Function | MediumTest | Level3)
911 {
912 Parcel parcel;
913 DistributedWantParams wp;
914 bool result = wp.WriteArrayToParcelLong(parcel, nullptr);
915 EXPECT_FALSE(result);
916 }
917
918 /**
919 * @tc.number: DistributedWantParams_WriteArrayToParFl_0100
920 * @tc.name: WriteArrayToParcelFloat
921 * @tc.desc: Test WriteArrayToParcelFloat float content.
922 */
923 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParFl_0100, Function | MediumTest | Level3)
924 {
925 Parcel parcel;
926 DistributedWantParams wp;
927 bool result = wp.WriteArrayToParcelFloat(parcel, nullptr);
928 EXPECT_FALSE(result);
929 }
930
931 /**
932 * @tc.number: DistributedWantParams_WriteArrayToParDou_0100
933 * @tc.name: WriteArrayToParcelDouble
934 * @tc.desc: Test WriteArrayToParcelDouble double content.
935 */
936 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_WriteArrayToParDou_0100, Function | MediumTest | Level3)
937 {
938 Parcel parcel;
939 DistributedWantParams wp;
940 bool result = wp.WriteArrayToParcelDouble(parcel, nullptr);
941 EXPECT_FALSE(result);
942 }
943
944 class DistributedUnsupportedDataTest : public testing::Test {
945 public:
DistributedUnsupportedDataTest()946 DistributedUnsupportedDataTest()
947 {}
~DistributedUnsupportedDataTest()948 ~DistributedUnsupportedDataTest()
949 {
950 }
951 static void SetUpTestCase(void);
952 static void TearDownTestCase(void);
953 void SetUp();
954 void TearDown();
955
956 std::shared_ptr<DistributedUnsupportedData> unsupportedData_ = nullptr;
957 };
958
SetUpTestCase(void)959 void DistributedUnsupportedDataTest::SetUpTestCase(void)
960 {}
961
TearDownTestCase(void)962 void DistributedUnsupportedDataTest::TearDownTestCase(void)
963 {}
964
SetUp(void)965 void DistributedUnsupportedDataTest::SetUp(void)
966 {
967 unsupportedData_ = std::make_shared<DistributedUnsupportedData>();
968 }
969
TearDown(void)970 void DistributedUnsupportedDataTest::TearDown(void)
971 {
972 }
973
974 /**
975 * @tc.number: DistributedWantParams_ReadArrayToParcel_1000
976 * @tc.name: ReadArrayToParcel
977 * @tc.desc: Test ReadArrayToParcel.
978 * @tc.require: issueI648W6
979 */
980 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_ReadArrayToParcel_1000, Function | MediumTest | Level3)
981 {
982 DistributedWantParams wantParams;
983 Parcel parcel;
984 int type = 1;
985 sptr<IArray> destAO = nullptr;
986 bool result = wantParams.ReadArrayToParcel(parcel, type, destAO);
987 EXPECT_EQ(result, true);
988 }
989
990 /**
991 * @tc.number: DistributedWantParams_ReadUnsupportedData_1000
992 * @tc.name: ReadUnsupportedData
993 * @tc.desc: Test ReadUnsupportedData.
994 * @tc.require: issueI648W6
995 */
996 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_ReadUnsupportedData_1000, Function | MediumTest | Level3)
997 {
998 DistributedWantParams wantParams;
999 Parcel parcel;
1000 std::string key = "this is key";
1001 int type = 1;
1002 bool result = wantParams.ReadUnsupportedData(parcel, key, type);
1003 EXPECT_EQ(result, false);
1004
1005 parcel.WriteInt32(-1);
1006 bool result1 = wantParams.ReadUnsupportedData(parcel, key, type);
1007 EXPECT_EQ(result1, false);
1008
1009 int type1 = 50;
1010 bool result2 = wantParams.ReadFromParcelParam(parcel, key, type1);
1011 EXPECT_EQ(result2, false);
1012 }
1013
1014 /**
1015 * @tc.number: DistributedWantParams_Operator_1000
1016 * @tc.name: Operator
1017 * @tc.desc: Test Operator.
1018 * @tc.require: I77HFZ
1019 */
1020 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Operator_1000, Function | MediumTest | Level3)
1021 {
1022 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_Operator_1000 begin" << std::endl;
1023 DistributedWantParams wantParams1;
1024 DistributedWantParams wantParams2;
1025 int32_t typeId = DistributedWantParams::VALUE_TYPE_WANTPARAMS;
1026 DistributedWantParams ret = (wantParams1 = wantParams2);
1027 EXPECT_EQ(typeId, DistributedWantParams::VALUE_TYPE_WANTPARAMS);
1028 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_Operator_1000 end" << std::endl;
1029 }
1030
1031 /**
1032 * @tc.number: DistributedWantParams_Operator_2000
1033 * @tc.name: Operator
1034 * @tc.desc: Test Operator.
1035 * @tc.require: I77HFZ
1036 */
1037 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Operator_2000, Function | MediumTest | Level3)
1038 {
1039 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_Operator_2000 begin" << std::endl;
1040 DistributedWantParams wantParams1;
1041 const DistributedWantParams wantParams2;
1042 int32_t typeId = DistributedWantParams::VALUE_TYPE_WANTPARAMS;
1043 DistributedWantParams ret = (wantParams1 = wantParams2);
1044 EXPECT_EQ(typeId, DistributedWantParams::VALUE_TYPE_WANTPARAMS);
1045 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_Operator_2000 end" << std::endl;
1046 }
1047
1048 /**
1049 * @tc.number: DistributedWantParams_Operator_3000
1050 * @tc.name: Operator
1051 * @tc.desc: Test Operator.
1052 * @tc.require: I77HFZ
1053 */
1054 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Operator_3000, Function | MediumTest | Level3)
1055 {
1056 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_Operator_3000 begin" << std::endl;
1057 DistributedUnsupportedData data1;
1058 const DistributedUnsupportedData data2;
1059 int32_t typeId = DistributedWantParams::VALUE_TYPE_WANTPARAMS;
1060 DistributedUnsupportedData ret = (data1 = data2);
1061 EXPECT_EQ(typeId, DistributedWantParams::VALUE_TYPE_WANTPARAMS);
1062 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_Operator_3000 end" << std::endl;
1063 }
1064
1065 /**
1066 * @tc.number: DistributedWantParams_CompareInterface_1200
1067 * @tc.name: CompareInterface
1068 * @tc.desc: Test CompareInterface.
1069 * @tc.require: I77HFZ
1070 */
1071 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_CompareInterface_1200, Function | MediumTest | Level3)
1072 {
1073 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_CompareInterface_1200 begin" << std::endl;
1074 const std::string value = "wantParam";
1075 sptr<IInterface> interfaceObj =
1076 DistributedWantParams::GetInterfaceByType(DistributedWantParams::VALUE_TYPE_NULL, value);
1077 bool result =
1078 DistributedWantParams::CompareInterface(interfaceObj, interfaceObj, DistributedWantParams::VALUE_TYPE_NULL);
1079 EXPECT_FALSE(result);
1080 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_CompareInterface_1200 end" << std::endl;
1081 }
1082
1083 /**
1084 * @tc.number: DistributedWantParams_remove_0100
1085 * @tc.name: remove
1086 * @tc.desc: Test remove.
1087 * @tc.require: I77HFZ
1088 */
1089 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_remove_0100, Function | MediumTest | Level3)
1090 {
1091 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_remove_0100 begin" << std::endl;
1092 distributedWantParams_->params_["hello"] = String::Box("World");
1093 distributedWantParams_->Remove("hello");
1094 distributedWantParams_->params_.clear();
1095 EXPECT_TRUE(distributedWantParams_->params_.empty());
1096 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_remove_0100 end" << std::endl;
1097 }
1098
1099 /**
1100 * @tc.number: DistributedWantParams_IsEmpty_0100
1101 * @tc.name: IsEmpty
1102 * @tc.desc: Test IsEmpty.
1103 * @tc.require: I77HFZ
1104 */
1105 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_IsEmpty_0100, Function | MediumTest | Level3)
1106 {
1107 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_IsEmpty_0100 begin" << std::endl;
1108 distributedWantParams_->params_.clear();
1109 EXPECT_TRUE(distributedWantParams_->IsEmpty());
1110 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_IsEmpty_0100 end" << std::endl;
1111 }
1112
1113 /**
1114 * @tc.number: DistributedWantParams_DoMarshalling_0100
1115 * @tc.name: DoMarshalling
1116 * @tc.desc: Test DoMarshalling.
1117 * @tc.require: I77HFZ
1118 */
1119 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_DoMarshalling_0100, Function | MediumTest | Level3)
1120 {
1121 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_DoMarshalling_0100 begin" << std::endl;
1122 DistributedUnsupportedData data;
1123 distributedWantParams_->cachedUnsupportedData_.emplace_back(std::move(data));
1124 Parcel tempParcel;
1125 bool result = wantParamsIn_->DoMarshalling(tempParcel);
1126 distributedWantParams_->cachedUnsupportedData_.clear();
1127 EXPECT_TRUE(result);
1128 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_DoMarshalling_0100 end" << std::endl;
1129 }
1130
1131
1132 /**
1133 * @tc.number: DistributedWantParams_ReadUnsupportedData_1100
1134 * @tc.name: ReadUnsupportedData
1135 * @tc.desc: Test ReadUnsupportedData.
1136 * @tc.require: I77HFZ
1137 */
1138 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_ReadUnsupportedData_1100, Function | MediumTest | Level3)
1139 {
1140 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_ReadUnsupportedData_1100 begin" << std::endl;
1141 DistributedWantParams wantParams;
1142 Parcel parcel;
1143 std::string key = "this is key";
1144 int type = 1;
1145 parcel.WriteInt32(0);
1146 bool result = wantParams.ReadUnsupportedData(parcel, key, type);
1147 EXPECT_FALSE(result);
1148
1149 int bufferSize = 1;
1150 parcel.WriteInt32(bufferSize);
1151 parcel.WriteInt32(0);
1152 bool result2 = wantParams.ReadUnsupportedData(parcel, key, type);
1153 EXPECT_FALSE(result2);
1154 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_ReadUnsupportedData_1100 end" << std::endl;
1155 }
1156
1157 /**
1158 * @tc.number: DistributedWantParams_ReadFromParcelParam_1000
1159 * @tc.name: ReadFromParcelParam
1160 * @tc.desc: Test ReadFromParcelParam.
1161 * @tc.require: I77HFZ
1162 */
1163 HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_ReadFromParcelParam_1000, Function | MediumTest | Level3)
1164 {
1165 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_ReadFromParcelParam_1000 begin" << std::endl;
1166 DistributedWantParams wantParams;
1167 Parcel parcel;
1168 std::string key = "this is key";
1169 int type = 51;
1170 int bufferSize = 1;
1171 parcel.WriteInt32(bufferSize);
1172 parcel.WriteInt32(0);
1173 bool result = wantParams.ReadFromParcelParam(parcel, key, type);
1174 EXPECT_TRUE(result);
1175 DTEST_LOG << "DistributedWantParamsBaseTest DistributedWantParams_ReadFromParcelParam_1000 end" << std::endl;
1176 }