1 /*
2 * Copyright (c) 2023-2024 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 #include "string_wrapper.h"
19 #include "base_obj.h"
20 #include "bool_wrapper.h"
21 #include "int_wrapper.h"
22 #include "float_wrapper.h"
23 #include "long_wrapper.h"
24 #include "array_wrapper.h"
25
26 #define private public
27 #define protected public
28 #include "distributed_operation.h"
29 #include "distributed_want.h"
30 #include "want.h"
31 #undef private
32 #undef protected
33
34 using namespace testing::ext;
35 using namespace OHOS::AAFwk;
36 using namespace OHOS;
37 using OHOS::Parcel;
38 using OHOS::AppExecFwk::ElementName;
39
40 namespace OHOS {
41 namespace DistributedSchedule {
42 class DistributedWantBaseTest : public testing::Test {
43 public:
DistributedWantBaseTest()44 DistributedWantBaseTest()
45 {}
~DistributedWantBaseTest()46 ~DistributedWantBaseTest()
47 {}
48 static void SetUpTestCase(void);
49 static void TearDownTestCase(void);
50 void SetUp();
51 void TearDown();
52
53 std::shared_ptr<DistributedWant> want_ = nullptr;
54
55 void CompareWant(const std::shared_ptr<DistributedWant> &want1,
56 const std::shared_ptr<DistributedWant> &want2) const;
57 bool CompareWant(const std::shared_ptr<DistributedWant> &want1,
58 const std::shared_ptr<DistributedWant> &want2, std::map<std::string, std::string> &keys) const;
59 bool CompareWantOthers(const std::shared_ptr<DistributedWant>& want1,
60 const std::shared_ptr<DistributedWant>& want2, std::map<std::string, std::string>::iterator it) const;
61 bool CompareWantNumber(const std::shared_ptr<DistributedWant>& want1,
62 const std::shared_ptr<DistributedWant>& want2, std::map<std::string, std::string>::iterator it) const;
63 bool CompareWantArray(const std::shared_ptr<DistributedWant>& want1,
64 const std::shared_ptr<DistributedWant>& want2, std::map<std::string, std::string>::iterator it) const;
65 void SendParcelTest(const std::shared_ptr<DistributedWant> &want, std::map<std::string, std::string> &keys) const;
66 void AddBoolParams(DistributedWant &want,
67 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
68 void AddByteParams(DistributedWant &want,
69 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
70 void AddCharParams(DistributedWant &want,
71 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
72 void AddShortParams(DistributedWant &want,
73 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
74 void AddIntParams(DistributedWant &want,
75 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
76 void AddLongParams(DistributedWant &want,
77 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
78 void AddFloatParams(DistributedWant &want,
79 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
80 void AddDoubleParams(DistributedWant &want,
81 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
82 void AddStringParams(DistributedWant &want,
83 std::map<std::string, std::string> &keys, int loop, unsigned int flag) const;
84 void TestStringForParseUri(std::string uri,
85 std::string keyString, std::size_t &length, std::string valueStringOrigin);
86 void TestFloatForParseUri(std::string uri,
87 std::string keyFloat, std::size_t &length, float valueFloatOrigin);
88 void TestFloatArrayForParseUri(std::string uri,
89 std::string keyFloatArray, std::size_t &length, std::vector<float> valueFloatArrayOrigin);
90 void TestStringArrayForParseUri(std::string uri,
91 std::string keyStringArray, std::size_t &length, std::vector<std::string> valueStringArrayOrigin);
92
93 std::string boolType = "bool";
94 std::string boolArrayType = "boolArray";
95 std::string byteType = "byte";
96 std::string byteArrayType = "byteArray";
97 std::string charType = "char";
98 std::string charArrayType = "charArray";
99 std::string shortType = "short";
100 std::string shortArrayType = "shortArray";
101 std::string intType = "int";
102 std::string intArrayType = "intArray";
103 std::string longType = "long";
104 std::string longArrayType = "longArray";
105 std::string floatType = "float";
106 std::string floatArrayType = "floatArray";
107 std::string doubleType = "double";
108 std::string doubleArrayType = "doubleArray";
109 std::string stringType = "string";
110 std::string stringArrayType = "stringArray";
111
112 static const std::string URI_STRING_HEAD;
113 static const std::string URI_STRING_END;
114 };
115
SetUpTestCase(void)116 void DistributedWantBaseTest::SetUpTestCase(void)
117 {}
118
TearDownTestCase(void)119 void DistributedWantBaseTest::TearDownTestCase(void)
120 {}
121
SetUp(void)122 void DistributedWantBaseTest::SetUp(void)
123 {
124 want_ = std::make_shared<DistributedWant>();
125 }
126
TearDown(void)127 void DistributedWantBaseTest::TearDown(void)
128 {}
129
130 template<typename T>
CompareArrayData(const std::vector<T> & arr1,const std::vector<T> & arr2)131 bool CompareArrayData(const std::vector<T> &arr1, const std::vector<T> &arr2)
132 {
133 if (arr1.size() != arr2.size()) {
134 return false;
135 }
136 for (std::uint32_t i = 0; i < arr1.size(); i++) {
137 if (arr1[i] != arr2[i]) {
138 return false;
139 }
140 }
141 return true;
142 };
143
144 enum Type { FLAG_TEST_SINGLE = 0x01, FLAG_TEST_ARRAY, FLAG_TEST_BOTH };
145 const std::string DistributedWantBaseTest::URI_STRING_HEAD("#Intent;");
146 const std::string DistributedWantBaseTest::URI_STRING_END(";end");
147
148 /**
149 * @tc.number: DistributedSchedule_DistributedWant_Convert_0100
150 * @tc.name: distributedwant
151 * @tc.desc: Verifying successful conversion of want to distributedwant.
152 */
153 HWTEST_F(DistributedWantBaseTest, DistributedSchedule_DistributedWant_Convert_0100, Function | MediumTest | Level3)
154 {
155 Want want;
156 std::string description = "liuuy";
157 want.SetType(description);
158 want.SetFlags(16);
159 want.SetElementName("deviceID", "com.bundle.com", "com.bundle.com.ability");
160 want.SetUri("wantUri");
161 want.SetAction("Action");
162 want.AddEntity("Entity1");
163 want.SetParam(boolType, true);
164 want.SetParam(byteType, 1);
165 want.SetParam(charType, 6);
166 want.SetParam(shortType, 444);
167 want.SetParam(intType, 1111);
168 want.SetParam(longType, 12345);
169 want.SetParam(floatType, 1.1);
170 want.SetParam(doubleType, 1.11);
171 want.SetParam(stringType, std::string("string..."));
172 std::vector<double> dbv;
173 dbv.emplace_back(1111.11);
174 dbv.emplace_back(2222.22);
175 dbv.emplace_back(3333.33);
176 dbv.emplace_back(4444.44);
177 want.SetParam(doubleArrayType, dbv);
178 std::vector<std::string> strv;
179 strv.emplace_back("1111.11");
180 strv.emplace_back("2222.22");
181 want.SetParam(stringArrayType, strv);
182 DistributedWant dstbWant(want);
183 EXPECT_STREQ(want.GetType().c_str(), dstbWant.GetType().c_str());
184 EXPECT_STREQ(want.GetElement().GetDeviceID().c_str(), dstbWant.GetElement().GetDeviceID().c_str());
185 EXPECT_STREQ(want.GetElement().GetBundleName().c_str(), dstbWant.GetElement().GetBundleName().c_str());
186 EXPECT_STREQ(want.GetElement().GetAbilityName().c_str(), dstbWant.GetElement().GetAbilityName().c_str());
187 EXPECT_EQ(want.GetFlags(), dstbWant.GetFlags());
188 EXPECT_STREQ(want.GetUriString().c_str(), dstbWant.GetUriString().c_str());
189 EXPECT_STREQ(want.GetAction().c_str(), dstbWant.GetAction().c_str());
190 EXPECT_EQ(want.GetEntities().size(), dstbWant.GetEntities().size());
191 EXPECT_EQ(want.GetBoolParam(boolType, false), dstbWant.GetBoolParam(boolType, true));
192 EXPECT_EQ(want.GetByteParam(byteType, 0), dstbWant.GetByteParam(byteType, 0));
193 EXPECT_EQ(want.GetCharParam(charType, 0), dstbWant.GetCharParam(charType, 0));
194 EXPECT_EQ(want.GetShortParam(shortType, 0), dstbWant.GetShortParam(shortType, 0));
195 EXPECT_EQ(want.GetIntParam(intType, 0), dstbWant.GetIntParam(intType, 0));
196 EXPECT_EQ(want.GetLongParam(longType, 0), dstbWant.GetLongParam(longType, 0));
197 EXPECT_EQ(want.GetFloatParam(floatType, 0), dstbWant.GetFloatParam(floatType, 0));
198 EXPECT_EQ(want.GetDoubleParam(doubleType, 0), dstbWant.GetDoubleParam(doubleType, 0));
199 EXPECT_STREQ(want.GetStringParam(stringType).c_str(), dstbWant.GetStringParam(stringType).c_str());
200 EXPECT_EQ(want.GetDoubleArrayParam(doubleArrayType).size(), dstbWant.GetDoubleArrayParam(doubleArrayType).size());
201 EXPECT_EQ(want.GetStringArrayParam(stringArrayType).size(), dstbWant.GetStringArrayParam(stringArrayType).size());
202 }
203
204 /**
205 * @tc.number: DistributedSchedule_DistributedWant_Convert_0101
206 * @tc.name: distributedwant
207 * @tc.desc: Verifying successful conversion of want to distributedwant.
208 */
209 HWTEST_F(DistributedWantBaseTest, DistributedSchedule_DistributedWant_Convert_0101, Function | MediumTest | Level3)
210 {
211 Want want;
212 std::vector<bool> bv;
213 bv.emplace_back(true);
214 bv.emplace_back(false);
215 want.SetParam(boolArrayType, bv);
216 std::vector<byte> byv;
217 byv.emplace_back(2);
218 byv.emplace_back(3);
219 want.SetParam(byteArrayType, byv);
220 std::vector<zchar> chv;
221 chv.emplace_back('\n');
222 chv.emplace_back('p');
223 chv.emplace_back('i');
224 want.SetParam(charArrayType, chv);
225 std::vector<short> shv;
226 shv.emplace_back(111);
227 shv.emplace_back(222);
228 shv.emplace_back(333);
229 want.SetParam(shortArrayType, shv);
230 std::vector<int> inv;
231 inv.emplace_back(1111);
232 inv.emplace_back(2222);
233 inv.emplace_back(3333);
234 inv.emplace_back(4444);
235 want.SetParam(intArrayType, inv);
236 std::vector<long> lgv;
237 lgv.emplace_back(1111);
238 lgv.emplace_back(2222);
239 lgv.emplace_back(3333);
240 lgv.emplace_back(4444);
241 want.SetParam(longArrayType, lgv);
242 std::vector<float> ftv;
243 ftv.emplace_back(1111.1);
244 ftv.emplace_back(2222.2);
245 ftv.emplace_back(3333.3);
246 ftv.emplace_back(4444.4);
247 want.SetParam(floatArrayType, ftv);
248 DistributedWant dstbWant(want);
249 EXPECT_EQ(want.GetBoolArrayParam(boolArrayType).size(), dstbWant.GetBoolArrayParam(boolArrayType).size());
250 EXPECT_EQ(want.GetByteArrayParam(byteArrayType).size(), dstbWant.GetByteArrayParam(byteArrayType).size());
251 EXPECT_EQ(want.GetCharArrayParam(charArrayType).size(), dstbWant.GetCharArrayParam(charArrayType).size());
252 EXPECT_EQ(want.GetShortArrayParam(shortArrayType).size(), dstbWant.GetShortArrayParam(shortArrayType).size());
253 EXPECT_EQ(want.GetIntArrayParam(intArrayType).size(), dstbWant.GetIntArrayParam(intArrayType).size());
254 EXPECT_EQ(want.GetLongArrayParam(longArrayType).size(), dstbWant.GetLongArrayParam(longArrayType).size());
255 EXPECT_EQ(want.GetFloatArrayParam(floatArrayType).size(), dstbWant.GetFloatArrayParam(floatArrayType).size());
256 }
257
258 /**
259 * @tc.number: DistributedSchedule_DistributedWant_Convert_0200
260 * @tc.name: ToWant
261 * @tc.desc: Verifying successful conversion of distributedwant to want.
262 */
263 HWTEST_F(DistributedWantBaseTest, DistributedSchedule_Distributedwant_Convert_0200, Function | MediumTest | Level3)
264 {
265 std::shared_ptr<DistributedWant> dwant = std::make_shared<DistributedWant>();
266 ASSERT_NE(dwant, nullptr);
267 std::string description = "liuuy";
268 dwant->SetType(description);
269 dwant->SetFlags(16);
270 dwant->SetElementName("deviceID", "com.bundle.com", "com.bundle.com.ability");
271 dwant->SetUri("wantUri");
272 dwant->SetAction("Action");
273 dwant->AddEntity("Entity1");
274 dwant->SetParam(boolType, true);
275 dwant->SetParam(byteType, 1);
276 dwant->SetParam(charType, 6);
277 dwant->SetParam(shortType, 444);
278 dwant->SetParam(intType, 1111);
279 dwant->SetParam(longType, 12345);
280 dwant->SetParam(floatType, 1.1);
281 dwant->SetParam(doubleType, 1.11);
282 dwant->SetParam(stringType, std::string("string..."));
283 std::vector<double> dbv;
284 dbv.emplace_back(1111.11);
285 dbv.emplace_back(2222.22);
286 dbv.emplace_back(3333.33);
287 dbv.emplace_back(4444.44);
288 dwant->SetParam(doubleArrayType, dbv);
289 std::vector<std::string> strv;
290 strv.emplace_back("1111.11");
291 strv.emplace_back("2222.22");
292 dwant->SetParam(stringArrayType, strv);
293 std::shared_ptr<Want> want = dwant->ToWant();
294 EXPECT_STREQ(want->GetType().c_str(), dwant->GetType().c_str());
295 EXPECT_STREQ(want->GetElement().GetDeviceID().c_str(), dwant->GetElement().GetDeviceID().c_str());
296 EXPECT_STREQ(want->GetElement().GetBundleName().c_str(), dwant->GetElement().GetBundleName().c_str());
297 EXPECT_STREQ(want->GetElement().GetAbilityName().c_str(), dwant->GetElement().GetAbilityName().c_str());
298 EXPECT_EQ(want->GetFlags(), dwant->GetFlags());
299 EXPECT_STREQ(want->GetUriString().c_str(), dwant->GetUriString().c_str());
300 EXPECT_STREQ(want->GetAction().c_str(), dwant->GetAction().c_str());
301 EXPECT_EQ(want->GetEntities().size(), dwant->GetEntities().size());
302 EXPECT_EQ(want->GetBoolParam(boolType, false), dwant->GetBoolParam(boolType, true));
303 EXPECT_EQ(want->GetByteParam(byteType, 0), dwant->GetByteParam(byteType, 0));
304 EXPECT_EQ(want->GetCharParam(charType, 0), dwant->GetCharParam(charType, 0));
305 EXPECT_EQ(want->GetShortParam(shortType, 0), dwant->GetShortParam(shortType, 0));
306 EXPECT_EQ(want->GetIntParam(intType, 0), dwant->GetIntParam(intType, 0));
307 EXPECT_EQ(want->GetLongParam(longType, 0), dwant->GetLongParam(longType, 0));
308 EXPECT_EQ(want->GetFloatParam(floatType, 0), dwant->GetFloatParam(floatType, 0));
309 EXPECT_EQ(want->GetDoubleParam(doubleType, 0), dwant->GetDoubleParam(doubleType, 0));
310 EXPECT_STREQ(want->GetStringParam(stringType).c_str(), dwant->GetStringParam(stringType).c_str());
311 EXPECT_EQ(want->GetDoubleArrayParam(doubleArrayType).size(), dwant->GetDoubleArrayParam(doubleArrayType).size());
312 EXPECT_EQ(want->GetStringArrayParam(stringArrayType).size(), dwant->GetStringArrayParam(stringArrayType).size());
313 }
314
315 /**
316 * @tc.number: DistributedSchedule_DistributedWant_Convert_0201
317 * @tc.name: ToWant
318 * @tc.desc: Verifying successful conversion of distributedwant to want.
319 */
320 HWTEST_F(DistributedWantBaseTest, DistributedSchedule_Distributedwant_Convert_0201, Function | MediumTest | Level3)
321 {
322 std::shared_ptr<DistributedWant> dwant = std::make_shared<DistributedWant>();
323 ASSERT_NE(dwant, nullptr);
324 std::vector<bool> bv;
325 bv.emplace_back(true);
326 bv.emplace_back(false);
327 dwant->SetParam(boolArrayType, bv);
328 std::vector<byte> byv;
329 byv.emplace_back(2);
330 byv.emplace_back(3);
331 dwant->SetParam(byteArrayType, byv);
332 std::vector<zchar> chv;
333 chv.emplace_back('\n');
334 chv.emplace_back('p');
335 chv.emplace_back('i');
336 dwant->SetParam(charArrayType, chv);
337 std::vector<short> shv;
338 shv.emplace_back(111);
339 shv.emplace_back(222);
340 shv.emplace_back(333);
341 dwant->SetParam(shortArrayType, shv);
342 std::vector<int> inv;
343 inv.emplace_back(1111);
344 inv.emplace_back(2222);
345 inv.emplace_back(3333);
346 inv.emplace_back(4444);
347 dwant->SetParam(intArrayType, inv);
348 std::vector<long> lgv;
349 lgv.emplace_back(1111);
350 lgv.emplace_back(2222);
351 lgv.emplace_back(3333);
352 lgv.emplace_back(4444);
353 dwant->SetParam(longArrayType, lgv);
354 std::vector<float> ftv;
355 ftv.emplace_back(1111.1);
356 ftv.emplace_back(2222.2);
357 ftv.emplace_back(3333.3);
358 ftv.emplace_back(4444.4);
359 dwant->SetParam(floatArrayType, ftv);
360 std::shared_ptr<Want> want = dwant->ToWant();
361 EXPECT_EQ(want->GetBoolArrayParam(boolArrayType).size(), dwant->GetBoolArrayParam(boolArrayType).size());
362 EXPECT_EQ(want->GetByteArrayParam(byteArrayType).size(), dwant->GetByteArrayParam(byteArrayType).size());
363 EXPECT_EQ(want->GetCharArrayParam(charArrayType).size(), dwant->GetCharArrayParam(charArrayType).size());
364 EXPECT_EQ(want->GetShortArrayParam(shortArrayType).size(), dwant->GetShortArrayParam(shortArrayType).size());
365 EXPECT_EQ(want->GetIntArrayParam(intArrayType).size(), dwant->GetIntArrayParam(intArrayType).size());
366 EXPECT_EQ(want->GetLongArrayParam(longArrayType).size(), dwant->GetLongArrayParam(longArrayType).size());
367 EXPECT_EQ(want->GetFloatArrayParam(floatArrayType).size(), dwant->GetFloatArrayParam(floatArrayType).size());
368 }
369
370 /**
371 * @tc.number: DistributedScheduleWant_Type_0100
372 * @tc.name: SetType/GetType
373 * @tc.desc: Validate when normally entering a string
374 */
375 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Type_0100, Function | MediumTest | Level3)
376 {
377 if (want_ != nullptr) {
378 std::string description = "liuuy";
379 want_->SetType(description);
380 EXPECT_STREQ(description.c_str(), want_->GetType().c_str());
381 }
382 }
383
384 /**
385 * @tc.number: DistributedScheduleWant_Action_0100
386 * @tc.name: SetAction/GetAction
387 * @tc.desc: Validate when normally entering a string
388 */
389 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Action_0100, Function | MediumTest | Level3)
390 {
391 if (want_ != nullptr) {
392 std::string actiondescription = "liuuy";
393 want_->SetAction(actiondescription);
394 EXPECT_STREQ(actiondescription.c_str(), want_->GetAction().c_str());
395 }
396 }
397
398 /**
399 * @tc.number: DistributedScheduleWant_Bundle_0100
400 * @tc.name: SetBundle/GetBundle
401 * @tc.desc: Validate when normally entering a string
402 */
403 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Bundle_0100, Function | MediumTest | Level3)
404 {
405 if (want_ != nullptr) {
406 std::string bundleName = "liuuy";
407 want_->SetBundle(bundleName);
408 EXPECT_STREQ(bundleName.c_str(), want_->GetBundle().c_str());
409 }
410 }
411
412 /**
413 * @tc.number: DistributedScheduleWant_Parcelable_0100
414 * @tc.name: Marshalling/Unmarshalling
415 * @tc.desc: marshalling Want, and then check result.
416 */
417 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0100, Function | MediumTest | Level3)
418 {
419 std::shared_ptr<DistributedWant> WantIn_ = std::make_shared<DistributedWant>();
420 if (WantIn_ == nullptr) {
421 return;
422 }
423
424 WantIn_->SetAction("12345");
425 WantIn_->SetFlags(123);
426 WantIn_->AddEntity("12345");
427 DistributedWantParams wantParams;
428 std::string keyStr = "12345667";
429 bool valueBool = true;
430 wantParams.SetParam(keyStr, Boolean::Box(valueBool));
431 WantIn_->SetParams(wantParams);
432 OHOS::AppExecFwk::ElementName element;
433 element.SetAbilityName("12345");
434 element.SetBundleName("12345");
435 element.SetDeviceID("12345");
436 WantIn_->SetElement(element);
437 WantIn_->SetType("12345");
438
439 Parcel in;
440 size_t pos1 = in.GetWritePosition();
441 bool result = WantIn_->Marshalling(in);
442 size_t pos2 = in.GetWritePosition();
443 EXPECT_EQ(result, true);
444 GTEST_LOG_(INFO) << " Marshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
445
446 pos1 = in.GetWritePosition();
447 result = WantIn_->Marshalling(in);
448 pos2 = in.GetWritePosition();
449 EXPECT_EQ(result, true);
450 GTEST_LOG_(INFO) << " Marshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
451
452 pos1 = in.GetReadPosition();
453 std::shared_ptr<DistributedWant> WantOut_(DistributedWant::Unmarshalling(in));
454 if (WantOut_ != nullptr) {
455 pos2 = in.GetReadPosition();
456 CompareWant(WantIn_, WantOut_);
457 EXPECT_EQ(valueBool, Boolean::Unbox(IBoolean::Query(WantOut_->GetParams().GetParam(keyStr))));
458 GTEST_LOG_(INFO) << " Unmarshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
459 }
460
461 pos1 = in.GetReadPosition();
462 std::shared_ptr<DistributedWant> WantOut2_(DistributedWant::Unmarshalling(in));
463 if (WantOut2_ != nullptr) {
464 pos2 = in.GetReadPosition();
465 CompareWant(WantIn_, WantOut2_);
466 EXPECT_EQ(valueBool, Boolean::Unbox(IBoolean::Query(WantOut2_->GetParams().GetParam(keyStr))));
467 GTEST_LOG_(INFO) << " Unmarshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
468 }
469 }
470 /**
471 * @tc.number: DistributedScheduleWant_Parcelable_0200
472 * @tc.name: Marshalling/Unmarshalling
473 * @tc.desc: marshalling Want, and then check result.
474 */
475 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0200, Function | MediumTest | Level3)
476 {
477 std::shared_ptr<DistributedWant> WantIn_ = std::make_shared<DistributedWant>();
478 if (WantIn_ == nullptr) {
479 return;
480 }
481 WantIn_->SetAction("@#¥#3243adsafdf_中文");
482 WantIn_->SetFlags(123);
483 WantIn_->AddEntity("@#¥#3243adsafdf_中文");
484 DistributedWantParams wantParams;
485 std::string keyStr = "@#¥#3243adsafdf_中文";
486 long valueLong = 123;
487 wantParams.SetParam(keyStr, Long::Box(valueLong));
488 WantIn_->SetParams(wantParams);
489 OHOS::AppExecFwk::ElementName element;
490 element.SetAbilityName("@#¥#3243adsafdf_中文");
491 element.SetBundleName("@#¥#3243adsafdf_中文");
492 element.SetDeviceID("@#¥#3243adsafdf_中文");
493 WantIn_->SetElement(element);
494 WantIn_->SetType("@#¥#3243adsafdf_中文");
495 size_t pos1;
496 size_t pos2;
497 bool result = false;
498 Parcel in;
499 pos1 = in.GetWritePosition();
500 result = WantIn_->Marshalling(in);
501 pos2 = in.GetWritePosition();
502 EXPECT_EQ(result, true);
503 GTEST_LOG_(INFO) << "Marshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
504 pos1 = in.GetWritePosition();
505 result = WantIn_->Marshalling(in);
506 pos2 = in.GetWritePosition();
507 EXPECT_EQ(result, true);
508 pos1 = in.GetReadPosition();
509 std::shared_ptr<DistributedWant> WantOut_(DistributedWant::Unmarshalling(in));
510 if (WantOut_ != nullptr) {
511 pos2 = in.GetReadPosition();
512 CompareWant(WantIn_, WantOut_);
513 std::string outString(String::Unbox(IString::Query(WantOut_->GetParams().GetParam(keyStr))));
514 EXPECT_STREQ(std::to_string(valueLong).c_str(), outString.c_str());
515 GTEST_LOG_(INFO) << "Unmarshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
516 }
517 pos1 = in.GetReadPosition();
518 std::shared_ptr<DistributedWant> WantOut2_(DistributedWant::Unmarshalling(in));
519 if (WantOut2_ != nullptr) {
520 pos2 = in.GetReadPosition();
521 CompareWant(WantIn_, WantOut2_);
522 std::string outString2(String::Unbox(IString::Query(WantOut2_->GetParams().GetParam(keyStr))));
523 EXPECT_STREQ(std::to_string(valueLong).c_str(), outString2.c_str());
524 }
525 }
526
527 /**
528 * @tc.number: DistributedScheduleWant_Parcelable_0300
529 * @tc.name: Marshalling/Unmarshalling
530 * @tc.desc: marshalling Want, and then check result.
531 */
532 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0300, Function | MediumTest | Level3)
533 {
534 std::shared_ptr<DistributedWant> WantIn_ = std::make_shared<DistributedWant>();
535 if (WantIn_ == nullptr) {
536 return;
537 }
538
539 WantIn_->SetAction("");
540 WantIn_->SetFlags(123);
541 WantIn_->AddEntity("");
542 DistributedWantParams wantParams;
543 std::string keyStr = "";
544 int valueInt = 123;
545 wantParams.SetParam(keyStr, Integer::Box(valueInt));
546 WantIn_->SetParams(wantParams);
547 OHOS::AppExecFwk::ElementName element;
548 element.SetAbilityName("");
549 element.SetBundleName("");
550 element.SetDeviceID("");
551 WantIn_->SetElement(element);
552 WantIn_->SetType("");
553
554 size_t pos1;
555 size_t pos2;
556 bool result = false;
557
558 Parcel in;
559 pos1 = in.GetWritePosition();
560 result = WantIn_->Marshalling(in);
561 pos2 = in.GetWritePosition();
562 EXPECT_EQ(result, true);
563 GTEST_LOG_(INFO) << "Marshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
564
565 pos1 = in.GetWritePosition();
566 result = WantIn_->Marshalling(in);
567 pos2 = in.GetWritePosition();
568 EXPECT_EQ(result, true);
569 GTEST_LOG_(INFO) << "Marshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
570
571 pos1 = in.GetReadPosition();
572 std::shared_ptr<DistributedWant> WantOut_(DistributedWant::Unmarshalling(in));
573 if (WantOut_ != nullptr) {
574 pos2 = in.GetReadPosition();
575 CompareWant(WantIn_, WantOut_);
576 EXPECT_EQ(valueInt, Integer::Unbox(IInteger::Query(WantOut_->GetParams().GetParam(keyStr))));
577 GTEST_LOG_(INFO) << "Unmarshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
578 }
579
580 pos1 = in.GetReadPosition();
581 std::shared_ptr<DistributedWant> WantOut2_(DistributedWant::Unmarshalling(in));
582 if (WantOut2_ != nullptr) {
583 pos2 = in.GetReadPosition();
584 CompareWant(WantIn_, WantOut2_);
585 EXPECT_EQ(valueInt, Integer::Unbox(IInteger::Query(WantOut2_->GetParams().GetParam(keyStr))));
586 GTEST_LOG_(INFO) << "Unmarshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
587 }
588 }
589
590 /**
591 * @tc.number: DistributedScheduleWant_Parcelable_0400
592 * @tc.name: Marshalling/Unmarshalling
593 * @tc.desc: marshalling Want, and then check result.
594 */
595 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0400, Function | MediumTest | Level3)
596 {
597 std::shared_ptr<DistributedWant> WantIn_ = std::make_shared<DistributedWant>();
598 if (WantIn_ == nullptr) {
599 return;
600 }
601
602 WantIn_->SetAction("12345");
603 WantIn_->SetFlags(123);
604 WantIn_->AddEntity("12345");
605 WantIn_->AddEntity("@#¥#3243adsafdf_中文");
606 WantIn_->AddEntity("");
607 DistributedWantParams wantParams;
608 std::string keyStr = "12345667";
609 std::string valueString = "123";
610 wantParams.SetParam(keyStr, String::Box(valueString));
611 WantIn_->SetParams(wantParams);
612 OHOS::AppExecFwk::ElementName element;
613 element.SetAbilityName("12345");
614 element.SetBundleName("12345");
615 element.SetDeviceID("12345");
616 WantIn_->SetElement(element);
617 WantIn_->SetType("12345");
618
619 Parcel in;
620 size_t pos1 = in.GetWritePosition();
621 bool result = WantIn_->Marshalling(in);
622 size_t pos2 = in.GetWritePosition();
623 EXPECT_EQ(result, true);
624 GTEST_LOG_(INFO) << "Marshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
625
626 pos1 = in.GetWritePosition();
627 result = WantIn_->Marshalling(in);
628 pos2 = in.GetWritePosition();
629 EXPECT_EQ(result, true);
630 GTEST_LOG_(INFO) << "Marshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
631
632 pos1 = in.GetReadPosition();
633 std::shared_ptr<DistributedWant> WantOut_(DistributedWant::Unmarshalling(in));
634 if (WantOut_ != nullptr) {
635 pos2 = in.GetReadPosition();
636 CompareWant(WantIn_, WantOut_);
637 EXPECT_EQ(valueString, String::Unbox(IString::Query(WantOut_->GetParams().GetParam(keyStr))));
638 GTEST_LOG_(INFO) << "Unmarshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
639 }
640
641 pos1 = in.GetReadPosition();
642 std::shared_ptr<DistributedWant> WantOut2_(DistributedWant::Unmarshalling(in));
643 if (WantOut2_ != nullptr) {
644 pos2 = in.GetReadPosition();
645 CompareWant(WantIn_, WantOut2_);
646 EXPECT_EQ(valueString, String::Unbox(IString::Query(WantOut2_->GetParams().GetParam(keyStr))));
647 GTEST_LOG_(INFO) << "Unmarshalling: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
648 }
649 }
650
651 /**
652 * @tc.number: DistributedScheduleWant_Parcelable_0500
653 * @tc.name: Marshalling/Unmarshalling
654 * @tc.desc: marshalling Want, and then check result.
655 */
656 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0500, Function | MediumTest | Level3)
657 {
658 GTEST_LOG_(INFO) << "DistributedScheduleWant_Parcelable_0500 start";
659 std::shared_ptr<DistributedWant> WantIn_ = std::make_shared<DistributedWant>();
660 if (WantIn_ == nullptr) {
661 return;
662 }
663
664 WantIn_->AddEntity("system.test.entity");
665
666 OHOS::AppExecFwk::ElementName element;
667 element.SetAbilityName("system.test.abilityname");
668 element.SetBundleName("system.test.bundlename");
669 element.SetDeviceID("system.test.deviceid");
670 WantIn_->SetElement(element);
671
672 DistributedWantParams wantParams;
673 std::string keyStr = "system.test.wantparams.key";
674 std::string MIMEKEY = "mime-type";
675 wantParams.SetParam(MIMEKEY, String::Box("system.test.uritype"));
676
677 std::string valueString = "system.wantparams.value.content.test";
678 wantParams.SetParam(keyStr, String::Box(valueString));
679 WantIn_->SetParams(wantParams);
680
681 Parcel in;
682 bool result = false;
683 result = WantIn_->Marshalling(in);
684 EXPECT_EQ(result, true);
685 std::shared_ptr<DistributedWant> WantOut_(DistributedWant::Unmarshalling(in));
686 if (WantOut_ != nullptr) {
687
688 bool hasentity = WantOut_->HasEntity("system.test.entity");
689 GTEST_LOG_(INFO) << "WantOut_->HasEntity(system.test.entity)" << hasentity;
690 EXPECT_EQ(hasentity, true);
691
692 WantOut_->RemoveEntity(std::string("system.test.entity"));
693 hasentity = WantOut_->HasEntity(std::string("system.test.entity"));
694 GTEST_LOG_(INFO) << "WantOut_->RemoveEntity(system.test.entity)" << hasentity;
695 EXPECT_EQ(hasentity, false);
696
697 std::string outtype = WantOut_->GetType();
698 GTEST_LOG_(INFO) << "WantOut_->GetType()" << outtype.c_str();
699 EXPECT_STREQ(outtype.c_str(), std::string("system.test.uritype").c_str());
700
701 element = WantOut_->GetElement();
702 GTEST_LOG_(INFO) << "element.GetAbilityName().c_str(): " << element.GetAbilityName().c_str();
703 EXPECT_STREQ(element.GetAbilityName().c_str(), std::string("system.test.abilityname").c_str());
704
705 GTEST_LOG_(INFO) << "element->GetBundleName().c_str(): " << element.GetBundleName().c_str();
706 EXPECT_STREQ(element.GetBundleName().c_str(), std::string("system.test.bundlename").c_str());
707
708 EXPECT_STREQ(element.GetDeviceID().c_str(), std::string("system.test.deviceid").c_str());
709
710 std::string param_content = WantOut_->GetStringParam(keyStr);
711 GTEST_LOG_(INFO) << "WantOut_->GetStringParam(keyStr): " << param_content.c_str();
712
713 GTEST_LOG_(INFO) << "DistributedScheduleWant_Parcelable_005 end";
714 }
715 }
716
717 /**
718 * @tc.number: DistributedScheduleWant_Parcelable_0501
719 * @tc.name: Marshalling/Unmarshalling
720 * @tc.desc: marshalling Want, and then check result.
721 */
722 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0501, Function | MediumTest | Level3)
723 {
724 GTEST_LOG_(INFO) << "DistributedScheduleWant_Parcelable_0501 start";
725 std::shared_ptr<DistributedWant> WantIn_ = std::make_shared<DistributedWant>();
726 if (WantIn_ == nullptr) {
727 return;
728 }
729
730 WantIn_->SetAction("system.test.action");
731
732 std::vector<bool> boolArrayValue = {true, false, true};
733 WantIn_->SetParam(std::string("bool_arraykey"), boolArrayValue);
734
735 std::vector<byte> byteArrayValue = {'?', 'a', '\\'};
736 WantIn_->SetParam(std::string("byte_arraykey"), byteArrayValue);
737
738 std::vector<zchar> charArrayValue = {U'e', U'l', U'l', U'o'};
739 WantIn_->SetParam(std::string("char_arraykey"), charArrayValue);
740
741 std::vector<std::string> stringArrayValue = {"stringtest1", "string@test2", "string@!#test2"};
742 WantIn_->SetParam(std::string("string_arraykey"), stringArrayValue);
743
744 DistributedWant wantCopy(*WantIn_);
745 std::vector<std::string> teststringArrayValue1 = WantIn_->GetStringArrayParam(std::string("string_arraykey"));
746 std::vector<std::string> teststringArrayValue2 = wantCopy.GetStringArrayParam(std::string("string_arraykey"));
747 bool copyarraycompare = CompareArrayData<std::string>(teststringArrayValue1, teststringArrayValue1);
748 EXPECT_EQ(copyarraycompare, true);
749 std::string str = (copyarraycompare == true) ? "true" : "false";
750 GTEST_LOG_(INFO) << "copyarraycompare=" << str.c_str();
751
752 Parcel in;
753 bool result = false;
754 result = WantIn_->Marshalling(in);
755 EXPECT_EQ(result, true);
756 std::shared_ptr<DistributedWant> WantOut_(DistributedWant::Unmarshalling(in));
757 if (WantOut_ != nullptr) {
758 GTEST_LOG_(INFO) << "WantOut_->GetAction().c_str(): " << WantOut_->GetAction().c_str();
759 EXPECT_STREQ(WantOut_->GetAction().c_str(), std::string("system.test.action").c_str());
760
761 std::vector<bool> retboolArray;
762 retboolArray = WantOut_->GetBoolArrayParam(std::string("bool_arraykey"));
763
764 bool arraycompare = CompareArrayData<bool>(retboolArray, boolArrayValue);
765 EXPECT_EQ(arraycompare, true);
766
767 std::vector<byte> retbyteArrayValue;
768 retbyteArrayValue = WantOut_->GetByteArrayParam(std::string("byte_arraykey"));
769 arraycompare = CompareArrayData<byte>(retbyteArrayValue, byteArrayValue);
770 EXPECT_EQ(arraycompare, true);
771
772 std::vector<zchar> retcharArrayValue;
773 retcharArrayValue = WantOut_->GetCharArrayParam(std::string("char_arraykey"));
774 arraycompare = CompareArrayData<zchar>(retcharArrayValue, charArrayValue);
775 EXPECT_EQ(arraycompare, true);
776
777 std::vector<std::string> retstringArrayValue;
778 retstringArrayValue = WantOut_->GetStringArrayParam(std::string("string_arraykey"));
779 arraycompare = CompareArrayData<std::string>(retstringArrayValue, stringArrayValue);
780 EXPECT_EQ(arraycompare, true);
781 }
782 }
783
784 /**
785 * @tc.number: DistributedScheduleWant_Parcelable_0502
786 * @tc.name: Marshalling/Unmarshalling
787 * @tc.desc: marshalling Want, and then check result.
788 */
789 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0502, Function | MediumTest | Level3)
790 {
791 GTEST_LOG_(INFO) << "DistributedScheduleWant_Parcelable_0502 start";
792 std::shared_ptr<DistributedWant> WantIn_ = std::make_shared<DistributedWant>();
793 if (WantIn_ == nullptr) {
794 return;
795 }
796
797 WantIn_->SetFlags(64);
798
799 std::vector<short> shortArrayValue = {-1, 0, 1};
800 WantIn_->SetParam(std::string("short_arraykey"), shortArrayValue);
801
802 std::vector<int> intArrayValue = {-10, 0, 10};
803 WantIn_->SetParam(std::string("int_arraykey"), intArrayValue);
804
805 std::vector<long> longArrayValue = {-100, 0, 100};
806 WantIn_->SetParam(std::string("long_arraykey"), longArrayValue);
807
808 std::vector<float> floatArrayValue = {-100.1, 0.1, 100.1};
809 WantIn_->SetParam(std::string("float_arraykey"), floatArrayValue);
810
811 std::vector<double> doubleArrayValue = {-1000.1, 0.1, 1000.1};
812 WantIn_->SetParam(std::string("double_arraykey"), doubleArrayValue);
813
814 Parcel in;
815 bool result = false;
816 result = WantIn_->Marshalling(in);
817 EXPECT_EQ(result, true);
818 std::shared_ptr<DistributedWant> WantOut_(DistributedWant::Unmarshalling(in));
819 if (WantOut_ != nullptr) {
820 int flags = WantOut_->GetFlags();
821 GTEST_LOG_(INFO) << "WantOut_->GetFlags(): " << flags;
822 EXPECT_EQ(static_cast<int>(flags), 64);
823
824 std::vector<short> retshortArrayValue;
825 retshortArrayValue = WantOut_->GetShortArrayParam(std::string("short_arraykey"));
826 bool arraycompare = CompareArrayData<short>(retshortArrayValue, shortArrayValue);
827 EXPECT_EQ(arraycompare, true);
828
829 std::vector<int> retintArrayValue;
830 retintArrayValue = WantOut_->GetIntArrayParam(std::string("int_arraykey"));
831 arraycompare = CompareArrayData<int>(retintArrayValue, intArrayValue);
832 EXPECT_EQ(arraycompare, true);
833
834 std::vector<long> retlonArrayValue;
835 retlonArrayValue = WantOut_->GetLongArrayParam(std::string("long_arraykey"));
836 arraycompare = CompareArrayData<long>(retlonArrayValue, longArrayValue);
837 EXPECT_EQ(arraycompare, true);
838
839 std::vector<float> retfloatArrayValue;
840 retfloatArrayValue = WantOut_->GetFloatArrayParam(std::string("float_arraykey"));
841 arraycompare = CompareArrayData<float>(retfloatArrayValue, floatArrayValue);
842 EXPECT_EQ(arraycompare, true);
843
844 std::vector<double> retdoubleArrayValue;
845 retdoubleArrayValue = WantOut_->GetDoubleArrayParam(std::string("double_arraykey"));
846 arraycompare = CompareArrayData<double>(retdoubleArrayValue, doubleArrayValue);
847 EXPECT_EQ(arraycompare, true);
848 }
849 }
850
CompareWant(const std::shared_ptr<DistributedWant> & want1,const std::shared_ptr<DistributedWant> & want2) const851 void DistributedWantBaseTest::CompareWant(const std::shared_ptr<DistributedWant>& want1,
852 const std::shared_ptr<DistributedWant>& want2) const
853 {
854 DistributedOperation opt1 = want1->GetOperation();
855 DistributedOperation opt2 = want2->GetOperation();
856 EXPECT_EQ(opt1.GetDeviceId(), opt2.GetDeviceId());
857 EXPECT_EQ(opt1.GetBundleName(), opt2.GetBundleName());
858 EXPECT_EQ(opt1.GetAbilityName(), opt2.GetAbilityName());
859
860 EXPECT_EQ(want1->GetAction(), want2->GetAction());
861 EXPECT_EQ(want1->GetFlags(), want2->GetFlags());
862 EXPECT_EQ(want1->GetType(), want2->GetType());
863 EXPECT_EQ(want1->CountEntities(), want2->CountEntities());
864
865 int count = want1->CountEntities();
866 std::vector<std::string> entities1 = want1->GetEntities();
867 std::vector<std::string> entities2 = want2->GetEntities();
868 for (int i = 0; i < count; i++) {
869 EXPECT_EQ(entities1.at(i), entities2.at(i));
870 }
871
872 OHOS::AppExecFwk::ElementName element1 = want1->GetElement();
873 OHOS::AppExecFwk::ElementName element2 = want2->GetElement();
874 EXPECT_EQ(element1.GetURI(), element1.GetURI());
875
876 std::set<std::string> key1;
877 std::set<std::string> key2;
878 key1 = want1->GetParams().KeySet();
879 key2 = want2->GetParams().KeySet();
880 EXPECT_EQ(key1.size(), key2.size());
881
882 std::set<std::string>::iterator iter1 = key1.begin();
883 std::set<std::string>::iterator iter2 = key2.begin();
884 for (; (iter1 != key1.end() && iter2 != key2.end()); iter1++, iter2++) {
885 EXPECT_EQ(*iter1, *iter2);
886 }
887 }
888
CompareWant(const std::shared_ptr<DistributedWant> & want1,const std::shared_ptr<DistributedWant> & want2,std::map<std::string,std::string> & keys) const889 bool DistributedWantBaseTest::CompareWant(const std::shared_ptr<DistributedWant>& want1,
890 const std::shared_ptr<DistributedWant>& want2, std::map<std::string, std::string>& keys) const
891 {
892 if (want1 == nullptr || want2 == nullptr) {
893 return false;
894 }
895 EXPECT_STREQ(want1->GetAction().c_str(), want2->GetAction().c_str());
896 EXPECT_EQ(want1->CountEntities(), want2->CountEntities());
897
898 if (want1->CountEntities() != want2->CountEntities()) {
899 return false;
900 }
901
902 int count = want1->CountEntities();
903
904 std::vector<std::string> entities1 = want1->GetEntities();
905 std::vector<std::string> entities2 = want2->GetEntities();
906 for (int i = 0; i < count; i++) {
907 EXPECT_EQ(entities1.at(i), entities2.at(i));
908 }
909 EXPECT_EQ(want1->GetFlags(), want2->GetFlags());
910 EXPECT_EQ(want1->GetElement(), want2->GetElement());
911
912 for (auto it = keys.begin(); it != keys.end(); it++) {
913 if (!CompareWantNumber(want1, want2, it) && !CompareWantOthers(want1, want2, it) &&
914 !CompareWantArray(want1, want2, it)) {};
915 }
916
917 return true;
918 }
919
CompareWantNumber(const std::shared_ptr<DistributedWant> & want1,const std::shared_ptr<DistributedWant> & want2,std::map<std::string,std::string>::iterator it) const920 bool DistributedWantBaseTest::CompareWantNumber(const std::shared_ptr<DistributedWant>& want1,
921 const std::shared_ptr<DistributedWant>& want2, std::map<std::string, std::string>::iterator it) const
922 {
923 if (it->second == shortType) {
924 short default1 = 123;
925 short default2 = 456;
926 short v1 = want1->GetShortParam(it->first, default1);
927 short v2 = want2->GetShortParam(it->first, default2);
928 EXPECT_EQ(v1, v2);
929 return true;
930 } else if (it->second == intType) {
931 int default1 = 1230000;
932 int default2 = 4560000;
933 int v1 = want1->GetIntParam(it->first, default1);
934 int v2 = want2->GetIntParam(it->first, default2);
935 EXPECT_EQ(v1, v2);
936 return true;
937 } else if (it->second == longType) {
938 long default1 = 1e8;
939 long default2 = 2e8;
940 long v1 = want1->GetLongParam(it->first, default1);
941 long v2 = want2->GetLongParam(it->first, default2);
942 EXPECT_EQ(v1, v2);
943 return true;
944 } else if (it->second == floatType) {
945 float default1 = 12.3;
946 float default2 = 45.6;
947 float v1 = want1->GetFloatParam(it->first, default1);
948 float v2 = want2->GetFloatParam(it->first, default2);
949 EXPECT_EQ(v1, v2);
950 return true;
951 } else if (it->second == doubleType) {
952 double default1 = 12.3;
953 double default2 = 45.6;
954 double v1 = want1->GetDoubleParam(it->first, default1);
955 double v2 = want2->GetDoubleParam(it->first, default2);
956 EXPECT_EQ(v1, v2);
957 return true;
958 }
959 return false;
960 }
961
CompareWantOthers(const std::shared_ptr<DistributedWant> & want1,const std::shared_ptr<DistributedWant> & want2,std::map<std::string,std::string>::iterator it) const962 bool DistributedWantBaseTest::CompareWantOthers(const std::shared_ptr<DistributedWant>& want1,
963 const std::shared_ptr<DistributedWant>& want2, std::map<std::string, std::string>::iterator it) const
964 {
965 if (it->second == boolType) {
966 bool v1 = want1->GetBoolParam(it->first, false);
967 bool v2 = want2->GetBoolParam(it->first, false);
968 EXPECT_EQ(v1, v2);
969 EXPECT_EQ(v1, true);
970 return true;
971 } else if (it->second == byteType) {
972 byte v1 = want1->GetByteParam(it->first, 'j');
973 byte v2 = want2->GetByteParam(it->first, 'k');
974 EXPECT_EQ(v1, v2);
975 return true;
976 } else if (it->second == charType) {
977 zchar v1 = want1->GetCharParam(it->first, 0x01AB);
978 zchar v2 = want2->GetCharParam(it->first, 0x02CD);
979 EXPECT_EQ(v1, v2);
980 return true;
981 } else if (it->second == stringType) {
982 std::string v1 = want1->GetStringParam(it->first);
983 std::string v2 = want2->GetStringParam(it->first);
984 EXPECT_EQ(v1, v2);
985 return true;
986 }
987 return false;
988 }
989
CompareWantArray(const std::shared_ptr<DistributedWant> & want1,const std::shared_ptr<DistributedWant> & want2,std::map<std::string,std::string>::iterator it) const990 bool DistributedWantBaseTest::CompareWantArray(const std::shared_ptr<DistributedWant>& want1,
991 const std::shared_ptr<DistributedWant>& want2, std::map<std::string, std::string>::iterator it) const
992 {
993 if (it->second == boolArrayType) {
994 std::vector<bool> v1 = want1->GetBoolArrayParam(it->first);
995 std::vector<bool> v2 = want2->GetBoolArrayParam(it->first);
996 EXPECT_EQ(v1, v2);
997 return true;
998 } else if (it->second == byteArrayType) {
999 std::vector<byte> v1 = want1->GetByteArrayParam(it->first);
1000 std::vector<byte> v2 = want2->GetByteArrayParam(it->first);
1001 EXPECT_EQ(v1, v2);
1002 return true;
1003 } else if (it->second == charArrayType) {
1004 std::vector<zchar> v1 = want1->GetCharArrayParam(it->first);
1005 std::vector<zchar> v2 = want2->GetCharArrayParam(it->first);
1006 EXPECT_EQ(v1, v2);
1007 return true;
1008 } else if (it->second == shortArrayType) {
1009 std::vector<short> v1 = want1->GetShortArrayParam(it->first);
1010 std::vector<short> v2 = want2->GetShortArrayParam(it->first);
1011 EXPECT_EQ(v1, v2);
1012 } else if (it->second == intArrayType) {
1013 std::vector<int> v1 = want1->GetIntArrayParam(it->first);
1014 std::vector<int> v2 = want2->GetIntArrayParam(it->first);
1015 EXPECT_EQ(v1, v2);
1016 return true;
1017 } else if (it->second == longArrayType) {
1018 std::vector<long> v1 = want1->GetLongArrayParam(it->first);
1019 std::vector<long> v2 = want2->GetLongArrayParam(it->first);
1020 EXPECT_EQ(v1, v2);
1021 return true;
1022 } else if (it->second == floatArrayType) {
1023 std::vector<float> v1 = want1->GetFloatArrayParam(it->first);
1024 std::vector<float> v2 = want2->GetFloatArrayParam(it->first);
1025 EXPECT_EQ(v1, v2);
1026 return true;
1027 } else if (it->second == doubleArrayType) {
1028 std::vector<double> v1 = want1->GetDoubleArrayParam(it->first);
1029 std::vector<double> v2 = want2->GetDoubleArrayParam(it->first);
1030 EXPECT_EQ(v1, v2);
1031 return true;
1032 } else if (it->second == stringArrayType) {
1033 std::vector<std::string> v1 = want1->GetStringArrayParam(it->first);
1034 std::vector<std::string> v2 = want2->GetStringArrayParam(it->first);
1035 EXPECT_EQ(v1, v2);
1036 return true;
1037 }
1038 return false;
1039 }
1040
SendParcelTest(const std::shared_ptr<DistributedWant> & want,std::map<std::string,std::string> & keys) const1041 void DistributedWantBaseTest::SendParcelTest(const std::shared_ptr<DistributedWant> &want,
1042 std::map<std::string, std::string> &keys) const
1043 {
1044 size_t pos1;
1045 size_t pos2;
1046 Parcel data;
1047 bool result = false;
1048
1049 pos1 = data.GetWritePosition();
1050 result = data.WriteParcelable(want.get());
1051 pos2 = data.GetWritePosition();
1052 EXPECT_EQ(result, true);
1053 GTEST_LOG_(INFO) << "SendParcelTest: pos1: " << pos1 << ", pos2: " << pos2 << ", result: " << result;
1054
1055 std::shared_ptr<DistributedWant> wantNew(data.ReadParcelable<DistributedWant>());
1056 EXPECT_NE(wantNew, nullptr);
1057
1058 if (wantNew != nullptr) {
1059 result = CompareWant(want, wantNew, keys);
1060 EXPECT_EQ(result, true);
1061 }
1062 }
1063
AddBoolParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1064 void DistributedWantBaseTest::AddBoolParams(DistributedWant& want,
1065 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1066 {
1067 std::string key;
1068 std::string boolKey = "boolKey";
1069 std::string boolArrayKey = "boolArrayKey";
1070 for (int i = 0; i < loop; i++) {
1071 if (flag & FLAG_TEST_SINGLE) {
1072 bool boolValue = true;
1073 keys[boolKey + std::to_string(i)] = boolType;
1074 want.SetParam(boolKey + std::to_string(i), boolValue);
1075 }
1076
1077 if (flag & FLAG_TEST_ARRAY) {
1078 std::vector<bool> boolArrayValue = {true, false, true};
1079 keys[key] = boolArrayType;
1080 want.SetParam(key, boolArrayValue);
1081 }
1082 }
1083 }
1084
AddByteParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1085 void DistributedWantBaseTest::AddByteParams(DistributedWant& want,
1086 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1087 {
1088 std::string key;
1089 std::string byteKey = "byteKey";
1090 std::string byteArrayKey = "byteArrayKey";
1091 for (int i = 0; i < loop; i++) {
1092 if (flag & FLAG_TEST_SINGLE) {
1093 byte byteValue = 'z';
1094 key = byteKey + std::to_string(i);
1095 keys[key] = byteType;
1096 want.SetParam(key, byteValue);
1097 }
1098
1099 if (flag & FLAG_TEST_ARRAY) {
1100 std::vector<byte> byteArrayValue = {'?', 'a', '\\'};
1101 key = byteArrayKey + std::to_string(i);
1102 keys[key] = byteArrayType;
1103 want.SetParam(key, byteArrayValue);
1104 }
1105 }
1106 }
1107
AddCharParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1108 void DistributedWantBaseTest::AddCharParams(DistributedWant& want,
1109 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1110 {
1111 std::string key;
1112 std::string charKey = "charKey";
1113 std::string charArrayKey = "charArrayKey";
1114 for (int i = 0; i < loop; i++) {
1115 if (flag & FLAG_TEST_SINGLE) {
1116 zchar charValue = U'h';
1117 key = charKey + std::to_string(i);
1118 keys[key] = charType;
1119 want.SetParam(key, charValue);
1120 }
1121
1122 if (flag & FLAG_TEST_ARRAY) {
1123 std::vector<zchar> charArrayValue = {U'e', U'l', U'l', U'o'};
1124 key = charArrayKey + std::to_string(i);
1125 keys[key] = charArrayType;
1126 want.SetParam(key, charArrayValue);
1127 }
1128 }
1129 }
1130
AddShortParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1131 void DistributedWantBaseTest::AddShortParams(DistributedWant& want,
1132 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1133 {
1134 std::string key;
1135 std::string shortKey = "shortKey";
1136 std::string shortArrayKey = "shortArrayKey";
1137 for (int i = 0; i < loop; i++) {
1138 if (flag & FLAG_TEST_SINGLE) {
1139 short shortValue = 1;
1140 key = shortKey + std::to_string(i);
1141 keys[key] = shortType;
1142 want.SetParam(key, shortValue);
1143 }
1144
1145 if (flag & FLAG_TEST_ARRAY) {
1146 std::vector<short> shortArrayValue = {-1, 0, 1};
1147 key = shortArrayKey + std::to_string(i);
1148 keys[key] = shortArrayType;
1149 want.SetParam(key, shortArrayValue);
1150 }
1151 }
1152 }
1153
AddIntParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1154 void DistributedWantBaseTest::AddIntParams(DistributedWant& want,
1155 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1156 {
1157 std::string key;
1158 std::string intKey = "intKey";
1159 std::string intArrayKey = "intArrayKey";
1160 for (int i = 0; i < loop; i++) {
1161 if (flag & FLAG_TEST_SINGLE) {
1162 int intValue = 10;
1163 key = intKey + std::to_string(i);
1164 keys[key] = intType;
1165 want.SetParam(key, intValue);
1166 }
1167
1168 if (flag & FLAG_TEST_ARRAY) {
1169 std::vector<int> intArrayValue = {-10, 0, 10};
1170 key = intArrayKey + std::to_string(i);
1171 keys[key] = intArrayType;
1172 want.SetParam(key, intArrayValue);
1173 }
1174 }
1175 }
1176
AddLongParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1177 void DistributedWantBaseTest::AddLongParams(DistributedWant& want,
1178 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1179 {
1180 std::string key;
1181 std::string longKey = "longKey";
1182 std::string longArrayKey = "longArrayKey";
1183 for (int i = 0; i < loop; i++) {
1184 if (flag & FLAG_TEST_SINGLE) {
1185 long longValue = 100L;
1186 key = longKey + std::to_string(i);
1187 keys[key] = longType;
1188 want.SetParam(key, longValue);
1189 }
1190
1191 if (flag & FLAG_TEST_ARRAY) {
1192 std::vector<long> longArrayValue = {-100, 0, 100};
1193 key = longArrayKey + std::to_string(i);
1194 keys[key] = longArrayType;
1195 want.SetParam(key, longArrayValue);
1196 }
1197 }
1198 }
1199
AddFloatParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1200 void DistributedWantBaseTest::AddFloatParams(DistributedWant& want,
1201 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1202 {
1203 std::string key;
1204 std::string floatKey = "floatKey";
1205 std::string floatArrayKey = "floatArrayKey";
1206 for (int i = 0; i < loop; i++) {
1207 if (flag & FLAG_TEST_SINGLE) {
1208 float floatValue = 100.1f;
1209 key = floatKey + std::to_string(i);
1210 keys[key] = floatType;
1211 want.SetParam(key, floatValue);
1212 }
1213
1214 if (flag & FLAG_TEST_ARRAY) {
1215 std::vector<float> floatArrayValue = {-100.1, 0.1, 100.1};
1216 key = floatArrayKey + std::to_string(i);
1217 keys[key] = floatArrayType;
1218 want.SetParam(key, floatArrayValue);
1219 }
1220 }
1221 }
1222
AddDoubleParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1223 void DistributedWantBaseTest::AddDoubleParams(DistributedWant& want,
1224 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1225 {
1226 std::string key;
1227 std::string doubleKey = "doubleKey";
1228 std::string doubleArrayKey = "doubleArrayKey";
1229 for (int i = 0; i < loop; i++) {
1230 if (flag & FLAG_TEST_SINGLE) {
1231 double doubleValue = 1000.1;
1232 key = doubleKey + std::to_string(i);
1233 keys[key] = doubleType;
1234 want.SetParam(key, doubleValue);
1235 }
1236
1237 if (flag & FLAG_TEST_ARRAY) {
1238 std::vector<double> doubleArrayValue = {-1000.1, 0.1, 1000.1};
1239 key = doubleArrayKey + std::to_string(i);
1240 keys[key] = doubleArrayType;
1241 want.SetParam(key, doubleArrayValue);
1242 }
1243 }
1244 }
1245
AddStringParams(DistributedWant & want,std::map<std::string,std::string> & keys,int loop,unsigned int flag) const1246 void DistributedWantBaseTest::AddStringParams(DistributedWant& want,
1247 std::map<std::string, std::string>& keys, int loop, unsigned int flag) const
1248 {
1249 std::string key;
1250 std::string stringKey = "stringKey";
1251 std::string stringArrayKey = "stringArrayKey";
1252 for (int i = 0; i < loop; i++) {
1253 if (flag & FLAG_TEST_SINGLE) {
1254 std::string stringValue = "zzzz";
1255 key = stringKey + std::to_string(i);
1256 keys[key] = stringType;
1257 want.SetParam(key, stringValue);
1258 }
1259
1260 if (flag & FLAG_TEST_ARRAY) {
1261 std::vector<std::string> stringArrayValue = {"??", "aa", "\\\\"};
1262 key = stringArrayKey + std::to_string(i);
1263 keys[key] = stringArrayType;
1264 want.SetParam(key, stringArrayValue);
1265 }
1266 }
1267 }
1268
TestStringForParseUri(std::string uri,std::string keyString,std::size_t & length,std::string valueStringOrigin)1269 void DistributedWantBaseTest::TestStringForParseUri(std::string uri,
1270 std::string keyString, std::size_t &length, std::string valueStringOrigin)
1271 {
1272 std::size_t head = length;
1273 std::string search = String::SIGNATURE + std::string(".") + keyString + std::string("=");
1274 std::size_t result = uri.find(search);
1275 EXPECT_NE(result, std::string::npos);
1276 EXPECT_GE(result, head);
1277 length += search.length();
1278 if (result != std::string::npos) {
1279 std::size_t pos = result + search.length();
1280 std::size_t delims = uri.find(";", pos);
1281 if (delims != std::string::npos) {
1282 std::string substring = uri.substr(pos, delims - pos);
1283 std::string valueStringNew = String::Unbox(String::Parse(substring));
1284 EXPECT_EQ(valueStringNew, valueStringOrigin);
1285 length += substring.length() + 1;
1286 }
1287 }
1288 }
1289
TestFloatForParseUri(std::string uri,std::string keyFloat,std::size_t & length,float valueFloatOrigin)1290 void DistributedWantBaseTest::TestFloatForParseUri(std::string uri,
1291 std::string keyFloat, std::size_t &length, float valueFloatOrigin)
1292 {
1293 std::size_t head = length;
1294 std::string search = Float::SIGNATURE + std::string(".") + keyFloat + std::string("=");
1295 std::size_t result = uri.find(search);
1296 EXPECT_NE(result, std::string::npos);
1297 EXPECT_GE(result, head);
1298 length += search.length();
1299 if (result != std::string::npos) {
1300 std::size_t pos = result + search.length();
1301 std::size_t delims = uri.find(";", pos);
1302 if (delims != std::string::npos) {
1303 std::string substring = uri.substr(pos, delims - pos);
1304 float valueFloatNew = Float::Unbox(Float::Parse(substring));
1305 EXPECT_EQ(valueFloatNew, valueFloatOrigin);
1306 length += substring.length() + 1;
1307 }
1308 }
1309 }
1310
TestFloatArrayForParseUri(std::string uri,std::string keyFloatArray,std::size_t & length,std::vector<float> valueFloatArrayOrigin)1311 void DistributedWantBaseTest::TestFloatArrayForParseUri(std::string uri,
1312 std::string keyFloatArray, std::size_t &length, std::vector<float> valueFloatArrayOrigin)
1313 {
1314 std::size_t head = length;
1315 std::string search = Array::SIGNATURE + std::string(".") + keyFloatArray + std::string("=");
1316 std::size_t result = uri.find(search);
1317 EXPECT_NE(result, std::string::npos);
1318 EXPECT_GE(result, head);
1319 length += search.length();
1320 if (result != std::string::npos) {
1321 std::size_t pos = result + search.length();
1322 std::size_t delims = uri.find(";", result);
1323 if (delims != std::string::npos) {
1324 std::string substring = uri.substr(pos, delims - pos);
1325 sptr<IArray> array = Array::Parse(substring);
1326 std::vector<float> valueFloatArrayNew;
1327 auto func = [&valueFloatArrayNew](
1328 IInterface *object) { valueFloatArrayNew.push_back(Float::Unbox(IFloat::Query(object))); };
1329 Array::ForEach(array, func);
1330 EXPECT_EQ(valueFloatArrayNew, valueFloatArrayOrigin);
1331 length += substring.length() + 1;
1332 }
1333 }
1334 }
1335
TestStringArrayForParseUri(std::string uri,std::string keyStringArray,std::size_t & length,std::vector<std::string> valueStringArrayOrigin)1336 void DistributedWantBaseTest::TestStringArrayForParseUri(std::string uri,
1337 std::string keyStringArray, std::size_t &length, std::vector<std::string> valueStringArrayOrigin)
1338 {
1339 std::size_t head = length;
1340 std::string search = Array::SIGNATURE + std::string(".") + keyStringArray + std::string("=");
1341 std::size_t result = uri.find(search);
1342 EXPECT_NE(result, std::string::npos);
1343 EXPECT_GE(result, head);
1344 length += search.length();
1345 if (result != std::string::npos) {
1346 std::size_t pos = result + search.length();
1347 std::size_t delims = uri.find(";", result);
1348 if (delims != std::string::npos) {
1349 std::string substring = uri.substr(pos, delims - pos);
1350 sptr<IArray> array = Array::Parse(substring);
1351 std::vector<std::string> valueStringArrayNew;
1352 auto func = [&valueStringArrayNew](IInterface *object) {
1353 valueStringArrayNew.push_back(String::Unbox(IString::Query(object)));
1354 };
1355 Array::ForEach(array, func);
1356 EXPECT_EQ(valueStringArrayNew, valueStringArrayOrigin);
1357 length += substring.length() + 1;
1358 }
1359 }
1360 }
1361
1362 /**
1363 * @tc.number: DistributedScheduleWant_Parcelable_0600
1364 * @tc.name: parcelable
1365 * @tc.desc: Verify parcelable.
1366 */
1367 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0600, Function | MediumTest | Level3)
1368 {
1369 std::string action = "want.action.test";
1370 unsigned int flag = 0x789;
1371 std::string entity = "want.entity.test";
1372 OHOS::AppExecFwk::ElementName element("bundlename", "appname", "abilityname");
1373
1374 std::shared_ptr<DistributedWant> want = std::make_shared<DistributedWant>();
1375 if (want != nullptr) {
1376 want->SetAction(action);
1377 want->AddEntity(entity);
1378 want->AddFlags(flag);
1379 want->SetElement(element);
1380
1381 std::map<std::string, std::string> keys;
1382
1383 SendParcelTest(want, keys);
1384 }
1385 }
1386
1387 /**
1388 * @tc.number: DistributedScheduleWant_Parcelable_0700
1389 * @tc.name: parcelable
1390 * @tc.desc: Verify parcelable.
1391 */
1392 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0700, Function | MediumTest | Level3)
1393 {
1394 std::string action = "want.action.test";
1395 unsigned int flag = 0x789;
1396 std::string entity = "want.entity.test";
1397 OHOS::AppExecFwk::ElementName element("bundlename", "appname", "abilityname");
1398
1399 std::shared_ptr<DistributedWant> want = std::make_shared<DistributedWant>();
1400 if (want != nullptr) {
1401 want->SetAction(action);
1402 want->AddEntity(entity);
1403 want->AddFlags(flag);
1404 want->SetElement(element);
1405
1406 int loop = 1;
1407 std::map<std::string, std::string> keys;
1408
1409 AddByteParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1410 AddCharParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1411 AddShortParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1412 AddIntParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1413 AddLongParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1414 AddFloatParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1415 AddDoubleParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1416 AddStringParams(*(want.get()), keys, loop, FLAG_TEST_BOTH);
1417
1418 SendParcelTest(want, keys);
1419 }
1420 }
1421
1422 /**
1423 * @tc.number: DistributedScheduleWant_Parcelable_0800
1424 * @tc.name: parcelable
1425 * @tc.desc: Verify parcelable.
1426 */
1427 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Parcelable_0800, Function | MediumTest | Level3)
1428 {
1429 std::string action = "want.action.test";
1430 unsigned int flag = 0x789;
1431 std::string entity = "want.entity.test";
1432 OHOS::AppExecFwk::ElementName element("bundlename", "appname", "abilityname");
1433
1434 std::shared_ptr<DistributedWant> want = std::make_shared<DistributedWant>();
1435 if (want != nullptr) {
1436 want->SetAction(action);
1437 want->AddEntity(entity);
1438 want->AddFlags(flag);
1439 want->SetElement(element);
1440 std::map<std::string, std::string> keys;
1441
1442 SendParcelTest(want, keys);
1443 }
1444 }
1445
1446 /**
1447 * @tc.number: DistributedScheduleWant_Flags_0100
1448 * @tc.name: SetFlags/AddFlags/GetFlags/RemoveFlags
1449 * @tc.desc: Verify SetFlags/AddFlags/GetFlags/RemoveFlags.
1450 */
1451 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Flags_0100, Function | MediumTest | Level3)
1452 {
1453 ASSERT_NE(want_, nullptr);
1454 int flags = 3;
1455 int returnsflags;
1456 int description = 8;
1457
1458 want_->SetFlags(description);
1459 want_->AddFlags(flags);
1460 returnsflags = want_->GetFlags();
1461 EXPECT_EQ(11, returnsflags);
1462
1463 want_->RemoveFlags(flags);
1464 returnsflags = want_->GetFlags();
1465 EXPECT_EQ(description, returnsflags);
1466 }
1467
1468 /**
1469 * @tc.number: DistributedScheduleWant_ClearWant_0100
1470 * @tc.name: ClearWant
1471 * @tc.desc: Verify ClearWant.
1472 */
1473 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_ClearWant_0100, Function | MediumTest | Level3)
1474 {
1475 ASSERT_NE(want_, nullptr);
1476 DistributedWant want;
1477 ElementName elementName;
1478 std::string empty = "";
1479 want_->ClearWant(&want);
1480
1481 EXPECT_EQ((uint)0, want_->GetFlags());
1482 EXPECT_EQ(empty, want_->GetType());
1483 EXPECT_EQ(empty, want_->GetAction());
1484 EXPECT_EQ(elementName, want_->GetElement());
1485 EXPECT_EQ((size_t)0, want_->GetEntities().size());
1486 EXPECT_EQ(0, want_->CountEntities());
1487 }
1488
1489 /**
1490 * @tc.number: DistributedScheduleWant_replaceParams_0100
1491 * @tc.name: replaceParams(wantParams)
1492 * @tc.desc: Verify the function when the input string is empty.
1493 */
1494 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_replaceParams_0100, Function | MediumTest | Level3)
1495 {
1496 ASSERT_NE(want_, nullptr);
1497 DistributedWantParams wantParams;
1498 std::string keyStr = "123";
1499 std::string valueStr = "123";
1500 wantParams.SetParam(keyStr, String::Box(valueStr));
1501 want_->ReplaceParams(wantParams);
1502
1503 EXPECT_EQ(valueStr, String::Unbox(IString::Query(want_->GetParams().GetParam(keyStr))));
1504 }
1505
1506 /**
1507 * @tc.number: DistributedScheduleWant_setElement_0100
1508 * @tc.name:setElement / setElementName
1509 * @tc.desc: Verify the function when the input string is empty.
1510 */
1511 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_setElement_0100, Function | MediumTest | Level3)
1512 {
1513 ASSERT_NE(want_, nullptr);
1514 std::string valueStr1 = "xxxxx";
1515 std::string valueStr2 = "uaid";
1516 std::string valueStr3 = "uaygfi";
1517
1518 OHOS::AppExecFwk::ElementName elementname1;
1519 OHOS::AppExecFwk::ElementName elementname2;
1520 OHOS::AppExecFwk::ElementName elementname3;
1521 ElementName elementname4;
1522 elementname1.SetAbilityName(valueStr1);
1523 elementname2.SetDeviceID(valueStr2);
1524 elementname3.SetBundleName(valueStr3);
1525 want_->SetElement(elementname1);
1526 EXPECT_EQ(valueStr1, want_->GetElement().GetAbilityName());
1527
1528 want_->SetElement(elementname2);
1529 EXPECT_EQ(valueStr2, want_->GetElement().GetDeviceID());
1530
1531 want_->SetElement(elementname3);
1532 EXPECT_EQ(valueStr3, want_->GetElement().GetBundleName());
1533
1534 want_->SetElementName(valueStr3, valueStr1);
1535 EXPECT_EQ(valueStr1, want_->GetElement().GetAbilityName());
1536 EXPECT_EQ(valueStr3, want_->GetElement().GetBundleName());
1537
1538 want_->SetElementName(valueStr2, valueStr3, valueStr1);
1539 EXPECT_EQ(valueStr1, want_->GetElement().GetAbilityName());
1540 EXPECT_EQ(valueStr2, want_->GetElement().GetDeviceID());
1541 EXPECT_EQ(valueStr3, want_->GetElement().GetBundleName());
1542 }
1543
1544 /**
1545 * @tc.number: DistributedScheduleWant_Action_0200
1546 * @tc.name:SetAction / GetAction
1547 * @tc.desc: Verify the function when the input string is empty.
1548 */
1549 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Action_0200, Function | MediumTest | Level3)
1550 {
1551 ASSERT_NE(want_, nullptr);
1552 std::string setValue;
1553 want_->SetAction(setValue);
1554 EXPECT_EQ(setValue, want_->GetAction());
1555 }
1556
1557 /**
1558 * @tc.number: DistributedScheduleWant_Action_0300
1559 * @tc.name:SetAction / GetAction
1560 * @tc.desc: Verify the function when the input string contains special characters.
1561 */
1562 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Action_0300, Function | MediumTest | Level3)
1563 {
1564 ASSERT_NE(want_, nullptr);
1565 std::string setValue("action.system.com");
1566 want_->SetAction(setValue);
1567 EXPECT_STREQ(setValue.c_str(), want_->GetAction().c_str());
1568 }
1569
1570 using testByteType = std::tuple<std::string, std::string, byte, byte, byte>;
1571 class DistributedWantParametersBoolArrayTest : public testing::TestWithParam<testByteType> {
1572 public:
DistributedWantParametersBoolArrayTest()1573 DistributedWantParametersBoolArrayTest()
1574 {
1575 want_ = nullptr;
1576 }
~DistributedWantParametersBoolArrayTest()1577 ~DistributedWantParametersBoolArrayTest()
1578 {
1579 want_ = nullptr;
1580 }
1581 static void SetUpTestCase(void);
1582 static void TearDownTestCase(void);
1583 void SetUp();
1584 void TearDown();
1585 std::shared_ptr<DistributedWant> want_;
1586 };
1587
SetUpTestCase(void)1588 void DistributedWantParametersBoolArrayTest::SetUpTestCase(void)
1589 {}
1590
TearDownTestCase(void)1591 void DistributedWantParametersBoolArrayTest::TearDownTestCase(void)
1592 {}
1593
SetUp(void)1594 void DistributedWantParametersBoolArrayTest::SetUp(void)
1595 {
1596 want_ = std::make_shared<DistributedWant>();
1597 }
1598
TearDown(void)1599 void DistributedWantParametersBoolArrayTest::TearDown(void)
1600 {}
1601
1602 /**
1603 * @tc.number: DistributedScheduleWant_BoolArr_0100
1604 * @tc.name:SetBoolArrayParam/GetBoolArrayParam
1605 * @tc.desc: Verify when parameter change.
1606 */
1607 HWTEST_P(DistributedWantParametersBoolArrayTest, DistributedScheduleWant_BoolArr_0100, Function | MediumTest | Level3)
1608 {
1609 std::string setKey = std::get<0>(GetParam());
1610 std::string getKey = std::get<1>(GetParam());
1611 byte setValue = std::get<2>(GetParam());
1612 byte defaultValue = std::get<3>(GetParam());
1613 byte result = std::get<4>(GetParam());
1614 want_->SetParam(setKey, setValue);
1615 EXPECT_EQ(result, want_->GetByteParam(getKey, defaultValue));
1616 }
1617
1618 INSTANTIATE_TEST_SUITE_P(WantParametersBoolArrayTestCaseP, DistributedWantParametersBoolArrayTest,
1619 testing::Values(testByteType("", "aa", '#', 'U', 'U'), testByteType("", "", 'N', 'K', 'N'),
1620 testByteType("1*中_aR", "aa", 'a', '%', '%'), testByteType("1*中_aR", "1*中_aR", 'a', 'z', 'a')));
1621
1622 using testBoolArrayType =
1623 std::tuple<std::string, std::string, std::vector<bool>, std::vector<bool>, std::vector<bool>>;
1624 class DistributedWantBoolArrayParamTest : public testing::TestWithParam<testBoolArrayType> {
1625 public:
DistributedWantBoolArrayParamTest()1626 DistributedWantBoolArrayParamTest()
1627 {
1628 want_ = nullptr;
1629 }
~DistributedWantBoolArrayParamTest()1630 ~DistributedWantBoolArrayParamTest()
1631 {
1632 want_ = nullptr;
1633 }
1634 static void SetUpTestCase(void);
1635 static void TearDownTestCase(void);
1636 void SetUp();
1637 void TearDown();
1638 std::shared_ptr<DistributedWant> want_;
1639 };
1640
SetUpTestCase(void)1641 void DistributedWantBoolArrayParamTest::SetUpTestCase(void)
1642 {}
1643
TearDownTestCase(void)1644 void DistributedWantBoolArrayParamTest::TearDownTestCase(void)
1645 {}
1646
SetUp(void)1647 void DistributedWantBoolArrayParamTest::SetUp(void)
1648 {
1649 want_ = std::make_shared<DistributedWant>();
1650 }
1651
TearDown(void)1652 void DistributedWantBoolArrayParamTest::TearDown(void)
1653 {}
1654
1655 /**
1656 * @tc.number: DistributedScheduleWant_BoolArray_0200
1657 * @tc.name:SetBoolArrayParam/GetBoolArrayParam
1658 * @tc.desc: Verify when parameter change.
1659 */
1660 HWTEST_P(DistributedWantBoolArrayParamTest, DistributedScheduleWant_BoolArray_0200, Function | MediumTest | Level3)
1661 {
1662 ASSERT_NE(want_, nullptr);
1663 std::string setKey = std::get<0>(GetParam());
1664 std::string getKey = std::get<1>(GetParam());
1665 std::vector<bool> setValue = std::get<2>(GetParam());
1666 std::vector<bool> defaultValue = std::get<3>(GetParam());
1667 std::vector<bool> result = std::get<4>(GetParam());
1668 want_->SetParam(setKey, setValue);
1669 EXPECT_EQ(result, want_->GetBoolArrayParam(getKey));
1670 }
1671
1672 INSTANTIATE_TEST_SUITE_P(WantBoolArrayParamTestCaseP, DistributedWantBoolArrayParamTest,
1673 testing::Values(testBoolArrayType("", "aa", {true, false}, {}, {}),
1674 testBoolArrayType("", "", {true, false}, {}, {true, false}),
1675 testBoolArrayType("1*中_aR", "aa", {true, false}, {}, {}),
1676 testBoolArrayType("1*中_aR", "1*中_aR", {false, true}, {}, {false, true})));
1677
1678 using testCharArrayType =
1679 std::tuple<std::string, std::string, std::vector<zchar>, std::vector<zchar>, std::vector<zchar>>;
1680 class DistributedWantCharArrayParamTest : public testing::TestWithParam<testCharArrayType> {
1681 public:
DistributedWantCharArrayParamTest()1682 DistributedWantCharArrayParamTest()
1683 {
1684 want_ = nullptr;
1685 }
~DistributedWantCharArrayParamTest()1686 ~DistributedWantCharArrayParamTest()
1687 {
1688 want_ = nullptr;
1689 }
1690 static void SetUpTestCase(void);
1691 static void TearDownTestCase(void);
1692 void SetUp();
1693 void TearDown();
1694 std::shared_ptr<DistributedWant> want_;
1695 };
1696
SetUpTestCase(void)1697 void DistributedWantCharArrayParamTest::SetUpTestCase(void)
1698 {}
1699
TearDownTestCase(void)1700 void DistributedWantCharArrayParamTest::TearDownTestCase(void)
1701 {}
1702
SetUp(void)1703 void DistributedWantCharArrayParamTest::SetUp(void)
1704 {
1705 want_ = std::make_shared<DistributedWant>();
1706 }
1707
TearDown(void)1708 void DistributedWantCharArrayParamTest::TearDown(void)
1709 {}
1710
1711 /**
1712 * @tc.number: DistributedScheduleWant_Parameters_CharArray_0100
1713 * @tc.name: SetParam/GetCharArrayParam
1714 * @tc.desc: Verify when parameter change.
1715 */
1716 HWTEST_P(DistributedWantCharArrayParamTest, DistributedScheduleWant_Parameters_CharArray_0100,
1717 Function | MediumTest | Level3)
1718 {
1719 ASSERT_NE(want_, nullptr);
1720 std::string setKey = std::get<0>(GetParam());
1721 std::string getKey = std::get<1>(GetParam());
1722 std::vector<zchar> setValue = std::get<2>(GetParam());
1723 std::vector<zchar> defaultValue = std::get<3>(GetParam());
1724 std::vector<zchar> result = std::get<4>(GetParam());
1725 want_->SetParam(setKey, setValue);
1726 EXPECT_EQ(result, want_->GetCharArrayParam(getKey));
1727 }
1728
1729 INSTANTIATE_TEST_SUITE_P(WantCharArrayParamTestCaseP, DistributedWantCharArrayParamTest,
1730 testing::Values(testCharArrayType("", "aa", {U'中', U'文'}, {}, {}),
1731 testCharArrayType("", "", {U'中', U'文'}, {}, {U'中', U'文'}),
1732 testCharArrayType("1*中_aR", "aa", {U'中', U'文'}, {}, {}),
1733 testCharArrayType("1*中_aR", "1*中_aR", {U'中', U'文'}, {}, {U'中', U'文'})));
1734
1735 /**
1736 * @tc.number: DistributedScheduleWant_Parameters_CharArray_0200
1737 * @tc.name: GetCharArrayParam
1738 * @tc.desc: Verify when the value is char array.
1739 */
1740 HWTEST_F(DistributedWantCharArrayParamTest, DistributedScheduleWant_Parameters_CharArray_0200,
1741 Function | MediumTest | Level3)
1742 {
1743 ASSERT_NE(want_, nullptr);
1744 std::vector<zchar> defaultValue;
1745 std::string getKey("aa");
1746 EXPECT_EQ(defaultValue, want_->GetCharArrayParam(getKey));
1747 }
1748
1749 /**
1750 * @tc.number: DistributedScheduleWant_Parameters_CharArray_0300
1751 * @tc.name: SetParam/GetCharArrayParam
1752 * @tc.desc: Verify when the value is char array.
1753 */
1754 HWTEST_F(DistributedWantCharArrayParamTest, DistributedScheduleWant_Parameters_CharArray_0300,
1755 Function | MediumTest | Level3)
1756 {
1757 ASSERT_NE(want_, nullptr);
1758 std::string emptyStr("ff");
1759 std::vector<zchar> firstValue({U'中', U'文'});
1760 std::vector<zchar> secondValue({U'字', U'符'});
1761 std::vector<zchar> thirdValue({U'集', U'英'});
1762 std::string keyStr("aa");
1763 want_->SetParam(emptyStr, firstValue);
1764 want_->SetParam(emptyStr, firstValue);
1765 want_->SetParam(emptyStr, secondValue);
1766 std::vector<zchar> defaultValue;
1767 EXPECT_EQ(defaultValue, want_->GetCharArrayParam(keyStr));
1768 want_->SetParam(emptyStr, thirdValue);
1769 EXPECT_EQ(thirdValue, want_->GetCharArrayParam(emptyStr));
1770 }
1771
1772 /**
1773 * @tc.number: DistributedScheduleWant_Parameters_CharArray_0400
1774 * @tc.name: SetParam/GetCharArrayParam
1775 * @tc.desc: Verify when the value is char array.
1776 */
1777 HWTEST_F(DistributedWantCharArrayParamTest, DistributedScheduleWant_Parameters_CharArray_0400,
1778 Function | MediumTest | Level3)
1779 {
1780 ASSERT_NE(want_, nullptr);
1781 std::string firstKey("%1uH3");
1782 std::vector<zchar> firstValue({U'中', U'文'});
1783 std::vector<zchar> secondValue({U'字', U'符'});
1784 std::vector<zchar> defaultValue;
1785 std::string secondKey("aa");
1786 want_->SetParam(firstKey, firstValue);
1787 want_->SetParam(firstKey, firstValue);
1788 want_->SetParam(firstKey, secondValue);
1789 EXPECT_EQ(secondValue, want_->GetCharArrayParam(firstKey));
1790 want_->SetParam(firstKey, firstValue);
1791 EXPECT_EQ(defaultValue, want_->GetCharArrayParam(secondKey));
1792 }
1793
1794 using testCharType = std::tuple<std::string, std::string, zchar, zchar, zchar>;
1795 class DistributedWantCharParamTest : public testing::TestWithParam<testCharType> {
1796 public:
DistributedWantCharParamTest()1797 DistributedWantCharParamTest()
1798 {
1799 want_ = nullptr;
1800 }
~DistributedWantCharParamTest()1801 ~DistributedWantCharParamTest()
1802 {
1803 want_ = nullptr;
1804 }
1805 static void SetUpTestCase(void);
1806 static void TearDownTestCase(void);
1807 void SetUp();
1808 void TearDown();
1809 std::shared_ptr<DistributedWant> want_;
1810 };
1811
SetUpTestCase(void)1812 void DistributedWantCharParamTest::SetUpTestCase(void)
1813 {}
1814
TearDownTestCase(void)1815 void DistributedWantCharParamTest::TearDownTestCase(void)
1816 {}
1817
SetUp(void)1818 void DistributedWantCharParamTest::SetUp(void)
1819 {
1820 want_ = std::make_shared<DistributedWant>();
1821 }
1822
TearDown(void)1823 void DistributedWantCharParamTest::TearDown(void)
1824 {}
1825
1826 /**
1827 * @tc.number: DistributedScheduleWant_Parameters_Char_0100
1828 * @tc.name: SetParam/GetCharParam
1829 * @tc.desc: Verify when the value is char array.
1830 */
1831 HWTEST_P(DistributedWantCharParamTest, DistributedScheduleWant_Parameters_Char_0100, Function | MediumTest | Level3)
1832 {
1833 ASSERT_NE(want_, nullptr);
1834 std::string setKey = std::get<0>(GetParam());
1835 std::string getKey = std::get<1>(GetParam());
1836 zchar setValue = std::get<2>(GetParam());
1837 zchar defaultValue = std::get<3>(GetParam());
1838 zchar result = std::get<4>(GetParam());
1839 want_->SetParam(setKey, setValue);
1840 EXPECT_EQ(result, want_->GetCharParam(getKey, defaultValue));
1841 }
1842
1843 INSTANTIATE_TEST_SUITE_P(WantParametersCharTestCaseP, DistributedWantCharParamTest,
1844 testing::Values(testCharType("", "aa", U'#', U'中', U'中'), testCharType("", "", U'中', U'K', U'中'),
1845 testCharType("1*中_aR", "aa", U'a', U'中', U'中'), testCharType("1*中_aR", "1*中_aR", U'中', U'z', U'中')));
1846
1847 /**
1848 * @tc.number: DistributedScheduleWant_Parameters_Char_0200
1849 * @tc.name: SetParam/GetCharParam
1850 * @tc.desc: Verify when the value is char
1851 */
1852 HWTEST_F(DistributedWantCharParamTest, DistributedScheduleWant_Parameters_Char_0200, Function | MediumTest | Level3)
1853 {
1854 ASSERT_NE(want_, nullptr);
1855 zchar defaultValue = U'文';
1856 std::string getKey("aa");
1857 EXPECT_EQ(defaultValue, want_->GetCharParam(getKey, defaultValue));
1858 }
1859
1860 /**
1861 * @tc.number: DistributedScheduleWant_Parameters_Char_0300
1862 * @tc.name: SetParam/GetCharParam
1863 * @tc.desc: Verify when the value is char.
1864 */
1865 HWTEST_F(DistributedWantCharParamTest, DistributedScheduleWant_Parameters_Char_0300, Function | MediumTest | Level3)
1866 {
1867 ASSERT_NE(want_, nullptr);
1868 std::string emptyStr("jj");
1869 zchar firstValue = U'中';
1870 zchar secondValue = U'文';
1871 zchar thirdValue = U'字';
1872 zchar firstDefaultValue = U'符';
1873 zchar secondDefaultValue = U'集';
1874 std::string keyStr("aa");
1875 want_->SetParam(emptyStr, firstValue);
1876 want_->SetParam(emptyStr, firstValue);
1877 want_->SetParam(emptyStr, secondValue);
1878 EXPECT_EQ(firstDefaultValue, want_->GetCharParam(keyStr, firstDefaultValue));
1879 want_->SetParam(emptyStr, thirdValue);
1880 EXPECT_EQ(thirdValue, want_->GetCharParam(emptyStr, secondDefaultValue));
1881 }
1882
1883 /**
1884 * @tc.number: DistributedScheduleWant_Parameters_Char_0400
1885 * @tc.name: SetParam/GetCharParam
1886 * @tc.desc: Verify when the value is char.
1887 */
1888 HWTEST_F(DistributedWantCharParamTest, DistributedScheduleWant_Parameters_Char_0400, Function | MediumTest | Level3)
1889 {
1890 ASSERT_NE(want_, nullptr);
1891 std::string firstKey("%1uH3");
1892 zchar firstValue = U'中';
1893 zchar secondValue = U'文';
1894 zchar firstDefaultValue = U'字';
1895 zchar secondDefaultValue = U'符';
1896 std::string secondKey("aa");
1897 want_->SetParam(firstKey, firstValue);
1898 want_->SetParam(firstKey, firstValue);
1899 want_->SetParam(firstKey, secondValue);
1900 EXPECT_EQ(secondValue, want_->GetCharParam(firstKey, firstDefaultValue));
1901 want_->SetParam(firstKey, firstValue);
1902 EXPECT_EQ(secondDefaultValue, want_->GetCharParam(secondKey, secondDefaultValue));
1903 }
1904
1905 using testDoubleArrayType =
1906 std::tuple<std::string, std::string, std::vector<double>, std::vector<double>, std::vector<double>>;
1907 class DistributedWantDoubleArrayParamTest : public testing::TestWithParam<testDoubleArrayType> {
1908 public:
DistributedWantDoubleArrayParamTest()1909 DistributedWantDoubleArrayParamTest()
1910 {
1911 want_ = nullptr;
1912 }
~DistributedWantDoubleArrayParamTest()1913 ~DistributedWantDoubleArrayParamTest()
1914 {
1915 want_ = nullptr;
1916 }
1917 static void SetUpTestCase(void);
1918 static void TearDownTestCase(void);
1919 void SetUp();
1920 void TearDown();
1921 std::shared_ptr<DistributedWant> want_;
1922 };
1923
SetUpTestCase(void)1924 void DistributedWantDoubleArrayParamTest::SetUpTestCase(void)
1925 {}
1926
TearDownTestCase(void)1927 void DistributedWantDoubleArrayParamTest::TearDownTestCase(void)
1928 {}
1929
SetUp(void)1930 void DistributedWantDoubleArrayParamTest::SetUp(void)
1931 {
1932 want_ = std::make_shared<DistributedWant>();
1933 }
1934
TearDown(void)1935 void DistributedWantDoubleArrayParamTest::TearDown(void)
1936 {}
1937
1938 /**
1939 * @tc.number: DistributedScheduleWant_DoubleArray_0100
1940 * @tc.name: SetParam/GetDoubleArrayParam
1941 * @tc.desc: Verify when parameter change.
1942 */
1943 HWTEST_P(DistributedWantDoubleArrayParamTest, DistributedScheduleWant_DoubleArray_0100, Function | MediumTest | Level3)
1944 {
1945 ASSERT_NE(want_, nullptr);
1946 std::string setKey = std::get<0>(GetParam());
1947 std::string getKey = std::get<1>(GetParam());
1948 std::vector<double> setValue = std::get<2>(GetParam());
1949 std::vector<double> defaultValue = std::get<3>(GetParam());
1950 std::vector<double> result = std::get<4>(GetParam());
1951 want_->SetParam(setKey, setValue);
1952 EXPECT_EQ(result, want_->GetDoubleArrayParam(getKey));
1953 }
1954
1955 INSTANTIATE_TEST_SUITE_P(WantDoubleArrayParamTestCaseP, DistributedWantDoubleArrayParamTest,
1956 testing::Values(testDoubleArrayType("", "aa", {-1.1, -2.1}, {}, {}),
1957 testDoubleArrayType("", "", {-41.1, -42.1}, {}, {-41.1, -42.1}),
1958 testDoubleArrayType("1*中_aR", "aa", {50.1, 51.1}, {}, {}),
1959 testDoubleArrayType("1*中_aR", "1*中_aR", {5000.1, 5001.1}, {}, {5000.1, 5001.1})));
1960
1961 /**
1962 * @tc.number: DistributedScheduleWant_DoubleArray_0200
1963 * @tc.name: SetParam/GetDoubleArrayParam
1964 * @tc.desc: Verify when parameter change.
1965 */
1966 HWTEST_F(DistributedWantDoubleArrayParamTest, DistributedScheduleWant_DoubleArray_0200, Function | MediumTest | Level3)
1967 {
1968 ASSERT_NE(want_, nullptr);
1969 std::vector<double> defaultValue;
1970 std::string key = "aa";
1971 EXPECT_EQ(defaultValue, want_->GetDoubleArrayParam(key));
1972 }
1973
1974 /**
1975 * @tc.number: DistributedScheduleWant_DoubleArray_0300
1976 * @tc.name: SetParam/GetDoubleArrayParam
1977 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key
1978 */
1979 HWTEST_F(DistributedWantDoubleArrayParamTest, DistributedScheduleWant_DoubleArray_0300, Function | MediumTest | Level3)
1980 {
1981 ASSERT_NE(want_, nullptr);
1982 std::vector<double> defaultValue;
1983 std::string setKey1 = "cc";
1984 std::string setKey2 = "aa";
1985 std::vector<double> setValue1 = {1.1, 2.1};
1986 std::vector<double> setValue2 = {5.1, 6.1};
1987 want_->SetParam(setKey1, setValue1);
1988 want_->SetParam(setKey1, setValue1);
1989 setValue1 = {2.1, 3.1};
1990 want_->SetParam(setKey1, setValue1);
1991 EXPECT_EQ(defaultValue, want_->GetDoubleArrayParam(setKey2));
1992 setValue1 = {4.1, 5.1};
1993 want_->SetParam(setKey1, setValue1);
1994 EXPECT_EQ(setValue1, want_->GetDoubleArrayParam(setKey1));
1995 }
1996
1997 /**
1998 * @tc.number: DistributedScheduleWant_DoubleArray_0400
1999 * @tc.name: SetParam/GetDoubleArrayParam
2000 * @tc.desc: set empty-string key repeatedly, then get param of the key
2001 */
2002 HWTEST_F(DistributedWantDoubleArrayParamTest, DistributedScheduleWant_DoubleArray_0400, Function | MediumTest | Level3)
2003 {
2004 ASSERT_NE(want_, nullptr);
2005 std::vector<double> defaultValue;
2006 std::string setKey1 = "%1uH3";
2007 std::string setKey2 = "aa";
2008 std::vector<double> setValue1 = {-1.1, -2.1};
2009 std::vector<double> setValue2 = {9.1, 10.1};
2010 want_->SetParam(setKey1, setValue1);
2011 want_->SetParam(setKey1, setValue1);
2012 setValue1 = {0.1, 1.1};
2013 want_->SetParam(setKey1, setValue1);
2014 EXPECT_EQ(setValue1, want_->GetDoubleArrayParam(setKey1));
2015 setValue1 = {4.1, 5.1};
2016 want_->SetParam(setKey1, setValue1);
2017 setValue1 = {-10.1, -11.1};
2018 EXPECT_EQ(defaultValue, want_->GetDoubleArrayParam(setKey2));
2019 }
2020
2021 using testFloatArrayType =
2022 std::tuple<std::string, std::string, std::vector<float>, std::vector<float>, std::vector<float>>;
2023 class DistributedWantFloatArrayParamTest : public testing::TestWithParam<testFloatArrayType> {
2024 public:
DistributedWantFloatArrayParamTest()2025 DistributedWantFloatArrayParamTest()
2026 {
2027 want_ = nullptr;
2028 }
~DistributedWantFloatArrayParamTest()2029 ~DistributedWantFloatArrayParamTest()
2030 {
2031 want_ = nullptr;
2032 }
2033 static void SetUpTestCase(void);
2034 static void TearDownTestCase(void);
2035 void SetUp();
2036 void TearDown();
2037 std::shared_ptr<DistributedWant> want_;
2038 };
2039
SetUpTestCase(void)2040 void DistributedWantFloatArrayParamTest::SetUpTestCase(void)
2041 {}
2042
TearDownTestCase(void)2043 void DistributedWantFloatArrayParamTest::TearDownTestCase(void)
2044 {}
2045
SetUp(void)2046 void DistributedWantFloatArrayParamTest::SetUp(void)
2047 {
2048 want_ = std::make_shared<DistributedWant>();
2049 }
2050
TearDown(void)2051 void DistributedWantFloatArrayParamTest::TearDown(void)
2052 {}
2053
2054 /**
2055 * @tc.number: DistributedScheduleWant_FloatArray_0100
2056 * @tc.name: SetParam/GetFloatArrayParam
2057 * @tc.desc: Verify when parameter change.
2058 */
2059 HWTEST_P(DistributedWantFloatArrayParamTest, DistributedScheduleWant_FloatArray_0100, Function | MediumTest | Level3)
2060 {
2061 ASSERT_NE(want_, nullptr);
2062 std::string setKey = std::get<0>(GetParam());
2063 std::string getKey = std::get<1>(GetParam());
2064 std::vector<float> setValue = std::get<2>(GetParam());
2065 std::vector<float> defaultValue = std::get<3>(GetParam());
2066 std::vector<float> result = std::get<4>(GetParam());
2067 want_->SetParam(setKey, setValue);
2068 EXPECT_EQ(result, want_->GetFloatArrayParam(getKey));
2069 }
2070
2071 INSTANTIATE_TEST_SUITE_P(WantFloatArrayParamTestCaseP, DistributedWantFloatArrayParamTest,
2072 testing::Values(testFloatArrayType("", "aa", {-1.1, -2.1}, {}, {}),
2073 testFloatArrayType("", "", {-41.1, -42.1}, {}, {-41.1, -42.1}),
2074 testFloatArrayType("1*中_aR", "aa", {50.1, 51.1}, {}, {}),
2075 testFloatArrayType("1*中_aR", "1*中_aR", {5000.1, 5001.1}, {}, {5000.1, 5001.1})));
2076
2077 /**
2078 * @tc.number: DistributedScheduleWant_FloatArray_0200
2079 * @tc.name: SetParam/GetFloatArrayParam
2080 * @tc.desc: get param when WantParam is empty
2081 */
2082 HWTEST_F(DistributedWantFloatArrayParamTest, DistributedScheduleWant_FloatArray_0200, Function | MediumTest | Level3)
2083 {
2084 ASSERT_NE(want_, nullptr);
2085 std::vector<float> defaultValue;
2086 std::string key = "aa";
2087 EXPECT_EQ(defaultValue, want_->GetFloatArrayParam(key));
2088 }
2089
2090 /**
2091 * @tc.number: DistributedScheduleWant_FloatArray_0300
2092 * @tc.name: SetParam & GetFloatArrayParam
2093 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key
2094 */
2095 HWTEST_F(DistributedWantFloatArrayParamTest, DistributedScheduleWant_FloatArray_0300, Function | MediumTest | Level3)
2096 {
2097 ASSERT_NE(want_, nullptr);
2098 std::vector<float> defaultValue;
2099 std::string setKey1 = "hh";
2100 std::string setKey2 = "aa";
2101 std::vector<float> setValue1 = {1.1, 2.1};
2102 want_->SetParam(setKey1, setValue1);
2103 want_->SetParam(setKey1, setValue1);
2104 setValue1 = {2.1, 3.1};
2105 want_->SetParam(setKey1, setValue1);
2106 EXPECT_EQ(defaultValue, want_->GetFloatArrayParam(setKey2));
2107 setValue1 = {4.1, 5.1};
2108 want_->SetParam(setKey1, setValue1);
2109 EXPECT_EQ(setValue1, want_->GetFloatArrayParam(setKey1));
2110 }
2111
2112 /**
2113 * @tc.number: DistributedScheduleWant_FloatArray_0400
2114 * @tc.name: SetParam & GetFloatArrayParam
2115 * @tc.desc: set empty-string key repeatedly, then get param of the key
2116 */
2117 HWTEST_F(DistributedWantFloatArrayParamTest, DistributedScheduleWant_FloatArray_0400, Function | MediumTest | Level3)
2118 {
2119 ASSERT_NE(want_, nullptr);
2120 std::vector<float> defaultValue;
2121 std::string setKey1 = "%1uH3";
2122 std::string setKey2 = "aa";
2123 std::vector<float> setValue1 = {-1.1, -2.1};
2124 std::vector<float> setValue2 = {9.1, 10.1};
2125 want_->SetParam(setKey1, setValue1);
2126 want_->SetParam(setKey1, setValue1);
2127 setValue1 = {0.1, 1.1};
2128 want_->SetParam(setKey1, setValue1);
2129 EXPECT_EQ(setValue1, want_->GetFloatArrayParam(setKey1));
2130 setValue1 = {4.1, 5.1};
2131 want_->SetParam(setKey1, setValue1);
2132 EXPECT_EQ(defaultValue, want_->GetFloatArrayParam(setKey2));
2133 }
2134
2135 using testLongArrayType =
2136 std::tuple<std::string, std::string, std::vector<long>, std::vector<long>, std::vector<long>>;
2137 class DistributedWantLongArrayParamTest : public testing::TestWithParam<testLongArrayType> {
2138 public:
DistributedWantLongArrayParamTest()2139 DistributedWantLongArrayParamTest()
2140 {
2141 want_ = nullptr;
2142 }
~DistributedWantLongArrayParamTest()2143 ~DistributedWantLongArrayParamTest()
2144 {
2145 want_ = nullptr;
2146 }
2147 static void SetUpTestCase(void);
2148 static void TearDownTestCase(void);
2149 void SetUp();
2150 void TearDown();
2151 std::shared_ptr<DistributedWant> want_;
2152 };
2153
SetUpTestCase(void)2154 void DistributedWantLongArrayParamTest::SetUpTestCase(void)
2155 {}
2156
TearDownTestCase(void)2157 void DistributedWantLongArrayParamTest::TearDownTestCase(void)
2158 {}
2159
SetUp(void)2160 void DistributedWantLongArrayParamTest::SetUp(void)
2161 {
2162 want_ = std::make_shared<DistributedWant>();
2163 }
2164
TearDown(void)2165 void DistributedWantLongArrayParamTest::TearDown(void)
2166 {}
2167
2168 /**
2169 * @tc.number: DistributedScheduleWant_LongArray_0100
2170 * @tc.name: SetParam & GetLongArrayParam
2171 * @tc.desc: Verify when parameter change.
2172 */
2173 HWTEST_P(DistributedWantLongArrayParamTest, DistributedScheduleWant_LongArray_0100, Function | MediumTest | Level3)
2174 {
2175 ASSERT_NE(want_, nullptr);
2176 std::string setKey = std::get<0>(GetParam());
2177 std::string getKey = std::get<1>(GetParam());
2178 std::vector<long> setValue = std::get<2>(GetParam());
2179 std::vector<long> defaultValue = std::get<3>(GetParam());
2180 std::vector<long> result = std::get<4>(GetParam());
2181 want_->SetParam(setKey, setValue);
2182 EXPECT_EQ(result, want_->GetLongArrayParam(getKey));
2183 }
2184
2185 INSTANTIATE_TEST_SUITE_P(WantLongArrayParamTestCaseP, DistributedWantLongArrayParamTest,
2186 testing::Values(testLongArrayType("", "aa", {-1, 3, 25, -9}, {}, {}),
2187 testLongArrayType("", "", {-41, 0, 0, 9}, {}, {-41, 0, 0, 9}),
2188 testLongArrayType("1*中_aR", "aa", {50, 2, -9}, {}, {}),
2189 testLongArrayType("1*中_aR", "1*中_aR", {-5000}, {}, {-5000})));
2190
2191 /**
2192 * @tc.number: DistributedScheduleWant_LongArray_0200
2193 * @tc.name: SetParam & GetLongArrayParam
2194 * @tc.desc: get param when WantParam is empty
2195 */
2196 HWTEST_F(DistributedWantLongArrayParamTest, DistributedScheduleWant_LongArray_0200, Function | MediumTest | Level3)
2197 {
2198 ASSERT_NE(want_, nullptr);
2199 std::vector<long> defaultValue;
2200 std::string key = "aa";
2201 EXPECT_EQ(defaultValue, want_->GetLongArrayParam(key));
2202 }
2203
2204 /**
2205 * @tc.number: DistributedScheduleWant_LongArray_0300
2206 * @tc.name: SetParam & GetLongArrayParam
2207 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key
2208 */
2209 HWTEST_F(DistributedWantLongArrayParamTest, DistributedScheduleWant_LongArray_0300, Function | MediumTest | Level3)
2210 {
2211 ASSERT_NE(want_, nullptr);
2212 std::vector<long> defaultValue;
2213 std::string setKey1 = "bb";
2214 std::string setKey2 = "aa";
2215 std::vector<long> setValue1 = {1, 2};
2216 want_->SetParam(setKey1, setValue1);
2217 want_->SetParam(setKey1, setValue1);
2218 setValue1 = {2, 3};
2219 want_->SetParam(setKey1, setValue1);
2220 EXPECT_EQ(defaultValue, want_->GetLongArrayParam(setKey2));
2221 setValue1 = {4, 5};
2222 want_->SetParam(setKey1, setValue1);
2223 EXPECT_EQ(setValue1, want_->GetLongArrayParam(setKey1));
2224 }
2225
2226 /**
2227 * @tc.number: DistributedScheduleWant_LongArray_0400
2228 * @tc.name: SetParam & GetLongArrayParam
2229 * @tc.desc: set empty-string key repeatedly, then get param of the key
2230 */
2231 HWTEST_F(DistributedWantLongArrayParamTest, DistributedScheduleWant_LongArray_0400, Function | MediumTest | Level3)
2232 {
2233 ASSERT_NE(want_, nullptr);
2234 std::vector<long> defaultValue;
2235 std::string setKey1 = "%1uH3";
2236 std::string setKey2 = "aa";
2237 std::vector<long> setValue1 = {-1, -2};
2238 want_->SetParam(setKey1, setValue1);
2239 want_->SetParam(setKey1, setValue1);
2240 setValue1 = {0, 1};
2241 want_->SetParam(setKey1, setValue1);
2242 EXPECT_EQ(setValue1, want_->GetLongArrayParam(setKey1));
2243 setValue1 = {4, 5};
2244 want_->SetParam(setKey1, setValue1);
2245 EXPECT_EQ(defaultValue, want_->GetLongArrayParam(setKey2));
2246 }
2247
2248 using testShortArrayType =
2249 std::tuple<std::string, std::string, std::vector<short>, std::vector<short>, std::vector<short>>;
2250 class DistributedWantShortArrayParamTest : public testing::TestWithParam<testShortArrayType> {
2251 public:
DistributedWantShortArrayParamTest()2252 DistributedWantShortArrayParamTest()
2253 {
2254 want_ = nullptr;
2255 }
~DistributedWantShortArrayParamTest()2256 ~DistributedWantShortArrayParamTest()
2257 {
2258 want_ = nullptr;
2259 }
2260 static void SetUpTestCase(void);
2261 static void TearDownTestCase(void);
2262 void SetUp();
2263 void TearDown();
2264 std::shared_ptr<DistributedWant> want_;
2265 };
2266
SetUpTestCase(void)2267 void DistributedWantShortArrayParamTest::SetUpTestCase(void)
2268 {}
2269
TearDownTestCase(void)2270 void DistributedWantShortArrayParamTest::TearDownTestCase(void)
2271 {}
2272
SetUp(void)2273 void DistributedWantShortArrayParamTest::SetUp(void)
2274 {
2275 want_ = std::make_shared<DistributedWant>();
2276 }
2277
TearDown(void)2278 void DistributedWantShortArrayParamTest::TearDown(void)
2279 {}
2280
2281 /**
2282 * @tc.number: DistributedScheduleWant_ShortArray_0100
2283 * @tc.name: SetParam/GetShortArrayParam
2284 * @tc.desc: Verify when parameter change.
2285 */
2286 HWTEST_P(DistributedWantShortArrayParamTest, DistributedScheduleWant_ShortArray_0100, Function | MediumTest | Level3)
2287 {
2288 ASSERT_NE(want_, nullptr);
2289 std::string setKey = std::get<0>(GetParam());
2290 std::string getKey = std::get<1>(GetParam());
2291 std::vector<short> setValue = std::get<2>(GetParam());
2292 std::vector<short> defaultValue = std::get<3>(GetParam());
2293 std::vector<short> result = std::get<4>(GetParam());
2294 want_->SetParam(setKey, setValue);
2295 EXPECT_EQ(result, want_->GetShortArrayParam(getKey));
2296 }
2297
2298 INSTANTIATE_TEST_SUITE_P(WantShortArrayParamTestCaseP, DistributedWantShortArrayParamTest,
2299 testing::Values(testShortArrayType("", "aa", {-1, 3, 25, -9}, {}, {}),
2300 testShortArrayType("", "", {-41, 0, 0, 9}, {}, {-41, 0, 0, 9}),
2301 testShortArrayType("1*中_aR", "aa", {50, 2, -9}, {}, {}),
2302 testShortArrayType("1*中_aR", "1*中_aR", {-5000}, {}, {-5000})));
2303
2304 /**
2305 * @tc.number: DistributedScheduleWant_ShortArray_0200
2306 * @tc.name: SetParam/GetShortArrayParam
2307 * @tc.desc: Verify when the value is short array
2308 */
2309 HWTEST_F(DistributedWantShortArrayParamTest, DistributedScheduleWant_ShortArray_0200, Function | MediumTest | Level3)
2310 {
2311 ASSERT_NE(want_, nullptr);
2312 std::vector<short> defaultValue;
2313 std::string getKey("aa");
2314 EXPECT_EQ(defaultValue, want_->GetShortArrayParam(getKey));
2315 }
2316
2317 /**
2318 * @tc.number: DistributedScheduleWant_ShortArray_0300
2319 * @tc.name: SetParam/GetShortArrayParam
2320 * @tc.desc: Verify when the value is short array
2321 */
2322 HWTEST_F(DistributedWantShortArrayParamTest, DistributedScheduleWant_ShortArray_0300, Function | MediumTest | Level3)
2323 {
2324 ASSERT_NE(want_, nullptr);
2325 std::string emptyStr("hh");
2326 std::vector<short> firstValue({1, 4, -9});
2327 std::vector<short> secondValue({1, 8, -9});
2328 std::vector<short> thirdValue({1, 4, 9});
2329 std::string keyStr("aa");
2330 want_->SetParam(emptyStr, firstValue);
2331 want_->SetParam(emptyStr, firstValue);
2332 want_->SetParam(emptyStr, secondValue);
2333 std::vector<short> defaultValue;
2334 EXPECT_EQ(defaultValue, want_->GetShortArrayParam(keyStr));
2335 want_->SetParam(emptyStr, thirdValue);
2336 EXPECT_EQ(thirdValue, want_->GetShortArrayParam(emptyStr));
2337 }
2338
2339 /**
2340 * @tc.number: DistributedScheduleWant_ShortArray_0400
2341 * @tc.name: SetParam/GetShortArrayParam
2342 * @tc.desc: Verify when the value is short array
2343 */
2344 HWTEST_F(DistributedWantShortArrayParamTest, DistributedScheduleWant_ShortArray_0400, Function | MediumTest | Level3)
2345 {
2346 ASSERT_NE(want_, nullptr);
2347 std::string firstKey("%1uH3");
2348 std::vector<short> firstValue({-1, -2});
2349 std::vector<short> secondValue({-1, -2, -1, -2, 0});
2350 std::vector<short> thirdValue({-1, -2, 100});
2351 std::string secondKey("aa");
2352 want_->SetParam(firstKey, firstValue);
2353 want_->SetParam(firstKey, firstValue);
2354 want_->SetParam(firstKey, secondValue);
2355 EXPECT_EQ(secondValue, want_->GetShortArrayParam(firstKey));
2356 want_->SetParam(firstKey, thirdValue);
2357 std::vector<short> defaultValue;
2358 EXPECT_EQ(defaultValue, want_->GetShortArrayParam(secondKey));
2359 }
2360
2361 using testShortType = std::tuple<std::string, std::string, short, short, short>;
2362 class DistributedWantShortParamTest : public testing::TestWithParam<testShortType> {
2363 public:
DistributedWantShortParamTest()2364 DistributedWantShortParamTest()
2365 {
2366 want_ = nullptr;
2367 }
~DistributedWantShortParamTest()2368 ~DistributedWantShortParamTest()
2369 {}
2370 static void SetUpTestCase(void);
2371 static void TearDownTestCase(void);
2372 void SetUp();
2373 void TearDown();
2374 std::shared_ptr<DistributedWant> want_;
2375 };
2376
SetUpTestCase(void)2377 void DistributedWantShortParamTest::SetUpTestCase(void)
2378 {}
2379
TearDownTestCase(void)2380 void DistributedWantShortParamTest::TearDownTestCase(void)
2381 {}
2382
SetUp(void)2383 void DistributedWantShortParamTest::SetUp(void)
2384 {
2385 want_ = std::make_shared<DistributedWant>();
2386 }
2387
TearDown(void)2388 void DistributedWantShortParamTest::TearDown(void)
2389 {}
2390
2391 /**
2392 * @tc.number: DistributedScheduleWant_Short_0100
2393 * @tc.name: SetParam/GetShortParam
2394 * @tc.desc: Verify when parameter change.
2395 */
2396 HWTEST_P(DistributedWantShortParamTest, DistributedScheduleWant_Short_0100, Function | MediumTest | Level3)
2397 {
2398 ASSERT_NE(want_, nullptr);
2399 std::string setKey = std::get<0>(GetParam());
2400 std::string getKey = std::get<1>(GetParam());
2401 short setValue = std::get<2>(GetParam());
2402 short defaultValue = std::get<3>(GetParam());
2403 short result = std::get<4>(GetParam());
2404 want_->SetParam(setKey, setValue);
2405 EXPECT_EQ(result, want_->GetShortParam(getKey, defaultValue));
2406 }
2407
2408 INSTANTIATE_TEST_SUITE_P(WantShortParamTestCaseP, DistributedWantShortParamTest,
2409 testing::Values(testShortType("", "aa", -1, 100, 100), testShortType("", "", -9, -41, -9),
2410 testShortType("1*中_aR", "aa", 50, 5, 5), testShortType("1*中_aR", "1*中_aR", -5000, 5000, -5000)));
2411
2412 /**
2413 * @tc.number: DistributedScheduleWant_Short_0200
2414 * @tc.name: SetParam/GetShortParam
2415 * @tc.desc: Verify when the value is short
2416 */
2417 HWTEST_F(DistributedWantShortParamTest, DistributedScheduleWant_Short_0200, Function | MediumTest | Level3)
2418 {
2419 short defaultValue = 200;
2420 std::string getKey("aa");
2421 EXPECT_EQ(defaultValue, want_->GetShortParam(getKey, defaultValue));
2422 }
2423 /**
2424 * @tc.number: DistributedScheduleWant_Short_0300
2425 * @tc.name: SetParam/GetShortParam
2426 * @tc.desc: Verify when the value is short
2427 */
2428 HWTEST_F(DistributedWantShortParamTest, DistributedScheduleWant_Short_0300, Function | MediumTest | Level3)
2429 {
2430 ASSERT_NE(want_, nullptr);
2431 std::string emptyStr("bb");
2432 short firstValue = 1;
2433 short secondValue = 2;
2434 short thirdValue = 4;
2435 short firstDefaultValue = 3;
2436 short secondDefaultValue = 5;
2437 std::string keyStr("aa");
2438 want_->SetParam(emptyStr, firstValue);
2439 want_->SetParam(emptyStr, firstValue);
2440 want_->SetParam(emptyStr, secondValue);
2441 EXPECT_EQ(firstDefaultValue, want_->GetShortParam(keyStr, firstDefaultValue));
2442 want_->SetParam(emptyStr, thirdValue);
2443 EXPECT_EQ(thirdValue, want_->GetShortParam(emptyStr, secondDefaultValue));
2444 }
2445
2446 /**
2447 * @tc.number: DistributedScheduleWant_Short_0400
2448 * @tc.name: SetParam/GetShortParam
2449 * @tc.desc: Verify when the value is short
2450 */
2451 HWTEST_F(DistributedWantShortParamTest, DistributedScheduleWant_Short_0400, Function | MediumTest | Level3)
2452 {
2453 ASSERT_NE(want_, nullptr);
2454 std::string firstKey("%1uH3");
2455 short firstValue = -1;
2456 short secondValue = 0;
2457 short thirdValue = 4;
2458 short firstDefaultValue = 9;
2459 short secondDefaultValue = -10;
2460 std::string secondKey("aa");
2461 want_->SetParam(firstKey, firstValue);
2462 want_->SetParam(firstKey, firstValue);
2463 want_->SetParam(firstKey, secondValue);
2464 EXPECT_EQ(secondValue, want_->GetShortParam(firstKey, firstDefaultValue));
2465 want_->SetParam(firstKey, thirdValue);
2466 EXPECT_EQ(secondDefaultValue, want_->GetShortParam(secondKey, secondDefaultValue));
2467 }
2468
2469 using testStrArrayType =
2470 std::tuple<std::string, std::string, std::vector<std::string>, std::vector<std::string>, std::vector<std::string>>;
2471 class DistributedWantStringArrayParamTest : public testing::TestWithParam<testStrArrayType> {
2472 public:
DistributedWantStringArrayParamTest()2473 DistributedWantStringArrayParamTest()
2474 {
2475 want_ = nullptr;
2476 }
~DistributedWantStringArrayParamTest()2477 ~DistributedWantStringArrayParamTest()
2478 {}
2479 static void SetUpTestCase(void);
2480 static void TearDownTestCase(void);
2481 void SetUp();
2482 void TearDown();
2483 std::shared_ptr<DistributedWant> want_ = nullptr;
2484 };
2485
SetUpTestCase(void)2486 void DistributedWantStringArrayParamTest::SetUpTestCase(void)
2487 {}
2488
TearDownTestCase(void)2489 void DistributedWantStringArrayParamTest::TearDownTestCase(void)
2490 {}
2491
SetUp(void)2492 void DistributedWantStringArrayParamTest::SetUp(void)
2493 {
2494 want_ = std::make_shared<DistributedWant>();
2495 }
2496
TearDown(void)2497 void DistributedWantStringArrayParamTest::TearDown(void)
2498 {}
2499
2500 /**
2501 * @tc.number: DistributedScheduleWant_StringArray_0100
2502 * @tc.name: SetParam/GetStringArrayParam
2503 * @tc.desc: Verify when parameter change.
2504 */
2505 HWTEST_P(DistributedWantStringArrayParamTest, DistributedScheduleWant_StringArray_0100, Function | MediumTest | Level3)
2506 {
2507 ASSERT_NE(want_, nullptr);
2508 std::string setKey = std::get<0>(GetParam());
2509 std::string getKey = std::get<1>(GetParam());
2510 std::vector<std::string> setValue = std::get<2>(GetParam());
2511 std::vector<std::string> defaultValue = std::get<3>(GetParam());
2512 std::vector<std::string> result = std::get<4>(GetParam());
2513 want_->SetParam(setKey, setValue);
2514 EXPECT_EQ(result, want_->GetStringArrayParam(getKey));
2515 }
2516
2517 INSTANTIATE_TEST_SUITE_P(WantStringArrayParamTestCaseP, DistributedWantStringArrayParamTest,
2518 testing::Values(testStrArrayType("", "aa", {"1*中_aR", "dbdb"}, {}, {}),
2519 testStrArrayType("", "", {"1*中_aR", "dbdb"}, {}, {"1*中_aR", "dbdb"}),
2520 testStrArrayType("1*中_aR", "aa", {"1*中_aR", "dbdb"}, {}, {}),
2521 testStrArrayType("1*中_aR", "1*中_aR", {"1*中_aR", "dbdb"}, {}, {"1*中_aR", "dbdb"})));
2522
2523 /**
2524 * @tc.number: DistributedScheduleWant_StringArray_0200
2525 * @tc.name: SetParam/GetStringArrayParam
2526 * @tc.desc: get param when WantParam is empty
2527 */
2528 HWTEST_F(DistributedWantStringArrayParamTest, DistributedScheduleWant_StringArray_0200, Function | MediumTest | Level3)
2529 {
2530 ASSERT_NE(want_, nullptr);
2531 std::vector<std::string> defaultValue;
2532 std::string key = "aa";
2533 std::vector<std::string> resultValue = want_->GetStringArrayParam(key);
2534 EXPECT_EQ(defaultValue, resultValue);
2535 }
2536
2537 /**
2538 * @tc.number: DistributedScheduleWant_StringArray_0300
2539 * @tc.name: SetParam/GetStringArrayParam
2540 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key
2541 */
2542 HWTEST_F(DistributedWantStringArrayParamTest, DistributedScheduleWant_StringArray_0300, Function | MediumTest | Level3)
2543 {
2544 ASSERT_NE(want_, nullptr);
2545 std::vector<std::string> defaultValue;
2546 std::vector<std::string> setValue1 = {"aaa", "2132"};
2547 std::vector<std::string> setValue2 = {"1*中_aR", "dbdb"};
2548 std::string key1 = "cc";
2549 std::string key2 = "aa";
2550 want_->SetParam(key1, setValue1);
2551 want_->SetParam(key1, setValue1);
2552 want_->SetParam(key1, setValue2);
2553 std::vector<std::string> resultValue = want_->GetStringArrayParam(key2);
2554 EXPECT_EQ(defaultValue, resultValue);
2555
2556 want_->SetParam(key1, setValue1);
2557 resultValue = want_->GetStringArrayParam(key1);
2558 EXPECT_EQ(setValue1, resultValue);
2559 }
2560
2561 /**
2562 * @tc.number: DistributedScheduleWant_StringArray_0400
2563 * @tc.name: SetParam/GetStringArrayParam
2564 * @tc.desc: set empty-string key repeatedly, then get param of the key
2565 */
2566 HWTEST_F(DistributedWantStringArrayParamTest, DistributedScheduleWant_StringArray_0400, Function | MediumTest | Level3)
2567 {
2568 ASSERT_NE(want_, nullptr);
2569 std::vector<std::string> defaultValue;
2570 std::vector<std::string> setValue = {"aaa", "2132"};
2571 std::string key1 = "%1uH3";
2572 std::string key2 = "aa";
2573 want_->SetParam(key1, setValue);
2574 want_->SetParam(key1, setValue);
2575 setValue = {"1*中_aR", "3#$%"};
2576 want_->SetParam(key1, setValue);
2577 std::vector<std::string> resultValue = want_->GetStringArrayParam(key1);
2578 EXPECT_EQ(setValue, resultValue);
2579
2580 setValue = {"aaa", "2132"};
2581 want_->SetParam(key1, setValue);
2582 resultValue = want_->GetStringArrayParam(key2);
2583 EXPECT_EQ(defaultValue, resultValue);
2584 }
2585
2586 using testStrType = std::tuple<std::string, std::string, std::string, std::string, std::string>;
2587 class DistributedWantStringParamTest : public testing::TestWithParam<testStrType> {
2588 public:
DistributedWantStringParamTest()2589 DistributedWantStringParamTest()
2590 {
2591 want_ = nullptr;
2592 }
~DistributedWantStringParamTest()2593 ~DistributedWantStringParamTest()
2594 {}
2595 static void SetUpTestCase(void);
2596 static void TearDownTestCase(void);
2597 void SetUp();
2598 void TearDown();
2599 std::shared_ptr<DistributedWant> want_;
2600 };
2601
SetUpTestCase(void)2602 void DistributedWantStringParamTest::SetUpTestCase(void)
2603 {}
2604
TearDownTestCase(void)2605 void DistributedWantStringParamTest::TearDownTestCase(void)
2606 {}
2607
SetUp(void)2608 void DistributedWantStringParamTest::SetUp(void)
2609 {
2610 want_ = std::make_shared<DistributedWant>();
2611 }
2612
TearDown(void)2613 void DistributedWantStringParamTest::TearDown(void)
2614 {}
2615
2616 /**
2617 * @tc.number: DistributedScheduleWant_String_0100
2618 * @tc.name: SetParam/GetStringParam
2619 * @tc.desc: Verify when parameter change.
2620 */
2621 HWTEST_P(DistributedWantStringParamTest, DistributedScheduleWant_String_0100, Function | MediumTest | Level3)
2622 {
2623 ASSERT_NE(want_, nullptr);
2624 std::string setKey = std::get<0>(GetParam());
2625 std::string getKey = std::get<1>(GetParam());
2626 std::string setValue = std::get<2>(GetParam());
2627 std::string defaultValue = std::get<3>(GetParam());
2628 std::string result = std::get<4>(GetParam());
2629 want_->SetParam(setKey, setValue);
2630 EXPECT_EQ(result, want_->GetStringParam(getKey));
2631 }
2632
2633 INSTANTIATE_TEST_SUITE_P(WantStringParamTestCaseP, DistributedWantStringParamTest,
2634 testing::Values(testStrType("", "aa", "1*中_aR", "", ""), testStrType("", "", "1*中_aR", "", "1*中_aR"),
2635 testStrType("1*中_aR", "aa", "aaa", "", ""), testStrType("1*中_aR", "1*中_aR", "aaa", "", "aaa")));
2636
2637 /**
2638 * @tc.number: DistributedScheduleWant_String_0200
2639 * @tc.name: SetParam/GetStringParam
2640 * @tc.desc: get param when WantParam is empty.
2641 */
2642 HWTEST_F(DistributedWantStringParamTest, DistributedScheduleWant_String_0200, Function | MediumTest | Level3)
2643 {
2644 ASSERT_NE(want_, nullptr);
2645 std::string defaultStrValue;
2646 std::string key = "aa";
2647 EXPECT_EQ(defaultStrValue, want_->GetStringParam(key));
2648 }
2649
2650 /**
2651 * @tc.number: DistributedScheduleWant_String_0300
2652 * @tc.name: SetParam/GetStringParam
2653 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key.
2654 */
2655 HWTEST_F(DistributedWantStringParamTest, DistributedScheduleWant_String_0300, Function | MediumTest | Level3)
2656 {
2657 ASSERT_NE(want_, nullptr);
2658 std::string defaultStrValue;
2659 std::string setValue1 = "aaa";
2660 std::string setValue2 = "1*中_aR";
2661 std::string key1 = "dd";
2662 std::string key2 = "aa";
2663 want_->SetParam(key1, setValue1);
2664 want_->SetParam(key1, setValue1);
2665 want_->SetParam(key1, setValue2);
2666 EXPECT_EQ(defaultStrValue, want_->GetStringParam(key2));
2667 want_->SetParam(key1, setValue1);
2668 EXPECT_EQ(setValue1, want_->GetStringParam(key1));
2669 }
2670
2671 /**
2672 * @tc.number: DistributedScheduleWant_String_0400
2673 * @tc.name: SetParam/GetStringParam
2674 * @tc.desc: set empty-string key repeatedly, then get param of the key.
2675 */
2676 HWTEST_F(DistributedWantStringParamTest, DistributedScheduleWant_String_0400, Function | MediumTest | Level3)
2677 {
2678 ASSERT_NE(want_, nullptr);
2679 std::string key1 = "%1uH3";
2680 std::string defaultStrValue;
2681 std::string setValue1 = "aaa";
2682 std::string setValue2 = "1*中_aR";
2683 std::string key2 = "aa";
2684 want_->SetParam(key1, setValue1);
2685 want_->SetParam(key1, setValue1);
2686 want_->SetParam(key1, setValue2);
2687 EXPECT_EQ("1*中_aR", want_->GetStringParam(key1));
2688 want_->SetParam(key1, setValue1);
2689 EXPECT_EQ(defaultStrValue, want_->GetStringParam(key2));
2690 }
2691
2692 using testLongType = std::tuple<std::string, std::string, long, long, long>;
2693 class DistributedWantLongParamTest : public testing::TestWithParam<testLongType> {
2694 public:
DistributedWantLongParamTest()2695 DistributedWantLongParamTest()
2696 {
2697 want_ = nullptr;
2698 }
~DistributedWantLongParamTest()2699 ~DistributedWantLongParamTest()
2700 {}
2701 static void SetUpTestCase(void);
2702 static void TearDownTestCase(void);
2703 void SetUp();
2704 void TearDown();
2705 std::shared_ptr<DistributedWant> want_ = nullptr;
2706 };
2707
SetUpTestCase(void)2708 void DistributedWantLongParamTest::SetUpTestCase(void)
2709 {}
2710
TearDownTestCase(void)2711 void DistributedWantLongParamTest::TearDownTestCase(void)
2712 {}
2713
SetUp(void)2714 void DistributedWantLongParamTest::SetUp(void)
2715 {
2716 want_ = std::make_shared<DistributedWant>();
2717 }
2718
TearDown(void)2719 void DistributedWantLongParamTest::TearDown(void)
2720 {}
2721
2722 /**
2723 * @tc.number: DistributedScheduleWant_LongParam_0100
2724 * @tc.name: SetParam/GetLongParam
2725 * @tc.desc: Verify when parameter change.
2726 */
2727 HWTEST_P(DistributedWantLongParamTest, DistributedScheduleWant_LongParam_0100, Function | MediumTest | Level3)
2728 {
2729 ASSERT_NE(want_, nullptr);
2730 std::string setKey = std::get<0>(GetParam());
2731 std::string getKey = std::get<1>(GetParam());
2732 long setValue = std::get<2>(GetParam());
2733 long defaultValue = std::get<3>(GetParam());
2734 long result = std::get<4>(GetParam());
2735 want_->SetParam(setKey, setValue);
2736 EXPECT_EQ(result, want_->GetLongParam(getKey, defaultValue));
2737 }
2738
2739 INSTANTIATE_TEST_SUITE_P(WantLongParamTestCaseP, DistributedWantLongParamTest,
2740 testing::Values(testLongType("b1", "b1", -1, 100, -1), testLongType("b3", "b4", 600, 200, 200),
2741 testLongType("b5", "b5", 50, 6, 50), testLongType("b6", "b7", 1000, 2200, 2200)));
2742
2743 /**
2744 * @tc.number: DistributedScheduleWant_LongParam_0200
2745 * @tc.name: SetParam/GetLongParam
2746 * @tc.desc: get param when WantParam is empty.
2747 */
2748 HWTEST_F(DistributedWantLongParamTest, DistributedScheduleWant_LongParam_0200, Function | MediumTest | Level3)
2749 {
2750 ASSERT_NE(want_, nullptr);
2751 long defaultValue = 100;
2752 std::string key = "aa";
2753 EXPECT_EQ(defaultValue, want_->GetLongParam(key, defaultValue));
2754 }
2755
2756 /**
2757 * @tc.number: DistributedScheduleWant_LongParam_0300
2758 * @tc.name: SetParam/GetLongParam
2759 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key.
2760 */
2761 HWTEST_F(DistributedWantLongParamTest, DistributedScheduleWant_LongParam_0300, Function | MediumTest | Level3)
2762 {
2763 ASSERT_NE(want_, nullptr);
2764 std::string setKey1 = "dd";
2765 std::string setKey2 = "aa";
2766 long setValue1 = 1;
2767 long setValue2 = 5;
2768 want_->SetParam(setKey1, setValue1);
2769 want_->SetParam(setKey1, setValue1);
2770 setValue1 = 2;
2771 want_->SetParam(setKey1, setValue1);
2772 setValue1 = 3;
2773 EXPECT_EQ(setValue1, want_->GetLongParam(setKey2, setValue1));
2774 setValue1 = 4;
2775 want_->SetParam(setKey1, setValue1);
2776 EXPECT_EQ(setValue1, want_->GetLongParam(setKey1, setValue2));
2777 }
2778
2779 /**
2780 * @tc.number: DistributedScheduleWant_LongParam_0400
2781 * @tc.name: SetParam/GetLongParam
2782 * @tc.desc: set empty-string key repeatedly, then get param of the key.
2783 */
2784 HWTEST_F(DistributedWantLongParamTest, DistributedScheduleWant_LongParam_0400, Function | MediumTest | Level3)
2785 {
2786 ASSERT_NE(want_, nullptr);
2787 std::string setKey1 = "%1uH3";
2788 std::string setKey2 = "aa";
2789 long setValue1 = -1;
2790 long setValue2 = 9;
2791 want_->SetParam(setKey1, setValue1);
2792 want_->SetParam(setKey1, setValue1);
2793 setValue1 = 0;
2794 want_->SetParam(setKey1, setValue1);
2795 EXPECT_EQ(setValue1, want_->GetLongParam(setKey1, setValue2));
2796 setValue1 = 4;
2797 want_->SetParam(setKey1, setValue1);
2798 setValue1 = -10;
2799 EXPECT_EQ(setValue1, want_->GetLongParam(setKey2, setValue1));
2800 }
2801
2802 using testIntType = std::tuple<std::string, std::string, int, int, int>;
2803 class DistributedWantIntParamTest : public testing::TestWithParam<testIntType> {
2804 public:
DistributedWantIntParamTest()2805 DistributedWantIntParamTest()
2806 {
2807 want_ = nullptr;
2808 }
~DistributedWantIntParamTest()2809 ~DistributedWantIntParamTest()
2810 {
2811 want_ = nullptr;
2812 }
2813 static void SetUpTestCase(void);
2814 static void TearDownTestCase(void);
2815 void SetUp();
2816 void TearDown();
2817 std::shared_ptr<DistributedWant> want_;
2818 };
2819
SetUpTestCase(void)2820 void DistributedWantIntParamTest::SetUpTestCase(void)
2821 {}
2822
TearDownTestCase(void)2823 void DistributedWantIntParamTest::TearDownTestCase(void)
2824 {}
2825
SetUp(void)2826 void DistributedWantIntParamTest::SetUp(void)
2827 {
2828 want_ = std::make_shared<DistributedWant>();
2829 }
2830
TearDown(void)2831 void DistributedWantIntParamTest::TearDown(void)
2832 {}
2833
2834 /**
2835 * @tc.number: DistributedScheduleWant_IntParam_0100
2836 * @tc.name: SetParam/GetIntParam
2837 * @tc.desc: Verify when parameter change.
2838 */
2839 HWTEST_P(DistributedWantIntParamTest, DistributedScheduleWant_IntParam_0100, Function | MediumTest | Level3)
2840 {
2841 ASSERT_NE(want_, nullptr);
2842 std::string setKey = std::get<0>(GetParam());
2843 std::string getKey = std::get<1>(GetParam());
2844 int setValue = std::get<2>(GetParam());
2845 int defaultValue = std::get<3>(GetParam());
2846 int result = std::get<4>(GetParam());
2847 want_->SetParam(setKey, setValue);
2848 EXPECT_EQ(result, want_->GetIntParam(getKey, defaultValue));
2849 }
2850
2851 INSTANTIATE_TEST_SUITE_P(WantParametersIntTestCaseP, DistributedWantIntParamTest,
2852 testing::Values(testIntType("", "aa", -1, 100, 100), testIntType("", "", -9, -41, -9),
2853 testIntType("1*中_aR", "aa", 50, 5, 5), testIntType("1*中_aR", "1*中_aR", -5000, 5000, -5000)));
2854
2855 /**
2856 * @tc.number: DistributedScheduleWant_IntParam_0200
2857 * @tc.name: SetParam/GetIntParam
2858 * @tc.desc: Verify when the value is integer.
2859 */
2860 HWTEST_F(DistributedWantIntParamTest, DistributedScheduleWant_IntParam_0200, Function | MediumTest | Level3)
2861 {
2862 int defaultValue = 200;
2863 std::string getKey("aa");
2864 EXPECT_EQ(defaultValue, want_->GetIntParam(getKey, defaultValue));
2865 }
2866
2867 /**
2868 * @tc.number: DistributedScheduleWant_IntParam_0300
2869 * @tc.name: SetParam/GetIntParam
2870 * @tc.desc: Verify when the value is integer.
2871 */
2872 HWTEST_F(DistributedWantIntParamTest, DistributedScheduleWant_IntParam_0300, Function | MediumTest | Level3)
2873 {
2874 ASSERT_NE(want_, nullptr);
2875 std::string emptyStr("bb");
2876 int firstValue = 1;
2877 int secondValue = 2;
2878 int thirdValue = 4;
2879 int firstDefaultValue = 3;
2880 int secondDefaultValue = 5;
2881 std::string keyStr("aa");
2882 want_->SetParam(emptyStr, firstValue);
2883 want_->SetParam(emptyStr, firstValue);
2884 want_->SetParam(emptyStr, secondValue);
2885 EXPECT_EQ(firstDefaultValue, want_->GetIntParam(keyStr, firstDefaultValue));
2886 want_->SetParam(emptyStr, thirdValue);
2887 EXPECT_EQ(thirdValue, want_->GetIntParam(emptyStr, secondDefaultValue));
2888 }
2889
2890 /**
2891 * @tc.number: DistributedScheduleWant_IntParam_0400
2892 * @tc.name: SetParam/GetIntParam
2893 * @tc.desc: Verify when the value is integer.
2894 */
2895 HWTEST_F(DistributedWantIntParamTest, DistributedScheduleWant_IntParam_0400, Function | MediumTest | Level3)
2896 {
2897 ASSERT_NE(want_, nullptr);
2898 std::string firstKey("%1uH3");
2899 int firstValue = -1;
2900 int secondValue = 0;
2901 int thirdValue = 4;
2902 int firstDefaultValue = 9;
2903 int secondDefaultValue = -10;
2904 std::string secondKey("aa");
2905 want_->SetParam(firstKey, firstValue);
2906 want_->SetParam(firstKey, firstValue);
2907 want_->SetParam(firstKey, secondValue);
2908 EXPECT_EQ(secondValue, want_->GetIntParam(firstKey, firstDefaultValue));
2909 want_->SetParam(firstKey, thirdValue);
2910 EXPECT_EQ(secondDefaultValue, want_->GetIntParam(secondKey, secondDefaultValue));
2911 }
2912
2913 using testIntArrayType = std::tuple<std::string, std::string, std::vector<int>, std::vector<int>, std::vector<int>>;
2914 class DistributedWantIntArrayParamTest : public testing::TestWithParam<testIntArrayType> {
2915 public:
DistributedWantIntArrayParamTest()2916 DistributedWantIntArrayParamTest()
2917 {
2918 want_ = nullptr;
2919 }
~DistributedWantIntArrayParamTest()2920 ~DistributedWantIntArrayParamTest()
2921 {
2922 want_ = nullptr;
2923 }
2924 static void SetUpTestCase(void);
2925 static void TearDownTestCase(void);
2926 void SetUp();
2927 void TearDown();
2928 std::shared_ptr<DistributedWant> want_;
2929 };
2930
SetUpTestCase(void)2931 void DistributedWantIntArrayParamTest::SetUpTestCase(void)
2932 {}
2933
TearDownTestCase(void)2934 void DistributedWantIntArrayParamTest::TearDownTestCase(void)
2935 {}
2936
SetUp(void)2937 void DistributedWantIntArrayParamTest::SetUp(void)
2938 {
2939 want_ = std::make_shared<DistributedWant>();
2940 }
2941
TearDown(void)2942 void DistributedWantIntArrayParamTest::TearDown(void)
2943 {}
2944
2945 /**
2946 * @tc.number: DistributedScheduleWant_IntArrayParam_0100
2947 * @tc.name: SetParam/GetIntArrayParam
2948 * @tc.desc: Verify when parameter change.
2949 */
2950 HWTEST_P(DistributedWantIntArrayParamTest, DistributedScheduleWant_IntArrayParam_0100, Function | MediumTest | Level3)
2951 {
2952 ASSERT_NE(want_, nullptr);
2953 std::string setKey = std::get<0>(GetParam());
2954 std::string getKey = std::get<1>(GetParam());
2955 std::vector<int> setValue = std::get<2>(GetParam());
2956 std::vector<int> defaultValue = std::get<3>(GetParam());
2957 std::vector<int> result = std::get<4>(GetParam());
2958 want_->SetParam(setKey, setValue);
2959 EXPECT_EQ(result, want_->GetIntArrayParam(getKey));
2960 }
2961
2962 INSTANTIATE_TEST_SUITE_P(WantIntArrayParamTestCaseP, DistributedWantIntArrayParamTest,
2963 testing::Values(testIntArrayType("", "aa", {-1, 3, 25, -9}, {}, {}),
2964 testIntArrayType("", "", {-41, 0, 0, 9}, {}, {-41, 0, 0, 9}),
2965 testIntArrayType("1*中_aR", "aa", {50, 2, -9}, {}, {}),
2966 testIntArrayType("1*中_aR", "1*中_aR", {-5000}, {}, {-5000})));
2967
2968 /**
2969 * @tc.number: DistributedScheduleWant_IntArrayParam_0200
2970 * @tc.name: SetParam/GetIntArrayParam
2971 * @tc.desc: Verify when the value is integer array.
2972 */
2973 HWTEST_F(DistributedWantIntArrayParamTest, DistributedScheduleWant_IntArrayParam_0200, Function | MediumTest | Level3)
2974 {
2975 ASSERT_NE(want_, nullptr);
2976 std::vector<int> defaultValue;
2977 std::string getKey("aa");
2978 EXPECT_EQ(defaultValue, want_->GetIntArrayParam(getKey));
2979 }
2980
2981 /**
2982 * @tc.number: DistributedScheduleWant_IntArrayParam_0300
2983 * @tc.name: SetParam/GetIntArrayParam
2984 * @tc.desc: Verify when the value is integer array.
2985 */
2986 HWTEST_F(DistributedWantIntArrayParamTest, DistributedScheduleWant_IntArrayParam_0300, Function | MediumTest | Level3)
2987 {
2988 ASSERT_NE(want_, nullptr);
2989 std::string emptyStr("cc");
2990 std::vector<int> firstValue({1, 4, -9});
2991 std::vector<int> secondValue({1, 8, -9});
2992 std::vector<int> thirdValue({1, 4, 9});
2993 std::string keyStr("aa");
2994 want_->SetParam(emptyStr, firstValue);
2995 want_->SetParam(emptyStr, firstValue);
2996 want_->SetParam(emptyStr, secondValue);
2997 std::vector<int> defaultValue;
2998 EXPECT_EQ(defaultValue, want_->GetIntArrayParam(keyStr));
2999 want_->SetParam(emptyStr, thirdValue);
3000 EXPECT_EQ(thirdValue, want_->GetIntArrayParam(emptyStr));
3001 }
3002
3003 /**
3004 * @tc.number: DistributedScheduleWant_IntArrayParam_0400
3005 * @tc.name: SetParam/GetIntArrayParam
3006 * @tc.desc: Verify when the value is integer array.
3007 */
3008 HWTEST_F(DistributedWantIntArrayParamTest, DistributedScheduleWant_IntArrayParam_0400, Function | MediumTest | Level3)
3009 {
3010 ASSERT_NE(want_, nullptr);
3011 std::string firstKey("%1uH3");
3012 std::vector<int> firstValue({-1, -2});
3013 std::vector<int> secondValue({-1, -2, -1, -2, 0});
3014 std::vector<int> thirdValue({-1, -2, 100});
3015 std::string secondKey("aa");
3016 want_->SetParam(firstKey, firstValue);
3017 want_->SetParam(firstKey, firstValue);
3018 want_->SetParam(firstKey, secondValue);
3019 EXPECT_EQ(secondValue, want_->GetIntArrayParam(firstKey));
3020 want_->SetParam(firstKey, thirdValue);
3021 std::vector<int> defaultValue;
3022 EXPECT_EQ(defaultValue, want_->GetIntArrayParam(secondKey));
3023 }
3024
3025 using testFloatType = std::tuple<std::string, std::string, float, float, float>;
3026 class DistributedWantFloatParamTest : public testing::TestWithParam<testFloatType> {
3027 public:
DistributedWantFloatParamTest()3028 DistributedWantFloatParamTest()
3029 {
3030 want_ = nullptr;
3031 }
~DistributedWantFloatParamTest()3032 ~DistributedWantFloatParamTest()
3033 {
3034 want_ = nullptr;
3035 }
3036
3037 static void SetUpTestCase(void);
3038 static void TearDownTestCase(void);
3039 void SetUp();
3040 void TearDown();
3041 std::shared_ptr<DistributedWant> want_;
3042 };
3043
SetUpTestCase(void)3044 void DistributedWantFloatParamTest::SetUpTestCase(void)
3045 {}
3046
TearDownTestCase(void)3047 void DistributedWantFloatParamTest::TearDownTestCase(void)
3048 {}
3049
SetUp(void)3050 void DistributedWantFloatParamTest::SetUp(void)
3051 {
3052 want_ = std::make_shared<DistributedWant>();
3053 }
3054
TearDown(void)3055 void DistributedWantFloatParamTest::TearDown(void)
3056 {}
3057
3058 /**
3059 * @tc.number: DistributedScheduleWant_FloatParam_0100
3060 * @tc.name: SetParam/GetFloatParam
3061 * @tc.desc: Verify when parameter change.
3062 */
3063 HWTEST_P(DistributedWantFloatParamTest, DistributedScheduleWant_FloatParam_0100, Function | MediumTest | Level3)
3064 {
3065 ASSERT_NE(want_, nullptr);
3066 std::string setKey = std::get<0>(GetParam());
3067 std::string getKey = std::get<1>(GetParam());
3068 float setValue = std::get<2>(GetParam());
3069 float defaultValue = std::get<3>(GetParam());
3070 float result = std::get<4>(GetParam());
3071 want_->SetParam(setKey, setValue);
3072 EXPECT_EQ(result, want_->GetFloatParam(getKey, defaultValue));
3073 }
3074
3075 INSTANTIATE_TEST_SUITE_P(WantFloatParamTestCaseP, DistributedWantFloatParamTest,
3076 testing::Values(testFloatType("", "aa", -1.1, 100.1, 100.1), testFloatType("", "", -9.1, -41.1, -9.1),
3077 testFloatType("1*中_aR", "aa", 50.1, 5.1, 5.1), testFloatType("1*中_aR", "1*中_aR", -5000.1, 5000.1, -5000.1)));
3078
3079 /**
3080 * @tc.number: DistributedScheduleWant_FloatParam_0200
3081 * @tc.name: SetParam/GetFloatParam
3082 * @tc.desc: get param when WantParam is empty.
3083 */
3084 HWTEST_F(DistributedWantFloatParamTest, DistributedScheduleWant_FloatParam_0200, Function | MediumTest | Level3)
3085 {
3086 float defaultValue = 100.1;
3087 std::string key = "aa";
3088 EXPECT_EQ(defaultValue, want_->GetFloatParam(key, defaultValue));
3089 }
3090
3091 /**
3092 * @tc.number: DistributedScheduleWant_FloatParam_0300
3093 * @tc.name: SetParam/GetFloatParam
3094 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key.
3095 */
3096 HWTEST_F(DistributedWantFloatParamTest, DistributedScheduleWant_FloatParam_0300, Function | MediumTest | Level3)
3097 {
3098 ASSERT_NE(want_, nullptr);
3099 std::string setKey1 = "ee";
3100 std::string setKey2 = "aa";
3101 float setValue1 = 1.1;
3102 float setValue2 = 5.1;
3103 want_->SetParam(setKey1, setValue1);
3104 want_->SetParam(setKey1, setValue1);
3105 setValue1 = 2.1;
3106 want_->SetParam(setKey1, setValue1);
3107 setValue1 = 3.1;
3108 EXPECT_EQ(setValue1, want_->GetFloatParam(setKey2, setValue1));
3109 setValue1 = 4.1;
3110 want_->SetParam(setKey1, setValue1);
3111 EXPECT_EQ(setValue1, want_->GetFloatParam(setKey1, setValue2));
3112 }
3113
3114 /**
3115 * @tc.number: DistributedScheduleWant_FloatParam_0400
3116 * @tc.name: SetParam/GetFloatParam
3117 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key.
3118 */
3119 HWTEST_F(DistributedWantFloatParamTest, DistributedScheduleWant_FloatParam_0400, Function | MediumTest | Level3)
3120 {
3121 ASSERT_NE(want_, nullptr);
3122 std::string setKey1 = "%1uH3";
3123 std::string setKey2 = "aa";
3124 float setValue1 = -1.1;
3125 float setValue2 = 9.1;
3126 want_->SetParam(setKey1, setValue1);
3127 want_->SetParam(setKey1, setValue1);
3128 setValue1 = 0.1;
3129 want_->SetParam(setKey1, setValue1);
3130 EXPECT_EQ(setValue1, want_->GetFloatParam(setKey1, setValue2));
3131 setValue1 = 4.1;
3132 want_->SetParam(setKey1, setValue1);
3133 setValue1 = -10.1;
3134 EXPECT_EQ(setValue1, want_->GetFloatParam(setKey2, setValue1));
3135 }
3136
3137 using testDoubleType = std::tuple<std::string, std::string, double, double, double>;
3138 class DistributedWantDoubleParamTest : public testing::TestWithParam<testDoubleType> {
3139 public:
DistributedWantDoubleParamTest()3140 DistributedWantDoubleParamTest()
3141 {
3142 want_ = nullptr;
3143 }
~DistributedWantDoubleParamTest()3144 ~DistributedWantDoubleParamTest()
3145 {
3146 want_ = nullptr;
3147 }
3148 static void SetUpTestCase(void);
3149 static void TearDownTestCase(void);
3150 void SetUp();
3151 void TearDown();
3152 std::shared_ptr<DistributedWant> want_;
3153 };
3154
SetUpTestCase(void)3155 void DistributedWantDoubleParamTest::SetUpTestCase(void)
3156 {}
3157
TearDownTestCase(void)3158 void DistributedWantDoubleParamTest::TearDownTestCase(void)
3159 {}
3160
SetUp(void)3161 void DistributedWantDoubleParamTest::SetUp(void)
3162 {
3163 want_ = std::make_shared<DistributedWant>();
3164 }
3165
TearDown(void)3166 void DistributedWantDoubleParamTest::TearDown(void)
3167 {}
3168
3169 /**
3170 * @tc.number: DistributedScheduleWant_DoubleParam_0100
3171 * @tc.name: SetParam/GetDoubleParam
3172 * @tc.desc: Verify when parameter change.
3173 */
3174 HWTEST_P(DistributedWantDoubleParamTest, DistributedScheduleWant_DoubleParam_0100, Function | MediumTest | Level3)
3175 {
3176 ASSERT_NE(want_, nullptr);
3177 std::string setKey = std::get<0>(GetParam());
3178 std::string getKey = std::get<1>(GetParam());
3179 double setValue = std::get<2>(GetParam());
3180 double defaultValue = std::get<3>(GetParam());
3181 double result = std::get<4>(GetParam());
3182 want_->SetParam(setKey, setValue);
3183 EXPECT_EQ(result, want_->GetDoubleParam(getKey, defaultValue));
3184 }
3185
3186 INSTANTIATE_TEST_SUITE_P(WantDoubleParamTestCaseP, DistributedWantDoubleParamTest,
3187 testing::Values(testDoubleType("", "aa", -1.1, 100.1, 100.1), testDoubleType("", "", -9.1, -41.1, -9.1),
3188 testDoubleType("1*中_aR", "aa", 50.1, 5.1, 5.1),
3189 testDoubleType("1*中_aR", "1*中_aR", -5000.1, 5000.1, -5000.1)));
3190
3191 /**
3192 * @tc.number: DistributedScheduleWant_DoubleParam_0300
3193 * @tc.name: SetParam & GetDoubleParam
3194 * @tc.desc: set empty-string key repeatedly, but get param of another nonexistent key.
3195 */
3196 HWTEST_F(DistributedWantDoubleParamTest, DistributedScheduleWant_DoubleParam_0300, Function | MediumTest | Level3)
3197 {
3198 ASSERT_NE(want_, nullptr);
3199 double defaultValue = 100.1;
3200 std::string key = "aa";
3201 EXPECT_EQ(defaultValue, want_->GetDoubleParam(key, defaultValue));
3202 }
3203
3204 /**
3205 * @tc.number: DistributedScheduleWant_DoubleParam_0400
3206 * @tc.name: SetParam & GetDoubleParam
3207 * @tc.desc: set empty-string key repeatedly, then get param of the key.
3208 */
3209 HWTEST_F(DistributedWantDoubleParamTest, DistributedScheduleWant_DoubleParam_0400, Function | MediumTest | Level3)
3210 {
3211 ASSERT_NE(want_, nullptr);
3212 std::string setKey1 = "ff";
3213 std::string setKey2 = "aa";
3214 double setValue1 = 1.1;
3215 double setValue2 = 5.1;
3216 want_->SetParam(setKey1, setValue1);
3217 want_->SetParam(setKey1, setValue1);
3218 setValue1 = 2.1;
3219 want_->SetParam(setKey1, setValue1);
3220 setValue1 = 3.1;
3221 EXPECT_EQ(setValue1, want_->GetDoubleParam(setKey2, setValue1));
3222 setValue1 = 4.1;
3223 want_->SetParam(setKey1, setValue1);
3224 EXPECT_EQ(setValue1, want_->GetDoubleParam(setKey1, setValue2));
3225 }
3226
3227 /**
3228 * @tc.number: DistributedScheduleWant_ByteArray_0100
3229 * @tc.name: SetParam/GetByteArrayParam
3230 * @tc.desc: Verify when parameter change.
3231 */
3232 HWTEST_F(DistributedWantDoubleParamTest, DistributedScheduleWant_ByteArray_0100, Function | MediumTest | Level3)
3233 {
3234 ASSERT_NE(want_, nullptr);
3235 std::string setKey1 = "%1uH3";
3236 std::string setKey2 = "aa";
3237 double setValue1 = -1.1;
3238 double setValue2 = 9.1;
3239 want_->SetParam(setKey1, setValue1);
3240 want_->SetParam(setKey1, setValue1);
3241 setValue1 = 0.1;
3242 want_->SetParam(setKey1, setValue1);
3243 EXPECT_EQ(setValue1, want_->GetDoubleParam(setKey1, setValue2));
3244 setValue1 = 4.1;
3245 want_->SetParam(setKey1, setValue1);
3246 setValue1 = -10.1;
3247 EXPECT_EQ(setValue1, want_->GetDoubleParam(setKey2, setValue1));
3248 }
3249
3250 using testByteArrayType =
3251 std::tuple<std::string, std::string, std::vector<byte>, std::vector<byte>, std::vector<byte>>;
3252 class DistributedWantByteArrayParamTest : public testing::TestWithParam<testByteArrayType> {
3253 public:
DistributedWantByteArrayParamTest()3254 DistributedWantByteArrayParamTest()
3255 {
3256 want_ = nullptr;
3257 }
~DistributedWantByteArrayParamTest()3258 ~DistributedWantByteArrayParamTest()
3259 {
3260 want_ = nullptr;
3261 }
3262 static void SetUpTestCase(void);
3263 static void TearDownTestCase(void);
3264 void SetUp();
3265 void TearDown();
3266 std::shared_ptr<DistributedWant> want_;
3267 };
3268
SetUpTestCase(void)3269 void DistributedWantByteArrayParamTest::SetUpTestCase(void)
3270 {}
3271
TearDownTestCase(void)3272 void DistributedWantByteArrayParamTest::TearDownTestCase(void)
3273 {}
3274
SetUp(void)3275 void DistributedWantByteArrayParamTest::SetUp(void)
3276 {
3277 want_ = std::make_shared<DistributedWant>();
3278 }
3279
TearDown(void)3280 void DistributedWantByteArrayParamTest::TearDown(void)
3281 {}
3282
3283 /**
3284 * @tc.number: DistributedScheduleWant_ByteArray_0100
3285 * @tc.name: SetParam/GetByteArrayParam
3286 * @tc.desc: Verify when parameter change.
3287 */
3288 HWTEST_P(DistributedWantByteArrayParamTest, DistributedScheduleWant_ByteArray_0100, Function | MediumTest | Level3)
3289 {
3290 ASSERT_NE(want_, nullptr);
3291 std::string setKey = std::get<0>(GetParam());
3292 std::string getKey = std::get<1>(GetParam());
3293 std::vector<byte> setValue = std::get<2>(GetParam());
3294 std::vector<byte> defaultValue = std::get<3>(GetParam());
3295 std::vector<byte> result = std::get<4>(GetParam());
3296 want_->SetParam(setKey, setValue);
3297 EXPECT_EQ(result, want_->GetByteArrayParam(getKey));
3298 }
3299
3300 INSTANTIATE_TEST_SUITE_P(WantByteArrayParamTestCaseP, DistributedWantByteArrayParamTest,
3301 testing::Values(testByteArrayType("", "aa", {'*', 'D'}, {}, {}),
3302 testByteArrayType("", "", {'%', ')'}, {}, {'%', ')'}), testByteArrayType("1*中_aR", "aa", {'R', '.'}, {}, {}),
3303 testByteArrayType("1*中_aR", "1*中_aR", {'R', 'b'}, {}, {'R', 'b'})));
3304
3305 /**
3306 * @tc.number: DistributedScheduleWant_ByteArray_0200
3307 * @tc.name: SetParam/GetByteArrayParam
3308 * @tc.desc: Verify when the value is byte array.
3309 */
3310 HWTEST_F(DistributedWantByteArrayParamTest, DistributedScheduleWant_ByteArray_0200, Function | MediumTest | Level3)
3311 {
3312 ASSERT_NE(want_, nullptr);
3313 std::vector<byte> defaultValue;
3314 std::string getKey("aa");
3315 EXPECT_EQ(defaultValue, want_->GetByteArrayParam(getKey));
3316 }
3317
3318 /**
3319 * @tc.number: DistributedScheduleWant_ByteArray_0300
3320 * @tc.name: SetParam/GetByteArrayParam
3321 * @tc.desc: Verify when the value is byte array.
3322 */
3323 HWTEST_F(DistributedWantByteArrayParamTest, DistributedScheduleWant_ByteArray_0300, Function | MediumTest | Level3)
3324 {
3325 ASSERT_NE(want_, nullptr);
3326 std::string emptyStr("gg");
3327 std::vector<byte> firstValue({'a', '2'});
3328 std::vector<byte> secondValue({'1', 'd'});
3329 std::vector<byte> thirdValue({'t', '3'});
3330 std::string keyStr("aa");
3331 want_->SetParam(emptyStr, firstValue);
3332 want_->SetParam(emptyStr, firstValue);
3333 want_->SetParam(emptyStr, secondValue);
3334 std::vector<byte> defaultValue;
3335 EXPECT_EQ(defaultValue, want_->GetByteArrayParam(keyStr));
3336 want_->SetParam(emptyStr, thirdValue);
3337 EXPECT_EQ(thirdValue, want_->GetByteArrayParam(emptyStr));
3338 }
3339
3340 /**
3341 * @tc.number: DistributedScheduleWant_ByteArray_0400
3342 * @tc.name: SetParam/GetByteArrayParam
3343 * @tc.desc: Verify when the value is byte array.
3344 */
3345 HWTEST_F(DistributedWantByteArrayParamTest, DistributedScheduleWant_ByteArray_0400, Function | MediumTest | Level3)
3346 {
3347 ASSERT_NE(want_, nullptr);
3348 std::string firstKey("%1uH3");
3349 std::vector<byte> firstValue({'a', '2'});
3350 std::vector<byte> secondValue({'w', '$'});
3351 std::vector<byte> defaultValue;
3352 std::string secondKey("aa");
3353 want_->SetParam(firstKey, firstValue);
3354 want_->SetParam(firstKey, firstValue);
3355 want_->SetParam(firstKey, secondValue);
3356 EXPECT_EQ(secondValue, want_->GetByteArrayParam(firstKey));
3357 want_->SetParam(firstKey, firstValue);
3358 EXPECT_EQ(defaultValue, want_->GetByteArrayParam(secondKey));
3359 }
3360
3361 using testBoolType = std::tuple<std::string, std::string, bool, bool, bool>;
3362 class DistributedWantBoolParamTest : public testing::TestWithParam<testBoolType> {
3363 public:
DistributedWantBoolParamTest()3364 DistributedWantBoolParamTest()
3365 {
3366 want_ = nullptr;
3367 }
~DistributedWantBoolParamTest()3368 ~DistributedWantBoolParamTest()
3369 {
3370 want_ = nullptr;
3371 }
3372 static void SetUpTestCase(void);
3373 static void TearDownTestCase(void);
3374 void SetUp();
3375 void TearDown();
3376 std::shared_ptr<DistributedWant> want_;
3377 };
3378
SetUpTestCase(void)3379 void DistributedWantBoolParamTest::SetUpTestCase(void)
3380 {}
3381
TearDownTestCase(void)3382 void DistributedWantBoolParamTest::TearDownTestCase(void)
3383 {}
3384
SetUp(void)3385 void DistributedWantBoolParamTest::SetUp(void)
3386 {
3387 want_ = std::make_shared<DistributedWant>();
3388 }
3389
TearDown(void)3390 void DistributedWantBoolParamTest::TearDown(void)
3391 {}
3392
3393 /**
3394 * @tc.number: DistributedScheduleWant_BoolParam_0100
3395 * @tc.name: SetParam/GetBoolParam
3396 * @tc.desc: Verify when parameter change.
3397 */
3398 HWTEST_P(DistributedWantBoolParamTest, DistributedScheduleWant_BoolParam_0100, Function | MediumTest | Level3)
3399 {
3400 ASSERT_NE(want_, nullptr);
3401 std::string setKey = std::get<0>(GetParam());
3402 std::string getKey = std::get<1>(GetParam());
3403 bool setValue = std::get<2>(GetParam());
3404 bool defaultValue = std::get<3>(GetParam());
3405 bool result = std::get<4>(GetParam());
3406 want_->SetParam(setKey, setValue);
3407 EXPECT_EQ(result, want_->GetBoolParam(getKey, defaultValue));
3408 }
3409
3410 INSTANTIATE_TEST_SUITE_P(WantBoolParamTestCaseP, DistributedWantBoolParamTest,
3411 testing::Values(testBoolType("b1", "aa", true, true, true), testBoolType("b1", "aa", true, false, false),
3412 testBoolType("b2", "b2", true, true, true), testBoolType("b3", "b3", true, false, true),
3413 testBoolType("123", "123", true, false, true), testBoolType("123", "aa", true, false, false),
3414 testBoolType("-~*&%¥", "-~*&%¥", true, false, true), testBoolType("-~*&%¥", "aa", true, false, false),
3415 testBoolType("中文", "中文", true, false, true), testBoolType("中文", "aa", true, false, false),
3416 testBoolType("_中文ddPEJKJ#(&*~#^%", "_中文ddPEJKJ#(&*~#^%", true, false, true),
3417 testBoolType("_中文ddPEJKJ#(&*~#^%", "123", true, false, false)));
3418
3419 /**
3420 * @tc.number: DistributedScheduleWant_BoolParam_0200
3421 * @tc.name: SetParam/GetBoolParam
3422 * @tc.desc: Verify when set twice and get twice.
3423 */
3424 HWTEST_F(DistributedWantBoolParamTest, DistributedScheduleWant_BoolParam_0200, Function | MediumTest | Level3)
3425 {
3426 ASSERT_NE(want_, nullptr);
3427 std::string firstKey("_中文ddPEJKJ#(&*~#^%");
3428 std::string secondKey("key33");
3429 want_->SetParam(firstKey, true);
3430 want_->SetParam(secondKey, true);
3431 EXPECT_EQ(true, want_->GetBoolParam(firstKey, false));
3432 EXPECT_EQ(true, want_->GetBoolParam(secondKey, false));
3433 }
3434
3435 /**
3436 * @tc.number: DistributedScheduleWant_BoolParam_0300
3437 * @tc.name: SetParam/GetBoolParam
3438 * @tc.desc: Verify when set 20 times, and get once.
3439 */
3440 HWTEST_F(DistributedWantBoolParamTest, DistributedScheduleWant_BoolParam_0300, Function | MediumTest | Level3)
3441 {
3442 ASSERT_NE(want_, nullptr);
3443 std::string keyStr("_中文ddPEJKJ#(&*~#^%");
3444 for (int i = 0; i < 20; i++) {
3445 want_->SetParam(keyStr, true);
3446 }
3447 EXPECT_EQ(true, want_->GetBoolParam(keyStr, false));
3448 }
3449
3450 /**
3451 * @tc.number: DistributedScheduleWant_Want_0100
3452 * @tc.name: Want() and Want(want)
3453 * @tc.desc: Verify Want()
3454 */
3455 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Want_0100, Function | MediumTest | Level3)
3456 {
3457 DistributedWant want;
3458
3459 EXPECT_EQ((uint)0, want.GetFlags());
3460 EXPECT_EQ(std::string(""), want.GetAction());
3461
3462 std::vector<std::string> vect = want.GetEntities();
3463 EXPECT_EQ((size_t)0, vect.size());
3464 EXPECT_EQ(std::string(""), want.GetType());
3465
3466 want.SetFlags(10);
3467 want.SetAction("system.Action.test");
3468 want.AddEntity("system.Entity.test");
3469 want.SetType("system.Type.test");
3470
3471 DistributedWant want2(want);
3472 EXPECT_EQ("system.Action.test", want2.GetAction());
3473 EXPECT_EQ(true, want2.HasEntity("system.Entity.test"));
3474 EXPECT_EQ("system.Type.test", want2.GetType());
3475 }
3476
3477 /**
3478 * @tc.number: DistributedScheduleWant_Entity_0100
3479 * @tc.name: [AddEntity or RemoveEntity] & HasEntity &CountEntities
3480 * @tc.desc: Verify [AddEntity or RemoveEntity] & HasEntity &CountEntities
3481 */
3482 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_Entity_0100, Function | MediumTest | Level3)
3483 {
3484 ASSERT_NE(want_, nullptr);
3485 std::string entity1 = "entity.system.entity1";
3486
3487 want_->AddEntity(entity1);
3488
3489 EXPECT_EQ(true, want_->HasEntity(entity1));
3490 EXPECT_EQ(1, want_->CountEntities());
3491 want_->RemoveEntity(entity1);
3492 EXPECT_EQ(false, want_->HasEntity(entity1));
3493 EXPECT_EQ(0, want_->CountEntities());
3494 int length = want_->GetEntities().size();
3495 EXPECT_EQ(0, length);
3496
3497 std::string entity2 = "entity.system.entity2";
3498
3499 want_->AddEntity(entity1);
3500 want_->AddEntity(entity2);
3501
3502 EXPECT_EQ(true, want_->HasEntity(entity1));
3503 EXPECT_EQ(2, want_->CountEntities());
3504 EXPECT_EQ(true, want_->HasEntity(entity2));
3505 EXPECT_EQ(2, want_->CountEntities());
3506
3507 want_->RemoveEntity(entity1);
3508 want_->RemoveEntity(entity2);
3509 EXPECT_EQ(0, want_->CountEntities());
3510 int length2 = want_->GetEntities().size();
3511
3512 EXPECT_EQ(0, length2);
3513 }
3514
3515 /**
3516 * @tc.number: DistributedScheduleWant_HasParameter_0100
3517 * @tc.name: SetParam and HasParameter
3518 * @tc.desc: Verify HasParameter()
3519 */
3520 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_HasParameter_0100, Function | MediumTest | Level3)
3521 {
3522 ASSERT_NE(want_, nullptr);
3523 std::vector<std::string> vector;
3524 std::string key = "system.want.test.key";
3525 std::string key2 = "system.want.test.key2";
3526
3527 vector.push_back("system.want.test.content");
3528 want_->SetParam(key, vector);
3529 EXPECT_EQ(true, want_->HasParameter(key));
3530
3531 want_->SetParam(key2, vector);
3532 EXPECT_EQ(true, want_->HasParameter(key2));
3533 }
3534 /**
3535 * @tc.number: DistributedScheduleWant_ToString_0100
3536 * @tc.name: ToString and FromString
3537 * @tc.desc: Verify FromString()
3538 */
3539 HWTEST_F(DistributedWantBaseTest, DistributedScheduleWant_ToString_0100, Function | MediumTest | Level3)
3540 {
3541 std::string deviceId = "deviceId";
3542 std::string bundleName = "bundleName";
3543 std::string abilityName ="abilityName";
3544 std::string uri = "url";
3545 std::string type = "type";
3546 unsigned int flags = 1;
3547 std::string action = "action";
3548 DistributedWantParams parameters;
3549 std::vector<std::string> entities = {"entity.system.entity1", "entity.system.entity2"};
3550
3551 std::string keyBool = "key_bool";
3552 bool valueBool = true;
3553 parameters.SetParam(keyBool, Boolean::Box(valueBool));
3554
3555 std::string keyStr = "key_string";
3556 std::string valueString = "123";
3557 parameters.SetParam(keyStr, String::Box(valueString));
3558
3559 std::string keyInt = "key_int";
3560 int valueInt = 111;
3561 parameters.SetParam(keyStr, Integer::Box(valueInt));
3562
3563 std::shared_ptr<DistributedWant> want1 = std::make_shared<DistributedWant>();
3564 if (want1 == nullptr) {
3565 return;
3566 }
3567 want1->SetElementName(deviceId, bundleName, abilityName);
3568 want1->SetUri(uri);
3569 want1->SetType(type);
3570 want1->SetFlags(flags);
3571 want1->SetAction(action);
3572 for (auto entity : entities) {
3573 want1->AddEntity(entity);
3574 }
3575
3576 std::string jsonString = want1->ToString();
3577 DistributedWant* newWant = DistributedWant::FromString(jsonString);
3578 if (newWant == nullptr) {
3579 return;
3580 }
3581 std::shared_ptr<DistributedWant> want2(newWant);
3582
3583 CompareWant(want1, want2);
3584 }
3585
3586 /*
3587 * Feature: Array
3588 * Function: GetLength and GetType
3589 * SubFunction: NA
3590 * FunctionPoints: GetLength and GetType
3591 * EnvConditions: NA
3592 * CaseDescription: Verify GetLength and GetType method of Array.
3593 */
3594 HWTEST_F(DistributedWantBaseTest, array_test_001, TestSize.Level3)
3595 {
3596 sptr<Array> arrayObj(new Array(9, g_IID_IInteger));
3597 ASSERT_NE(arrayObj, nullptr);
3598 long size = 0;
3599 arrayObj->GetLength(size);
3600 EXPECT_EQ(size, 9);
3601 InterfaceID type;
3602 arrayObj->GetType(type);
3603 EXPECT_EQ(type, g_IID_IInteger);
3604 }
3605
3606 /*
3607 * Feature: Array
3608 * Function: Get and Set
3609 * SubFunction: NA
3610 * FunctionPoints: Get and Set
3611 * EnvConditions: NA
3612 * CaseDescription: Verify Get and Set method of Array.
3613 */
3614 HWTEST_F(DistributedWantBaseTest, array_test_002, TestSize.Level3)
3615 {
3616 sptr<Array> arrayObj(new Array(19, g_IID_IInteger));
3617 ASSERT_NE(arrayObj, nullptr);
3618 arrayObj->Set(0, Integer::Box(23));
3619 sptr<IInterface> valueObj = nullptr;
3620 arrayObj->Get(0, valueObj);
3621 EXPECT_TRUE(valueObj != nullptr);
3622 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 23);
3623 arrayObj->Get(1, valueObj);
3624 EXPECT_TRUE(valueObj == nullptr);
3625 }
3626
3627 /*
3628 * Feature: Array
3629 * Function: ToString
3630 * SubFunction: NA
3631 * FunctionPoints: ToString
3632 * EnvConditions: NA
3633 * CaseDescription: Verify ToString method of Array.
3634 */
3635 HWTEST_F(DistributedWantBaseTest, array_test_003, TestSize.Level3)
3636 {
3637 sptr<Array> arrayObj(new Array(5, g_IID_IInteger));
3638 ASSERT_NE(arrayObj, nullptr);
3639 arrayObj->Set(0, Integer::Box(2));
3640 arrayObj->Set(1, Integer::Box(3));
3641 arrayObj->Set(2, Integer::Box(5));
3642 arrayObj->Set(3, Integer::Box(7));
3643 arrayObj->Set(4, Integer::Box(11));
3644 EXPECT_EQ(arrayObj->ToString(), std::string("I5{2,3,5,7,11}"));
3645 }
3646
3647 /*
3648 * Feature: Array
3649 * Function: Parse
3650 * SubFunction: NA
3651 * FunctionPoints: Parse
3652 * EnvConditions: NA
3653 * CaseDescription: Verify Parse method of Array.
3654 */
3655 HWTEST_F(DistributedWantBaseTest, array_test_004, TestSize.Level3)
3656 {
3657 sptr<IArray> arrayObj = Array::Parse("I5{2,3,5,7,11}");
3658 sptr<IInterface> valueObj = nullptr;
3659 ASSERT_NE(arrayObj, nullptr);
3660 arrayObj->Get(0, valueObj);
3661 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 2);
3662 arrayObj->Get(1, valueObj);
3663 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 3);
3664 arrayObj->Get(2, valueObj);
3665 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 5);
3666 arrayObj->Get(3, valueObj);
3667 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 7);
3668 arrayObj->Get(4, valueObj);
3669 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 11);
3670 }
3671
3672 /*
3673 * Feature: Array
3674 * Function: Equals
3675 * SubFunction: NA
3676 * FunctionPoints: Equals
3677 * EnvConditions: NA
3678 * CaseDescription: Verify Equals method of Array.
3679 */
3680 HWTEST_F(DistributedWantBaseTest, array_test_005, TestSize.Level3)
3681 {
3682 sptr<IArray> arrayObj1 = Array::Parse("I5{2,3,5,7,11}");
3683 sptr<IArray> arrayObj2 = Array::Parse("I5{2,3,7,7,11}");
3684 sptr<IArray> arrayObj3 = Array::Parse("I5{2,3,5,7,11}");
3685 ASSERT_NE(arrayObj1, nullptr);
3686 ASSERT_NE(arrayObj2, nullptr);
3687 ASSERT_NE(arrayObj3, nullptr);
3688 EXPECT_FALSE(Object::Equals(*(arrayObj1.GetRefPtr()), *(arrayObj2.GetRefPtr())));
3689 EXPECT_TRUE(Object::Equals(*(arrayObj1.GetRefPtr()), *(arrayObj3.GetRefPtr())));
3690 }
3691
3692 /**
3693 * @tc.number: SetElementModuleName_test_001
3694 * @tc.name: SetElementModuleName
3695 * @tc.desc: Test the want function SetElementModuleName.
3696 * @tc.require: issueI648W6
3697 */
3698 HWTEST_F(DistributedWantBaseTest, SetElementModuleName_test_001, TestSize.Level3)
3699 {
3700 GTEST_LOG_(INFO) << "SetElementModuleName_test_001 start";
3701
3702 std::shared_ptr<OHOS::AppExecFwk::ElementName> element = std::make_shared<OHOS::AppExecFwk::ElementName>();
3703 ASSERT_NE(nullptr, element);
3704 const char* moduleName = "12345";
3705 element->SetModuleName(moduleName);
3706
3707 GTEST_LOG_(INFO) << "SetElementModuleName_test_001 end";
3708 }
3709
3710 /**
3711 * @tc.number: ParseURI_test_001
3712 * @tc.name: ParseURI
3713 * @tc.desc: Test the want function ParseURI.
3714 * @tc.require: issueI648W6
3715 */
3716 HWTEST_F(DistributedWantBaseTest, ParseURI_test_001, TestSize.Level3)
3717 {
3718 GTEST_LOG_(INFO) << "ParseURI_test_001 start";
3719
3720 OHOS::AppExecFwk::ElementName element;
3721 std::string uri = "#Intent;action;end";
3722 bool result = element.ParseURI(uri);
3723 EXPECT_EQ(result, false);
3724
3725 GTEST_LOG_(INFO) << "ParseURI_test_001 end";
3726 }
3727
3728 /**
3729 * @tc.number: GetLowerCaseScheme_test_001
3730 * @tc.name: GetLowerCaseScheme
3731 * @tc.desc: Test GetLowerCaseScheme.
3732 * @tc.require: I77HFZ
3733 */
3734 HWTEST_F(DistributedWantBaseTest, GetLowerCaseScheme_test_001, TestSize.Level3)
3735 {
3736 GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_001 start";
3737 std::string strUri = "";
3738 Uri uri(strUri);
3739 Want want;
3740 want.GetLowerCaseScheme(uri);
3741 EXPECT_TRUE(strUri.empty());
3742 GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_001 end";
3743 }
3744
3745 /**
3746 * @tc.number: GetLowerCaseScheme_test_002
3747 * @tc.name: GetLowerCaseScheme
3748 * @tc.desc: Test GetLowerCaseScheme.
3749 * @tc.require: I77HFZ
3750 */
3751 HWTEST_F(DistributedWantBaseTest, GetLowerCaseScheme_test_002, TestSize.Level3)
3752 {
3753 GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_002 start";
3754 std::string strUri = "#Test;action;end";
3755 Uri uri(strUri);
3756 Want want;
3757 want.GetLowerCaseScheme(uri);
3758 EXPECT_FALSE(strUri.empty());
3759 GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_002 end";
3760 }
3761
3762 /**
3763 * @tc.number: GetLowerCaseScheme_test_003
3764 * @tc.name: GetLowerCaseScheme
3765 * @tc.desc: Test GetLowerCaseScheme.
3766 * @tc.require: I77HFZ
3767 */
3768 HWTEST_F(DistributedWantBaseTest, GetLowerCaseScheme_test_003, TestSize.Level3)
3769 {
3770 GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_003 start";
3771 std::string strUri = "#Test;action;end";
3772 Uri uri(strUri);
3773 uri.scheme_ = "NOT VALID";
3774 Want want;
3775 want.GetLowerCaseScheme(uri);
3776 EXPECT_FALSE(strUri.empty());
3777 GTEST_LOG_(INFO) << "GetLowerCaseScheme_test_003 end";
3778 }
3779 } // namespace DistributedSchedule
3780 } // namespace OHOS