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