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