1 /*
2 * Copyright (c) 2021-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 <gtest/gtest.h>
17
18 #define private public
19 #define protected public
20 #include "array_wrapper.h"
21 #include "base_obj.h"
22 #include "bool_wrapper.h"
23 #include "byte_wrapper.h"
24 #include "double_wrapper.h"
25 #include "float_wrapper.h"
26 #include "int_wrapper.h"
27 #include "long_wrapper.h"
28 #include "short_wrapper.h"
29 #include "string_wrapper.h"
30 #include "want_params.h"
31 #include "want_params_wrapper.h"
32 #include "zchar_wrapper.h"
33 #undef private
34 #undef protected
35
36 using namespace testing::ext;
37 using namespace OHOS::AAFwk;
38 using OHOS::Parcel;
39
40 namespace OHOS {
41 namespace AAFwk {
42 class WantParamsBaseTest : public testing::Test {
43 public:
WantParamsBaseTest()44 WantParamsBaseTest()
45 {}
~WantParamsBaseTest()46 ~WantParamsBaseTest()
47 {
48 }
49 static void SetUpTestCase(void);
50 static void TearDownTestCase(void);
51 void SetUp();
52 void TearDown();
53
54 std::shared_ptr<WantParams> wantParamsIn_ = nullptr;
55 std::shared_ptr<WantParams> wantParamsOut_ = nullptr;
56 };
57
SetUpTestCase(void)58 void WantParamsBaseTest::SetUpTestCase(void)
59 {}
60
TearDownTestCase(void)61 void WantParamsBaseTest::TearDownTestCase(void)
62 {}
63
SetUp(void)64 void WantParamsBaseTest::SetUp(void)
65 {
66 wantParamsIn_ = std::make_shared<WantParams>();
67 wantParamsOut_ = std::make_shared<WantParams>();
68 }
69
TearDown(void)70 void WantParamsBaseTest::TearDown(void)
71 {
72 }
73
74 /**
75 * @tc.number: AaFwk_WantParams_Parcelable_0100
76 * @tc.name: Marshalling/Unmarshalling
77 * @tc.desc: marshalling WantParams, and then check result.
78 */
79 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0100, Function | MediumTest | Level1)
80 {
81 std::string keyStr = "12345667";
82 std::string valueStr = "sdasdfdsffdgfdg";
83 wantParamsIn_->SetParam(keyStr, String::Box(valueStr));
84
85 Parcel in;
86 if (wantParamsOut_ != nullptr) {
87 wantParamsIn_->Marshalling(in);
88 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
89 EXPECT_EQ(valueStr, String::Unbox(IString::Query(wantParamsOut_->GetParam(keyStr))));
90 }
91 }
92
93 /**
94 * @tc.number: AaFwk_WantParams_Parcelable_0200
95 * @tc.name: Marshalling/Unmarshalling
96 * @tc.desc: marshalling WantParams, and then check result.
97 */
98 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0200, Function | MediumTest | Level1)
99 {
100 std::string keyStr = "12345667";
101 bool valueBool = true;
102 wantParamsIn_->SetParam(keyStr, Boolean::Box(valueBool));
103
104 Parcel in;
105 if (wantParamsOut_ != nullptr) {
106 wantParamsIn_->Marshalling(in);
107 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
108 EXPECT_EQ(valueBool, Boolean::Unbox(IBoolean::Query(wantParamsOut_->GetParam(keyStr))));
109 }
110 }
111
112 /**
113 * @tc.number: AaFwk_WantParams_Parcelable_0300
114 * @tc.name: Marshalling/Unmarshalling
115 * @tc.desc: marshalling WantParams, and then check result.
116 */
117 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0300, Function | MediumTest | Level1)
118 {
119 std::string keyStr = "12345667";
120 int valueInteger = 12345;
121 wantParamsIn_->SetParam(keyStr, Integer::Box(valueInteger));
122 int right = Integer::Unbox(IInteger::Query(wantParamsIn_->GetParam(keyStr)));
123
124 Parcel in;
125 wantParamsIn_->Marshalling(in);
126 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
127 if (wantParamsOut_ != nullptr) {
128 right = Integer::Unbox(IInteger::Query(wantParamsOut_->GetParam(keyStr)));
129 EXPECT_EQ(valueInteger, right);
130
131 wantParamsOut_ = nullptr;
132 }
133 }
134
135 /**
136 * @tc.number: AaFwk_WantParams_Parcelable_0400
137 * @tc.name: Marshalling/Unmarshalling
138 * @tc.desc: marshalling WantParams, and then check result.
139 */
140 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0400, Function | MediumTest | Level1)
141 {
142 std::string keyStr = "12345667";
143 long valueLong = 1234567;
144 wantParamsIn_->SetParam(keyStr, Long::Box(valueLong));
145
146 Parcel in;
147 wantParamsIn_->Marshalling(in);
148 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
149 long retLong = Long::Unbox(ILong::Query(wantParamsOut_->GetParam(keyStr)));
150 EXPECT_EQ(retLong, valueLong);
151 }
152
153 /**
154 * @tc.number: AaFwk_WantParams_Parcelable_0500
155 * @tc.name: Marshalling/Unmarshalling
156 * @tc.desc: marshalling nested WantParams inside array, and then check result.
157 */
158 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0500, Function | MediumTest | Level1)
159 {
160 sptr<AAFwk::IArray> ao = new (std::nothrow) AAFwk::Array(2, AAFwk::g_IID_IWantParams);
161 for (size_t i = 0; i < 2; i++) {
162 WantParams wp;
163 wp.SetParam("hello", String::Box("World"));
164 ao->Set(i, AAFwk::WantParamWrapper::Box(wp));
165 }
166 WantParams l1;
167 l1.SetParam("l1", ao);
168 WantParams l2;
169 l2.SetParam("l2", AAFwk::WantParamWrapper::Box(l1));
170 wantParamsIn_->SetParam("l3", AAFwk::WantParamWrapper::Box(l2));
171 wantParamsIn_->DumpInfo(0);
172
173 Parcel in;
174 wantParamsIn_->Marshalling(in);
175 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
176 wantParamsOut_->DumpInfo(0);
177
178 WantParams l2Out = WantParamWrapper::Unbox(IWantParams::Query(wantParamsOut_->GetParam("l3")));
179 WantParams l1Out = WantParamWrapper::Unbox(IWantParams::Query(l2Out.GetParam("l2")));
180
181 IArray *aoOut = IArray::Query(l1Out.GetParam("l1"));
182 long size;
183 aoOut->GetLength(size);
184 EXPECT_EQ(size, 2);
185 sptr<IInterface> ww0;
186 sptr<IInterface> ww1;
187 aoOut->Get(0, ww0);
188 aoOut->Get(1, ww1);
189
190 WantParams wp0 = WantParamWrapper::Unbox(static_cast<IWantParams *>(ww0->Query(g_IID_IWantParams)));
191 WantParams wp1 = WantParamWrapper::Unbox(static_cast<IWantParams *>(ww1->Query(g_IID_IWantParams)));
192
193 std::string hello0(String::Unbox(IString::Query(wp0.GetParam("hello"))));
194 EXPECT_EQ(hello0, "World");
195 std::string hello1(String::Unbox(IString::Query(wp1.GetParam("hello"))));
196 EXPECT_EQ(hello1, "World");
197 }
198
199 /**
200 * @tc.number: AaFwk_WantParams_Parcelable_0600
201 * @tc.name: Marshalling/Unmarshalling
202 * @tc.desc: marshalling nested WantParams, and then check result.
203 */
204 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0600, Function | MediumTest | Level1)
205 {
206 WantParams wp;
207
208 wp.SetParam("hello", String::Box("World"));
209 wp.SetParam("welcome", String::Box("NY"));
210
211 WantParams l1;
212 l1.SetParam("l1", AAFwk::WantParamWrapper::Box(wp));
213 wantParamsIn_->SetParam("l2", AAFwk::WantParamWrapper::Box(l1));
214 wantParamsIn_->DumpInfo(0);
215 Parcel in;
216 wantParamsIn_->Marshalling(in);
217 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
218 wantParamsOut_->DumpInfo(0);
219 WantParams l1Out = WantParamWrapper::Unbox(IWantParams::Query(wantParamsOut_->GetParam("l2")));
220 WantParams wpOut = WantParamWrapper::Unbox(IWantParams::Query(l1.GetParam("l1")));
221 std::string hello(String::Unbox(IString::Query(wpOut.GetParam("hello"))));
222 EXPECT_EQ(hello, "World");
223 std::string welcome(String::Unbox(IString::Query(wpOut.GetParam("welcome"))));
224 EXPECT_EQ(welcome, "NY");
225 }
226
227 /**
228 * @tc.number: AaFwk_WantParams_Parcelable_0700
229 * @tc.name: Marshalling/Unmarshalling
230 * @tc.desc: marshalling array, and then check result.
231 */
232 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0700, Function | MediumTest | Level1)
233 {
234 sptr<AAFwk::IArray> ao = new (std::nothrow) AAFwk::Array(2, AAFwk::g_IID_IString);
235
236 std::string valueStr0 = "TestValue0";
237 ao->Set(0, String::Box(valueStr0));
238 std::string valueStr1 = "TestValue1";
239 ao->Set(1, String::Box(valueStr1));
240
241 WantParams l1;
242 l1.SetParam("l1", ao);
243 wantParamsIn_->SetParam("l2", AAFwk::WantParamWrapper::Box(l1));
244 wantParamsIn_->DumpInfo(0);
245
246 Parcel in;
247 wantParamsIn_->Marshalling(in);
248 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
249 wantParamsOut_->DumpInfo(0);
250
251 WantParams l1Out = WantParamWrapper::Unbox(IWantParams::Query(wantParamsOut_->GetParam("l2")));
252 IArray *aoOut = IArray::Query(l1Out.GetParam("l1"));
253
254 long size;
255 aoOut->GetLength(size);
256 EXPECT_EQ(size, 2);
257 sptr<IInterface> str0;
258 sptr<IInterface> str1;
259 aoOut->Get(0, str0);
260 aoOut->Get(1, str1);
261
262 EXPECT_EQ(valueStr0, String::Unbox(IString::Query(str0)));
263 EXPECT_EQ(valueStr1, String::Unbox(IString::Query(str1)));
264 }
265 /**
266 * @brief Helper function to generate a wantParam with desired nested depth.
267 * @param depth the desired depth.
268 */
MaliciousRecursionGenerator(int depth)269 WantParams MaliciousRecursionGenerator(int depth)
270 {
271 WantParams wp;
272 if (depth <= 1) {
273 wp.SetParam("hello", String::Box("World"));
274 wp.SetParam("welcome", String::Box("NY"));
275 return wp;
276 } else {
277 wp.SetParam(std::to_string(depth), AAFwk::WantParamWrapper::Box(MaliciousRecursionGenerator(depth-1)));
278 }
279 return wp;
280 }
281
282 /**
283 * @tc.number: AaFwk_WantParams_Parcelable_0800
284 * @tc.name: Marshalling/Unmarshalling
285 * @tc.desc: Test within the recursion depth limits when marshalling with nested wantParam.
286 */
287 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0800, Function | MediumTest | Level1)
288 {
289 WantParams wp = MaliciousRecursionGenerator(98);
290 wantParamsIn_->SetParam("l99", AAFwk::WantParamWrapper::Box(wp));
291 Parcel in;
292 EXPECT_EQ(wantParamsIn_->Marshalling(in), true);
293 }
294
295 /**
296 * @tc.number: AaFwk_WantParams_Parcelable_0900
297 * @tc.name: Marshalling/Unmarshalling
298 * @tc.desc: Test exceeding the recursion depth limits when marshalling with nested wantParam.
299 */
300 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0900, Function | MediumTest | Level1)
301 {
302 WantParams wp = MaliciousRecursionGenerator(99);
303 wantParamsIn_->SetParam("l100", AAFwk::WantParamWrapper::Box(wp));
304 Parcel in;
305 EXPECT_EQ(wantParamsIn_->Marshalling(in), false);
306 }
307
308 /**
309 * @tc.number: AaFwk_WantParams_Parcelable_1000
310 * @tc.name: Marshalling/Unmarshalling
311 * @tc.desc: Test exceeding the recursion depth limits when marshalling with nested wantParam.
312 */
313 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_1000, Function | MediumTest | Level1)
314 {
315 WantParams wp = MaliciousRecursionGenerator(100);
316 wantParamsIn_->SetParam("l101", AAFwk::WantParamWrapper::Box(wp));
317 Parcel in;
318 EXPECT_EQ(wantParamsIn_->Marshalling(in), false);
319 }
320
321 /**
322 * @tc.number: AaFwk_WantParams_Parcelable_1100
323 * @tc.name: DeepCopy
324 * @tc.desc: Test copy constructor of wantParam uses DeepCopy.
325 */
326 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_1100, Function | MediumTest | Level1)
327 {
328 WantParams wp = MaliciousRecursionGenerator(0);
329 sptr<IWantParams> wrapper = AAFwk::WantParamWrapper::Box(wp);
330 WantParams wp2;
331 wp2.SetParam("l1", wrapper);
332 // DeepCopy
333 WantParams wp3(wp2);
334 // The wrapper ptr should not be the same.
335 EXPECT_NE(wp3.GetParam("l1"), wp2.GetParam("l1"));
336 // checks if inner values remain the same, wp1 should contain the values in wp
337 WantParams wp1 = WantParamWrapper::Unbox(IWantParams::Query(wp3.GetParam("l1")));
338 EXPECT_EQ(String::Unbox(IString::Query(wp1.GetParam("hello"))), "World");
339 }
340
341 /**
342 * @tc.number: AaFwk_WantParams_GetStringByType_0100
343 * @tc.name: GetStringByType
344 * @tc.desc: Test get string with invalid type in the WantParam.
345 */
346 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0100, Function | MediumTest | Level1)
347 {
348 WantParams wp = MaliciousRecursionGenerator(0);
349 sptr<IWantParams> wrapper = AAFwk::WantParamWrapper::Box(wp);
350 std::string value = WantParams::GetStringByType(wp.GetParam("l1"), WantParams::VALUE_TYPE_NULL);
351 EXPECT_EQ(value, "");
352 }
353
354 /**
355 * @tc.number: AaFwk_WantParams_GetStringByType_0200
356 * @tc.name: GetStringByType
357 * @tc.desc: Test get bool with invalid type in the WantParam.
358 */
359 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0200, Function | MediumTest | Level1)
360 {
361 const std::string value = "true";
362 sptr<IInterface> boolObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BOOLEAN, value);
363 std::string stringVal = WantParams::GetStringByType(boolObj, WantParams::VALUE_TYPE_BOOLEAN);
364 EXPECT_EQ(stringVal, "true");
365 }
366
367 /**
368 * @tc.number: AaFwk_WantParams_GetStringByType_0300
369 * @tc.name: GetStringByType
370 * @tc.desc: Test get string with invalid type in the WantParam.
371 */
372 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0300, Function | MediumTest | Level1)
373 {
374 const std::string value = "string";
375 sptr<IInterface> stringObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_STRING, value);
376 std::string stringVal = WantParams::GetStringByType(stringObj, WantParams::VALUE_TYPE_STRING);
377 EXPECT_EQ(stringVal, "string");
378 }
379
380 /**
381 * @tc.number: AaFwk_WantParams_GetStringByType_0400
382 * @tc.name: GetStringByType
383 * @tc.desc: Test get byte with invalid type in the WantParam.
384 */
385 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0400, Function | MediumTest | Level1)
386 {
387 const std::string value = "129";
388 sptr<IInterface> byteObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BYTE, value);
389 std::string byteVal = WantParams::GetStringByType(byteObj, WantParams::VALUE_TYPE_BYTE);
390 EXPECT_EQ(byteVal, "129");
391 }
392
393 /**
394 * @tc.number: AaFwk_WantParams_GetStringByType_0500
395 * @tc.name: GetStringByType
396 * @tc.desc: Test get char with invalid type in the WantParam.
397 */
398 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0500, Function | MediumTest | Level1)
399 {
400 const std::string value = "I";
401 sptr<IInterface> charObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_CHAR, value);
402 std::string charVal = WantParams::GetStringByType(charObj, WantParams::VALUE_TYPE_CHAR);
403 EXPECT_EQ(charVal, "I");
404 }
405
406 /**
407 * @tc.number: AaFwk_WantParams_GetStringByType_0600
408 * @tc.name: GetStringByType
409 * @tc.desc: Test get short with invalid type in the WantParam.
410 */
411 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0600, Function | MediumTest | Level1)
412 {
413 const std::string value = "123";
414 sptr<IInterface> shortObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_SHORT, value);
415 std::string shortVal = WantParams::GetStringByType(shortObj, WantParams::VALUE_TYPE_SHORT);
416 EXPECT_EQ(shortVal, "123");
417 }
418
419 /**
420 * @tc.number: AaFwk_WantParams_GetStringByType_0700
421 * @tc.name: GetStringByType
422 * @tc.desc: Test get int with invalid type in the WantParam.
423 */
424 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0700, Function | MediumTest | Level1)
425 {
426 const std::string value = "-1";
427 sptr<IInterface> intObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_INT, value);
428 std::string intVal = WantParams::GetStringByType(intObj, WantParams::VALUE_TYPE_INT);
429 EXPECT_EQ(intVal, "-1");
430 }
431
432 /**
433 * @tc.number: AaFwk_WantParams_GetStringByType_0800
434 * @tc.name: GetStringByType
435 * @tc.desc: Test get long with invalid type in the WantParam.
436 */
437 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0800, Function | MediumTest | Level1)
438 {
439 const std::string value = "-1";
440 sptr<IInterface> longObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_LONG, value);
441 std::string longVal = WantParams::GetStringByType(longObj, WantParams::VALUE_TYPE_LONG);
442 EXPECT_EQ(longVal, "-1");
443 }
444
445 /**
446 * @tc.number: AaFwk_WantParams_GetStringByType_0900
447 * @tc.name: GetStringByType
448 * @tc.desc: Test get float with invalid type in the WantParam.
449 */
450 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_0900, Function | MediumTest | Level1)
451 {
452 const std::string value = "-1.0004";
453 sptr<IInterface> floatObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_FLOAT, value);
454 std::string floatVal = WantParams::GetStringByType(floatObj, WantParams::VALUE_TYPE_FLOAT);
455 EXPECT_EQ(floatVal, "-1.000400");
456 }
457
458 /**
459 * @tc.number: AaFwk_WantParams_GetStringByType_1000
460 * @tc.name: GetStringByType
461 * @tc.desc: Test get float with invalid type in the WantParam.
462 */
463 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_1000, Function | MediumTest | Level1)
464 {
465 const std::string value = "-1.00000004";
466 sptr<IInterface> doubleObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_DOUBLE, value);
467 std::string doubleVal = WantParams::GetStringByType(doubleObj, WantParams::VALUE_TYPE_DOUBLE);
468 EXPECT_EQ(doubleVal, "-1.000000");
469 }
470
471 /**
472 * @tc.number: AaFwk_WantParams_GetStringByType_1100
473 * @tc.name: GetStringByType
474 * @tc.desc: Test get float with invalid type in the WantParam.
475 */
476 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringByType_1100, Function | MediumTest | Level1)
477 {
478 const std::string value = "I5{2,3,5,7,11}";
479 sptr<IInterface> arrayObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_ARRAY, value);
480 std::string arrayVal = WantParams::GetStringByType(arrayObj, WantParams::VALUE_TYPE_ARRAY);
481 EXPECT_EQ(arrayVal, "I5{2,3,5,7,11}");
482 }
483
484 /**
485 * @tc.number: AaFwk_WantParams_NewArrayData_0100
486 * @tc.name: NewArrayData
487 * @tc.desc: Test NewArrayData with invalid sptr<IArray> parameter.
488 */
489 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_NewArrayData_0100, Function | MediumTest | Level1)
490 {
491 sptr<AAFwk::IArray> array = new (std::nothrow) AAFwk::Array(0, AAFwk::g_IID_IWantParams);
492 WantParams wp;
493 wp.SetParam("param1", array);
494 IArray *iarray = IArray::Query(array);
495 sptr<IArray> destAO = nullptr;
496 bool result = wp.NewArrayData(iarray, destAO);
497 EXPECT_FALSE(result);
498 }
499
500 /**
501 * @tc.number: AaFwk_WantParams_GetDataType_0100
502 * @tc.name: GetDataType
503 * @tc.desc: Test GetDataType with invalid parameter.
504 */
505 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0100, Function | MediumTest | Level1)
506 {
507 int type = WantParams::GetDataType(nullptr);
508 EXPECT_EQ(type, WantParams::VALUE_TYPE_NULL);
509 }
510
511 /**
512 * @tc.number: AaFwk_WantParams_GetDataType_0200
513 * @tc.name: GetDataType
514 * @tc.desc: Test GetDataType with bool parameter.
515 */
516 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0200, Function | MediumTest | Level1)
517 {
518 const std::string value = "true";
519 sptr<IInterface> boolObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BOOLEAN, value);
520 int type = WantParams::GetDataType(boolObj);
521 EXPECT_EQ(type, WantParams::VALUE_TYPE_BOOLEAN);
522 }
523
524 /**
525 * @tc.number: AaFwk_WantParams_GetDataType_0300
526 * @tc.name: GetDataType
527 * @tc.desc: Test GetDataType with byte parameter.
528 */
529 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0300, Function | MediumTest | Level1)
530 {
531 const std::string value = "129";
532 sptr<IInterface> byteObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BYTE, value);
533 int type = WantParams::GetDataType(byteObj);
534 EXPECT_EQ(type, WantParams::VALUE_TYPE_BYTE);
535 }
536
537 /**
538 * @tc.number: AaFwk_WantParams_GetDataType_0400
539 * @tc.name: GetDataType
540 * @tc.desc: Test GetDataType with char parameter.
541 */
542 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0400, Function | MediumTest | Level1)
543 {
544 const std::string value = "I";
545 sptr<IInterface> charObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_CHAR, value);
546 int type = WantParams::GetDataType(charObj);
547 EXPECT_EQ(type, WantParams::VALUE_TYPE_CHAR);
548 }
549
550 /**
551 * @tc.number: AaFwk_WantParams_GetDataType_0500
552 * @tc.name: GetDataType
553 * @tc.desc: Test GetDataType with short parameter.
554 */
555 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0500, Function | MediumTest | Level1)
556 {
557 const std::string value = "123";
558 sptr<IInterface> shortObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_SHORT, value);
559 int type = WantParams::GetDataType(shortObj);
560 EXPECT_EQ(type, WantParams::VALUE_TYPE_SHORT);
561 }
562
563 /**
564 * @tc.number: AaFwk_WantParams_GetDataType_0600
565 * @tc.name: GetDataType
566 * @tc.desc: Test GetDataType with int parameter.
567 */
568 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0600, Function | MediumTest | Level1)
569 {
570 const std::string value = "-1";
571 sptr<IInterface> intObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_INT, value);
572 int type = WantParams::GetDataType(intObj);
573 EXPECT_EQ(type, WantParams::VALUE_TYPE_INT);
574 }
575
576 /**
577 * @tc.number: AaFwk_WantParams_GetDataType_0700
578 * @tc.name: GetDataType
579 * @tc.desc: Test GetDataType with long parameter.
580 */
581 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0700, Function | MediumTest | Level1)
582 {
583 const std::string value = "-1";
584 sptr<IInterface> longObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_LONG, "-1");
585 int type = WantParams::GetDataType(longObj);
586 EXPECT_EQ(type, WantParams::VALUE_TYPE_LONG);
587 }
588
589 /**
590 * @tc.number: AaFwk_WantParams_GetDataType_0800
591 * @tc.name: GetDataType
592 * @tc.desc: Test GetDataType with float parameter.
593 */
594 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0800, Function | MediumTest | Level1)
595 {
596 const std::string value = "-1.0004";
597 sptr<IInterface> floatObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_FLOAT, "-1.0004");
598 int type = WantParams::GetDataType(floatObj);
599 EXPECT_EQ(type, WantParams::VALUE_TYPE_FLOAT);
600 }
601
602 /**
603 * @tc.number: AaFwk_WantParams_GetDataType_0900
604 * @tc.name: GetDataType
605 * @tc.desc: Test GetDataType with double parameter.
606 */
607 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_0900, Function | MediumTest | Level1)
608 {
609 const std::string value = "-1.00000004";
610 sptr<IInterface> doubleObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_DOUBLE, "-1.00000004");
611 int type = WantParams::GetDataType(doubleObj);
612 EXPECT_EQ(type, WantParams::VALUE_TYPE_DOUBLE);
613 }
614
615 /**
616 * @tc.number: AaFwk_WantParams_GetDataType_1000
617 * @tc.name: GetDataType
618 * @tc.desc: Test GetDataType with string parameter.
619 */
620 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_1000, Function | MediumTest | Level1)
621 {
622 const std::string value = "hello";
623 sptr<IInterface> stringObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_STRING, "hello");
624 int type = WantParams::GetDataType(stringObj);
625 EXPECT_EQ(type, WantParams::VALUE_TYPE_STRING);
626 }
627
628 /**
629 * @tc.number: AaFwk_WantParams_GetDataType_1100
630 * @tc.name: GetDataType
631 * @tc.desc: Test GetDataType with array parameter.
632 */
633 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetDataType_1100, Function | MediumTest | Level1)
634 {
635 const std::string value = "I5{2,3,5,7,11}";
636 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_ARRAY, value);
637 int type = WantParams::GetDataType(interfaceObj);
638 EXPECT_EQ(type, WantParams::VALUE_TYPE_ARRAY);
639 }
640
641 /**
642 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0100
643 * @tc.name: GetInterfaceByType
644 * @tc.desc: Test GetInterfaceByType with boolean type.
645 */
646 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0100, Function | MediumTest | Level1)
647 {
648 const std::string value = "true";
649 sptr<IInterface> boolObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BOOLEAN, value);
650 EXPECT_TRUE(Boolean::Unbox(IBoolean::Query(boolObj)));
651 }
652
653 /**
654 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0200
655 * @tc.name: GetInterfaceByType
656 * @tc.desc: Test GetInterfaceByType with byte type.
657 */
658 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0200, Function | MediumTest | Level1)
659 {
660 const std::string value = "129";
661 sptr<IInterface> byteObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BYTE, value);
662 EXPECT_EQ(Byte::Unbox(IByte::Query(byteObj)), 129);
663 }
664
665 /**
666 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0300
667 * @tc.name: GetInterfaceByType
668 * @tc.desc: Test GetInterfaceByType with char type.
669 */
670 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0300, Function | MediumTest | Level1)
671 {
672 const std::string value = "I";
673 sptr<IInterface> charObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_CHAR, value);
674 EXPECT_EQ(Char::Unbox(IChar::Query(charObj)), 'I');
675 }
676
677 /**
678 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0400
679 * @tc.name: GetInterfaceByType
680 * @tc.desc: Test GetInterfaceByType with short type.
681 */
682 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0400, Function | MediumTest | Level1)
683 {
684 const std::string value = "123";
685 sptr<IInterface> shortObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_SHORT, value);
686 EXPECT_EQ(Short::Unbox(IShort::Query(shortObj)), 123);
687 }
688
689 /**
690 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0500
691 * @tc.name: GetInterfaceByType
692 * @tc.desc: Test GetInterfaceByType with integer type.
693 */
694 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0500, Function | MediumTest | Level1)
695 {
696 const std::string value = "-1";
697 sptr<IInterface> intObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_INT, value);
698 EXPECT_EQ(Integer::Unbox(IInteger::Query(intObj)), -1);
699 }
700
701 /**
702 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0600
703 * @tc.name: GetInterfaceByType
704 * @tc.desc: Test GetInterfaceByType with long type.
705 */
706 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0600, Function | MediumTest | Level1)
707 {
708 const std::string value = "-1";
709 sptr<IInterface> longObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_LONG, "-1");
710 EXPECT_EQ(Long::Unbox(ILong::Query(longObj)), -1);
711 }
712
713 /**
714 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0700
715 * @tc.name: GetInterfaceByType
716 * @tc.desc: Test GetInterfaceByType with float type.
717 */
718 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0700, Function | MediumTest | Level1)
719 {
720 const std::string value = "-1.0004";
721 sptr<IInterface> floatObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_FLOAT, "-1.0004");
722 EXPECT_FLOAT_EQ(Float::Unbox(IFloat::Query(floatObj)), -1.0004);
723 }
724
725 /**
726 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0800
727 * @tc.name: GetInterfaceByType
728 * @tc.desc: Test GetInterfaceByType with double type.
729 */
730 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0800, Function | MediumTest | Level1)
731 {
732 const std::string value = "-1.00000004";
733 sptr<IInterface> doubleObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_DOUBLE, "-1.00000004");
734 EXPECT_DOUBLE_EQ(Double::Unbox(IDouble::Query(doubleObj)), -1.00000004);
735 }
736
737 /**
738 * @tc.number: AaFwk_WantParams_GetInterfaceByType_0900
739 * @tc.name: GetInterfaceByType
740 * @tc.desc: Test GetInterfaceByType with string type.
741 */
742 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_0900, Function | MediumTest | Level1)
743 {
744 const std::string value = "hello";
745 sptr<IInterface> stringObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_STRING, "hello");
746 EXPECT_EQ(String::Unbox(IString::Query(stringObj)), std::string("hello"));
747 }
748
749 /**
750 * @tc.number: AaFwk_WantParams_GetInterfaceByType_1000
751 * @tc.name: GetInterfaceByType
752 * @tc.desc: Test GetInterfaceByType with array type.
753 */
754 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_1000, Function | MediumTest | Level1)
755 {
756 const std::string value = "I5{2,3,5,7,11}";
757 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_ARRAY, value);
758 Array* arrayObj = static_cast<Array *>(IArray::Query(interfaceObj));
759 sptr<IInterface> valueObj;
760 arrayObj->Get(0, valueObj);
761 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 2);
762 arrayObj->Get(1, valueObj);
763 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 3);
764 arrayObj->Get(2, valueObj);
765 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 5);
766 arrayObj->Get(3, valueObj);
767 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 7);
768 arrayObj->Get(4, valueObj);
769 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 11);
770 }
771
772 /**
773 * @tc.number: AaFwk_WantParams_GetInterfaceByType_1100
774 * @tc.name: GetInterfaceByType
775 * @tc.desc: Test GetInterfaceByType with invalid type.
776 */
777 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetInterfaceByType_1100, Function | MediumTest | Level1)
778 {
779 const std::string value = "123";
780 sptr<IInterface> arrayObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_NULL, value);
781 EXPECT_EQ(arrayObj, nullptr);
782 }
783
784 /**
785 * @tc.number: AaFwk_WantParams_CompareInterface_0100
786 * @tc.name: CompareInterface
787 * @tc.desc: Test CompareInterface with bool type.
788 */
789 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0100, Function | MediumTest | Level1)
790 {
791 const std::string value = "true";
792 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BOOLEAN, value);
793 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_BOOLEAN);
794 EXPECT_TRUE(result);
795 }
796
797 /**
798 * @tc.number: AaFwk_WantParams_CompareInterface_0200
799 * @tc.name: CompareInterface
800 * @tc.desc: Test CompareInterface with byte type.
801 */
802 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0200, Function | MediumTest | Level1)
803 {
804 const std::string value = "129";
805 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_BYTE, value);
806 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_BYTE);
807 EXPECT_TRUE(result);
808 }
809
810 /**
811 * @tc.number: AaFwk_WantParams_CompareInterface_0300
812 * @tc.name: CompareInterface
813 * @tc.desc: Test CompareInterface with char type.
814 */
815 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0300, Function | MediumTest | Level1)
816 {
817 const std::string value = "I";
818 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_CHAR, value);
819 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_CHAR);
820 EXPECT_TRUE(result);
821 }
822
823 /**
824 * @tc.number: AaFwk_WantParams_CompareInterface_0400
825 * @tc.name: CompareInterface
826 * @tc.desc: Test CompareInterface with short type.
827 */
828 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0400, Function | MediumTest | Level1)
829 {
830 const std::string value = "123";
831 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_SHORT, value);
832 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_SHORT);
833 EXPECT_TRUE(result);
834 }
835
836 /**
837 * @tc.number: AaFwk_WantParams_CompareInterface_0500
838 * @tc.name: CompareInterface
839 * @tc.desc: Test CompareInterface with integer type.
840 */
841 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0500, Function | MediumTest | Level1)
842 {
843 const std::string value = "-1";
844 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_INT, value);
845 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_INT);
846 EXPECT_TRUE(result);
847 }
848
849 /**
850 * @tc.number: AaFwk_WantParams_CompareInterface_0600
851 * @tc.name: CompareInterface
852 * @tc.desc: Test CompareInterface with long type.
853 */
854 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0600, Function | MediumTest | Level1)
855 {
856 const std::string value = "-1";
857 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_LONG, "-1");
858 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_LONG);
859 EXPECT_TRUE(result);
860 }
861
862 /**
863 * @tc.number: AaFwk_WantParams_CompareInterface_0700
864 * @tc.name: CompareInterface
865 * @tc.desc: Test CompareInterface with float type.
866 */
867 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0700, Function | MediumTest | Level1)
868 {
869 const std::string value = "-1.0004";
870 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_FLOAT, "-1.0004");
871 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_FLOAT);
872 EXPECT_TRUE(result);
873 }
874
875 /**
876 * @tc.number: AaFwk_WantParams_CompareInterface_0800
877 * @tc.name: CompareInterface
878 * @tc.desc: Test CompareInterface with double type.
879 */
880 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0800, Function | MediumTest | Level1)
881 {
882 const std::string value = "-1.00000004";
883 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_DOUBLE, "-1.00000004");
884 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_DOUBLE);
885 EXPECT_TRUE(result);
886 }
887
888 /**
889 * @tc.number: AaFwk_WantParams_CompareInterface_0900
890 * @tc.name: CompareInterface
891 * @tc.desc: Test CompareInterface with string type.
892 */
893 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_0900, Function | MediumTest | Level1)
894 {
895 const std::string value = "hello";
896 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_STRING, "hello");
897 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_STRING);
898 EXPECT_TRUE(result);
899 }
900
901 /**
902 * @tc.number: AaFwk_WantParams_CompareInterface_1000
903 * @tc.name: CompareInterface
904 * @tc.desc: Test CompareInterface with array type.
905 */
906 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_1000, Function | MediumTest | Level1)
907 {
908 const std::string value = "I5{2,3,5,7,11}";
909 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_ARRAY, value);
910 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, WantParams::VALUE_TYPE_ARRAY);
911 EXPECT_TRUE(result);
912 }
913
914 /**
915 * @tc.number: AaFwk_WantParams_CompareInterface_1002
916 * @tc.name: CompareInterface
917 * @tc.desc: Test CompareInterface with array type.
918 */
919 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_CompareInterface_1002, Function | MediumTest | Level1)
920 {
921 const std::string value = "I5{2,3,5,7,11}";
922 sptr<IInterface> interfaceObj = WantParams::GetInterfaceByType(WantParams::VALUE_TYPE_ARRAY, value);
923 bool result = WantParams::CompareInterface(interfaceObj, interfaceObj, 102);
924 EXPECT_TRUE(result);
925 }
926
927 /**
928 * @tc.number: AaFwk_WantParams_WriteArrayToParcelString_0100
929 * @tc.name: WriteArrayToParcelString
930 * @tc.desc: Test WriteArrayToParcelString string content.
931 */
932 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelString_0100, Function | MediumTest | Level1)
933 {
934 Parcel parcel;
935 WantParams wp;
936 bool result = wp.WriteArrayToParcelString(parcel, nullptr);
937 EXPECT_FALSE(result);
938 }
939
940 /**
941 * @tc.number: AaFwk_WantParams_WriteArrayToParcelBool_0100
942 * @tc.name: WriteArrayToParcelBool
943 * @tc.desc: Test WriteArrayToParcelBool bool content.
944 */
945 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelBool_0100, Function | MediumTest | Level1)
946 {
947 Parcel parcel;
948 WantParams wp;
949 bool result = wp.WriteArrayToParcelBool(parcel, nullptr);
950 EXPECT_FALSE(result);
951 }
952
953 /**
954 * @tc.number: AaFwk_WantParams_WriteArrayToParcelByte_0100
955 * @tc.name: WriteArrayToParcelByte
956 * @tc.desc: Test WriteArrayToParcelByte byte content.
957 */
958 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelByte_0100, Function | MediumTest | Level1)
959 {
960 Parcel parcel;
961 WantParams wp;
962 bool result = wp.WriteArrayToParcelByte(parcel, nullptr);
963 EXPECT_FALSE(result);
964 }
965
966 /**
967 * @tc.number: AaFwk_WantParams_WriteArrayToParcelChar_0100
968 * @tc.name: WriteArrayToParcelChar
969 * @tc.desc: Test WriteArrayToParcelChar char content.
970 */
971 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelChar_0100, Function | MediumTest | Level1)
972 {
973 Parcel parcel;
974 WantParams wp;
975 bool result = wp.WriteArrayToParcelChar(parcel, nullptr);
976 EXPECT_FALSE(result);
977 }
978
979 /**
980 * @tc.number: AaFwk_WantParams_WriteArrayToParcelShort_0100
981 * @tc.name: WriteArrayToParcelShort
982 * @tc.desc: Test WriteArrayToParcelShort short content.
983 */
984 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelShort_0100, Function | MediumTest | Level1)
985 {
986 Parcel parcel;
987 WantParams wp;
988 bool result = wp.WriteArrayToParcelShort(parcel, nullptr);
989 EXPECT_FALSE(result);
990 }
991
992 /**
993 * @tc.number: AaFwk_WantParams_WriteArrayToParcelInt_0100
994 * @tc.name: WriteArrayToParcelInt
995 * @tc.desc: Test WriteArrayToParcelInt int content.
996 */
997 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelInt_0100, Function | MediumTest | Level1)
998 {
999 Parcel parcel;
1000 WantParams wp;
1001 bool result = wp.WriteArrayToParcelInt(parcel, nullptr);
1002 EXPECT_FALSE(result);
1003 }
1004
1005 /**
1006 * @tc.number: AaFwk_WantParams_WriteArrayToParcelLong_0100
1007 * @tc.name: WriteArrayToParcelLong
1008 * @tc.desc: Test WriteArrayToParcelLong long content.
1009 */
1010 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelLong_0100, Function | MediumTest | Level1)
1011 {
1012 Parcel parcel;
1013 WantParams wp;
1014 bool result = wp.WriteArrayToParcelLong(parcel, nullptr);
1015 EXPECT_FALSE(result);
1016 }
1017
1018 /**
1019 * @tc.number: AaFwk_WantParams_WriteArrayToParcelFloat_0100
1020 * @tc.name: WriteArrayToParcelFloat
1021 * @tc.desc: Test WriteArrayToParcelFloat float content.
1022 */
1023 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelFloat_0100, Function | MediumTest | Level1)
1024 {
1025 Parcel parcel;
1026 WantParams wp;
1027 bool result = wp.WriteArrayToParcelFloat(parcel, nullptr);
1028 EXPECT_FALSE(result);
1029 }
1030
1031 /**
1032 * @tc.number: AaFwk_WantParams_WriteArrayToParcelDouble_0100
1033 * @tc.name: WriteArrayToParcelDouble
1034 * @tc.desc: Test WriteArrayToParcelDouble double content.
1035 */
1036 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelDouble_0100, Function | MediumTest | Level1)
1037 {
1038 Parcel parcel;
1039 WantParams wp;
1040 bool result = wp.WriteArrayToParcelDouble(parcel, nullptr);
1041 EXPECT_FALSE(result);
1042 }
1043
1044 class UnsupportedDataTest : public testing::Test {
1045 public:
UnsupportedDataTest()1046 UnsupportedDataTest()
1047 {}
~UnsupportedDataTest()1048 ~UnsupportedDataTest()
1049 {
1050 }
1051 static void SetUpTestCase(void);
1052 static void TearDownTestCase(void);
1053 void SetUp();
1054 void TearDown();
1055
1056 std::shared_ptr<UnsupportedData> unsupportedData_ = nullptr;
1057 };
1058
SetUpTestCase(void)1059 void UnsupportedDataTest::SetUpTestCase(void)
1060 {}
1061
TearDownTestCase(void)1062 void UnsupportedDataTest::TearDownTestCase(void)
1063 {}
1064
SetUp(void)1065 void UnsupportedDataTest::SetUp(void)
1066 {
1067 unsupportedData_ = std::make_shared<UnsupportedData>();
1068 }
1069
TearDown(void)1070 void UnsupportedDataTest::TearDown(void)
1071 {
1072 }
1073
1074 /**
1075 * @tc.number: AaFwk_WantParams_GetStringParam_1000
1076 * @tc.name: GetStringParam
1077 * @tc.desc: Test GetStringParam.
1078 * @tc.require: issueI648W6
1079 */
1080 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetStringParam_1000, Function | MediumTest | Level1)
1081 {
1082 WantParams wantParams;
1083 std::string key = "";
1084 std::string result = wantParams.GetStringParam(key);
1085 EXPECT_EQ(result, "");
1086 }
1087
1088 /**
1089 * @tc.number: AaFwk_WantParams_WriteToParcelFD_1000
1090 * @tc.name: WriteToParcelFD
1091 * @tc.desc: Test WriteToParcelFD.
1092 * @tc.require: issueI648W6
1093 */
1094 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteToParcelFD_1000, Function | MediumTest | Level1)
1095 {
1096 WantParams wantParams;
1097 Parcel parcel;
1098 WantParams value;
1099 bool result = wantParams.WriteToParcelFD(parcel, value);
1100 EXPECT_EQ(result, false);
1101 }
1102
1103 /**
1104 * @tc.number: AaFwk_WantParams_WriteToParcelRemoteObject_1000
1105 * @tc.name: WriteToParcelRemoteObject
1106 * @tc.desc: Test WriteToParcelRemoteObject.
1107 * @tc.require: issueI648W6
1108 */
1109 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteToParcelRemoteObject_1000, Function | MediumTest | Level1)
1110 {
1111 WantParams wantParams;
1112 Parcel parcel;
1113 WantParams value;
1114 bool result = wantParams.WriteToParcelRemoteObject(parcel, value);
1115 EXPECT_EQ(result, false);
1116
1117 std::string keyStr = "vlan";
1118 std::string valueStr = "vlan";
1119 wantParamsIn_->SetParam(keyStr, String::Box(valueStr));
1120 bool result1 = wantParams.WriteToParcelRemoteObject(parcel, value);
1121 EXPECT_EQ(result1, false);
1122 }
1123
1124 /**
1125 * @tc.number: AaFwk_WantParams_WriteArrayToParcelWantParams_1000
1126 * @tc.name: WriteArrayToParcelWantParams
1127 * @tc.desc: Test WriteArrayToParcelWantParams.
1128 * @tc.require: issueI648W6
1129 */
1130 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_WriteArrayToParcelWantParams_1000, Function | MediumTest | Level1)
1131 {
1132 WantParams wantParams;
1133 Parcel parcel;
1134 int depth = 1;
1135 bool result = wantParams.WriteArrayToParcelWantParams(parcel, nullptr, depth);
1136 EXPECT_EQ(result, false);
1137 }
1138
1139 /**
1140 * @tc.number: AaFwk_WantParams_ReadArrayToParcel_1000
1141 * @tc.name: ReadArrayToParcel
1142 * @tc.desc: Test ReadArrayToParcel.
1143 * @tc.require: issueI648W6
1144 */
1145 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_ReadArrayToParcel_1000, Function | MediumTest | Level1)
1146 {
1147 WantParams wantParams;
1148 Parcel parcel;
1149 int type = 1;
1150 sptr<IArray> destAO = nullptr;
1151 bool result = wantParams.ReadArrayToParcel(parcel, type, destAO, 1);
1152 EXPECT_EQ(result, true);
1153 }
1154
1155 /**
1156 * @tc.number: AaFwk_WantParams_ReadFromParcelFD_1000
1157 * @tc.name: ReadFromParcelFD
1158 * @tc.desc: Test ReadFromParcelFD.
1159 * @tc.require: issueI648W6
1160 */
1161 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_ReadFromParcelFD_1000, Function | MediumTest | Level1)
1162 {
1163 WantParams wantParams;
1164 Parcel parcel;
1165 std::string key = "this is key";
1166 bool result = wantParams.ReadFromParcelFD(parcel, key);
1167 EXPECT_EQ(result, true);
1168 }
1169
1170 /**
1171 * @tc.number: AaFwk_WantParams_ReadFromParcelRemoteObject_1000
1172 * @tc.name: ReadFromParcelRemoteObject
1173 * @tc.desc: Test ReadFromParcelRemoteObject.
1174 * @tc.require: issueI648W6
1175 */
1176 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_ReadFromParcelRemoteObject_1000, Function | MediumTest | Level1)
1177 {
1178 WantParams wantParams;
1179 Parcel parcel;
1180 std::string key = "this is key";
1181 bool result = wantParams.ReadFromParcelRemoteObject(parcel, key);
1182 EXPECT_EQ(result, true);
1183 }
1184
1185 /**
1186 * @tc.number: AaFwk_WantParams_ReadUnsupportedData_1000
1187 * @tc.name: ReadUnsupportedData
1188 * @tc.desc: Test ReadUnsupportedData.
1189 * @tc.require: issueI648W6
1190 */
1191 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_ReadUnsupportedData_1000, Function | MediumTest | Level1)
1192 {
1193 WantParams wantParams;
1194 Parcel parcel;
1195 std::string key = "this is key";
1196 int type = 1;
1197 bool result = wantParams.ReadUnsupportedData(parcel, key, type);
1198 EXPECT_EQ(result, false);
1199
1200 parcel.WriteInt32(-1);
1201 bool result1 = wantParams.ReadUnsupportedData(parcel, key, type);
1202 EXPECT_EQ(result1, false);
1203
1204 int type1 = 50;
1205 bool result2 = wantParams.ReadFromParcelParam(parcel, key, type1, 1);
1206 EXPECT_EQ(result2, false);
1207 UnsupportedData other;
1208 std::shared_ptr<UnsupportedData> unsupportedData = std::make_shared<UnsupportedData>(other);
1209 }
1210
1211 /**
1212 * @tc.number: AaFwk_WantParams_GetCachedUnsupportedData_1000
1213 * @tc.name: GetCachedUnsupportedData
1214 * @tc.desc: Test GetCachedUnsupportedData.
1215 * @tc.require: issueI648W6
1216 */
1217 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_GetCachedUnsupportedData_1000, Function | MediumTest | Level1)
1218 {
1219 OHOS::AAFwk::WantParams wantParams;
1220 AAFwk::UnsupportedData data;
1221 data.key = Str8ToStr16("dataKey2");
1222 data.type = 2;
1223 data.size = 1;
1224 int32_t bufferSize = 256;
1225 data.buffer = new (std::nothrow) uint8_t[bufferSize];
1226 std::vector<AAFwk::UnsupportedData> cacheData;
1227 cacheData.emplace_back(std::move(data));
1228 wantParams.SetCachedUnsupportedData(cacheData);
1229 std::vector<AAFwk::UnsupportedData> getCacheData;
1230 wantParams.GetCachedUnsupportedData(getCacheData);
1231 EXPECT_EQ(1, getCacheData.size());
1232 for (auto item : getCacheData) {
1233 EXPECT_EQ(item.key, Str8ToStr16("dataKey2"));
1234 EXPECT_EQ(item.type, 2);
1235 EXPECT_EQ(item.size, 1);
1236 }
1237 }
1238
1239 /**
1240 * @tc.number: AaFwk_WantParams_DupAllFd_1000
1241 * @tc.name: DupAllFd
1242 * @tc.desc: Test DupAllFd.
1243 */
1244 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_DupAllFd_1000, Function | MediumTest | Level1)
1245 {
1246 std::string keyStr = "FD";
1247 std::string valueStr = "sdasdfdsffdgfdg";
1248 WantParams wantParams;
1249 wantParams.DupAllFd();
1250 wantParamsIn_->SetParam(keyStr, String::Box(valueStr));
1251 Parcel in;
1252 if (wantParamsOut_ != nullptr) {
1253 wantParamsIn_->Marshalling(in);
1254 std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
1255 EXPECT_EQ(valueStr, String::Unbox(IString::Query(wantParamsOut_->GetParam(keyStr))));
1256 }
1257 }
1258 }
1259 }
1260