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 }
2705 }