1 /*
2 * Copyright (c) 2021-2022 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 #include "../include/notificationgetparam.h"
16
17 #include <cfloat>
18 #include <chrono>
19 #include <climits>
20 #include <functional>
21 #include <random>
22
23 #include "abs_shared_result_set.h"
24 #include "data_ability_predicates.h"
25 #include "values_bucket.h"
26 using namespace std;
27 using namespace OHOS::AppExecFwk;
28 using namespace OHOS::EventFwk;
29 using Uri = OHOS::Uri;
30
31 namespace {
32 static const int INDEX_ZERO = 0;
33 static const int INDEX_ONE = 1;
34 static const int INDEX_TWO = 2;
35 static const int INDEX_THREE = 3;
36 static const int INDEX_FOUR = 4;
37 static const int INDEX_FIVE = 5;
38 static const int INDEX_SIX = 6;
39 static const int INDEX_SEVEN = 7;
40 static const int INDEX_EIGHT = 8;
41 static const int INDEX_NINE = 9;
42 static const int INDEX_TEN = 10;
43 static const int CHAR_MINCOUNT = -128;
44 static const int CHAR_MAXCOUNT = 127;
45 static const int MAX_LENGTH = 255;
46 } // namespace
47
48 namespace OHOS {
49 namespace Notification {
50 std::mutex TestAnsSubscriber::mutex = std::mutex();
GetBoolParam()51 bool GetBoolParam()
52 {
53 bool param;
54 if (GetIntParam() % INDEX_TWO == 0) {
55 param = true;
56 } else {
57 param = false;
58 }
59 return param;
60 }
61
GenRandom(size_t min,size_t max)62 size_t GenRandom(size_t min, size_t max)
63 {
64 std::random_device rd;
65 static uniform_int_distribution<size_t> u(min, max);
66 static default_random_engine e(rd());
67 size_t param = u(e);
68 return param;
69 }
70
GetS8Param()71 int8_t GetS8Param()
72 {
73 std::random_device rd;
74 static uniform_int_distribution<int8_t> u(INT8_MIN, INT8_MAX);
75 static default_random_engine e(rd());
76 int8_t param = u(e);
77 return param;
78 }
GetS16Param()79 int16_t GetS16Param()
80 {
81 std::random_device rd;
82 static uniform_int_distribution<int16_t> u(INT16_MIN, INT16_MAX);
83 static default_random_engine e(rd());
84 int16_t param = u(e);
85 return param;
86 }
GetS32Param()87 int32_t GetS32Param()
88 {
89 std::random_device rd;
90 static uniform_int_distribution<int32_t> u(INT32_MIN, INT32_MAX);
91 static default_random_engine e(rd());
92 int32_t param = u(e);
93 return param;
94 }
95
GetS64Param()96 int64_t GetS64Param()
97 {
98 std::random_device rd;
99 static uniform_int_distribution<int64_t> u(INT64_MIN, INT64_MAX);
100 static default_random_engine e(rd());
101 int64_t param = u(e);
102 return param;
103 }
104
105 template <class T>
GetUnsignParam()106 T GetUnsignParam()
107 {
108 std::random_device rd;
109 static uniform_int_distribution<T> u;
110 static default_random_engine e(rd());
111 T param = u(e);
112 return param;
113 }
114
GetSizeTParam()115 size_t GetSizeTParam()
116 {
117 size_t param = GetUnsignParam<size_t>();
118 return param;
119 }
120
GetU8Param()121 uint8_t GetU8Param()
122 {
123 uint8_t param = GetUnsignParam<uint8_t>();
124 return param;
125 }
126
GetUIntParam()127 unsigned int GetUIntParam()
128 {
129 unsigned int param = GetUnsignParam<unsigned int>();
130 return param;
131 }
132
GetU16Param()133 uint16_t GetU16Param()
134 {
135 uint16_t param = GetUnsignParam<uint16_t>();
136 return param;
137 }
138
GetU32Param()139 uint32_t GetU32Param()
140 {
141 uint32_t param = GetUnsignParam<uint32_t>();
142 return param;
143 }
144
GetU64Param()145 uint64_t GetU64Param()
146 {
147 uint64_t param = GetUnsignParam<uint64_t>();
148 return param;
149 }
150
GetShortParam()151 short GetShortParam()
152 {
153 std::random_device rd;
154 static uniform_int_distribution<short> u(SHRT_MIN, SHRT_MAX);
155 static default_random_engine e(rd());
156 short param = u(e);
157 return param;
158 }
159
GetLongParam()160 long GetLongParam()
161 {
162 std::random_device rd;
163 static uniform_int_distribution<long> u(LONG_MIN, LONG_MAX);
164 static default_random_engine e(rd());
165 long param = u(e);
166 return param;
167 }
168
GetIntParam()169 int GetIntParam()
170 {
171 std::random_device rd;
172 static uniform_int_distribution<> u(INT_MIN, INT_MAX);
173 static default_random_engine e(rd());
174 int param = u(e);
175 return param;
176 }
177
GetDoubleParam()178 double GetDoubleParam()
179 {
180 double param = 0;
181 std::random_device rd;
182 static uniform_real_distribution<double> u(DBL_MIN, DBL_MAX);
183 static default_random_engine e(rd());
184 param = u(e);
185 return param;
186 }
187
GetFloatParam()188 float GetFloatParam()
189 {
190 float param = 0;
191 std::random_device rd;
192 static uniform_real_distribution<float> u(FLT_MIN, FLT_MAX);
193 static default_random_engine e(rd());
194 param = u(e);
195 return param;
196 }
197
GetCharParam()198 char GetCharParam()
199 {
200 std::random_device rd;
201 static uniform_int_distribution<> u(CHAR_MINCOUNT, CHAR_MAXCOUNT);
202 static default_random_engine e(rd());
203 char param = u(e);
204 return param;
205 }
206
GetChar32Param()207 char32_t GetChar32Param()
208 {
209 char32_t param = ' ';
210 std::random_device rd;
211 static uniform_int_distribution<char32_t> u;
212 static default_random_engine e(rd());
213 param = u(e);
214 return param;
215 }
216
GetCharArryParam()217 char *GetCharArryParam()
218 {
219 static char param[256];
220 size_t len = 0;
221 string strparam = GetStringParam();
222 if (!strparam.empty()) {
223 len = strparam.size() + 1;
224 if (len > sizeof(param)) {
225 len = sizeof(param) - 1;
226 }
227
228 int ret = strcpy_s(param, len, strparam.c_str());
229 if (ret == 0) {
230 return param;
231 } else {
232 return nullptr;
233 }
234 } else {
235 return nullptr;
236 }
237 }
238
GetStringParam()239 string GetStringParam()
240 {
241 string param = "";
242 char ch = GetCharParam();
243 size_t len = GenRandom(0, MAX_LENGTH);
244 while (len--) {
245 ch = GetCharParam();
246 param += ch;
247 }
248 return param;
249 }
250
251 template <class T>
GetUnsignVectorParam()252 vector<T> GetUnsignVectorParam()
253 {
254 vector<T> param;
255 size_t len = GenRandom(0, MAX_LENGTH);
256 while (len--) {
257 T t = GetUnsignParam<T>();
258 param.push_back(t);
259 }
260 return param;
261 }
262
263 template <class T>
GetClassParam()264 T GetClassParam()
265 {
266 T param;
267 return param;
268 }
269
GetBoolVectorParam()270 std::vector<bool> GetBoolVectorParam()
271 {
272 vector<bool> param;
273 size_t len = GenRandom(0, MAX_LENGTH);
274 while (len--) {
275 int t = GetBoolParam();
276 param.push_back(t);
277 }
278 return param;
279 }
280
GetShortVectorParam()281 std::vector<short> GetShortVectorParam()
282 {
283 vector<short> param;
284 size_t len = GenRandom(0, MAX_LENGTH);
285 while (len--) {
286 short t = GetShortParam();
287 param.push_back(t);
288 }
289 return param;
290 }
291
GetLongVectorParam()292 std::vector<long> GetLongVectorParam()
293 {
294 vector<long> param;
295 size_t len = GenRandom(0, MAX_LENGTH);
296 while (len--) {
297 long t = GetLongParam();
298 param.push_back(t);
299 }
300 return param;
301 }
302
GetIntVectorParam()303 vector<int> GetIntVectorParam()
304 {
305 vector<int> param;
306 size_t len = GenRandom(0, MAX_LENGTH);
307 while (len--) {
308 int t = GetIntParam();
309 param.push_back(t);
310 }
311 return param;
312 }
313
GetFloatVectorParam()314 std::vector<float> GetFloatVectorParam()
315 {
316 vector<float> param;
317 size_t len = GenRandom(0, MAX_LENGTH);
318 while (len--) {
319 float t = GetIntParam();
320 param.push_back(t);
321 }
322 return param;
323 }
324
GetDoubleVectorParam()325 std::vector<double> GetDoubleVectorParam()
326 {
327 vector<double> param;
328 size_t len = GenRandom(0, MAX_LENGTH);
329 while (len--) {
330 double t = GetIntParam();
331 param.push_back(t);
332 }
333 return param;
334 }
335
GetCharVectorParam()336 vector<char> GetCharVectorParam()
337 {
338 vector<char> param;
339 size_t len = GenRandom(0, MAX_LENGTH);
340 while (len--) {
341 char t = GetCharParam();
342 param.push_back(t);
343 }
344 return param;
345 }
346
GetChar32VectorParam()347 vector<char32_t> GetChar32VectorParam()
348 {
349 vector<char32_t> param;
350 size_t len = GenRandom(0, MAX_LENGTH);
351 while (len--) {
352 char32_t t = GetChar32Param();
353 param.push_back(t);
354 }
355 return param;
356 }
357
GetStringVectorParam()358 vector<string> GetStringVectorParam()
359 {
360 vector<string> param;
361 size_t len = GenRandom(0, MAX_LENGTH);
362 while (len--) {
363 string t = GetStringParam();
364 param.push_back(t);
365 }
366 return param;
367 }
368
GetS8VectorParam()369 vector<int8_t> GetS8VectorParam()
370 {
371 vector<int8_t> param;
372 size_t len = GenRandom(0, MAX_LENGTH);
373 while (len--) {
374 int8_t temp = GetS8Param();
375 param.push_back(temp);
376 }
377 return param;
378 }
379
GetS16VectorParam()380 vector<int16_t> GetS16VectorParam()
381 {
382 vector<int16_t> param;
383 size_t len = GenRandom(0, MAX_LENGTH);
384 while (len--) {
385 int16_t temp = GetS16Param();
386 param.push_back(temp);
387 }
388 return param;
389 }
390
GetS32VectorParam()391 vector<int32_t> GetS32VectorParam()
392 {
393 vector<int32_t> param;
394 size_t len = GenRandom(0, MAX_LENGTH);
395 while (len--) {
396 int32_t temp = GetS32Param();
397 param.push_back(temp);
398 }
399 return param;
400 }
401
GetS64VectorParam()402 vector<int64_t> GetS64VectorParam()
403 {
404 vector<int64_t> param;
405 size_t len = GenRandom(0, MAX_LENGTH);
406 while (len--) {
407 int64_t temp = GetS64Param();
408 param.push_back(temp);
409 }
410 return param;
411 }
412
GetParamParcel()413 std::shared_ptr<Parcel> GetParamParcel()
414 {
415 return make_shared<Parcel>();
416 }
GetParamWant()417 std::shared_ptr<Want> GetParamWant()
418 {
419 return make_shared<Want>();
420 }
421
GetParamWantVector()422 std::vector<std::shared_ptr<Want>> GetParamWantVector()
423 {
424 vector<std::shared_ptr<Want>> param;
425 size_t len = GenRandom(0, MAX_LENGTH);
426 while (len--) {
427 std::shared_ptr<Want> t = GetParamWant();
428 param.push_back(t);
429 }
430 return param;
431 }
432
GetParamOperation()433 OHOS::AAFwk::Operation GetParamOperation()
434 {
435 return OHOS::AAFwk::Operation();
436 }
437
GetParamSptrRemote()438 sptr<IRemoteObject> GetParamSptrRemote()
439 {
440 return sptr<TestRemoteObject>();
441 }
442
GetParamEventRunner()443 std::shared_ptr<EventRunner> GetParamEventRunner()
444 {
445 return EventRunner::Create(GetCharArryParam());
446 }
GetParamAbility()447 std::shared_ptr<OHOS::AppExecFwk::Ability> GetParamAbility()
448 {
449 return make_shared<OHOS::AppExecFwk::Ability>();
450 }
451
GetParamWantParams()452 std::shared_ptr<OHOS::AAFwk::WantParams> GetParamWantParams()
453 {
454 return make_shared<OHOS::AAFwk::WantParams>();
455 }
456
GetParamApplicationFlag()457 OHOS::AppExecFwk::ApplicationFlag GetParamApplicationFlag()
458 {
459 if (GetBoolParam()) {
460 return OHOS::AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO;
461 } else {
462 return OHOS::AppExecFwk::ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMS;
463 }
464 }
465
GetParamApplicationInfo()466 OHOS::AppExecFwk::ApplicationInfo GetParamApplicationInfo()
467 {
468 return OHOS::AppExecFwk::ApplicationInfo();
469 }
GetParamAbilityInfo()470 OHOS::AppExecFwk::AbilityInfo GetParamAbilityInfo()
471 {
472 return OHOS::AppExecFwk::AbilityInfo();
473 }
474
GetParamIBundleStatusCallback()475 sptr<OHOS::AppExecFwk::IBundleStatusCallback> GetParamIBundleStatusCallback()
476 {
477 return sptr<TestIBundleStatusCallback>();
478 }
479
GetParamNotificationSorting()480 std::shared_ptr<NotificationSorting> GetParamNotificationSorting()
481 {
482 return std::make_shared<NotificationSorting>();
483 }
484
GetParamNotificationSortingVector()485 std::vector<NotificationSorting> GetParamNotificationSortingVector()
486 {
487 vector<NotificationSorting> param;
488 size_t len = GenRandom(0, MAX_LENGTH);
489 while (len--) {
490 NotificationSorting t;
491 param.push_back(t);
492 }
493 return param;
494 }
495
GetParamNotificationSortingMap()496 std::shared_ptr<NotificationSortingMap> GetParamNotificationSortingMap()
497 {
498 if (GetBoolParam()) {
499 return std::make_shared<NotificationSortingMap>();
500 } else {
501 std::vector<NotificationSorting> sortingList = GetParamNotificationSortingVector();
502 return std::make_shared<NotificationSortingMap>(sortingList);
503 }
504 }
505
GetParamNotificationSlot()506 std::shared_ptr<OHOS::Notification::NotificationSlot> GetParamNotificationSlot()
507 {
508 return std::make_shared<OHOS::Notification::NotificationSlot>(GetParamSlotType());
509 }
510
GetParamNotificationSlotSptr()511 sptr<OHOS::Notification::NotificationSlot> GetParamNotificationSlotSptr()
512 {
513 sptr<OHOS::Notification::NotificationSlot> param = new OHOS::Notification::NotificationSlot(GetParamSlotType());
514 return param;
515 }
516
GetParamSlotType()517 OHOS::Notification::NotificationConstant::SlotType GetParamSlotType()
518 {
519 switch (GetIntParam() % INDEX_FIVE) {
520 case INDEX_ZERO:
521 return OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
522 break;
523 case INDEX_ONE:
524 return OHOS::Notification::NotificationConstant::SlotType::SERVICE_REMINDER;
525 break;
526 case INDEX_TWO:
527 return OHOS::Notification::NotificationConstant::SlotType::CONTENT_INFORMATION;
528 break;
529 case INDEX_THREE:
530 return OHOS::Notification::NotificationConstant::SlotType::CUSTOM;
531 break;
532 case INDEX_FOUR:
533 return OHOS::Notification::NotificationConstant::SlotType::OTHER;
534 break;
535 default:
536 return OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
537 break;
538 }
539 }
GetParamNotificationSlotSptrVector()540 std::vector<sptr<OHOS::Notification::NotificationSlot>> GetParamNotificationSlotSptrVector()
541 {
542 vector<sptr<NotificationSlot>> param;
543 size_t len = GenRandom(0, MAX_LENGTH);
544 while (len--) {
545 sptr<NotificationSlot> t = GetParamNotificationSlotSptr();
546 param.push_back(t);
547 }
548 return param;
549 }
550
GetParamNotificationSlotVector()551 std::vector<OHOS::Notification::NotificationSlot> GetParamNotificationSlotVector()
552 {
553 vector<NotificationSlot> param;
554 size_t len = GenRandom(0, MAX_LENGTH);
555 while (len--) {
556 NotificationSlot t = *GetParamNotificationSlot();
557 param.push_back(t);
558 }
559 return param;
560 }
561
GetParamNotificationBundleOption()562 std::shared_ptr<OHOS::Notification::NotificationBundleOption> GetParamNotificationBundleOption()
563 {
564 if (GetBoolParam()) {
565 return std::make_shared<NotificationBundleOption>();
566 } else {
567 return std::make_shared<NotificationBundleOption>(GetStringParam(), GetS32Param());
568 }
569 }
GetParamNotificationRequest()570 std::shared_ptr<OHOS::Notification::NotificationRequest> GetParamNotificationRequest()
571 {
572 switch (GetIntParam() % INDEX_THREE) {
573 case INDEX_ZERO:
574 return std::make_shared<OHOS::Notification::NotificationRequest>();
575 break;
576 case INDEX_ONE:
577 return std::make_shared<OHOS::Notification::NotificationRequest>(GetS32Param());
578 break;
579 case INDEX_TWO:
580 return std::make_shared<OHOS::Notification::NotificationRequest>(GetParamContext(), GetS32Param());
581 break;
582 default:
583 return std::make_shared<OHOS::Notification::NotificationRequest>();
584 break;
585 }
586 }
587
GetParamNotificationRequestSptr()588 sptr<OHOS::Notification::NotificationRequest> GetParamNotificationRequestSptr()
589 {
590 switch (GetIntParam() % INDEX_THREE) {
591 case INDEX_ZERO: {
592 sptr<OHOS::Notification::NotificationRequest> param = new OHOS::Notification::NotificationRequest();
593 return param;
594 } break;
595 case INDEX_ONE: {
596 sptr<OHOS::Notification::NotificationRequest> param =
597 new OHOS::Notification::NotificationRequest(GetS32Param());
598 return param;
599 } break;
600 case INDEX_TWO: {
601 sptr<OHOS::Notification::NotificationRequest> param =
602 new OHOS::Notification::NotificationRequest(GetParamContext(), GetS32Param());
603 return param;
604 } break;
605 default: {
606 sptr<OHOS::Notification::NotificationRequest> param = new OHOS::Notification::NotificationRequest();
607 return param;
608 } break;
609 }
610 }
611
GetParamNotificationRequestVector()612 std::vector<sptr<OHOS::Notification::NotificationRequest>> GetParamNotificationRequestVector()
613 {
614 vector<sptr<OHOS::Notification::NotificationRequest>> param;
615 size_t len = GenRandom(0, MAX_LENGTH);
616 while (len--) {
617 sptr<OHOS::Notification::NotificationRequest> t = GetParamNotificationRequestSptr();
618 param.push_back(t);
619 }
620 return param;
621 }
GetParamNotificationSortingMapSptr()622 sptr<OHOS::Notification::NotificationSortingMap> GetParamNotificationSortingMapSptr()
623 {
624 sptr<OHOS::Notification::NotificationSortingMap> param;
625 if (GetBoolParam()) {
626 param = new OHOS::Notification::NotificationSortingMap();
627 } else {
628 std::vector<NotificationSorting> sortingList = GetParamNotificationSortingVector();
629 param = new OHOS::Notification::NotificationSortingMap(sortingList);
630 }
631 return param;
632 }
GetParamNotificationLevel()633 OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLevel()
634 {
635 switch (GetIntParam() % INDEX_SIX) {
636 case INDEX_ZERO:
637 return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE;
638 break;
639 case INDEX_ONE:
640 return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_MIN;
641 break;
642 case INDEX_TWO:
643 return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_LOW;
644 break;
645 case INDEX_THREE:
646 return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_DEFAULT;
647 break;
648 case INDEX_FOUR:
649 return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_HIGH;
650 break;
651 case INDEX_FIVE:
652 return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_UNDEFINED;
653 break;
654 default:
655 return OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE;
656 break;
657 }
658 }
659
GetParamNotificationSubscriber()660 std::shared_ptr<OHOS::Notification::NotificationSubscriber> GetParamNotificationSubscriber()
661 {
662 return std::make_shared<TestAnsSubscriber>();
663 }
664
GetParamNotificationSubscribeInfo()665 std::shared_ptr<OHOS::Notification::NotificationSubscribeInfo> GetParamNotificationSubscribeInfo()
666 {
667 return std::make_shared<OHOS::Notification::NotificationSubscribeInfo>();
668 }
669
GetParamWantAgentInfo()670 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgentInfo> GetParamWantAgentInfo()
671 {
672 switch (GetIntParam() % INDEX_THREE) {
673 case INDEX_ZERO:
674 return std::make_shared<OHOS::AbilityRuntime::WantAgent::WantAgentInfo>();
675 break;
676 case INDEX_ONE: {
677 std::vector<std::shared_ptr<Want>> param = GetParamWantVector();
678 return std::make_shared<OHOS::AbilityRuntime::WantAgent::WantAgentInfo>(
679 GetIntParam(), GetParamOperationType(), GetParamFlags(), param, GetParamWantParams());
680 } break;
681 case INDEX_TWO: {
682 std::vector<std::shared_ptr<Want>> param = GetParamWantVector();
683 return std::make_shared<OHOS::AbilityRuntime::WantAgent::WantAgentInfo>(
684 GetIntParam(), GetParamOperationType(), GetParamFlagsVector(), param, GetParamWantParams());
685 } break;
686 default:
687 return std::make_shared<OHOS::AbilityRuntime::WantAgent::WantAgentInfo>();
688 break;
689 }
690 }
691
GetParamOperationType()692 OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType GetParamOperationType()
693 {
694 switch (GetIntParam() % INDEX_SIX) {
695 case INDEX_ZERO:
696 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE;
697 break;
698 case INDEX_ONE:
699 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY;
700 break;
701 case INDEX_TWO:
702 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITIES;
703 break;
704 case INDEX_THREE:
705 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_SERVICE;
706 break;
707 case INDEX_FOUR:
708 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT;
709 break;
710 case INDEX_FIVE:
711 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_FOREGROUND_SERVICE;
712 break;
713 default:
714 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE;
715 break;
716 }
717 }
GetParamFlags()718 OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags GetParamFlags()
719 {
720 switch (GetIntParam() % INDEX_TEN) {
721 case INDEX_ZERO:
722 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG;
723 break;
724 case INDEX_ONE:
725 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::NO_BUILD_FLAG;
726 break;
727 case INDEX_TWO:
728 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::CANCEL_PRESENT_FLAG;
729 break;
730 case INDEX_THREE:
731 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG;
732 break;
733 case INDEX_FOUR:
734 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG;
735 break;
736 case INDEX_FIVE:
737 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ELEMENT;
738 break;
739 case INDEX_SIX:
740 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ACTION;
741 break;
742 case INDEX_SEVEN:
743 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_URI;
744 break;
745 case INDEX_EIGHT:
746 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ENTITIES;
747 break;
748 case INDEX_NINE:
749 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_BUNDLE;
750 break;
751 default:
752 return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG;
753 break;
754 }
755 }
GetParamFlagsVector()756 std::vector<OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags> GetParamFlagsVector()
757 {
758 vector<OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags> param;
759 size_t len = GenRandom(0, MAX_LENGTH);
760 while (len--) {
761 OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags t = GetParamFlags();
762 param.push_back(t);
763 }
764 return param;
765 }
766
GetParamNotification()767 std::shared_ptr<OHOS::Notification::Notification> GetParamNotification()
768 {
769 sptr<OHOS::Notification::NotificationRequest> param = GetParamNotificationRequestSptr();
770 return std::make_shared<OHOS::Notification::Notification>(param);
771 }
772
GetParamNotificationSptr()773 sptr<OHOS::Notification::Notification> GetParamNotificationSptr()
774 {
775 sptr<OHOS::Notification::NotificationRequest> t = GetParamNotificationRequestSptr();
776 sptr<OHOS::Notification::Notification> param = new OHOS::Notification::Notification(t);
777 return param;
778 }
779
GetParamNotificationSptrVector()780 std::vector<sptr<OHOS::Notification::Notification>> GetParamNotificationSptrVector()
781 {
782 std::vector<sptr<OHOS::Notification::Notification>> param;
783 size_t len = GenRandom(0, MAX_LENGTH);
784 while (len--) {
785 sptr<OHOS::Notification::Notification> t = GetParamNotificationSptr();
786 param.push_back(t);
787 }
788 return param;
789 }
GetParamPendingWant()790 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::PendingWant> GetParamPendingWant()
791 {
792 sptr<AAFwk::IWantSender> target = new WantSender();
793 sptr<IRemoteObject> allowlistToken = GetParamSptrRemote();
794 if (GetBoolParam()) {
795 return std::make_shared<OHOS::AbilityRuntime::WantAgent::PendingWant>(target);
796 } else {
797 return std::make_shared<OHOS::AbilityRuntime::WantAgent::PendingWant>(target, allowlistToken);
798 }
799 }
GetParamWantAgent()800 std::shared_ptr<OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgent> GetParamWantAgent()
801 {
802 if (GetBoolParam()) {
803 return std::make_shared<OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgent>();
804 } else {
805 return std::make_shared<OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgent>(GetParamPendingWant());
806 }
807 }
GetParamCompletedCallback()808 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::CompletedCallback> GetParamCompletedCallback()
809 {
810 return std::make_shared<TestCompletedCallback>();
811 }
GetParamTriggerInfo()812 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::TriggerInfo> GetParamTriggerInfo()
813 {
814 if (GetBoolParam()) {
815 return std::make_shared<OHOS::AbilityRuntime::WantAgent::TriggerInfo>();
816 } else {
817 return std::make_shared<OHOS::AbilityRuntime::WantAgent::TriggerInfo>(
818 GetStringParam(), GetParamWantParams(), GetParamWant(), GetIntParam());
819 }
820 }
GetParamCancelListener()821 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::CancelListener> GetParamCancelListener()
822 {
823 return std::make_shared<TestCancelListener>();
824 }
825
GetParamLauncherService()826 std::shared_ptr<OHOS::AppExecFwk::LauncherService> GetParamLauncherService()
827 {
828 return make_shared<OHOS::AppExecFwk::LauncherService>();
829 }
GetParamLauncherAbilityInfoVector()830 std::vector<OHOS::AppExecFwk::LauncherAbilityInfo> GetParamLauncherAbilityInfoVector()
831 {
832 std::vector<OHOS::AppExecFwk::LauncherAbilityInfo> param;
833 size_t len = GenRandom(0, MAX_LENGTH);
834 while (len--) {
835 OHOS::AppExecFwk::LauncherAbilityInfo t;
836 param.push_back(t);
837 }
838 return param;
839 }
GetParamLauncherAbilityInfo()840 std::shared_ptr<OHOS::AppExecFwk::LauncherAbilityInfo> GetParamLauncherAbilityInfo()
841 {
842 return make_shared<OHOS::AppExecFwk::LauncherAbilityInfo>();
843 }
GetParamLauncherShortcutInfoVector()844 std::vector<OHOS::AppExecFwk::LauncherShortcutInfo> GetParamLauncherShortcutInfoVector()
845 {
846 std::vector<OHOS::AppExecFwk::LauncherShortcutInfo> param;
847 size_t len = GenRandom(0, MAX_LENGTH);
848 while (len--) {
849 OHOS::AppExecFwk::LauncherShortcutInfo t;
850 param.push_back(t);
851 }
852 return param;
853 }
GetParamFormInfoVector()854 std::vector<OHOS::AppExecFwk::FormInfo> GetParamFormInfoVector()
855 {
856 std::vector<OHOS::AppExecFwk::FormInfo> param;
857 size_t len = GenRandom(0, MAX_LENGTH);
858 while (len--) {
859 OHOS::AppExecFwk::FormInfo t;
860 param.push_back(t);
861 }
862 return param;
863 }
GetParamShortcutInfoVector()864 std::vector<OHOS::AppExecFwk::ShortcutInfo> GetParamShortcutInfoVector()
865 {
866 std::vector<OHOS::AppExecFwk::ShortcutInfo> param;
867 size_t len = GenRandom(0, MAX_LENGTH);
868 while (len--) {
869 OHOS::AppExecFwk::ShortcutInfo t;
870 param.push_back(t);
871 }
872 return param;
873 }
GetParamModuleUsageRecordVector()874 std::vector<OHOS::AppExecFwk::ModuleUsageRecord> GetParamModuleUsageRecordVector()
875 {
876 std::vector<OHOS::AppExecFwk::ModuleUsageRecord> param;
877 size_t len = GenRandom(0, MAX_LENGTH);
878 while (len--) {
879 OHOS::AppExecFwk::ModuleUsageRecord t;
880 param.push_back(t);
881 }
882 return param;
883 }
GetParamOnPermissionChangedCallback()884 sptr<OHOS::AppExecFwk::OnPermissionChangedCallback> GetParamOnPermissionChangedCallback()
885 {
886 return sptr<TestOnPermissionChangedCallback>();
887 }
888
GetParamTaskDispatcher()889 std::shared_ptr<OHOS::AppExecFwk::TaskDispatcher> GetParamTaskDispatcher()
890 {
891 switch (GetIntParam() % INDEX_FOUR) {
892 case INDEX_ZERO:
893 return GetParamContext()->GetMainTaskDispatcher();
894 break;
895 case INDEX_ONE:
896 return GetParamContext()->CreateParallelTaskDispatcher(GetStringParam(), GetParamTaskPriority());
897 break;
898 case INDEX_TWO:
899 return GetParamContext()->CreateSerialTaskDispatcher(GetStringParam(), GetParamTaskPriority());
900 break;
901 case INDEX_THREE:
902 return GetParamContext()->GetGlobalTaskDispatcher(GetParamTaskPriority());
903 break;
904 default:
905 return GetParamContext()->GetMainTaskDispatcher();
906 break;
907 }
908 }
909
GetParamTaskPriority()910 OHOS::AppExecFwk::TaskPriority GetParamTaskPriority()
911 {
912 switch (GetIntParam() % INDEX_THREE) {
913 case INDEX_ZERO:
914 return OHOS::AppExecFwk::TaskPriority::HIGH;
915 break;
916 case INDEX_ONE:
917 return OHOS::AppExecFwk::TaskPriority::DEFAULT;
918 break;
919 case INDEX_TWO:
920 return OHOS::AppExecFwk::TaskPriority::LOW;
921 break;
922 default:
923 return OHOS::AppExecFwk::TaskPriority::HIGH;
924 break;
925 }
926 }
927
GetParamRunnable()928 std::shared_ptr<OHOS::AppExecFwk::Runnable> GetParamRunnable()
929 {
930 return std::make_shared<Runnable>([]() { std::cout << "Start task runnable."; });
931 }
932
GetParamGroup()933 std::shared_ptr<OHOS::AppExecFwk::Group> GetParamGroup()
934 {
935 return std::make_shared<OHOS::AppExecFwk::Group>();
936 }
937
GetParamIteratableTask()938 std::shared_ptr<IteratableTask<long>> GetParamIteratableTask()
939 {
940 return std::make_shared<IteratableTask<long>>([](long data) { std::cout << "Start IteratableTask."; });
941 }
942
GetParamSubscribeResult()943 OHOS::Notification::NotificationConstant::SubscribeResult GetParamSubscribeResult()
944 {
945 switch (GetIntParam() % INDEX_THREE) {
946 case INDEX_ZERO:
947 return OHOS::Notification::NotificationConstant::SubscribeResult::SUCCESS;
948 case INDEX_ONE:
949 return OHOS::Notification::NotificationConstant::SubscribeResult::PREMISSION_FAIL;
950 case INDEX_TWO:
951 return OHOS::Notification::NotificationConstant::SubscribeResult::RESOURCES_FAIL;
952 default:
953 return OHOS::Notification::NotificationConstant::SubscribeResult::SUCCESS;
954 }
955 }
956
GetParamMissionInformation()957 OHOS::AppExecFwk::MissionInformation GetParamMissionInformation()
958 {
959 return OHOS::AppExecFwk::MissionInformation();
960 }
961
GetParamAbilityLifecycleCallbacks()962 std::shared_ptr<OHOS::AppExecFwk::AbilityLifecycleCallbacks> GetParamAbilityLifecycleCallbacks()
963 {
964 return std::make_shared<TestAbilityLifecycleCallbacks>();
965 }
966
GetParamBaseTaskDispatcher()967 std::shared_ptr<OHOS::AppExecFwk::BaseTaskDispatcher> GetParamBaseTaskDispatcher()
968 {
969 std::shared_ptr<OHOS::AppExecFwk::TaskDispatcherContext> context =
970 std::make_shared<OHOS::AppExecFwk::TaskDispatcherContext>();
971 std::shared_ptr<OHOS::AppExecFwk::SpecDispatcherConfig> config =
972 std::make_shared<SpecDispatcherConfig>(GetStringParam(), GetParamTaskPriority());
973 std::shared_ptr<OHOS::AppExecFwk::SpecTaskDispatcher> specTaskDispatcher =
974 std::make_shared<SpecTaskDispatcher>(config, GetParamEventRunner());
975 switch (GetIntParam() % INDEX_THREE) {
976 case INDEX_ZERO:
977 return context->CreateSerialDispatcher(GetStringParam(), GetParamTaskPriority());
978 case INDEX_ONE:
979 return context->CreateParallelDispatcher(GetStringParam(), GetParamTaskPriority());
980 case INDEX_TWO:
981 return specTaskDispatcher;
982 default:
983 return context->CreateSerialDispatcher(GetStringParam(), GetParamTaskPriority());
984 }
985 }
986
GetParamIAbilityManager()987 std::shared_ptr<OHOS::AAFwk::IAbilityManager> GetParamIAbilityManager()
988 {
989 std::shared_ptr<OHOS::AAFwk::IAbilityManager> param =
990 DelayedSingleton<OHOS::AAFwk::AbilityManagerService>::GetInstance();
991 return param;
992 }
993
GetParamNotificationDoNotDisturbDate()994 std::shared_ptr<OHOS::Notification::NotificationDoNotDisturbDate> GetParamNotificationDoNotDisturbDate()
995 {
996 if (GetBoolParam()) {
997 return std::make_shared<OHOS::Notification::NotificationDoNotDisturbDate>();
998 } else {
999 return std::make_shared<OHOS::Notification::NotificationDoNotDisturbDate>(
1000 GetParamDoNotDisturbType(), GetS64Param(), GetS64Param());
1001 }
1002 }
1003
GetParamDoNotDisturbType()1004 OHOS::Notification::NotificationConstant::DoNotDisturbType GetParamDoNotDisturbType()
1005 {
1006 switch (GetIntParam() % INDEX_FOUR) {
1007 case INDEX_ZERO:
1008 return OHOS::Notification::NotificationConstant::DoNotDisturbType::NONE;
1009 break;
1010 case INDEX_ONE:
1011 return OHOS::Notification::NotificationConstant::DoNotDisturbType::ONCE;
1012 break;
1013 case INDEX_TWO:
1014 return OHOS::Notification::NotificationConstant::DoNotDisturbType::DAILY;
1015 break;
1016 case INDEX_THREE:
1017 return OHOS::Notification::NotificationConstant::DoNotDisturbType::CLEARLY;
1018 break;
1019 default:
1020 return OHOS::Notification::NotificationConstant::DoNotDisturbType::NONE;
1021 break;
1022 }
1023 }
1024 } // namespace Notification
1025 } // namespace OHOS