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