• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <thread>
17 #include <chrono>
18 
19 #include <sys/time.h>
20 
21 // redefine private and protected since testcase need to invoke and test private function
22 #define private public
23 #define protected public
24 #include "common_event.h"
25 #include "common_event_manager.h"
26 #include "common_event_stub.h"
27 #include "common_event_subscriber_manager.h"
28 #include "inner_common_event_manager.h"
29 #include "common_event_publish_info.h"
30 #include "common_event_subscribe_info.h"
31 #include "matching_skills.h"
32 #undef private
33 #undef protected
34 
35 #include "datetime_ex.h"
36 
37 #include <gtest/gtest.h>
38 
39 using namespace testing::ext;
40 using namespace OHOS::EventFwk;
41 using OHOS::Parcel;
42 
43 namespace {
44 const std::string EVENT = "com.ces.test.event";
45 std::mutex mtx;
46 const time_t TIME_OUT_SECONDS_LIMIT = 5;
47 constexpr uint16_t SYSTEM_UID = 1000;
48 constexpr int32_t ERR_COMMON = -1;
49 }  // namespace
50 
51 class SubscriberTest;
52 
53 class CommonEventSubscribeTest : public testing::Test {
54 public:
55     static void SetUpTestCase(void);
56     static void TearDownTestCase(void);
57     void SetUp();
58     void TearDown();
59 
60 public:
61     static constexpr int TEST_WAIT_TIME = 100000;
62     CommonEventManager commonEventManager;
63     MatchingSkills matchingSkills;
64 };
65 
66 class SubscriberTest : public CommonEventSubscriber {
67 public:
SubscriberTest(const CommonEventSubscribeInfo & sp)68     explicit SubscriberTest(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp)
69     {}
70 
~SubscriberTest()71     ~SubscriberTest()
72     {}
73 
OnReceiveEvent(const CommonEventData & data)74     virtual void OnReceiveEvent(const CommonEventData &data)
75     {
76         mtx.unlock();
77     }
78 };
79 
80 class EventReceiveStubTest : public EventReceiveStub {
81 public:
EventReceiveStubTest()82     EventReceiveStubTest()
83     {}
84 
~EventReceiveStubTest()85     ~EventReceiveStubTest()
86     {}
87 
NotifyEvent(const CommonEventData & commonEventData,const bool & ordered,const bool & sticky)88     virtual void NotifyEvent(const CommonEventData &commonEventData, const bool &ordered, const bool &sticky)
89     {}
90 };
91 
92 class CommonEventStubTest : public CommonEventStub {
93 public:
CommonEventStubTest()94     CommonEventStubTest()
95     {}
96 
PublishCommonEvent(const CommonEventData & event,const CommonEventPublishInfo & publishinfo,const OHOS::sptr<IRemoteObject> & commonEventListener,const int32_t & userId)97     virtual int32_t PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
98         const OHOS::sptr<IRemoteObject> &commonEventListener, const int32_t &userId)
99     {
100         return ERR_COMMON;
101     }
102 
SubscribeCommonEvent(const CommonEventSubscribeInfo & subscribeInfo,const OHOS::sptr<IRemoteObject> & commonEventListener)103     virtual int32_t SubscribeCommonEvent(
104         const CommonEventSubscribeInfo &subscribeInfo, const OHOS::sptr<IRemoteObject> &commonEventListener)
105     {
106         return ERR_COMMON;
107     }
108 
UnsubscribeCommonEvent(const OHOS::sptr<IRemoteObject> & commonEventListener)109     virtual int32_t UnsubscribeCommonEvent(const OHOS::sptr<IRemoteObject> &commonEventListener)
110     {
111         return ERR_COMMON;
112     }
113 
DumpState(const uint8_t & dumpType,const std::string & event,const int32_t & userId,std::vector<std::string> & state)114     virtual bool DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
115         std::vector<std::string> &state)
116     {
117         return false;
118     }
119 
~CommonEventStubTest()120     virtual ~CommonEventStubTest()
121     {}
122 
FinishReceiver(const OHOS::sptr<IRemoteObject> & proxy,const int32_t & code,const std::string & receiverData,const bool & abortEvent)123     virtual bool FinishReceiver(const OHOS::sptr<IRemoteObject> &proxy, const int32_t &code,
124         const std::string &receiverData, const bool &abortEvent)
125     {
126         return false;
127     }
128 };
129 
SetUpTestCase(void)130 void CommonEventSubscribeTest::SetUpTestCase(void)
131 {}
132 
TearDownTestCase(void)133 void CommonEventSubscribeTest::TearDownTestCase(void)
134 {}
135 
SetUp(void)136 void CommonEventSubscribeTest::SetUp(void)
137 {}
138 
TearDown(void)139 void CommonEventSubscribeTest::TearDown(void)
140 {}
141 
142 /*
143  * Feature: CommonEventSubscribeTest
144  * Function:CommonEvent SubscribeCommonEvent
145  * SubFunction: Subscribe common event
146  * FunctionPoints: test subscribe event
147  * EnvConditions: system run normally
148  * CaseDescription:  1. subscribe common event
149  *                   2. success subscribe common event with right parameters
150  */
151 
152 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_001, TestSize.Level1)
153 {
154     /* Subscribe */
155     MatchingSkills matchingSkills;
156     matchingSkills.AddEvent(EVENT);
157     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
158     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
159     bool subscribeResult = CommonEventManager::SubscribeCommonEvent(subscriber);
160 
161     EXPECT_EQ(true, subscribeResult);
162 
163     /* Publish */
164 
165     // make a want
166     Want want;
167     want.SetAction(EVENT);
168 
169     // make common event data
170     CommonEventData data;
171     data.SetWant(want);
172 
173     // lock the mutex
174     mtx.lock();
175 
176     // publish a common event
177     bool publishResult = CommonEventManager::PublishCommonEvent(data);
178 
179     EXPECT_EQ(true, publishResult);
180 
181     // record start time of publishing
182     struct tm startTime = {0};
183     EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true);
184 
185     // record current time
186     struct tm doingTime = {0};
187     int64_t seconds = 0;
188 
189     while (!mtx.try_lock()) {
190         // get current time and compare it with the start time
191         EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true);
192         seconds = OHOS::GetSecondsBetween(startTime, doingTime);
193         if (seconds >= TIME_OUT_SECONDS_LIMIT) {
194             break;
195         }
196     }
197 
198     // expect the subscriber could receive the event within 5 seconds.
199     EXPECT_LT(seconds, TIME_OUT_SECONDS_LIMIT);
200     mtx.unlock();
201 }
202 
203 /*
204  * Feature: CommonEventSubscribeTest
205  * Function:CommonEventSubscriberManager InsertSubscriber
206  * SubFunction: Subscribe common event
207  * FunctionPoints: test subscribe event
208  * EnvConditions: system run normally
209  * CaseDescription:  1. subscribe common event
210  *                   2. different subscriber subscribe event
211  *                   3. success subscribe common event with right parameters
212  */
213 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_002, TestSize.Level1)
214 {
215     MatchingSkills matchingSkills;
216     matchingSkills.AddEvent(EVENT);
217     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
218     std::shared_ptr<SubscriberTest> subscribera = std::make_shared<SubscriberTest>(subscribeInfo);
219     std::shared_ptr<SubscriberTest> subscriberb = std::make_shared<SubscriberTest>(subscribeInfo);
220 
221     bool subscribeResulta = CommonEventManager::SubscribeCommonEvent(subscribera);
222 
223     EXPECT_EQ(true, subscribeResulta);
224 
225     bool subscribeResultb = CommonEventManager::SubscribeCommonEvent(subscriberb);
226 
227     EXPECT_EQ(true, subscribeResultb);
228 }
229 
230 /*
231  * Feature: CommonEventSubscribeTest
232  * Function:CommonEvent SubscribeCommonEvent
233  * SubFunction: Subscribe common event
234  * FunctionPoints: test subscribe event
235  * EnvConditions: system run normally
236  * CaseDescription:  1. subscribe common event
237  *                   2. fail subscribe common event kit with null subscriber
238  */
239 
240 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_003, TestSize.Level1)
241 {
242     bool subscribeResult = CommonEventManager::SubscribeCommonEvent(nullptr);
243 
244     EXPECT_EQ(false, subscribeResult);
245 }
246 
247 /*
248  * Feature: CommonEventSubscribeTest
249  * Function:CommonEvent SubscribeCommonEvent
250  * SubFunction: Subscribe common event
251  * FunctionPoints: test subscribe event
252  * EnvConditions: system run normally
253  * CaseDescription:  1. subscribe common event
254  *                   2. fail subscribe common event with no event
255  */
256 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_004, TestSize.Level1)
257 {
258     MatchingSkills matchingSkills;
259     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
260     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
261 
262     bool subscribeResult = CommonEventManager::SubscribeCommonEvent(subscriber);
263 
264     EXPECT_EQ(false, subscribeResult);
265 }
266 
267 /*
268  * Feature: CommonEventSubscribeTest
269  * Function:CommonEvent SubscribeCommonEvent
270  * SubFunction: Subscribe common event
271  * FunctionPoints: test subscribe event
272  * EnvConditions: system run normally
273  * CaseDescription:  1. subscribe common event
274  *                   2. fail subscribe common event because common event listener has subsrciber
275  */
276 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_005, TestSize.Level1)
277 {
278     MatchingSkills matchingSkills;
279     matchingSkills.AddEvent(EVENT);
280     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
281     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
282 
283     CommonEventManager::SubscribeCommonEvent(subscriber);
284 
285     bool subscribeResult = CommonEventManager::SubscribeCommonEvent(subscriber);
286 
287     EXPECT_EQ(true, subscribeResult);
288 }
289 
290 /*
291  * Feature: CommonEventSubscribeTest
292  * Function: InnerCommonEventManager SubscribeCommonEvent
293  * SubFunction: Subscribe common event
294  * FunctionPoints: test subscribe event
295  * EnvConditions: system run normally
296  * CaseDescription:  1. subscribe common event
297  *                   2. fail subscribe common event, inner common event manager
298  *                      common event listener is null
299  */
300 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_009, TestSize.Level1)
301 {
302     MatchingSkills matchingSkills;
303     matchingSkills.AddEvent(EVENT);
304     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
305     std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = std::make_shared<InnerCommonEventManager>();
306     OHOS::sptr<OHOS::IRemoteObject> sp(nullptr);
307 
308     struct tm curTime {0};
309     OHOS::Security::AccessToken::AccessTokenID tokenID = 1;
310 
311     EXPECT_EQ(false, innerCommonEventManager->SubscribeCommonEvent(subscribeInfo, sp, curTime, 0, 0, tokenID, ""));
312 }
313 
314 /*
315  * Feature: CommonEventSubscribeTest
316  * Function: CommonEventSubscriberManager InsertSubscriber
317  * SubFunction: Subscribe common event
318  * FunctionPoints: test subscribe event
319  * EnvConditions: system run normally
320  * CaseDescription:  1. subscribe common event
321  *                   2. fail subscribe common event , common event subscriber manager
322  *                      event subscriber info is null
323  */
324 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_010, TestSize.Level1)
325 {
326     MatchingSkills matchingSkills;
327     matchingSkills.AddEvent(EVENT);
328     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
329     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
330     OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriber);
331     std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = std::make_shared<InnerCommonEventManager>();
332     OHOS::sptr<OHOS::IRemoteObject> commonEventListenerPtr(commonEventListener);
333 
334     struct tm curTime {0};
335     EventRecordInfo eventRecordInfo;
336     eventRecordInfo.pid = 0;
337     eventRecordInfo.uid = 0;
338     eventRecordInfo.bundleName = "bundleName";
339 
340     auto result = OHOS::DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->InsertSubscriber(
341         nullptr, commonEventListenerPtr, curTime, eventRecordInfo);
342 
343     EXPECT_EQ(nullptr, result);
344 }
345 
346 /*
347  * Feature: CommonEventSubscribeTest
348  * Function: CommonEventSubscriberManager InsertSubscriber
349  * SubFunction: Subscribe common event
350  * FunctionPoints: test subscribe event
351  * EnvConditions: system run normally
352  * CaseDescription:  1. subscribe common event
353  *                   2. fail subscribe common event , common event subscriber manager
354  *                      event common event listener is null
355  */
356 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_011, TestSize.Level1)
357 {
358     MatchingSkills matchingSkills;
359     matchingSkills.AddEvent(EVENT);
360     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
361     std::shared_ptr<CommonEventSubscribeInfo> commonEventSubscribeInfo =
362         std::make_shared<CommonEventSubscribeInfo>(subscribeInfo);
363 
364     struct tm curTime {0};
365     EventRecordInfo eventRecordInfo;
366     eventRecordInfo.pid = 0;
367     eventRecordInfo.uid = 0;
368     eventRecordInfo.bundleName = "bundleName";
369 
370     auto result = OHOS::DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->InsertSubscriber(
371         commonEventSubscribeInfo, nullptr, curTime, eventRecordInfo);
372 
373     EXPECT_EQ(nullptr, result);
374 }
375 
376 /*
377  * Feature: CommonEventSubscribeTest
378  * Function: CommonEventSubscriberManager InsertSubscriber
379  * SubFunction: Subscribe common event
380  * FunctionPoints: test subscribe event
381  * EnvConditions: system run normally
382  * CaseDescription:  1. subscribe common event
383  *                   2. fail subscribe common event , common event subscriber manager
384  *                      event size is null
385  */
386 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_012, TestSize.Level1)
387 {
388     MatchingSkills matchingSkills;
389     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
390     std::shared_ptr<CommonEventSubscribeInfo> commonEventSubscribeInfo =
391         std::make_shared<CommonEventSubscribeInfo>(subscribeInfo);
392     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
393     OHOS::sptr<CommonEventListener> commonEventListener = new CommonEventListener(subscriber);
394     std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = std::make_shared<InnerCommonEventManager>();
395     OHOS::sptr<OHOS::IRemoteObject> commonEventListenerSp(commonEventListener);
396 
397     struct tm curTime {0};
398     EventRecordInfo eventRecordInfo;
399     eventRecordInfo.pid = 0;
400     eventRecordInfo.uid = 0;
401     eventRecordInfo.bundleName = "bundleName";
402 
403     auto result = OHOS::DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->InsertSubscriber(
404         commonEventSubscribeInfo, nullptr, curTime, eventRecordInfo);
405 
406     EXPECT_EQ(nullptr, result);
407 }
408 
409 /*
410  * Feature: CommonEventSubscribeTest
411  * Function: CommonEventListener IsReady
412  * SubFunction: Subscribe common event
413  * FunctionPoints: test is ready
414  * EnvConditions: system run normally
415  * CaseDescription:  1. ready fail because runner is null
416  */
417 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_014, TestSize.Level1)
418 {
419     MatchingSkills matchingSkills;
420     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
421     std::shared_ptr<CommonEventSubscribeInfo> commonEventSubscribeInfo =
422         std::make_shared<CommonEventSubscribeInfo>(subscribeInfo);
423     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
424     CommonEventListener commonEventListener(subscriber);
425     commonEventListener.runner_ = nullptr;
426 
427     bool result = commonEventListener.IsReady();
428 
429     EXPECT_EQ(false, result);
430 }
431 
432 /*
433  * Feature: CommonEventSubscribeTest
434  * Function: CommonEventListener IsReady
435  * SubFunction: Subscribe common event
436  * FunctionPoints: test is ready
437  * EnvConditions: system run normally
438  * CaseDescription:  1. ready fail because handler is null
439  */
440 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_015, TestSize.Level1)
441 {
442     MatchingSkills matchingSkills;
443     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
444     std::shared_ptr<CommonEventSubscribeInfo> commonEventSubscribeInfo =
445         std::make_shared<CommonEventSubscribeInfo>(subscribeInfo);
446     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
447     CommonEventListener commonEventListener(subscriber);
448     commonEventListener.handler_ = nullptr;
449 
450     bool result = commonEventListener.IsReady();
451 
452     EXPECT_EQ(false, result);
453 }
454 
455 /*
456  * tc.number: CommonEventManager_001
457  * tc.name: test Freeze
458  * tc.type: FUNC
459  * tc.require: issueI5NGO7
460  * tc.desc: Invoke Freeze interface verify whether it is normal
461  */
462 HWTEST_F(CommonEventSubscribeTest, CommonEventManager_001, TestSize.Level1)
463 {
464     CommonEventManager commonEventManager;
465     bool freeze = commonEventManager.Freeze(SYSTEM_UID);
466     EXPECT_EQ(false, freeze);
467 }
468 
469 /*
470  * tc.number: CommonEventManager_002
471  * tc.name: test Unfreeze
472  * tc.type: FUNC
473  * tc.require: issueI5NGO7
474  * tc.desc: Invoke Unfreeze interface verify whether it is normal
475  */
476 HWTEST_F(CommonEventSubscribeTest, CommonEventManager_002, TestSize.Level1)
477 {
478     CommonEventManager commonEventManager;
479     bool unfreeze = commonEventManager.Unfreeze(SYSTEM_UID);
480     EXPECT_EQ(false, unfreeze);
481 }
482 
483 /*
484  * tc.number: CommonEventManager_003
485  * tc.name: test UnfreezeAll
486  * tc.type: FUNC
487  * tc.require: issueI5NGO7
488  * tc.desc: Invoke UnfreezeAll interface verify whether it is normal
489  */
490 HWTEST_F(CommonEventSubscribeTest, CommonEventManager_003, TestSize.Level1)
491 {
492     CommonEventManager commonEventManager;
493     bool unfreezeAll = commonEventManager.UnfreezeAll();
494     EXPECT_EQ(false, unfreezeAll);
495 }
496 
497 /*
498  * tc.number: CommonEventManager_004
499  * tc.name: test Freeze
500  * tc.type: FUNC
501  * tc.require: issue
502  * tc.desc: Invoke PublishCommonEventAsUser interface verify whether it is normal
503  */
504 HWTEST_F(CommonEventSubscribeTest, CommonEventManager_004, TestSize.Level1)
505 {
506     CommonEventManager commonEventManager;
507     CommonEventData data;
508     int32_t userId = 10;
509     bool result = commonEventManager.PublishCommonEventAsUser(data, userId);
510     EXPECT_EQ(result, false);
511 }
512 
513 /*
514  * tc.number: CommonEventManager_005
515  * tc.name: test Freeze
516  * tc.type: FUNC
517  * tc.require: issue
518  * tc.desc: Invoke PublishCommonEventAsUser interface verify whether it is normal
519  */
520 HWTEST_F(CommonEventSubscribeTest, CommonEventManager_005, TestSize.Level1)
521 {
522     CommonEventManager commonEventManager;
523     CommonEventData data;
524     int32_t userId = 10;
525     CommonEventPublishInfo publishInfo;
526     bool result = commonEventManager.PublishCommonEventAsUser(data, publishInfo, userId);
527     EXPECT_EQ(result, false);
528 }
529 
530 /*
531  * tc.number: CommonEventManager_006
532  * tc.name: test SetStaticSubscriberState
533  * tc.type: FUNC
534  * tc.require: issueI5NGO7
535  * tc.desc: Invoke Unfreeze interface verify whether it is normal
536  */
537 HWTEST_F(CommonEventSubscribeTest, CommonEventManager_006, TestSize.Level1)
538 {
539     CommonEventManager commonEventManager;
540     int32_t ret = commonEventManager.SetStaticSubscriberState(true);
541     EXPECT_NE(ret, OHOS::ERR_OK);
542 }
543 
544 /*
545  * tc.number: CommonEventPublishInfo_001
546  * tc.name: test ReadFromParcel
547  * tc.type: FUNC
548  * tc.require: issueI5RULW
549  * tc.desc: Invoke ReadFromParcel interface verify whether it is normal
550  */
551 HWTEST_F(CommonEventSubscribeTest, CommonEventPublishInfo_001, TestSize.Level1)
552 {
553     Parcel parcel;
554     CommonEventPublishInfo commonEventPublishInfo;
555     bool result = commonEventPublishInfo.ReadFromParcel(parcel);
556     EXPECT_EQ(result, true);
557 }
558 
559 /*
560  * tc.number: CommonEventSubscribeInfo_001
561  * tc.name: test ReadFromParcel
562  * tc.type: FUNC
563  * tc.require: issueI5RULW
564  * tc.desc: Invoke ReadFromParcel interface verify whether it is normal
565  */
566 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribeInfo_001, TestSize.Level1)
567 {
568     Parcel parcel;
569     CommonEventSubscribeInfo commonEventSubscribeInfo;
570     bool result = commonEventSubscribeInfo.ReadFromParcel(parcel);
571     EXPECT_EQ(result, false);
572 }
573 
574 /*
575  * tc.number: MatchingSkills_001
576  * tc.name: test ReadFromParcel
577  * tc.type: FUNC
578  * tc.require: issueI5RULW
579  * tc.desc: Invoke ReadFromParcel interface verify whether it is normal
580  */
581 HWTEST_F(CommonEventSubscribeTest, MatchingSkills_001, TestSize.Level1)
582 {
583     Parcel parcel;
584     MatchingSkills matchingSkills;
585 
586     // write entity
587     int32_t value = 1;
588     parcel.WriteInt32(value);
589     std::vector<std::u16string> actionU16Entity;
590     for (std::vector<std::string>::size_type i = 0; i < 3; i++) {
591         actionU16Entity.emplace_back(OHOS::Str8ToStr16("test"));
592     }
593     matchingSkills.WriteVectorInfo(parcel, actionU16Entity);
594 
595     //write event
596     parcel.WriteInt32(value);
597     std::vector<std::u16string> actionU16Event;
598     for (std::vector<std::string>::size_type i = 0; i < 3; i++) {
599         actionU16Event.emplace_back(OHOS::Str8ToStr16("test"));
600     }
601     matchingSkills.WriteVectorInfo(parcel, actionU16Event);
602 
603     // write scheme
604     parcel.WriteInt32(value);
605     std::vector<std::u16string> actionU16Scheme;
606     for (std::vector<std::string>::size_type i = 0; i < 3; i++) {
607         actionU16Scheme.emplace_back(OHOS::Str8ToStr16("test"));
608     }
609     matchingSkills.WriteVectorInfo(parcel, actionU16Scheme);
610 
611     bool result = matchingSkills.ReadFromParcel(parcel);
612     EXPECT_EQ(result, true);
613 }
614 
615 /*
616  * tc.number: CommonEventSubscriber_001
617  * tc.name: test SetCode
618  * tc.type: FUNC
619  * tc.require: issue
620  * tc.desc: when SetCode return false
621  */
622 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscriber_001, TestSize.Level1)
623 {
624     MatchingSkills matchingSkills;
625     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
626     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
627 
628     subscriber->SetAsyncCommonEventResult(nullptr);
629     EXPECT_EQ(subscriber->CheckSynchronous(), false);
630     bool result = subscriber->SetCode(1);
631     EXPECT_EQ(result, false);
632 }
633 
634 /*
635  * tc.number: CommonEventSubscriber_002
636  * tc.name: test GetCode
637  * tc.type: FUNC
638  * tc.require: issue
639  * tc.desc: when GetCode return false
640  */
641 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscriber_002, TestSize.Level1)
642 {
643     MatchingSkills matchingSkills;
644     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
645     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
646 
647     subscriber->SetAsyncCommonEventResult(nullptr);
648     EXPECT_EQ(subscriber->CheckSynchronous(), false);
649     bool result = subscriber->GetCode();
650     EXPECT_EQ(result, false);
651 }
652 
653 /*
654  * tc.number: CommonEventSubscriber_003
655  * tc.name: test SetData
656  * tc.type: FUNC
657  * tc.require: issue
658  * tc.desc: when SetData return false
659  */
660 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscriber_003, TestSize.Level1)
661 {
662     MatchingSkills matchingSkills;
663     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
664     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
665 
666     subscriber->SetAsyncCommonEventResult(nullptr);
667     EXPECT_EQ(subscriber->CheckSynchronous(), false);
668     std::string data = "this is data";
669     bool result = subscriber->SetData(data);
670     EXPECT_EQ(result, false);
671 }
672 
673 /*
674  * tc.number: CommonEventSubscriber_004
675  * tc.name: test GetData
676  * tc.type: FUNC
677  * tc.require: issue
678  * tc.desc: when GetData return null
679  */
680 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscriber_004, TestSize.Level1)
681 {
682     MatchingSkills matchingSkills;
683     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
684     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
685 
686     subscriber->SetAsyncCommonEventResult(nullptr);
687     EXPECT_EQ(subscriber->CheckSynchronous(), false);
688     std::string result = subscriber->GetData();
689     std::string ret = "";
690     EXPECT_EQ(result, ret);
691 }
692 
693 /*
694  * tc.number: CommonEventSubscriber_005
695  * tc.name: test SetCodeAndData
696  * tc.type: FUNC
697  * tc.require: issue
698  * tc.desc: when SetCodeAndData return false
699  */
700 HWTEST_F(CommonEventSubscribeTest, CommonEventSubscriber_005, TestSize.Level1)
701 {
702     MatchingSkills matchingSkills;
703     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
704     std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscribeInfo);
705 
706     subscriber->SetAsyncCommonEventResult(nullptr);
707     EXPECT_EQ(subscriber->CheckSynchronous(), false);
708     int32_t code = 1;
709     std::string data = "this is data";
710     bool result = subscriber->SetCodeAndData(code, data);
711     EXPECT_EQ(result, false);
712 }