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