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
16 #include <iostream>
17 #include <string>
18 #include <thread>
19
20 #include "common_event_manager.h"
21 #define private public
22 #define protected public
23 #include "common_event_manager_service.h"
24 #undef private
25 #undef protected
26 #include "ces_inner_error_code.h"
27 #include "common_event_subscriber.h"
28 #include "common_event_support.h"
29 #include "datetime_ex.h"
30 #include "event_log_wrapper.h"
31
32 #include "testConfigParser.h"
33
34 #include <gtest/gtest.h>
35
36 using namespace testing::ext;
37
38 namespace OHOS {
39 namespace EventFwk {
40 namespace {
41 std::mutex g_mtx;
42 const time_t g_TIME_OUT_SECONDS_LIMIT = 5;
43 const time_t g_TIME_OUT_SECONDS = 3;
44
45 const std::string COMPARE_STR = "cesComparesStrForCase";
46 const std::string COMPARE_STR_FALSE = "cesComparesStrForCaseFalse";
47
48 const int32_t g_CODE_COMPARE1 = 1;
49 const int32_t g_CODE_COMPARE2 = 200;
50 int SIGNUMFIRST = 0;
51 int SIGNUMSECOND = 0;
52 int SIGNUMTHIRD = 0;
53 } // namespace
54
55 class CommonEventServicesSystemTest : public CommonEventSubscriber {
56 public:
57 explicit CommonEventServicesSystemTest(const CommonEventSubscribeInfo &subscribeInfo);
~CommonEventServicesSystemTest()58 virtual ~CommonEventServicesSystemTest() {};
59 virtual void OnReceiveEvent(const CommonEventData &data);
60 };
61
CommonEventServicesSystemTest(const CommonEventSubscribeInfo & subscribeInfo)62 CommonEventServicesSystemTest::CommonEventServicesSystemTest(const CommonEventSubscribeInfo &subscribeInfo)
63 : CommonEventSubscriber(subscribeInfo)
64 {}
65
OnReceiveEvent(const CommonEventData & data)66 void CommonEventServicesSystemTest::OnReceiveEvent(const CommonEventData &data)
67 {
68 GTEST_LOG_(INFO) << " ActsCESManagertest:CommonEventServicesSystemTest:OnReceiveEvent \n";
69 std::string action = data.GetWant().GetAction();
70 if (action == COMPARE_STR) {
71 EXPECT_TRUE(data.GetCode() == g_CODE_COMPARE1);
72 ++SIGNUMFIRST;
73 }
74 g_mtx.unlock();
75 }
76
77 class CommonEventServicesSystemTestSubscriber : public CommonEventSubscriber {
78 public:
79 explicit CommonEventServicesSystemTestSubscriber(const CommonEventSubscribeInfo &subscribeInfo);
~CommonEventServicesSystemTestSubscriber()80 virtual ~CommonEventServicesSystemTestSubscriber() {};
81 void OnReceiveEvent(const CommonEventData &data);
82 };
83
CommonEventServicesSystemTestSubscriber(const CommonEventSubscribeInfo & subscribeInfo)84 CommonEventServicesSystemTestSubscriber::CommonEventServicesSystemTestSubscriber(
85 const CommonEventSubscribeInfo &subscribeInfo)
86 : CommonEventSubscriber(subscribeInfo)
87 {}
88
OnReceiveEvent(const CommonEventData & data)89 void CommonEventServicesSystemTestSubscriber::OnReceiveEvent(const CommonEventData &data)
90 {
91 GTEST_LOG_(INFO) << " ActsCESManagertest:CommonEventServicesSystemTestSubscriber:OnReceiveEvent \n";
92 std::string action = data.GetWant().GetAction();
93 if (action == COMPARE_STR) {
94 EXPECT_TRUE(data.GetCode() == g_CODE_COMPARE1);
95 ++SIGNUMSECOND;
96 } else if (action == COMPARE_STR_FALSE) {
97 EXPECT_TRUE(data.GetCode() == g_CODE_COMPARE2);
98 ++SIGNUMTHIRD;
99 }
100 }
101
102 class ActsCESManagertest : public testing::Test {
103 public:
104 static void SetUpTestCase();
105 static void TearDownTestCase();
106 void SetUp();
107 void TearDown();
108
109 static StressTestLevel stLevel_;
110 };
111 StressTestLevel ActsCESManagertest::stLevel_ {};
112
SetUpTestCase()113 void ActsCESManagertest::SetUpTestCase()
114 {
115 TestConfigParser tcp;
116 tcp.ParseFromFile4StressTest(STRESS_TEST_CONFIG_FILE_PATH, stLevel_);
117 std::cout << "stress test level : "
118 << "AMS : " << stLevel_.AMSLevel << " "
119 << "BMS : " << stLevel_.BMSLevel << " "
120 << "CES : " << stLevel_.CESLevel << std::endl;
121 }
122
TearDownTestCase()123 void ActsCESManagertest::TearDownTestCase()
124 {}
125
SetUp()126 void ActsCESManagertest::SetUp()
127 {}
128
TearDown()129 void ActsCESManagertest::TearDown()
130 {}
131
132 /*
133 * @tc.number: CES_SubscriptionEvent_0100
134 * @tc.name: SubscribeCommonEvent
135 * @tc.desc: Verify the function when the input string is normal
136 */
137 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0100, Function | MediumTest | Level0)
138 {
139 bool result = false;
140 std::string eventName = "TESTEVENT_SUBSCRIBER";
141 MatchingSkills matchingSkills;
142 for (int i = 1; i <= stLevel_.CESLevel; i++) {
143 matchingSkills.AddEvent(eventName);
144 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
145 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
146 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
147 result = false;
148 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0100 failed, frequency: " << i;
149 break;
150 } else {
151 result = true;
152 }
153 matchingSkills.RemoveEvent(eventName);
154 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
155 }
156 if (result && stLevel_.CESLevel >= 1) {
157 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0100 stress level: " << stLevel_.CESLevel;
158 }
159 EXPECT_TRUE(result);
160 }
161
162 /*
163 * @tc.number: CES_SubscriptionEvent_0200
164 * @tc.name: SubscribeCommonEvent
165 * @tc.desc: Verify the function when the input string is number
166 */
167 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0200, Function | MediumTest | Level0)
168 {
169 bool result = false;
170 std::string eventName = "1";
171 MatchingSkills matchingSkills;
172 for (int i = 1; i <= stLevel_.CESLevel; i++) {
173 matchingSkills.AddEvent(eventName);
174 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
175 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
176 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
177 result = false;
178 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0200 failed, frequency: " << i;
179 break;
180 } else {
181 result = true;
182 }
183 matchingSkills.RemoveEvent(eventName);
184 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
185 }
186 if (result && stLevel_.CESLevel >= 1) {
187 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0200 stress level: " << stLevel_.CESLevel;
188 }
189 EXPECT_TRUE(result);
190 }
191
192 /*
193 * @tc.number: CES_SubscriptionEvent_0300
194 * @tc.name: SubscribeCommonEvent
195 * @tc.desc: Verify the function when the input string is empty
196 */
197 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0300, Function | MediumTest | Level2)
198 {
199 bool result = false;
200 std::string eventName = "";
201 MatchingSkills matchingSkills;
202 for (int i = 1; i <= stLevel_.CESLevel; i++) {
203 matchingSkills.AddEvent(eventName);
204 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
205 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
206 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
207 result = false;
208 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0300 failed, frequency: " << i;
209 break;
210 } else {
211 result = true;
212 }
213 matchingSkills.RemoveEvent(eventName);
214 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
215 }
216 if (result && stLevel_.CESLevel >= 1) {
217 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0300 stress level: " << stLevel_.CESLevel;
218 }
219 EXPECT_TRUE(result);
220 }
221
222 /*
223 * @tc.number: CES_SubscriptionEvent_0400
224 * @tc.name: SubscribeCommonEvent
225 * @tc.desc: Verify the function when the input string is points
226 */
227 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0400, Function | MediumTest | Level2)
228 {
229 bool result = false;
230 std::string eventName = ".............";
231 MatchingSkills matchingSkills;
232 for (int i = 1; i <= stLevel_.CESLevel; i++) {
233 matchingSkills.AddEvent(eventName);
234 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
235 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
236 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
237 result = false;
238 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0400 failed, frequency: " << i;
239 break;
240 } else {
241 result = true;
242 }
243 matchingSkills.RemoveEvent(eventName);
244 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
245 }
246 if (result && stLevel_.CESLevel >= 1) {
247 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0400 stress level: " << stLevel_.CESLevel;
248 }
249 EXPECT_TRUE(result);
250 }
251
252 /*
253 * @tc.number: CES_SubscriptionEvent_0500
254 * @tc.name: SubscribeCommonEvent
255 * @tc.desc: Verify the function when the input string with \0
256 */
257 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0500, Function | MediumTest | Level2)
258 {
259 bool result = false;
260 std::string eventName = "HELLO\0\0\0WORLD";
261 MatchingSkills matchingSkills;
262 for (int i = 1; i <= stLevel_.CESLevel; i++) {
263 matchingSkills.AddEvent(eventName);
264 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
265 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
266 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
267 result = false;
268 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0500 failed, frequency: " << i;
269 break;
270 } else {
271 result = true;
272 }
273 matchingSkills.RemoveEvent(eventName);
274 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
275 }
276 if (result && stLevel_.CESLevel >= 1) {
277 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0500 stress level: " << stLevel_.CESLevel;
278 }
279 EXPECT_TRUE(result);
280 }
281
282 /*
283 * @tc.number: CES_SubscriptionEvent_0600
284 * @tc.name: SubscribeCommonEvent
285 * @tc.desc: Verify that the ordered common event was subsribered succseefully
286 */
287 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0600, Function | MediumTest | Level0)
288 {
289 bool result = false;
290 std::string eventName = "TESTEVENT_SUBSCRIBER_SETPRIORITY";
291 MatchingSkills matchingSkills;
292 for (int i = 1; i <= stLevel_.CESLevel; i++) {
293 matchingSkills.AddEvent(eventName);
294 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
295 subscribeInfo.SetPriority(100);
296 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
297 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
298 result = false;
299 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0600 failed, frequency: " << i;
300 break;
301 } else {
302 result = true;
303 }
304 matchingSkills.RemoveEvent(eventName);
305 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
306 }
307 if (result && stLevel_.CESLevel >= 1) {
308 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0600 stress level: " << stLevel_.CESLevel;
309 }
310 EXPECT_TRUE(result);
311 }
312
313 /*
314 * @tc.number: CES_SubscriptionEvent_0700
315 * @tc.name: SubscribeCommonEvent
316 * @tc.desc: erify that the ordered common event was unsubsribered successfully
317 */
318 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0700, Function | MediumTest | Level0)
319 {
320 bool result = false;
321 std::string eventName = "TESTEVENT_UNSUBSCRIBE_SETPRIORITY";
322 MatchingSkills matchingSkills;
323 for (int i = 1; i <= stLevel_.CESLevel; i++) {
324 matchingSkills.AddEvent(eventName);
325 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
326 subscribeInfo.SetPriority(100);
327 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
328 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
329 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
330 result = false;
331 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0700 failed, frequency: " << i;
332 break;
333 } else {
334 result = true;
335 }
336 matchingSkills.RemoveEvent(eventName);
337 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
338 }
339 if (result && stLevel_.CESLevel >= 1) {
340 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0700 stress level: " << stLevel_.CESLevel;
341 }
342 EXPECT_TRUE(result);
343 }
344
345 /*
346 * @tc.number: CES_SubscriptionEvent_0800
347 * @tc.name: SubscribeCommonEvent
348 * @tc.desc: Verify the same input string three times
349 */
350 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0800, Function | MediumTest | Level2)
351 {
352 bool result = false;
353 std::string eventName1 = "TESTEVENT1";
354 std::string eventName2 = "TESTEVENT1";
355 std::string eventName3 = "TESTEVENT1";
356 MatchingSkills matchingSkills1;
357 MatchingSkills matchingSkills2;
358 MatchingSkills matchingSkills3;
359 for (int i = 1; i <= stLevel_.CESLevel; i++) {
360 matchingSkills1.AddEvent(eventName1);
361 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
362 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
363 bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1);
364
365 matchingSkills2.AddEvent(eventName2);
366 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
367 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
368 bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2);
369
370 matchingSkills3.AddEvent(eventName3);
371 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
372 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
373 bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3);
374
375 if (!result1 || !result2 || !result3) {
376 result = false;
377 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0800 failed, frequency: " << i;
378 break;
379 } else {
380 result = true;
381 }
382 matchingSkills1.RemoveEvent(eventName1);
383 matchingSkills2.RemoveEvent(eventName2);
384 matchingSkills3.RemoveEvent(eventName3);
385 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
386 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
387 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
388 }
389 if (result && stLevel_.CESLevel >= 1) {
390 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0800 stress level: " << stLevel_.CESLevel;
391 }
392 EXPECT_TRUE(result);
393 }
394
395 /*
396 * @tc.number: CES_SubscriptionEvent_0900
397 * @tc.name: SubscribeCommonEvent
398 * @tc.desc: Verify the same input empty string three times
399 */
400 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_0900, Function | MediumTest | Level2)
401 {
402 bool result = false;
403 std::string eventName1 = "";
404 std::string eventName2 = "";
405 std::string eventName3 = "";
406 MatchingSkills matchingSkills1;
407 MatchingSkills matchingSkills2;
408 MatchingSkills matchingSkills3;
409 for (int i = 1; i <= stLevel_.CESLevel; i++) {
410 matchingSkills1.AddEvent(eventName1);
411 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
412 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
413 bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1);
414
415 matchingSkills2.AddEvent(eventName2);
416 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
417 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
418 bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2);
419
420 matchingSkills3.AddEvent(eventName3);
421 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
422 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
423 bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3);
424
425 if (!result1 || !result2 || !result3) {
426 result = false;
427 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0900 failed, frequency: " << i;
428 break;
429 } else {
430 result = true;
431 }
432 matchingSkills1.RemoveEvent(eventName1);
433 matchingSkills2.RemoveEvent(eventName2);
434 matchingSkills3.RemoveEvent(eventName3);
435 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
436 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
437 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
438 }
439 if (result && stLevel_.CESLevel >= 1) {
440 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0900 stress level: " << stLevel_.CESLevel;
441 }
442 EXPECT_TRUE(result);
443 }
444
445 /*
446 * @tc.number: CES_SubscriptionEvent_1000
447 * @tc.name: SubscribeCommonEvent
448 * @tc.desc: Verify the normal input string three times
449 */
450 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1000, Function | MediumTest | Level0)
451 {
452 bool result = false;
453 std::string eventName1 = "TESTEVENT1";
454 std::string eventName2 = "TESTEVENT2";
455 std::string eventName3 = "TESTEVENT3";
456 MatchingSkills matchingSkills1;
457 MatchingSkills matchingSkills2;
458 MatchingSkills matchingSkills3;
459 for (int i = 1; i <= stLevel_.CESLevel; i++) {
460 matchingSkills1.AddEvent(eventName1);
461 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
462 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
463 bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1);
464
465 matchingSkills2.AddEvent(eventName2);
466 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
467 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
468 bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2);
469
470 matchingSkills3.AddEvent(eventName3);
471 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
472 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
473 bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3);
474
475 if (!result1 || !result2 || !result3) {
476 result = false;
477 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1000 failed, frequency: " << i;
478 break;
479 } else {
480 result = true;
481 }
482 matchingSkills1.RemoveEvent(eventName1);
483 matchingSkills2.RemoveEvent(eventName2);
484 matchingSkills3.RemoveEvent(eventName3);
485 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
486 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
487 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
488 }
489 if (result && stLevel_.CESLevel >= 1) {
490 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1000 stress level: " << stLevel_.CESLevel;
491 }
492 EXPECT_TRUE(result);
493 }
494
495 /*
496 * @tc.number: CES_SubscriptionEvent_1100
497 * @tc.name: SubscribeCommonEvent
498 * @tc.desc: Verify the normal input string two times
499 */
500 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1100, Function | MediumTest | Level0)
501 {
502 bool result = false;
503 std::string eventName1 = "TEST1";
504 std::string eventName2 = "TEST2";
505 MatchingSkills matchingSkills1;
506 MatchingSkills matchingSkills2;
507 for (int i = 1; i <= stLevel_.CESLevel; i++) {
508 matchingSkills1.AddEvent(eventName1);
509 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
510 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
511 bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1);
512
513 matchingSkills2.AddEvent(eventName2);
514 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
515 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
516 bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2);
517 if (!result1 || !result2) {
518 result = false;
519 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1100 failed, frequency: " << i;
520 break;
521 } else {
522 result = true;
523 }
524 matchingSkills1.RemoveEvent(eventName1);
525 matchingSkills2.RemoveEvent(eventName2);
526 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
527 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
528 }
529 if (result && stLevel_.CESLevel >= 1) {
530 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1100 stress level: " << stLevel_.CESLevel;
531 }
532 EXPECT_TRUE(result);
533 }
534
535 /*
536 * @tc.number: CES_SubscriptionEvent_1200
537 * @tc.name: SubscribeCommonEvent
538 * @tc.desc: Verify the normal, number and empty input string
539 */
540 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1200, Function | MediumTest | Level2)
541 {
542 bool result = false;
543 std::string eventName1 = "TESTEVENT1";
544 std::string eventName2 = "1";
545 std::string eventName3 = "";
546 MatchingSkills matchingSkills1;
547 MatchingSkills matchingSkills2;
548 MatchingSkills matchingSkills3;
549 for (int i = 1; i <= stLevel_.CESLevel; i++) {
550 matchingSkills1.AddEvent(eventName1);
551 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
552 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
553 bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1);
554
555 matchingSkills2.AddEvent(eventName2);
556 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
557 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
558 bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2);
559
560 matchingSkills3.AddEvent(eventName3);
561 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
562 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
563 bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3);
564
565 if (!result1 || !result2 || !result3) {
566 result = false;
567 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1200 failed, frequency: " << i;
568 break;
569 } else {
570 result = true;
571 }
572 matchingSkills1.RemoveEvent(eventName1);
573 matchingSkills2.RemoveEvent(eventName2);
574 matchingSkills3.RemoveEvent(eventName3);
575 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
576 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
577 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
578 }
579 if (result && stLevel_.CESLevel >= 1) {
580 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1200 stress level: " << stLevel_.CESLevel;
581 }
582 EXPECT_TRUE(result);
583 }
584
585 /*
586 * @tc.number: CES_SubscriptionEvent_1300
587 * @tc.name: SubscribeCommonEvent
588 * @tc.desc: Verify the function when the input string is normal
589 */
590 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1300, Function | MediumTest | Level0)
591 {
592 bool result = false;
593 std::string eventName = "TESTEVENT_UNSUBSCRIBE";
594 MatchingSkills matchingSkills;
595 for (int i = 1; i <= stLevel_.CESLevel; i++) {
596 matchingSkills.AddEvent(eventName);
597 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
598 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
599 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
600 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
601 result = false;
602 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1300 failed, frequency: " << i;
603 break;
604 } else {
605 result = true;
606 }
607 matchingSkills.RemoveEvent(eventName);
608 }
609 if (result && stLevel_.CESLevel >= 1) {
610 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1300 stress level: " << stLevel_.CESLevel;
611 }
612 EXPECT_TRUE(result);
613 }
614
615 /*
616 * @tc.number: CES_SubscriptionEvent_1400
617 * @tc.name: UnSubscribeCommonEvent
618 * @tc.desc: Verify the function when the input string is number
619 */
620 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1400, Function | MediumTest | Level0)
621 {
622 bool result = false;
623 std::string eventName = "2";
624 MatchingSkills matchingSkills;
625 for (int i = 1; i <= stLevel_.CESLevel; i++) {
626 matchingSkills.AddEvent(eventName);
627 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
628 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
629 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
630 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
631 result = false;
632 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1400 failed, frequency: " << i;
633 break;
634 } else {
635 result = true;
636 }
637 matchingSkills.RemoveEvent(eventName);
638 }
639 if (result && stLevel_.CESLevel >= 1) {
640 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1400 stress level: " << stLevel_.CESLevel;
641 }
642 EXPECT_TRUE(result);
643 }
644
645 /*
646 * @tc.number: CCES_SubscriptionEvent_1500
647 * @tc.name: UnSubscribeCommonEvent
648 * @tc.desc: Verify the function when the input string is empty
649 */
650 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1500, Function | MediumTest | Level2)
651 {
652 bool result = false;
653 std::string eventName = "";
654 MatchingSkills matchingSkills;
655 for (int i = 1; i <= stLevel_.CESLevel; i++) {
656 matchingSkills.AddEvent(eventName);
657 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
658 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
659 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
660 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
661 result = false;
662 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1500 failed, frequency: " << i;
663 break;
664 } else {
665 result = true;
666 }
667 matchingSkills.RemoveEvent(eventName);
668 }
669 if (result && stLevel_.CESLevel >= 1) {
670 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1500 stress level: " << stLevel_.CESLevel;
671 }
672 EXPECT_TRUE(result);
673 }
674
675 /*
676 * @tc.number: CES_SubscriptionEvent_1600
677 * @tc.name: UnSubscribeCommonEvent
678 * @tc.desc: Verify the function when the input string is points
679 */
680 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1600, Function | MediumTest | Level2)
681 {
682 bool result = false;
683 std::string eventName = "..................";
684 MatchingSkills matchingSkills;
685 for (int i = 1; i <= stLevel_.CESLevel; i++) {
686 matchingSkills.AddEvent(eventName);
687 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
688 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
689 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
690 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
691 result = false;
692 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1600 failed, frequency: " << i;
693 break;
694 } else {
695 result = true;
696 }
697 matchingSkills.RemoveEvent(eventName);
698 }
699 if (result && stLevel_.CESLevel >= 1) {
700 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1600 stress level: " << stLevel_.CESLevel;
701 }
702 EXPECT_TRUE(result);
703 }
704
705 /*
706 * @tc.number: CES_SubscriptionEvent_1700
707 * @tc.name: SubscribeCommonEvent
708 * @tc.desc: Verify the function when the input string with \0
709 */
710 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1700, Function | MediumTest | Level2)
711 {
712 bool result = false;
713 std::string eventName = "HELLO\0\0\0WORLD";
714 MatchingSkills matchingSkills;
715 for (int i = 1; i <= stLevel_.CESLevel; i++) {
716 matchingSkills.AddEvent(eventName);
717 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
718 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
719 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
720 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
721 result = false;
722 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1700 failed, frequency: " << i;
723 break;
724 } else {
725 result = true;
726 }
727 matchingSkills.RemoveEvent(eventName);
728 }
729 if (result && stLevel_.CESLevel >= 1) {
730 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1700 stress level: " << stLevel_.CESLevel;
731 }
732 EXPECT_TRUE(result);
733 }
734
735 /*
736 * @tc.number: CES_SubscriptionEvent_1800
737 * @tc.name: UnSubscribeCommonEvent
738 * @tc.desc: Verify the normal input string three times
739 */
740 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1800, Function | MediumTest | Level0)
741 {
742 bool result = false;
743 std::string eventName1 = "TESTEVENT4";
744 std::string eventName2 = "TESTEVENT5";
745 std::string eventName3 = "TESTEVENT6";
746 MatchingSkills matchingSkills1;
747 MatchingSkills matchingSkills2;
748 MatchingSkills matchingSkills3;
749 for (int i = 1; i <= stLevel_.CESLevel; i++) {
750 bool result1 = false;
751 matchingSkills1.AddEvent(eventName1);
752 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
753 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
754 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) {
755 result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
756 }
757
758 bool result2 = false;
759 matchingSkills2.AddEvent(eventName2);
760 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
761 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
762 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) {
763 result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
764 }
765
766 bool result3 = false;
767 matchingSkills3.AddEvent(eventName3);
768 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
769 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
770 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) {
771 result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
772 }
773
774 if (!result1 || !result2 || !result3) {
775 result = false;
776 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1800 failed, frequency: " << i;
777 break;
778 } else {
779 result = true;
780 }
781 matchingSkills1.RemoveEvent(eventName1);
782 matchingSkills2.RemoveEvent(eventName2);
783 matchingSkills3.RemoveEvent(eventName3);
784 }
785 if (result && stLevel_.CESLevel >= 1) {
786 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1800 stress level: " << stLevel_.CESLevel;
787 }
788 EXPECT_TRUE(result);
789 }
790
791 /*
792 * @tc.number: CES_SubscriptionEvent_1900
793 * @tc.name: UnSubscribeCommonEvent
794 * @tc.desc: Verify the normal input string two times
795 */
796 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_1900, Function | MediumTest | Level0)
797 {
798 bool result = false;
799 std::string eventName1 = "TEST3";
800 std::string eventName2 = "TEST4";
801 MatchingSkills matchingSkills1;
802 MatchingSkills matchingSkills2;
803 for (int i = 1; i <= stLevel_.CESLevel; i++) {
804 bool result1 = false;
805 matchingSkills1.AddEvent(eventName1);
806 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
807 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
808 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) {
809 result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
810 }
811
812 bool result2 = false;
813 matchingSkills2.AddEvent(eventName2);
814 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
815 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
816 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) {
817 result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
818 }
819
820 if (!result1 || !result2) {
821 result = false;
822 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1900 failed, frequency: " << i;
823 break;
824 } else {
825 result = true;
826 }
827 matchingSkills1.RemoveEvent(eventName1);
828 matchingSkills2.RemoveEvent(eventName2);
829 }
830 if (result && stLevel_.CESLevel >= 1) {
831 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_1900 stress level: " << stLevel_.CESLevel;
832 }
833 EXPECT_TRUE(result);
834 }
835
836 /*
837 * @tc.number: CES_SubscriptionEvent_2000
838 * @tc.name: SubscribeCommonEvent
839 * @tc.desc: Verify the normal, number and empty input string
840 */
841 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_2000, Function | MediumTest | Level2)
842 {
843 bool result = false;
844 std::string eventName1 = "TESTEVENT7";
845 std::string eventName2 = "3";
846 std::string eventName3 = "";
847 MatchingSkills matchingSkills1;
848 MatchingSkills matchingSkills2;
849 MatchingSkills matchingSkills3;
850 for (int i = 1; i <= stLevel_.CESLevel; i++) {
851 bool result1 = false;
852 matchingSkills1.AddEvent(eventName1);
853 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
854 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
855 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) {
856 result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
857 }
858
859 bool result2 = false;
860 matchingSkills2.AddEvent(eventName2);
861 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
862 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
863 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) {
864 result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
865 }
866
867 bool result3 = false;
868 matchingSkills3.AddEvent(eventName3);
869 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
870 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
871 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) {
872 result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
873 }
874
875 if (!result1 || !result2 || !result3) {
876 result = false;
877 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_2000 failed, frequency: " << i;
878 break;
879 } else {
880 result = true;
881 }
882 matchingSkills1.RemoveEvent(eventName1);
883 matchingSkills2.RemoveEvent(eventName2);
884 matchingSkills3.RemoveEvent(eventName3);
885 }
886 if (result && stLevel_.CESLevel >= 1) {
887 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_2000 stress level: " << stLevel_.CESLevel;
888 }
889 EXPECT_TRUE(result);
890 }
891
892 /*
893 * @tc.number: CES_SubscriptionEvent_2100
894 * @tc.name: UnSubscribeCommonEvent
895 * @tc.desc: Verify the same input string three times
896 */
897 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_2100, Function | MediumTest | Level2)
898 {
899 bool result = false;
900 std::string eventName1 = "TESTEVENT4";
901 std::string eventName2 = "TESTEVENT4";
902 std::string eventName3 = "TESTEVENT4";
903 MatchingSkills matchingSkills1;
904 MatchingSkills matchingSkills2;
905 MatchingSkills matchingSkills3;
906 for (int i = 1; i <= stLevel_.CESLevel; i++) {
907 bool result1 = false;
908 matchingSkills1.AddEvent(eventName1);
909 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
910 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
911 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) {
912 result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
913 }
914
915 bool result2 = false;
916 matchingSkills2.AddEvent(eventName2);
917 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
918 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
919 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) {
920 result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
921 }
922
923 bool result3 = false;
924 matchingSkills3.AddEvent(eventName3);
925 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
926 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
927 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) {
928 result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
929 }
930
931 if (!result1 || !result2 || !result3) {
932 result = false;
933 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_2100 failed, frequency: " << i;
934 break;
935 } else {
936 result = true;
937 }
938 matchingSkills1.RemoveEvent(eventName1);
939 matchingSkills2.RemoveEvent(eventName2);
940 matchingSkills3.RemoveEvent(eventName3);
941 }
942 if (result && stLevel_.CESLevel >= 1) {
943 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_2100 stress level: " << stLevel_.CESLevel;
944 }
945 EXPECT_TRUE(result);
946 }
947
948 /*
949 * @tc.number: CES_SubscriptionEvent_2200
950 * @tc.name: UnSubscribeCommonEvent
951 * @tc.desc: Verify the same input empty string three time
952 */
953 HWTEST_F(ActsCESManagertest, CES_SubscriptionEvent_2200, Function | MediumTest | Level2)
954 {
955 bool result = false;
956 std::string eventName1 = "";
957 std::string eventName2 = "";
958 std::string eventName3 = "";
959 MatchingSkills matchingSkills1;
960 MatchingSkills matchingSkills2;
961 MatchingSkills matchingSkills3;
962 for (int i = 1; i <= stLevel_.CESLevel; i++) {
963 bool result1 = false;
964 matchingSkills1.AddEvent(eventName1);
965 CommonEventSubscribeInfo subscribeInfo1(matchingSkills1);
966 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo1);
967 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) {
968 result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
969 }
970
971 bool result2 = false;
972 matchingSkills2.AddEvent(eventName2);
973 CommonEventSubscribeInfo subscribeInfo2(matchingSkills2);
974 auto subscriberPtr2 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo2);
975 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) {
976 result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2);
977 }
978
979 bool result3 = false;
980 matchingSkills3.AddEvent(eventName3);
981 CommonEventSubscribeInfo subscribeInfo3(matchingSkills3);
982 auto subscriberPtr3 = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo3);
983 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) {
984 result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3);
985 }
986
987 if (!result1 || !result2 || !result3) {
988 result = false;
989 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_2200 failed, frequency: " << i;
990 break;
991 } else {
992 result = true;
993 }
994 matchingSkills1.RemoveEvent(eventName1);
995 matchingSkills2.RemoveEvent(eventName2);
996 matchingSkills3.RemoveEvent(eventName3);
997 }
998 if (result && stLevel_.CESLevel >= 1) {
999 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_2200 stress level: " << stLevel_.CESLevel;
1000 }
1001 EXPECT_TRUE(result);
1002 }
1003
1004 /*
1005 * @tc.number: CES_SendEvent_0100
1006 * @tc.name: PublishCommonEvent
1007 * @tc.desc: Verify the function when only set action
1008 */
1009 HWTEST_F(ActsCESManagertest, CES_SendEvent_0100, Function | MediumTest | Level0)
1010 {
1011 bool result = false;
1012 std::string eventName = "TESTEVENT_PUBLISH_ACTION";
1013 std::string eventAction = "TESTEVENT_PUBLISH_ACTION";
1014 MatchingSkills matchingSkills;
1015 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1016 matchingSkills.AddEvent(eventName);
1017 Want wantTest;
1018 wantTest.SetAction(eventAction);
1019 CommonEventData commonEventData(wantTest);
1020 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1021 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1022 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1023 if (!CommonEventManager::PublishCommonEvent(commonEventData)) {
1024 result = false;
1025 GTEST_LOG_(INFO) << "CES_SendEvent_0100 failed, frequency: " << i;
1026 break;
1027 } else {
1028 result = true;
1029 }
1030 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1031 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1032 matchingSkills.RemoveEvent(eventName);
1033 }
1034 if (result && stLevel_.CESLevel >= 1) {
1035 GTEST_LOG_(INFO) << "CES_SendEvent_0100 stress level: " << stLevel_.CESLevel;
1036 }
1037 EXPECT_TRUE(result);
1038 }
1039
1040 /*
1041 * @tc.number: CES_SendEvent_0200
1042 * @tc.name: PublishCommonEvent
1043 * @tc.desc: Verify the function when add entity
1044 */
1045 HWTEST_F(ActsCESManagertest, CES_SendEvent_0200, Function | MediumTest | Level0)
1046 {
1047 bool result = false;
1048 std::string eventName = "TESTEVENT_PUBLISH_ENTITY";
1049 std::string eventAction = "TESTEVENT_PUBLISH_ENTITY";
1050 std::string entity = "ADDENTITY";
1051 MatchingSkills matchingSkills;
1052 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1053 matchingSkills.AddEvent(eventName);
1054 Want wantTest;
1055 wantTest.SetAction(eventAction);
1056 wantTest.AddEntity(entity);
1057 CommonEventData commonEventData(wantTest);
1058 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1059 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1060 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1061 if (!CommonEventManager::PublishCommonEvent(commonEventData)) {
1062 result = false;
1063 GTEST_LOG_(INFO) << "CES_SendEvent_0200 failed, frequency: " << i;
1064 break;
1065 } else {
1066 result = true;
1067 }
1068 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1069 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1070 matchingSkills.RemoveEvent(eventName);
1071 }
1072 if (result && stLevel_.CESLevel >= 1) {
1073 GTEST_LOG_(INFO) << "CES_SendEvent_0200 stress level: " << stLevel_.CESLevel;
1074 }
1075 EXPECT_TRUE(result);
1076 }
1077
1078 /*
1079 * @tc.number: CES_SendEvent_0300
1080 * @tc.name: PublishCommonEvent
1081 * @tc.desc: Verify the function when set scheme
1082 */
1083 HWTEST_F(ActsCESManagertest, CES_SendEvent_0300, Function | MediumTest | Level0)
1084 {
1085 bool result = false;
1086 std::string eventName = "TESTEVENT_PUBLISH_SCHEME";
1087 std::string eventAction = "TESTEVENT_PUBLISH_SCHEME";
1088 std::string scheme = "SETSCHEME";
1089 MatchingSkills matchingSkills;
1090 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1091 matchingSkills.AddEvent(eventName);
1092 Want wantTest;
1093 wantTest.SetAction(eventAction);
1094 CommonEventData commonEventData(wantTest);
1095 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1096 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1097 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1098 if (!CommonEventManager::PublishCommonEvent(commonEventData)) {
1099 result = false;
1100 GTEST_LOG_(INFO) << "CES_SendEvent_0300 failed, frequency: " << i;
1101 break;
1102 } else {
1103 result = true;
1104 }
1105 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1106 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1107 matchingSkills.RemoveEvent(eventName);
1108 }
1109 if (result && stLevel_.CESLevel >= 1) {
1110 GTEST_LOG_(INFO) << "CES_SendEvent_0300 stress level: " << stLevel_.CESLevel;
1111 }
1112 EXPECT_TRUE(result);
1113 }
1114
1115 /*
1116 * @tc.number: CES_SendEvent_0400
1117 * @tc.name: PublishCommonEvent
1118 * @tc.desc: Verify the function when set scheme and add entity
1119 */
1120 HWTEST_F(ActsCESManagertest, CES_SendEvent_0400, Function | MediumTest | Level0)
1121 {
1122 bool result = false;
1123 std::string eventName = "TESTEVENT_PUBLISH_SCHEME_ENTITY";
1124 std::string eventAction = "TESTEVENT_PUBLISH_SCHEME_ENTITY";
1125 std::string scheme = "SETSCHEME";
1126 std::string entity = "ADDENTITY";
1127 MatchingSkills matchingSkills;
1128 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1129 matchingSkills.AddEvent(eventName);
1130 Want wantTest;
1131 wantTest.SetAction(eventAction);
1132 wantTest.AddEntity(entity);
1133 CommonEventData commonEventData(wantTest);
1134 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1135 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1136 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1137 if (!CommonEventManager::PublishCommonEvent(commonEventData)) {
1138 result = false;
1139 GTEST_LOG_(INFO) << "CES_SendEvent_0400 failed, frequency: " << i;
1140 break;
1141 } else {
1142 result = true;
1143 }
1144 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1145 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1146 matchingSkills.RemoveEvent(eventName);
1147 }
1148 if (result && stLevel_.CESLevel >= 1) {
1149 GTEST_LOG_(INFO) << "CES_SendEvent_0400 stress level: " << stLevel_.CESLevel;
1150 }
1151 EXPECT_TRUE(result);
1152 }
1153
1154 /*
1155 * @tc.number: CES_SendEvent_0500
1156 * @tc.name: PublishCommonEvent
1157 * @tc.desc: Verify set action with sticky is false
1158 */
1159 HWTEST_F(ActsCESManagertest, CES_SendEvent_0500, Function | MediumTest | Level0)
1160 {
1161 bool result = false;
1162 std::string eventName = "TESTEVENT_PUBLISH_ACTION_INFO_FALSE";
1163 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_INFO_FALSE";
1164 MatchingSkills matchingSkills;
1165 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1166 bool stickty = false;
1167 matchingSkills.AddEvent(eventName);
1168 Want wantTest;
1169 wantTest.SetAction(eventAction);
1170 CommonEventData commonEventData(wantTest);
1171 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1172 CommonEventPublishInfo publishInfo;
1173 publishInfo.SetSticky(stickty);
1174 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1175 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1176 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1177 result = false;
1178 GTEST_LOG_(INFO) << "CES_SendEvent_0500 failed, frequency: " << i;
1179 break;
1180 } else {
1181 result = true;
1182 }
1183 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1184 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1185 matchingSkills.RemoveEvent(eventName);
1186 }
1187 if (result && stLevel_.CESLevel >= 1) {
1188 GTEST_LOG_(INFO) << "CES_SendEvent_0500 stress level: " << stLevel_.CESLevel;
1189 }
1190 EXPECT_TRUE(result);
1191 }
1192
1193 /*
1194 * @tc.number: CES_SendEvent_0600
1195 * @tc.name: PublishCommonEvent
1196 * @tc.desc: Verify add entity with sticky is true
1197 */
1198 HWTEST_F(ActsCESManagertest, CES_SendEvent_0600, Function | MediumTest | Level0)
1199 {
1200 bool result = false;
1201 std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_TRUE";
1202 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_TRUE";
1203 MatchingSkills matchingSkills;
1204 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1205 std::string entity = "ADDENTITY";
1206 bool stickty = true;
1207 matchingSkills.AddEvent(eventName);
1208 Want wantTest;
1209 wantTest.SetAction(eventAction);
1210 wantTest.AddEntity(entity);
1211 CommonEventData commonEventData(wantTest);
1212 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1213 CommonEventPublishInfo publishInfo;
1214 publishInfo.SetSticky(stickty);
1215 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1216 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1217 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1218 result = false;
1219 GTEST_LOG_(INFO) << "CES_SendEvent_0600 failed, frequency: " << i;
1220 break;
1221 } else {
1222 result = true;
1223 }
1224 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1225 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1226 matchingSkills.RemoveEvent(eventName);
1227 }
1228 if (result && stLevel_.CESLevel >= 1) {
1229 GTEST_LOG_(INFO) << "CES_SendEvent_0600 stress level: " << stLevel_.CESLevel;
1230 }
1231 EXPECT_TRUE(result);
1232 }
1233
1234 /*
1235 * @tc.number: CES_SendEvent_0700
1236 * @tc.name: PublishCommonEvent
1237 * @tc.desc: Verify add entity with sticky is false
1238 */
1239 HWTEST_F(ActsCESManagertest, CES_SendEvent_0700, Function | MediumTest | Level0)
1240 {
1241 bool result = false;
1242 std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_FALSE";
1243 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_FALSE";
1244 std::string entity = "ADDENTITY";
1245 MatchingSkills matchingSkills;
1246 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1247 bool stickty = false;
1248 matchingSkills.AddEvent(eventName);
1249 Want wantTest;
1250 wantTest.SetAction(eventAction);
1251 wantTest.AddEntity(entity);
1252 CommonEventData commonEventData(wantTest);
1253 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1254 CommonEventPublishInfo publishInfo;
1255 publishInfo.SetSticky(stickty);
1256 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1257 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1258 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1259 result = false;
1260 GTEST_LOG_(INFO) << "CES_SendEvent_0700 failed, frequency: " << i;
1261 break;
1262 } else {
1263 result = true;
1264 }
1265 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1266 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1267 matchingSkills.RemoveEvent(eventName);
1268 }
1269 if (result && stLevel_.CESLevel >= 1) {
1270 GTEST_LOG_(INFO) << "CES_SendEvent_0700 stress level: " << stLevel_.CESLevel;
1271 }
1272 EXPECT_TRUE(result);
1273 }
1274
1275 /*
1276 * @tc.number: CES_SendEvent_0800
1277 * @tc.name: PublishCommonEvent
1278 * @tc.desc: Verify set action with sticky is true
1279 */
1280 HWTEST_F(ActsCESManagertest, CES_SendEvent_0800, Function | MediumTest | Level0)
1281 {
1282 bool result = false;
1283 std::string eventName = "TESTEVENT_PUBLISH_ACTION_INFO_TRUE";
1284 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_INFO_TRUE";
1285 MatchingSkills matchingSkills;
1286 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1287 bool stickty = true;
1288 matchingSkills.AddEvent(eventName);
1289 Want wantTest;
1290 wantTest.SetAction(eventAction);
1291 CommonEventData commonEventData(wantTest);
1292 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1293 CommonEventPublishInfo publishInfo;
1294 publishInfo.SetSticky(stickty);
1295 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1296 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1297 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1298 result = false;
1299 GTEST_LOG_(INFO) << "CES_SendEvent_0800 failed, frequency: " << i;
1300 break;
1301 } else {
1302 result = true;
1303 }
1304 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1305 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1306 matchingSkills.RemoveEvent(eventName);
1307 }
1308 if (result && stLevel_.CESLevel >= 1) {
1309 GTEST_LOG_(INFO) << "CES_SendEvent_0800 stress level: " << stLevel_.CESLevel;
1310 }
1311 EXPECT_TRUE(result);
1312 }
1313
1314 /*
1315 * @tc.number: CES_SendEvent_0900
1316 * @tc.name: PublishCommonEvent
1317 * @tc.desc: Verify set scheme with sticky is true
1318 */
1319 HWTEST_F(ActsCESManagertest, CES_SendEvent_0900, Function | MediumTest | Level0)
1320 {
1321 bool result = false;
1322 std::string eventName = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_TRUE";
1323 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_TRUE";
1324 MatchingSkills matchingSkills;
1325 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1326 std::string scheme = "SETSCHEME";
1327 bool stickty = true;
1328 matchingSkills.AddEvent(eventName);
1329 Want wantTest;
1330 wantTest.SetAction(eventAction);
1331 CommonEventData commonEventData(wantTest);
1332 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1333 CommonEventPublishInfo publishInfo;
1334 publishInfo.SetSticky(stickty);
1335 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1336 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1337 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1338 result = false;
1339 GTEST_LOG_(INFO) << "CES_SendEvent_0900 failed, frequency: " << i;
1340 break;
1341 } else {
1342 result = true;
1343 }
1344 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1345 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1346 matchingSkills.RemoveEvent(eventName);
1347 }
1348 if (result && stLevel_.CESLevel >= 1) {
1349 GTEST_LOG_(INFO) << "CES_SendEvent_0900 stress level: " << stLevel_.CESLevel;
1350 }
1351 EXPECT_TRUE(result);
1352 }
1353
1354 /*
1355 * @tc.number: CES_SendEvent_1000
1356 * @tc.name: SPublishCommonEvent
1357 * @tc.desc: Verify set scheme with sticky is false
1358 */
1359 HWTEST_F(ActsCESManagertest, CES_SendEvent_1000, Function | MediumTest | Level0)
1360 {
1361 bool result = false;
1362 std::string eventName = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_FALSE";
1363 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_FALSE";
1364 std::string scheme = "SETSCHEME";
1365 MatchingSkills matchingSkills;
1366 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1367 bool stickty = false;
1368 matchingSkills.AddEvent(eventName);
1369 Want wantTest;
1370 wantTest.SetAction(eventAction);
1371 CommonEventData commonEventData(wantTest);
1372 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1373 CommonEventPublishInfo publishInfo;
1374 publishInfo.SetSticky(stickty);
1375 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1376 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1377 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1378 result = false;
1379 GTEST_LOG_(INFO) << "CES_SendEvent_1000 failed, frequency: " << i;
1380 break;
1381 } else {
1382 result = true;
1383 }
1384 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1385 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1386 matchingSkills.RemoveEvent(eventName);
1387 }
1388 if (result && stLevel_.CESLevel >= 1) {
1389 GTEST_LOG_(INFO) << "CES_SendEvent_1000 stress level: " << stLevel_.CESLevel;
1390 }
1391 EXPECT_TRUE(result);
1392 }
1393
1394 /*
1395 * @tc.number: CES_SendEvent_1100
1396 * @tc.name: PublishCommonEvent
1397 * @tc.desc: VVerify set scheme and add entity with sticky is true
1398 */
1399 HWTEST_F(ActsCESManagertest, CES_SendEvent_1100, Function | MediumTest | Level0)
1400 {
1401 bool result = false;
1402 std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_TRUE";
1403 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_TRUE";
1404 std::string entity = "ADDENTITY";
1405 std::string scheme = "SETSCHEME";
1406 MatchingSkills matchingSkills;
1407 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1408 bool stickty = true;
1409 matchingSkills.AddEvent(eventName);
1410 Want wantTest;
1411 wantTest.SetAction(eventAction);
1412 wantTest.AddEntity(entity);
1413 CommonEventData commonEventData(wantTest);
1414 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1415 CommonEventPublishInfo publishInfo;
1416 publishInfo.SetSticky(stickty);
1417 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1418 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1419 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1420 result = false;
1421 GTEST_LOG_(INFO) << "CES_SendEvent_1100 failed, frequency: " << i;
1422 break;
1423 } else {
1424 result = true;
1425 }
1426 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1427 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1428 matchingSkills.RemoveEvent(eventName);
1429 }
1430 if (result && stLevel_.CESLevel >= 1) {
1431 GTEST_LOG_(INFO) << "CES_SendEvent_1100 stress level: " << stLevel_.CESLevel;
1432 }
1433 EXPECT_TRUE(result);
1434 }
1435
1436 /*
1437 * @tc.number: CES_SendEvent_1200
1438 * @tc.name: PublishCommonEvent
1439 * @tc.desc: Verify set scheme and add entity with sticky is false
1440 */
1441 HWTEST_F(ActsCESManagertest, CES_SendEvent_1200, Function | MediumTest | Level0)
1442 {
1443 bool result = false;
1444 std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_FALSE";
1445 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_FALSE";
1446 std::string entity = "ADDENTITY";
1447 std::string scheme = "SETSCHEME";
1448 MatchingSkills matchingSkills;
1449 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1450 bool stickty = false;
1451 matchingSkills.AddEvent(eventName);
1452 Want wantTest;
1453 wantTest.SetAction(eventAction);
1454 wantTest.AddEntity(entity);
1455 CommonEventData commonEventData(wantTest);
1456 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1457 CommonEventPublishInfo publishInfo;
1458 publishInfo.SetSticky(stickty);
1459 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1460 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1461 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1462 result = false;
1463 GTEST_LOG_(INFO) << "CES_SendEvent_1200 failed, frequency: " << i;
1464 break;
1465 } else {
1466 result = true;
1467 }
1468 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1469 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1470 matchingSkills.RemoveEvent(eventName);
1471 }
1472 if (result && stLevel_.CESLevel >= 1) {
1473 GTEST_LOG_(INFO) << "CES_SendEvent_1200 stress level: " << stLevel_.CESLevel;
1474 }
1475 EXPECT_TRUE(result);
1476 }
1477
1478 /*
1479 * @tc.number: CES_SendEventSetViscosity_0100
1480 * @tc.name: SetSticky
1481 * @tc.desc: Verify set action with sticky is false
1482 */
1483 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0100, Function | MediumTest | Level0)
1484 {
1485 bool result = false;
1486 std::string eventName = "TESTEVENT_STICHY_ACTION_INFO_FALSE";
1487 std::string eventAction = "TESTEVENT_STICHY_ACTION_INFO_FALSE";
1488 MatchingSkills matchingSkills;
1489 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1490 bool stickty = false;
1491 matchingSkills.AddEvent(eventName);
1492 Want wantTest;
1493 wantTest.SetAction(eventAction);
1494 CommonEventData commonEventData(wantTest);
1495 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1496 CommonEventPublishInfo publishInfo;
1497 publishInfo.SetSticky(stickty);
1498 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1499 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1500 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1501 result = false;
1502 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0100 failed, frequency: " << i;
1503 break;
1504 } else {
1505 result = true;
1506 }
1507 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1508 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1509 matchingSkills.RemoveEvent(eventName);
1510 }
1511 if (result && stLevel_.CESLevel >= 1) {
1512 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0100 stress level: " << stLevel_.CESLevel;
1513 }
1514 EXPECT_TRUE(result);
1515 }
1516
1517 /*
1518 * @tc.number: CES_SendEventSetViscosity_0200
1519 * @tc.name: SetSticky
1520 * @tc.desc: Verify add entity with sticky is true
1521 */
1522 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0200, Function | MediumTest | Level0)
1523 {
1524 bool result = false;
1525 std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_TRUE";
1526 std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_TRUE";
1527 std::string entity = "ADDENTITY";
1528 MatchingSkills matchingSkills;
1529 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1530 bool stickty = true;
1531 matchingSkills.AddEvent(eventName);
1532 Want wantTest;
1533 wantTest.SetAction(eventAction);
1534 wantTest.AddEntity(entity);
1535 CommonEventData commonEventData(wantTest);
1536 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1537 CommonEventPublishInfo publishInfo;
1538 publishInfo.SetSticky(stickty);
1539 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1540 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1541 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1542 result = false;
1543 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0200 failed, frequency: " << i;
1544 break;
1545 } else {
1546 result = true;
1547 }
1548 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1549 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1550 matchingSkills.RemoveEvent(eventName);
1551 }
1552 if (result && stLevel_.CESLevel >= 1) {
1553 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0200 stress level: " << stLevel_.CESLevel;
1554 }
1555 EXPECT_TRUE(result);
1556 }
1557
1558 /*
1559 * @tc.number: CES_SendEventSetViscosity_0300
1560 * @tc.name: SetSticky
1561 * @tc.desc: Verify add entity with sticky is false
1562 */
1563 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0300, Function | MediumTest | Level0)
1564 {
1565 bool result = false;
1566 std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_FALSE";
1567 std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_FALSE";
1568 std::string entity = "ADDENTITY";
1569 MatchingSkills matchingSkills;
1570 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1571 bool stickty = false;
1572 matchingSkills.AddEvent(eventName);
1573 Want wantTest;
1574 wantTest.SetAction(eventAction);
1575 wantTest.AddEntity(entity);
1576 CommonEventData commonEventData(wantTest);
1577 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1578 CommonEventPublishInfo publishInfo;
1579 publishInfo.SetSticky(stickty);
1580 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1581 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1582 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1583 result = false;
1584 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0300 failed, frequency: " << i;
1585 break;
1586 } else {
1587 result = true;
1588 }
1589 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1590 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1591 matchingSkills.RemoveEvent(eventName);
1592 }
1593 if (result && stLevel_.CESLevel >= 1) {
1594 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0300 stress level: " << stLevel_.CESLevel;
1595 }
1596 EXPECT_TRUE(result);
1597 }
1598
1599 /*
1600 * @tc.number: CES_SendEventSetViscosity_0400
1601 * @tc.name: SetSticky
1602 * @tc.desc: Verify set action with sticky is true
1603 */
1604 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0400, Function | MediumTest | Level0)
1605 {
1606 bool result = false;
1607 std::string eventName = "TESTEVENT_STICKY_ACTION_INFO_TRUE";
1608 std::string eventAction = "TESTEVENT_STICKY_ACTION_INFO_TRUE";
1609 MatchingSkills matchingSkills;
1610 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1611 bool stickty = true;
1612 matchingSkills.AddEvent(eventName);
1613 Want wantTest;
1614 wantTest.SetAction(eventAction);
1615 CommonEventData commonEventData(wantTest);
1616 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1617 CommonEventPublishInfo publishInfo;
1618 publishInfo.SetSticky(stickty);
1619 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1620 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1621 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1622 result = false;
1623 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0400 failed, frequency: " << i;
1624 break;
1625 } else {
1626 result = true;
1627 }
1628 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1629 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1630 matchingSkills.RemoveEvent(eventName);
1631 }
1632 if (result && stLevel_.CESLevel >= 1) {
1633 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0400 stress level: " << stLevel_.CESLevel;
1634 }
1635 EXPECT_TRUE(result);
1636 }
1637
1638 /*
1639 * @tc.number: CCES_SendEventSetViscosity_0500
1640 * @tc.name: SetSticky
1641 * @tc.desc: Verify set scheme with sticky is true
1642 */
1643 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0500, Function | MediumTest | Level0)
1644 {
1645 bool result = false;
1646 std::string eventName = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_TRUE";
1647 std::string eventAction = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_TRUE";
1648 std::string scheme = "SETSCHEME";
1649 MatchingSkills matchingSkills;
1650 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1651 bool stickty = true;
1652 matchingSkills.AddEvent(eventName);
1653 Want wantTest;
1654 wantTest.SetAction(eventAction);
1655 CommonEventData commonEventData(wantTest);
1656 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1657 CommonEventPublishInfo publishInfo;
1658 publishInfo.SetSticky(stickty);
1659 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1660 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1661 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1662 result = false;
1663 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0500 failed, frequency: " << i;
1664 break;
1665 } else {
1666 result = true;
1667 }
1668 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1669 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1670 matchingSkills.RemoveEvent(eventName);
1671 }
1672 if (result && stLevel_.CESLevel >= 1) {
1673 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0500 stress level: " << stLevel_.CESLevel;
1674 }
1675 EXPECT_TRUE(result);
1676 }
1677
1678 /*
1679 * @tc.number: CES_SendEventSetViscosity_0600
1680 * @tc.name: SetSticky
1681 * @tc.desc: Verify set scheme with sticky is false
1682 */
1683 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0600, Function | MediumTest | Level0)
1684 {
1685 bool result = false;
1686 std::string eventName = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_FALSE";
1687 std::string eventAction = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_FALSE";
1688 std::string scheme = "SETSCHEME";
1689 MatchingSkills matchingSkills;
1690 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1691 bool stickty = false;
1692 matchingSkills.AddEvent(eventName);
1693 Want wantTest;
1694 wantTest.SetAction(eventAction);
1695 CommonEventData commonEventData(wantTest);
1696 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1697 CommonEventPublishInfo publishInfo;
1698 publishInfo.SetSticky(stickty);
1699 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1700 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1701 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1702 result = false;
1703 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0600 failed, frequency: " << i;
1704 break;
1705 } else {
1706 result = true;
1707 }
1708 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1709 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1710 matchingSkills.RemoveEvent(eventName);
1711 }
1712 if (result && stLevel_.CESLevel >= 1) {
1713 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0600 stress level: " << stLevel_.CESLevel;
1714 }
1715 EXPECT_TRUE(result);
1716 }
1717
1718 /*
1719 * @tc.number: CES_SendEventSetViscosity_0700
1720 * @tc.name: SetSticky
1721 * @tc.desc: Verify set scheme and add entity with sticky is true
1722 */
1723 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0700, Function | MediumTest | Level0)
1724 {
1725 bool result = false;
1726 std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_TRUE";
1727 std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_TRUE";
1728 std::string entity = "ADDENTITY";
1729 std::string scheme = "SETSCHEME";
1730 MatchingSkills matchingSkills;
1731 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1732 bool stickty = true;
1733 matchingSkills.AddEvent(eventName);
1734 Want wantTest;
1735 wantTest.SetAction(eventAction);
1736 wantTest.AddEntity(entity);
1737 CommonEventData commonEventData(wantTest);
1738 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1739 CommonEventPublishInfo publishInfo;
1740 publishInfo.SetSticky(stickty);
1741 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1742 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1743 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1744 result = false;
1745 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0700 failed, frequency: " << i;
1746 break;
1747 } else {
1748 result = true;
1749 }
1750 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1751 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1752 matchingSkills.RemoveEvent(eventName);
1753 }
1754 if (result && stLevel_.CESLevel >= 1) {
1755 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0700 stress level: " << stLevel_.CESLevel;
1756 }
1757 EXPECT_TRUE(result);
1758 }
1759
1760 /*
1761 * @tc.number: CES_SendEventSetViscosity_0800
1762 * @tc.name: SetSticky
1763 * @tc.desc: Verify set scheme and add entity with sticky is false
1764 */
1765 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0800, Function | MediumTest | Level0)
1766 {
1767 bool result = false;
1768 std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_FALSE";
1769 std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_FALSE";
1770 std::string entity = "ADDENTITY";
1771 std::string scheme = "SETSCHEME";
1772 MatchingSkills matchingSkills;
1773 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1774 bool stickty = false;
1775 matchingSkills.AddEvent(eventName);
1776 Want wantTest;
1777 wantTest.SetAction(eventAction);
1778 wantTest.AddEntity(entity);
1779 CommonEventData commonEventData(wantTest);
1780 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1781 CommonEventPublishInfo publishInfo;
1782 publishInfo.SetSticky(stickty);
1783 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1784 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
1785 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1786 result = false;
1787 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0800 failed, frequency: " << i;
1788 break;
1789 } else {
1790 result = true;
1791 }
1792 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1793 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1794 matchingSkills.RemoveEvent(eventName);
1795 }
1796 if (result && stLevel_.CESLevel >= 1) {
1797 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0800 stress level: " << stLevel_.CESLevel;
1798 }
1799 EXPECT_TRUE(result);
1800 }
1801
1802 /*
1803 * @tc.number: CES_SendEventSetViscosity_0900
1804 * @tc.name: GetStickyCommonEvent
1805 * @tc.desc: publish common event set sticky to true and verify the action of stickyData
1806 */
1807 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_0900, Function | MediumTest | Level0)
1808 {
1809 bool result = false;
1810 std::string eventName = "TESTEVENT_GETSTICKY_";
1811 std::string eventAction = "TESTEVENT_GETSTICKY_";
1812 std::string eventActionStr = "TESTEVENT_GETSTICKY_Str";
1813 MatchingSkills matchingSkills;
1814 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1815 bool stickty = true;
1816 matchingSkills.AddEvent(eventName);
1817 Want wantTest;
1818 wantTest.SetAction(eventAction);
1819 CommonEventData commonEventData(wantTest);
1820 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1821 CommonEventPublishInfo publishInfo;
1822 publishInfo.SetSticky(stickty);
1823 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1824 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
1825 CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1826 result = true;
1827 }
1828 EXPECT_TRUE(result);
1829 result = false;
1830 CommonEventData stickyData;
1831 CommonEventManager::GetStickyCommonEvent(eventAction, stickyData);
1832 if (eventActionStr == stickyData.GetWant().GetAction()) {
1833 result = false;
1834 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0900 failed, frequency: " << i;
1835 break;
1836 } else {
1837 result = true;
1838 }
1839 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1840 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1841 matchingSkills.RemoveEvent(eventName);
1842 }
1843 if (result && stLevel_.CESLevel >= 1) {
1844 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_0900 stress level: " << stLevel_.CESLevel;
1845 }
1846 EXPECT_TRUE(result);
1847 }
1848
1849 /*
1850 * @tc.number: CES_SendEventSetViscosity_1000
1851 * @tc.name: GetStickyCommonEvent
1852 * @tc.desc: publish common event set sticky to true and verify the action of stickyData
1853 */
1854 HWTEST_F(ActsCESManagertest, CES_SendEventSetViscosity_1000, Function | MediumTest | Level2)
1855 {
1856 bool result = false;
1857 std::string eventName = "TESTEVENT_GETSTICKY_FALSE";
1858 std::string eventAction = "TESTEVENT_GETSTICKY_FALSE";
1859 std::string actionTest = "CHECKTESTACTION";
1860 MatchingSkills matchingSkills;
1861 for (int i = 1; i <= stLevel_.CESLevel; i++) {
1862 bool stickty = true;
1863 matchingSkills.AddEvent(eventName);
1864 Want wantTest;
1865 wantTest.SetAction(eventAction);
1866 CommonEventData commonEventData(wantTest);
1867 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1868 CommonEventPublishInfo publishInfo;
1869 publishInfo.SetSticky(stickty);
1870 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1871 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
1872 CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
1873 result = true;
1874 }
1875 EXPECT_TRUE(result);
1876 result = false;
1877 CommonEventData stickyData;
1878 if (CommonEventManager::GetStickyCommonEvent(actionTest, stickyData)) {
1879 result = false;
1880 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_1000 failed, frequency: " << i;
1881 break;
1882 } else {
1883 result = true;
1884 }
1885 std::this_thread::sleep_for(std::chrono::milliseconds(100));
1886 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1887 matchingSkills.RemoveEvent(eventName);
1888 }
1889 if (result && stLevel_.CESLevel >= 1) {
1890 GTEST_LOG_(INFO) << "CES_SendEventSetViscosity_1000 stress level: " << stLevel_.CESLevel;
1891 }
1892 EXPECT_FALSE(result);
1893 }
1894
1895 /*
1896 * @tc.number: CES_ReceiveEvent_0100
1897 * @tc.name: OnReceiveEvent
1898 * @tc.desc: Verify the function when only set action
1899 */
1900 HWTEST_F(ActsCESManagertest, CES_ReceiveEvent_0100, Function | MediumTest | Level0)
1901 {
1902 std::string eventName = "TESTEVENT_RECEIVE_ACTION";
1903 std::string eventAction = "TESTEVENT_RECEIVE_ACTION";
1904 MatchingSkills matchingSkills;
1905 matchingSkills.AddEvent(eventName);
1906 Want wantTest;
1907 wantTest.SetAction(eventAction);
1908 CommonEventData commonEventData(wantTest);
1909 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1910 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1911 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
1912 (CommonEventManager::PublishCommonEvent(commonEventData))) {
1913 g_mtx.lock();
1914 }
1915 struct tm startTime = {0};
1916 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
1917 struct tm doingTime = {0};
1918 int64_t seconds = 0;
1919 while (!g_mtx.try_lock()) {
1920 // get current time and compare it with the start time
1921 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
1922 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
1923 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
1924 break;
1925 }
1926 }
1927 // expect the subscriber could receive the event within 5 seconds.
1928 EXPECT_LE(seconds, g_TIME_OUT_SECONDS_LIMIT);
1929 g_mtx.unlock();
1930 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1931 }
1932
1933 /*
1934 * @tc.number: CES_ReceiveEvent_0200
1935 * @tc.name: OnReceiveEvent
1936 * @tc.desc: Verify the function when add entity
1937 */
1938 HWTEST_F(ActsCESManagertest, CES_ReceiveEvent_0200, Function | MediumTest | Level0)
1939 {
1940 std::string eventName = "TESTEVENT_RECEIVE_ENTITY";
1941 std::string eventAction = "TESTEVENT_RECEIVE_ENTITY";
1942 std::string entity = "ADDENTITY";
1943 bool result = true;
1944 MatchingSkills matchingSkills;
1945 matchingSkills.AddEvent(eventName);
1946 Want wantTest;
1947 wantTest.SetAction(eventAction);
1948 wantTest.AddEntity(entity);
1949 CommonEventData commonEventData(wantTest);
1950 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1951 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1952 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
1953 (CommonEventManager::PublishCommonEvent(commonEventData))) {
1954 g_mtx.lock();
1955 }
1956 struct tm startTime = {0};
1957 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
1958 struct tm doingTime = {0};
1959 int64_t seconds = 0;
1960 while (!g_mtx.try_lock()) {
1961 // get current time and compare it with the start time
1962 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
1963 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
1964 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
1965 result = false;
1966 break;
1967 }
1968 }
1969 // The publisher sets the Entity, the receiver must set it, otherwise the receiver will not receive the information
1970 EXPECT_FALSE(result);
1971 g_mtx.unlock();
1972 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
1973 }
1974
1975 /*
1976 * @tc.number: CES_ReceiveEvent_0300
1977 * @tc.name: OnReceiveEvent
1978 * @tc.desc: Verify set action with sticky is false
1979 */
1980 HWTEST_F(ActsCESManagertest, CES_ReceiveEvent_0300, Function | MediumTest | Level0)
1981 {
1982 std::string eventName = "TESTEVENT_RECEIVE_ACTION_INFO_FALSE";
1983 std::string eventAction = "TESTEVENT_RECEIVE_ACTION_INFO_FALSE";
1984 bool stickty = false;
1985 MatchingSkills matchingSkills;
1986 matchingSkills.AddEvent(eventName);
1987 Want wantTest;
1988 wantTest.SetAction(eventAction);
1989 CommonEventData commonEventData(wantTest);
1990 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
1991 CommonEventPublishInfo publishInfo;
1992 publishInfo.SetSticky(stickty);
1993 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
1994 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
1995 (CommonEventManager::PublishCommonEvent(commonEventData, publishInfo))) {
1996 g_mtx.lock();
1997 }
1998 struct tm startTime = {0};
1999 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2000 struct tm doingTime = {0};
2001 int64_t seconds = 0;
2002 while (!g_mtx.try_lock()) {
2003 // get current time and compare it with the start time
2004 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2005 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2006 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
2007 break;
2008 }
2009 }
2010 // expect the subscriber could receive the event within 5 seconds.
2011 EXPECT_LE(seconds, g_TIME_OUT_SECONDS_LIMIT);
2012 g_mtx.unlock();
2013 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2014 }
2015
2016 /*
2017 * @tc.number: CES_ReceiveEvent_0400
2018 * @tc.name: OnReceiveEvent
2019 * @tc.desc: Verify set action with sticky is true
2020 */
2021 HWTEST_F(ActsCESManagertest, CES_ReceiveEvent_0400, Function | MediumTest | Level0)
2022 {
2023 std::string eventName = "TESTEVENT_RECEIVE_ACTION_INFO_TRUE";
2024 std::string eventAction = "TESTEVENT_RECEIVE_ACTION_INFO_TRUE";
2025 bool stickty = true;
2026 bool result = true;
2027 MatchingSkills matchingSkills;
2028 matchingSkills.AddEvent(eventName);
2029 Want wantTest;
2030 wantTest.SetAction(eventAction);
2031 CommonEventData commonEventData(wantTest);
2032 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2033 CommonEventPublishInfo publishInfo;
2034 publishInfo.SetSticky(stickty);
2035 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2036 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
2037 (CommonEventManager::PublishCommonEvent(commonEventData, publishInfo))) {
2038 g_mtx.lock();
2039 }
2040 struct tm startTime = {0};
2041 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2042 struct tm doingTime = {0};
2043 int64_t seconds = 0;
2044 while (!g_mtx.try_lock()) {
2045 // get current time and compare it with the start time
2046 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2047 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2048 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
2049 result = false;
2050 break;
2051 }
2052 }
2053 // expect the subscriber could receive the event within 5 seconds.
2054 EXPECT_FALSE(result); // not system app
2055 g_mtx.unlock();
2056 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2057 }
2058
2059 /*
2060 * @tc.number: CES_ReceiveEvent_0500
2061 * @tc.name: OnReceiveEvent
2062 * @tc.desc: Verify add entity with sticky is false
2063 */
2064 HWTEST_F(ActsCESManagertest, CES_ReceiveEvent_0500, Function | MediumTest | Level0)
2065 {
2066 std::string eventName = "TESTEVENT_RECEIVE_ENTITY_INFO_FALSE";
2067 std::string eventAction = "TESTEVENT_RECEIVE_ENTITY_INFO_FALSE";
2068 std::string entity = "ADDENTITY";
2069 bool result = true;
2070 bool stickty = false;
2071 MatchingSkills matchingSkills;
2072 matchingSkills.AddEvent(eventName);
2073 Want wantTest;
2074 wantTest.SetAction(eventAction);
2075 wantTest.AddEntity(entity);
2076 CommonEventData commonEventData(wantTest);
2077 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2078 CommonEventPublishInfo publishInfo;
2079 publishInfo.SetSticky(stickty);
2080 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2081 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
2082 (CommonEventManager::PublishCommonEvent(commonEventData, publishInfo))) {
2083 g_mtx.lock();
2084 }
2085 struct tm startTime = {0};
2086 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2087 struct tm doingTime = {0};
2088 int64_t seconds = 0;
2089 while (!g_mtx.try_lock()) {
2090 // get current time and compare it with the start time
2091 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2092 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2093 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
2094 result = false;
2095 break;
2096 }
2097 }
2098 // The publisher sets the Entity, the receiver must set it, otherwise the receiver will not receive the information
2099 EXPECT_FALSE(result);
2100 g_mtx.unlock();
2101 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2102 }
2103
2104 /*
2105 * @tc.number: CES_ReceiveEvent_0600
2106 * @tc.name: OnReceiveEvent
2107 * @tc.desc: Verify add entity with sticky is true
2108 */
2109 HWTEST_F(ActsCESManagertest, CES_ReceiveEvent_0600, Function | MediumTest | Level0)
2110 {
2111 std::string eventName = "ActsCESManagertestTestEventReceiveEntityInfoFalse";
2112 std::string eventAction = "ActsCESManagertestTestEventReceiveEntityInfoFalse";
2113 std::string entity = "addEntity";
2114 bool result = true;
2115 bool stickty = true;
2116 MatchingSkills matchingSkills;
2117 matchingSkills.AddEvent(eventName);
2118 Want wantTest;
2119 wantTest.SetAction(eventAction);
2120 wantTest.AddEntity(entity);
2121 CommonEventData commonEventData(wantTest);
2122 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2123 CommonEventPublishInfo publishInfo;
2124 publishInfo.SetSticky(stickty);
2125 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2126 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
2127 (CommonEventManager::PublishCommonEvent(commonEventData, publishInfo))) {
2128 g_mtx.lock();
2129 }
2130 struct tm startTime = {0};
2131 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2132 struct tm doingTime = {0};
2133 int64_t seconds = 0;
2134 while (!g_mtx.try_lock()) {
2135 // get current time and compare it with the start time
2136 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2137 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2138 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
2139 result = false;
2140 break;
2141 }
2142 }
2143 // The publisher sets the Entity, the receiver must set it, otherwise the receiver will not receive the information
2144 EXPECT_FALSE(result);
2145 g_mtx.unlock();
2146 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2147 }
2148
2149 /*
2150 * @tc.number: CES_SubscriptionEventTheme_0100
2151 * @tc.name: AddEvent
2152 * @tc.desc: Verify add an event Theme
2153 */
2154 HWTEST_F(ActsCESManagertest, CES_SubscriptionEventTheme_0100, Function | MediumTest | Level0)
2155 {
2156 bool result = false;
2157 std::string eventName = "TESTADDTHEME";
2158 MatchingSkills matchingSkills;
2159 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2160 matchingSkills.AddEvent(eventName);
2161 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2162 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2163 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2164 result = false;
2165 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0100 failed, frequency: " << i;
2166 break;
2167 } else {
2168 result = true;
2169 }
2170 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2171 matchingSkills.RemoveEvent(eventName);
2172 }
2173 if (result && stLevel_.CESLevel >= 1) {
2174 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0100 stress level: " << stLevel_.CESLevel;
2175 }
2176 EXPECT_TRUE(result);
2177 }
2178
2179 /*
2180 * @tc.number: CES_SubscriptionEventTheme_0200
2181 * @tc.name: AddEvent
2182 * @tc.desc: Verify add multiple event themes
2183 */
2184 HWTEST_F(ActsCESManagertest, CES_SubscriptionEventTheme_0200, Function | MediumTest | Level0)
2185 {
2186 bool result = false;
2187 std::string eventName1 = "TESTADDTHEME1";
2188 std::string eventName2 = "TESTADDTHEME2";
2189 MatchingSkills matchingSkills;
2190 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2191 matchingSkills.AddEvent(eventName1);
2192 matchingSkills.AddEvent(eventName2);
2193
2194 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2195 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2196 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2197 result = false;
2198 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0200 failed, frequency: " << i;
2199 break;
2200 } else {
2201 result = true;
2202 }
2203 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2204 matchingSkills.RemoveEvent(eventName1);
2205 matchingSkills.RemoveEvent(eventName2);
2206 }
2207 if (result && stLevel_.CESLevel >= 1) {
2208 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0200 stress level: " << stLevel_.CESLevel;
2209 }
2210 EXPECT_TRUE(result);
2211 }
2212
2213 /*
2214 * @tc.number: CES_SubscriptionEventTheme_0300
2215 * @tc.name: MatchEvent
2216 * @tc.desc: Verify match an event theme
2217 */
2218 HWTEST_F(ActsCESManagertest, CES_SubscriptionEventTheme_0300, Function | MediumTest | Level0)
2219 {
2220 bool result = false;
2221 std::string eventName = "TESTEVENT_MATCHEVENTTEST";
2222 MatchingSkills matchingSkills;
2223 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2224 Want wantTest;
2225 wantTest.SetAction(eventName);
2226 matchingSkills.AddEvent(eventName);
2227 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2228 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2229 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2230 if (!matchingSkills.Match(wantTest)) {
2231 result = false;
2232 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0300 failed, frequency: " << i;
2233 break;
2234 } else {
2235 result = true;
2236 }
2237 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2238 matchingSkills.RemoveEvent(eventName);
2239 }
2240 if (result && stLevel_.CESLevel >= 1) {
2241 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0300 stress level: " << stLevel_.CESLevel;
2242 }
2243 EXPECT_TRUE(result);
2244 }
2245
2246 /*
2247 * @tc.number: CES_SubscriptionEventTheme_0400
2248 * @tc.name: MatchEvent
2249 * @tc.desc: Verify match other event theme
2250 */
2251 HWTEST_F(ActsCESManagertest, CES_SubscriptionEventTheme_0400, Function | MediumTest | Level0)
2252 {
2253 bool result = true;
2254 std::string eventName = "TESTMATCHEVENTTOPICAL";
2255 std::string eventNameCompare = "TESTMATCHEVENTTOPICAL_COMPARE";
2256 MatchingSkills matchingSkills;
2257 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2258 Want wantTest;
2259 wantTest.SetAction(eventNameCompare);
2260 matchingSkills.AddEvent(eventName);
2261 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2262 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2263 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2264 if (matchingSkills.Match(wantTest)) {
2265 result = false;
2266 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0400 failed, frequency: " << i;
2267 break;
2268 } else {
2269 result = true;
2270 }
2271 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2272 matchingSkills.RemoveEvent(eventName);
2273 }
2274 if (result && stLevel_.CESLevel >= 1) {
2275 GTEST_LOG_(INFO) << "CES_SubscriptionEventTheme_0400 stress level: " << stLevel_.CESLevel;
2276 }
2277 EXPECT_TRUE(result);
2278 }
2279
2280 /*
2281 * @tc.number: CES_SendEvent_1300
2282 * @tc.name: PublishCommonEvent
2283 * @tc.desc: The publisher can send normally, but does not have permission
2284 * to send system events and cannot receive published system events
2285 * This test case has been covered in the module test, and the system test
2286 * cannot simulate the non-subsystem scenario
2287 */
2288 HWTEST_F(ActsCESManagertest, CES_SendEvent_1300, Function | MediumTest | Level0)
2289 {
2290 std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_ADDED;
2291 std::string eventAction = CommonEventSupport::COMMON_EVENT_ABILITY_ADDED;
2292 bool result = false;
2293 bool sysResult = false;
2294 MatchingSkills matchingSkills;
2295 matchingSkills.AddEvent(eventName);
2296 Want wantTest;
2297 wantTest.SetAction(eventAction);
2298 CommonEventData commonEventData(wantTest);
2299 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2300 CommonEventPublishInfo publishInfo;
2301 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2302 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2303 result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo);
2304 g_mtx.lock();
2305 }
2306 // The publisher can send normally, but does not have permission to send system events
2307 EXPECT_TRUE(result);
2308 struct tm startTime = {0};
2309 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2310 struct tm doingTime = {0};
2311 int64_t seconds = 0;
2312
2313 while (!g_mtx.try_lock()) {
2314 // get current time and compare it with the start time
2315 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2316 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2317 if (seconds >= g_TIME_OUT_SECONDS) {
2318 sysResult = true;
2319 break;
2320 }
2321 }
2322 // Unable to receive published system events, failed to send system events
2323 EXPECT_TRUE(true);
2324 g_mtx.unlock();
2325 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2326 }
2327
2328 /*
2329 * @tc.number: CES_SendEvent_1400
2330 * @tc.name: PublishCommonEvent
2331 * @tc.desc:The publisher can send normally, but does not have permission
2332 * to send system events and cannot receive published system events
2333 * This test case has been covered in the module test, and the system test
2334 * cannot simulate the non-subsystem scenario
2335 */
2336 HWTEST_F(ActsCESManagertest, CES_SendEvent_1400, Function | MediumTest | Level0)
2337 {
2338 std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_REMOVED;
2339 std::string eventAction = CommonEventSupport::COMMON_EVENT_ABILITY_REMOVED;
2340 bool result = false;
2341 bool sysResult = false;
2342 MatchingSkills matchingSkills;
2343 matchingSkills.AddEvent(eventName);
2344 Want wantTest;
2345 wantTest.SetAction(eventAction);
2346 CommonEventData commonEventData(wantTest);
2347 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2348 CommonEventPublishInfo publishInfo;
2349 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2350 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2351 result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo);
2352 g_mtx.lock();
2353 }
2354 // The publisher can send normally, but does not have permission to send system events
2355 EXPECT_TRUE(result);
2356 struct tm startTime = {0};
2357 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2358 struct tm doingTime = {0};
2359 int64_t seconds = 0;
2360
2361 while (!g_mtx.try_lock()) {
2362 // get current time and compare it with the start time
2363 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2364 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2365 if (seconds >= g_TIME_OUT_SECONDS) {
2366 sysResult = true;
2367 break;
2368 }
2369 }
2370 // Unable to receive published system events, failed to send system events
2371 EXPECT_TRUE(true);
2372 g_mtx.unlock();
2373 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2374 }
2375
2376 /*
2377 * @tc.number: CES_SendEvent_1500
2378 * @tc.name: PublishCommonEvent
2379 * @tc.desc:The publisher can send normally, but does not have permission
2380 * to send system events and cannot receive published system events
2381 * This test case has been covered in the module test, and the system test
2382 * cannot simulate the non-subsystem scenario
2383 */
2384 HWTEST_F(ActsCESManagertest, CES_SendEvent_1500, Function | MediumTest | Level0)
2385 {
2386 std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED;
2387 std::string eventAction = CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED;
2388 bool result = false;
2389 bool sysResult = false;
2390 MatchingSkills matchingSkills;
2391 matchingSkills.AddEvent(eventName);
2392 Want wantTest;
2393 wantTest.SetAction(eventAction);
2394 CommonEventData commonEventData(wantTest);
2395 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2396 CommonEventPublishInfo publishInfo;
2397 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2398 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2399 result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo);
2400 g_mtx.lock();
2401 }
2402 // The publisher can send normally, but does not have permission to send system events
2403 EXPECT_TRUE(result);
2404 struct tm startTime = {0};
2405 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2406 struct tm doingTime = {0};
2407 int64_t seconds = 0;
2408
2409 while (!g_mtx.try_lock()) {
2410 // get current time and compare it with the start time
2411 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2412 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2413 if (seconds >= g_TIME_OUT_SECONDS) {
2414 sysResult = true;
2415 break;
2416 }
2417 }
2418 // Unable to receive published system events, failed to send system events
2419 EXPECT_TRUE(true);
2420 g_mtx.unlock();
2421 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2422 }
2423
2424 /*
2425 * @tc.number: CES_SendEvent_1600
2426 * @tc.name: PublishCommonEvent
2427 * @tc.desc: publisher cannot receive published system events
2428 * This test case has been covered in the module test, and the system test
2429 * cannot simulate the non-subsystem scenario
2430 */
2431 HWTEST_F(ActsCESManagertest, CES_SendEvent_1600, Function | MediumTest | Level0)
2432 {
2433 std::string eventName = CommonEventSupport::COMMON_EVENT_ACCOUNT_DELETED;
2434 std::string eventAction = CommonEventSupport::COMMON_EVENT_ACCOUNT_DELETED;
2435 bool result = true;
2436 MatchingSkills matchingSkills;
2437 matchingSkills.AddEvent(eventName);
2438 Want wantTest;
2439 wantTest.SetAction(eventAction);
2440 CommonEventData commonEventData(wantTest);
2441 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2442 CommonEventPublishInfo publishInfo;
2443 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2444 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
2445 (CommonEventManager::PublishCommonEvent(commonEventData, publishInfo))) {
2446 g_mtx.lock();
2447 }
2448 struct tm startTime = {0};
2449 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2450 struct tm doingTime = {0};
2451 int64_t seconds = 0;
2452 while (!g_mtx.try_lock()) {
2453 // get current time and compare it with the start time
2454 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2455 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2456 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
2457 result = false;
2458 break;
2459 }
2460 }
2461 // System events published by ordinary publishers, the publication fails, and the receiver cannot receive it
2462 EXPECT_FALSE(false);
2463 g_mtx.unlock();
2464 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2465 }
2466
2467 /*
2468 * @tc.number: CES_SendEvent_1700
2469 * @tc.name: PublishCommonEvent
2470 * @tc.desc: Both subscribers subscribe to the event, after the event is published, both the subscribers can receive
2471 * the event
2472 */
2473 HWTEST_F(ActsCESManagertest, CES_SendEvent_1700, Function | MediumTest | Level0)
2474 {
2475 std::string eventName = COMPARE_STR;
2476 std::string eventAction = COMPARE_STR;
2477 MatchingSkills matchingSkills;
2478 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2479 matchingSkills.AddEvent(eventName);
2480 Want wantTest;
2481 wantTest.SetAction(eventAction);
2482 CommonEventData commonEventData(wantTest);
2483 commonEventData.SetCode(1);
2484 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2485 CommonEventPublishInfo publishInfo;
2486 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2487 auto subscriberPtr1 = std::make_shared<CommonEventServicesSystemTestSubscriber>(subscribeInfo);
2488 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
2489 CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) {
2490 CommonEventManager::PublishCommonEvent(commonEventData, publishInfo);
2491 }
2492 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2493 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1);
2494 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2495 matchingSkills.RemoveEvent(eventName);
2496 }
2497 EXPECT_TRUE(SIGNUMFIRST == stLevel_.CESLevel && SIGNUMSECOND == stLevel_.CESLevel && SIGNUMTHIRD == 0);
2498 GTEST_LOG_(INFO) << "SIGNUMFIRST: " << SIGNUMFIRST << "SIGNUMSECOND: " << SIGNUMSECOND
2499 << "SIGNUMTHIRD: " << SIGNUMTHIRD << "stLevel_.CESLevel: " << stLevel_.CESLevel;
2500 SIGNUMFIRST = 0;
2501 SIGNUMSECOND = 0;
2502 SIGNUMTHIRD = 0;
2503 }
2504
2505 /*
2506 * @tc.number: CES_SendEvent_1800
2507 * @tc.name: PublishCommonEvent
2508 * @tc.desc: One subscriber subscribe to the event and another subscriber does not subscribe to the event,
2509 * after the event is published, subscribed subscriber can receive the event and unsubscribed
2510 * subscribe can not receive the event
2511 */
2512 HWTEST_F(ActsCESManagertest, CES_SendEvent_1800, Function | MediumTest | Level0)
2513 {
2514 std::string eventName = COMPARE_STR_FALSE;
2515 std::string eventAction = COMPARE_STR_FALSE;
2516 MatchingSkills matchingSkills;
2517 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2518 matchingSkills.AddEvent(eventName);
2519 Want wantTest;
2520 wantTest.SetAction(eventAction);
2521 CommonEventData commonEventData(wantTest);
2522 commonEventData.SetCode(200);
2523 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2524 CommonEventPublishInfo publishInfo;
2525 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTestSubscriber>(subscribeInfo);
2526 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2527 CommonEventManager::PublishCommonEvent(commonEventData, publishInfo);
2528 }
2529 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2530 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2531 matchingSkills.RemoveEvent(eventName);
2532 }
2533 EXPECT_TRUE(SIGNUMFIRST == 0 && SIGNUMSECOND == 0 && SIGNUMTHIRD == stLevel_.CESLevel);
2534 GTEST_LOG_(INFO) << "SIGNUMFIRST: " << SIGNUMFIRST << "SIGNUMSECOND: " << SIGNUMSECOND
2535 << "SIGNUMTHIRD: " << SIGNUMTHIRD << "stLevel_.CESLevel: " << stLevel_.CESLevel;
2536 SIGNUMFIRST = 0;
2537 SIGNUMSECOND = 0;
2538 SIGNUMTHIRD = 0;
2539 }
2540
2541 /*
2542 * @tc.number: CES_SetEventAuthority_0100
2543 * @tc.name: SetPermission
2544 * @tc.desc: Set permission for common event subscribers and verify successfully subscribe to common events
2545 */
2546 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0100, Function | MediumTest | Level0)
2547 {
2548 bool result = false;
2549 std::string eventName = "TESTEVENT_SUBSCRIBER_PERMISSION";
2550 std::string permissin = "PERMISSION";
2551 MatchingSkills matchingSkills;
2552 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2553 matchingSkills.AddEvent(eventName);
2554 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2555 subscribeInfo.SetPermission(permissin);
2556 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2557 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2558 result = false;
2559 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0100 failed, frequency: " << i;
2560 break;
2561 } else {
2562 result = true;
2563 }
2564 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2565 matchingSkills.RemoveEvent(eventName);
2566 }
2567 if (result && stLevel_.CESLevel >= 1) {
2568 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0100 stress level: " << stLevel_.CESLevel;
2569 }
2570 EXPECT_TRUE(result);
2571 }
2572
2573 /*
2574 * @tc.number: CES_SetEventAuthority_0200
2575 * @tc.name: SetPermission and SetPriority
2576 * @tc.desc: Set permission and priority for common event subscribers and verify successfully subscribe to common events
2577 */
2578 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0200, Function | MediumTest | Level0)
2579 {
2580 bool result = false;
2581 std::string eventName = "TESTEVENT_SUBSCRIBER_PERMISSION_PRIORITY";
2582 std::string permissin = "PERMISSION";
2583 MatchingSkills matchingSkills;
2584 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2585 matchingSkills.AddEvent(eventName);
2586 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2587 subscribeInfo.SetPermission(permissin);
2588 subscribeInfo.SetPriority(1);
2589 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2590 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2591 result = false;
2592 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0200 failed, frequency: " << i;
2593 break;
2594 } else {
2595 result = true;
2596 }
2597 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2598 matchingSkills.RemoveEvent(eventName);
2599 }
2600 if (result && stLevel_.CESLevel >= 1) {
2601 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0200 stress level: " << stLevel_.CESLevel;
2602 }
2603 EXPECT_TRUE(result);
2604 }
2605
2606 /*
2607 * @tc.number: CES_SetEventAuthority_0300
2608 * @tc.name: SetPermission SetPriority and SetDeviceId
2609 * @tc.desc: Set permission and priority and DeviceId for common event subscribers and verify successfully
2610 * subscribe to common events
2611 */
2612 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0300, Function | MediumTest | Level0)
2613 {
2614 bool result = false;
2615 std::string eventName = "TESTEVENT_SUBSCRIBER_PERMISSION_PRIORITY_D";
2616 std::string permissin = "PERMISSION";
2617 std::string deviceId = "deviceId";
2618 MatchingSkills matchingSkills;
2619 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2620 matchingSkills.AddEvent(eventName);
2621 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2622 subscribeInfo.SetPermission(permissin);
2623 subscribeInfo.SetPriority(1);
2624 subscribeInfo.SetDeviceId(deviceId);
2625 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2626 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2627 result = false;
2628 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0200 failed, frequency: " << i;
2629 break;
2630 } else {
2631 result = true;
2632 }
2633 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2634 matchingSkills.RemoveEvent(eventName);
2635 }
2636 if (result && stLevel_.CESLevel >= 1) {
2637 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0200 stress level: " << stLevel_.CESLevel;
2638 }
2639 EXPECT_TRUE(result);
2640 }
2641
2642 /*
2643 * @tc.number: CES_SetEventAuthority_0400
2644 * @tc.name: SetPermission
2645 * @tc.desc: Set permission for common event subscribers and verify successfully Unsubscribe to common events
2646 */
2647 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0400, Function | MediumTest | Level0)
2648 {
2649 bool result = false;
2650 std::string eventName = "TESTEVENT_UNSUBSCRIBER_PERMISSION";
2651 std::string permissin = "PERMISSION";
2652 MatchingSkills matchingSkills;
2653 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2654 matchingSkills.AddEvent(eventName);
2655 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2656 subscribeInfo.SetPermission(permissin);
2657 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2658 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2659 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
2660 result = false;
2661 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0400 failed, frequency: " << i;
2662 break;
2663 } else {
2664 result = true;
2665 }
2666 matchingSkills.RemoveEvent(eventName);
2667 }
2668 if (result && stLevel_.CESLevel >= 1) {
2669 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0400 stress level: " << stLevel_.CESLevel;
2670 }
2671 EXPECT_TRUE(result);
2672 }
2673
2674 /*
2675 * @tc.number: CES_SetEventAuthority_0500
2676 * @tc.name: SetPermission and SetPriority
2677 * @tc.desc: Set permission and priority for common event subscribers and verify successfully Unsubscribe to
2678 * common events
2679 */
2680 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0500, Function | MediumTest | Level0)
2681 {
2682 bool result = false;
2683 std::string eventName = "TESTEVENT_UNSUBSCRIBER_PERMISSION_PRIORITY";
2684 std::string permissin = "PERMISSION";
2685 MatchingSkills matchingSkills;
2686 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2687 matchingSkills.AddEvent(eventName);
2688 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2689 subscribeInfo.SetPermission(permissin);
2690 subscribeInfo.SetPriority(1);
2691 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2692 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2693 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
2694 result = false;
2695 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0500 failed, frequency: " << i;
2696 break;
2697 } else {
2698 result = true;
2699 }
2700 matchingSkills.RemoveEvent(eventName);
2701 }
2702 if (result && stLevel_.CESLevel >= 1) {
2703 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0500 stress level: " << stLevel_.CESLevel;
2704 }
2705 EXPECT_TRUE(result);
2706 }
2707
2708 /*
2709 * @tc.number: CES_SetEventAuthority_0600
2710 * @tc.name: SetPermission SetPriority and SetDeviceId
2711 * @tc.desc: Set permission and priority and DeviceId for common event subscribers and verify successfully
2712 * Unsubscribe to common events
2713 */
2714 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0600, Function | MediumTest | Level0)
2715 {
2716 bool result = false;
2717 std::string eventName = "TESTEVENT_UNSUBSCRIBER_PERMISSION_PRIORITY_D";
2718 std::string permissin = "PERMISSION";
2719 std::string deviceId = "deviceId";
2720 MatchingSkills matchingSkills;
2721 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2722 matchingSkills.AddEvent(eventName);
2723 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2724 subscribeInfo.SetPermission(permissin);
2725 subscribeInfo.SetPriority(1);
2726 subscribeInfo.SetDeviceId(deviceId);
2727 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2728 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2729 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
2730 result = false;
2731 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0600 failed, frequency: " << i;
2732 break;
2733 } else {
2734 result = true;
2735 }
2736 matchingSkills.RemoveEvent(eventName);
2737 }
2738 if (result && stLevel_.CESLevel >= 1) {
2739 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0600 stress level: " << stLevel_.CESLevel;
2740 }
2741 EXPECT_TRUE(result);
2742 }
2743
2744 /*
2745 * @tc.number: CES_SetEventAuthority_0700
2746 * @tc.name: OnReceiveEvent
2747 * @tc.desc: Set permission for common event subscribers and verify successfully publish common events
2748 */
2749 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0700, Function | MediumTest | Level0)
2750 {
2751 bool result = false;
2752 std::string eventName = "TESTEVENT_PUBLISH_ACTION_PERMISSION";
2753 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_PERMISSION";
2754 std::string permissin = "PERMISSION";
2755 MatchingSkills matchingSkills;
2756 std::vector<std::string> permissins;
2757 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2758 permissins.emplace_back(permissin);
2759 matchingSkills.AddEvent(eventName);
2760 Want wantTest;
2761 wantTest.SetAction(eventAction);
2762 CommonEventData commonEventData(wantTest);
2763 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2764 CommonEventPublishInfo publishInfo;
2765 publishInfo.SetSubscriberPermissions(permissins);
2766 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2767 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2768 if (!CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) {
2769 result = false;
2770 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0700 failed, frequency: " << i;
2771 break;
2772 } else {
2773 result = true;
2774 }
2775 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2776 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2777 matchingSkills.RemoveEvent(eventName);
2778 permissins.clear();
2779 }
2780 if (result && stLevel_.CESLevel >= 1) {
2781 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0700 stress level: " << stLevel_.CESLevel;
2782 }
2783 EXPECT_TRUE(result);
2784 }
2785
2786 /*
2787 * @tc.number: CES_SetEventAuthority_0800
2788 * @tc.name: SetSubscriberPermissions
2789 * @tc.desc: Set permission for common event subscribers and verify successfully receive common events
2790 */
2791 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0800, Function | MediumTest | Level0)
2792 {
2793 std::string eventName = "TESTEVENT_PUBLISH_ACTION_PERMISSION_R";
2794 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_PERMISSION_R";
2795 std::string permissin = "PERMISSION";
2796 bool result = false;
2797 std::vector<std::string> permissins;
2798 permissins.emplace_back(permissin);
2799 MatchingSkills matchingSkills;
2800 matchingSkills.AddEvent(eventName);
2801 Want wantTest;
2802 wantTest.SetAction(eventAction);
2803 CommonEventData commonEventData(wantTest);
2804 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2805 CommonEventPublishInfo publishInfo;
2806 publishInfo.SetSubscriberPermissions(permissins);
2807 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2808 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
2809 (CommonEventManager::PublishCommonEvent(commonEventData, publishInfo))) {
2810 g_mtx.lock();
2811 }
2812 struct tm startTime = {0};
2813 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2814 struct tm doingTime = {0};
2815 int64_t seconds = 0;
2816 while (!g_mtx.try_lock()) {
2817 // get current time and compare it with the start time
2818 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2819 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2820 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
2821 break;
2822 }
2823 }
2824 g_mtx.unlock();
2825 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2826 }
2827
2828 /*
2829 * @tc.number: CES_SetEventAuthority_0900
2830 * @tc.name: SetThreadMode
2831 * @tc.desc: Set ThreadMode for common event subscribers and verify successfully subscribe to common events
2832 */
2833 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_0900, Function | MediumTest | Level0)
2834 {
2835 bool result = false;
2836 std::string eventName = "TESTEVENT_SUBSCRIBER_SETTHREADMODE";
2837 MatchingSkills matchingSkills;
2838 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2839 matchingSkills.AddEvent(eventName);
2840 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2841 subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::HANDLER);
2842 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2843 if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
2844 result = false;
2845 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0700 failed, frequency: " << i;
2846 break;
2847 } else {
2848 result = true;
2849 }
2850 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2851 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2852 matchingSkills.RemoveEvent(eventName);
2853 }
2854 if (result && stLevel_.CESLevel >= 1) {
2855 GTEST_LOG_(INFO) << "CES_SetEventAuthority_0700 stress level: " << stLevel_.CESLevel;
2856 }
2857 EXPECT_TRUE(result);
2858 }
2859
2860 /*
2861 * @tc.number: CES_SetEventAuthority_1000
2862 * @tc.name: SetThreadMode
2863 * @tc.desc: Set ThreadMode for common event subscribers and verify successfully Unsubscribe to common events
2864 */
2865 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_1000, Function | MediumTest | Level0)
2866 {
2867 bool result = false;
2868 std::string eventName = "TESTEVENT_UNSUBSCRIBER_SETTHREADMODE";
2869 MatchingSkills matchingSkills;
2870 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2871 matchingSkills.AddEvent(eventName);
2872 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2873 subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::HANDLER);
2874 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2875 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2876 if (!CommonEventManager::UnSubscribeCommonEvent(subscriberPtr)) {
2877 result = false;
2878 GTEST_LOG_(INFO) << "CES_SetEventAuthority_1000 failed, frequency: " << i;
2879 break;
2880 } else {
2881 result = true;
2882 }
2883 matchingSkills.RemoveEvent(eventName);
2884 }
2885 if (result && stLevel_.CESLevel >= 1) {
2886 GTEST_LOG_(INFO) << "CES_SetEventAuthority_1000 stress level: " << stLevel_.CESLevel;
2887 }
2888 EXPECT_TRUE(result);
2889 }
2890
2891 /*
2892 * @tc.number: CES_SetEventAuthority_1100
2893 * @tc.name: SetThreadMode
2894 * @tc.desc: Set ThreadMode for common event subscribers and verify successfully publish to common events
2895 */
2896 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_1100, Function | MediumTest | Level0)
2897 {
2898 bool result = false;
2899 std::string eventName = "TESTEVENT_PUBLISH_ACTION_SETTHREADMODE";
2900 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SETTHREADMODE";
2901 MatchingSkills matchingSkills;
2902 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2903 matchingSkills.AddEvent(eventName);
2904 Want wantTest;
2905 wantTest.SetAction(eventAction);
2906 CommonEventData commonEventData(wantTest);
2907 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2908 subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::HANDLER);
2909 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2910 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2911 if (!CommonEventManager::PublishCommonEvent(commonEventData)) {
2912 result = false;
2913 GTEST_LOG_(INFO) << "CES_SetEventAuthority_1000 failed, frequency: " << i;
2914 break;
2915 } else {
2916 result = true;
2917 }
2918 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2919 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2920 matchingSkills.RemoveEvent(eventName);
2921 }
2922 if (result && stLevel_.CESLevel >= 1) {
2923 GTEST_LOG_(INFO) << "CES_SetEventAuthority_1000 stress level: " << stLevel_.CESLevel;
2924 }
2925 EXPECT_TRUE(result);
2926 }
2927
2928 /*
2929 * @tc.number: CES_SetEventAuthority_1200
2930 * @tc.name: SetThreadMode
2931 * @tc.desc: Set ThreadMode for common event subscribers and verify successfully receive to common events
2932 */
2933 HWTEST_F(ActsCESManagertest, CES_SetEventAuthority_1200, Function | MediumTest | Level0)
2934 {
2935 std::string eventName = "TESTEVENT_PUBLISH_ACTION_SETHANDLER_HANDLER";
2936 std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SETHANDLER_HANDLER";
2937 bool result = false;
2938 MatchingSkills matchingSkills;
2939 matchingSkills.AddEvent(eventName);
2940 Want wantTest;
2941 wantTest.SetAction(eventAction);
2942 CommonEventData commonEventData(wantTest);
2943 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2944 subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::HANDLER);
2945 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2946 if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) &&
2947 (CommonEventManager::PublishCommonEvent(commonEventData))) {
2948 g_mtx.lock();
2949 }
2950 struct tm startTime = {0};
2951 EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
2952 struct tm doingTime = {0};
2953 int64_t seconds = 0;
2954 while (!g_mtx.try_lock()) {
2955 // get current time and compare it with the start time
2956 EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
2957 seconds = OHOS::GetSecondsBetween(startTime, doingTime);
2958 if (seconds >= g_TIME_OUT_SECONDS_LIMIT) {
2959 result = true;
2960 break;
2961 }
2962 }
2963 // expect the subscriber could receive the event within 5 seconds.
2964 EXPECT_TRUE(result);
2965 g_mtx.unlock();
2966 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2967 }
2968
2969 /*
2970 * @tc.number: CES_VerifyMatchingSkills_0100
2971 * @tc.name: GetEvent
2972 * @tc.desc: check to get the added event
2973 */
2974 HWTEST_F(ActsCESManagertest, CES_VerifyMatchingSkills_0100, Function | MediumTest | Level0)
2975 {
2976 bool result = false;
2977 std::string eventName = "TESTEVENT_GETMATCHINGSKILLS";
2978 MatchingSkills matchingSkills;
2979 for (int i = 1; i <= stLevel_.CESLevel; i++) {
2980 matchingSkills.AddEvent(eventName);
2981 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
2982 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
2983 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
2984 MatchingSkills testMatching = subscribeInfo.GetMatchingSkills();
2985 if (!(testMatching.GetEvent(0) == eventName)) {
2986 result = false;
2987 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0100 failed, frequency: " << i;
2988 break;
2989 } else {
2990 result = true;
2991 }
2992 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
2993 matchingSkills.RemoveEvent(eventName);
2994 }
2995 if (result && stLevel_.CESLevel >= 1) {
2996 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0100 stress level: " << stLevel_.CESLevel;
2997 }
2998 EXPECT_TRUE(result);
2999 }
3000
3001 /*
3002 * @tc.number: CES_VerifyMatchingSkills_0200
3003 * @tc.name: GetEntity
3004 * @tc.desc: check to get the added entity
3005 */
3006 HWTEST_F(ActsCESManagertest, CES_VerifyMatchingSkills_0200, Function | MediumTest | Level0)
3007 {
3008 bool result = false;
3009 std::string eventName = "TESTEVENT_ADDENTITY_GETENTITY";
3010 std::string entity = "entity";
3011 MatchingSkills matchingSkills;
3012 for (int i = 1; i <= stLevel_.CESLevel; i++) {
3013 matchingSkills.AddEvent(eventName);
3014 matchingSkills.AddEntity(entity);
3015 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
3016 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
3017 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
3018 if (!(matchingSkills.GetEntity(0) == entity)) {
3019 result = false;
3020 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0200 failed, frequency: " << i;
3021 break;
3022 } else {
3023 result = true;
3024 }
3025 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
3026 matchingSkills.RemoveEvent(eventName);
3027 }
3028 if (result && stLevel_.CESLevel >= 1) {
3029 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0200 stress level: " << stLevel_.CESLevel;
3030 }
3031 EXPECT_TRUE(result);
3032 }
3033
3034 /*
3035 * @tc.number: CES_VerifyMatchingSkills_0300
3036 * @tc.name: HasEntity
3037 * @tc.desc: verify that entity is in MatchingSkills
3038 */
3039 HWTEST_F(ActsCESManagertest, CES_VerifyMatchingSkills_0300, Function | MediumTest | Level0)
3040 {
3041 bool result = false;
3042 std::string eventName = "TESTEVENT_ADDENTITY_HASENTITY";
3043 std::string entity = "entity";
3044 MatchingSkills matchingSkills;
3045 for (int i = 1; i <= stLevel_.CESLevel; i++) {
3046 matchingSkills.AddEvent(eventName);
3047 matchingSkills.AddEntity(entity);
3048 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
3049 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
3050 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
3051 if (!matchingSkills.HasEntity(entity)) {
3052 result = false;
3053 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0300 failed, frequency: " << i;
3054 break;
3055 } else {
3056 result = true;
3057 }
3058 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
3059 matchingSkills.RemoveEvent(eventName);
3060 }
3061 if (result && stLevel_.CESLevel >= 1) {
3062 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0300 stress level: " << stLevel_.CESLevel;
3063 }
3064 EXPECT_TRUE(result);
3065 }
3066
3067 /*
3068 * @tc.number: CES_VerifyMatchingSkills_0400
3069 * @tc.name: RemoveEntity
3070 * @tc.desc: verify that the entity was successfully removed
3071 */
3072 HWTEST_F(ActsCESManagertest, CES_VerifyMatchingSkills_0400, Function | MediumTest | Level0)
3073 {
3074 bool result = false;
3075 std::string eventName = "TESTEVENT_ADDENTITY_REMOVEENTITY";
3076 std::string entity = "entity";
3077 MatchingSkills matchingSkills;
3078 for (int i = 1; i <= stLevel_.CESLevel; i++) {
3079 matchingSkills.AddEvent(eventName);
3080 matchingSkills.AddEntity(entity);
3081 matchingSkills.RemoveEntity(entity);
3082 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
3083 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
3084 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
3085 if (matchingSkills.HasEntity(entity)) {
3086 result = false;
3087 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0400 failed, frequency: " << i;
3088 break;
3089 } else {
3090 result = true;
3091 }
3092 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
3093 matchingSkills.RemoveEvent(eventName);
3094 }
3095 if (result && stLevel_.CESLevel >= 1) {
3096 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0400 stress level: " << stLevel_.CESLevel;
3097 }
3098 EXPECT_TRUE(result);
3099 }
3100
3101 /*
3102 * @tc.number: CES_VerifyMatchingSkills_0500
3103 * @tc.name: CountEntities
3104 * @tc.desc: verify that count correct number of entities
3105 */
3106 HWTEST_F(ActsCESManagertest, CES_VerifyMatchingSkills_0500, Function | MediumTest | Level0)
3107 {
3108 bool result = false;
3109 std::string eventName = "TESTEVENT_ADDENTITY_ENTITYCOUNT";
3110 std::string entity = "entity";
3111 MatchingSkills matchingSkills;
3112 for (int i = 1; i <= stLevel_.CESLevel; i++) {
3113 matchingSkills.AddEvent(eventName);
3114 matchingSkills.AddEntity(entity);
3115 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
3116 auto subscriberPtr = std::make_shared<CommonEventServicesSystemTest>(subscribeInfo);
3117 EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberPtr));
3118 if (!(matchingSkills.CountEntities() >= 1)) {
3119 result = false;
3120 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0500 failed, frequency: " << i;
3121 break;
3122 } else {
3123 result = true;
3124 }
3125 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
3126 matchingSkills.RemoveEvent(eventName);
3127 }
3128 if (result && stLevel_.CESLevel >= 1) {
3129 GTEST_LOG_(INFO) << "CES_VerifyMatchingSkills_0500 stress level: " << stLevel_.CESLevel;
3130 }
3131 EXPECT_TRUE(result);
3132 }
3133 } // namespace EventFwk
3134 } // namespace OHOS