diff --git a/frameworks/core/include/common_event_listener.h b/frameworks/core/include/common_event_listener.h index a2c74c93bea4cfd7b687b94c5a8598928fa595e3..0e3b253f1532486920273e135e6d206f5be04fc1 100644 --- a/frameworks/core/include/common_event_listener.h +++ b/frameworks/core/include/common_event_listener.h @@ -16,6 +16,8 @@ #ifndef FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_LISTENER_H #define FOUNDATION_EVENT_CESFWK_INNERKITS_INCLUDE_COMMON_EVENT_LISTENER_H +#include + #include "event_handler.h" #include "common_event_subscriber.h" #include "event_receive_stub.h" @@ -43,6 +45,7 @@ private: void OnReceiveEvent(const CommonEventData &commonEventData, const bool &ordered, const bool &sticky); private: + std::mutex mutex_; std::shared_ptr commonEventSubscriber_; std::shared_ptr runner_; std::shared_ptr handler_; diff --git a/frameworks/core/src/common_event.cpp b/frameworks/core/src/common_event.cpp index b7becd116b4b68d11fcf7b7a73fc3688f1c5dcd6..33fa756f08f35b29fee38666f49178ae1bdc82b8 100644 --- a/frameworks/core/src/common_event.cpp +++ b/frameworks/core/src/common_event.cpp @@ -267,7 +267,6 @@ int CommonEvent::CreateCommonEventListener( EVENT_LOGW("subscriber has common event listener"); return ALREADY_SUBSCRIBED; } else { - if (eventListeners_.size() == SUBSCRIBER_MAX_SIZE) { EVENT_LOGE("the maximum number of subscriptions has been reached"); return SUBSCRIBE_FAILD; diff --git a/frameworks/core/src/common_event_listener.cpp b/frameworks/core/src/common_event_listener.cpp index 4ee7b642dfd4c39533a696bef38cd01561a6763c..b0c5ed259b88041ea96c265e3f41b172b54d6dae 100644 --- a/frameworks/core/src/common_event_listener.cpp +++ b/frameworks/core/src/common_event_listener.cpp @@ -31,6 +31,7 @@ void CommonEventListener::NotifyEvent(const CommonEventData &commonEventData, co { EVENT_LOGI("enter"); + std::lock_guard lock(mutex_); if (!IsReady()) { EVENT_LOGE("not ready"); return; @@ -45,6 +46,7 @@ ErrCode CommonEventListener::Init() { EVENT_LOGD("ready to init"); + std::lock_guard lock(mutex_); if (runner_ == nullptr) { if (!commonEventSubscriber_) { EVENT_LOGE("Failed to init with CommonEventSubscriber nullptr"); @@ -90,7 +92,9 @@ bool CommonEventListener::IsReady() void CommonEventListener::OnReceiveEvent( const CommonEventData &commonEventData, const bool &ordered, const bool &sticky) { - EVENT_LOGI("enter"); + EVENT_LOGI("enter %{public}s", commonEventData.GetWant().GetAction().c_str()); + + std::lock_guard lock(mutex_); int code = commonEventData.GetCode(); std::string data = commonEventData.GetData(); @@ -113,10 +117,13 @@ void CommonEventListener::OnReceiveEvent( if ((commonEventSubscriber_->GetAsyncCommonEventResult() != nullptr) && ordered) { commonEventSubscriber_->GetAsyncCommonEventResult()->FinishCommonEvent(); } + EVENT_LOGI("end"); } void CommonEventListener::Stop() { + EVENT_LOGI("enter"); + std::lock_guard lock(mutex_); if (handler_) { handler_.reset(); } diff --git a/services/ces/include/common_event_control_manager.h b/services/ces/include/common_event_control_manager.h index d2ad30bfaa167fa8b39f8f695f4f0909c5d71061..16b7ec1947f3e8c68094c5ad11a720f194731691 100644 --- a/services/ces/include/common_event_control_manager.h +++ b/services/ces/include/common_event_control_manager.h @@ -35,7 +35,7 @@ public: bool PublishCommonEvent(const CommonEventRecord &eventRecord, const sptr &commonEventListener); - std::shared_ptr GetMatchingOrderedReceiver(sptr proxy); + std::shared_ptr GetMatchingOrderedReceiver(const sptr &proxy); bool FinishReceiverAction(std::shared_ptr recordPtr, const int &code, const std::string &receiverData, const bool &abortEvent); @@ -95,24 +95,24 @@ private: void GetUnorderedEventRecords(const std::string &event, std::vector> &records); - void GetHistoryEventRecords(const std::string &event, std::vector &records); + void GetHistoryEventRecords(const std::string &event, std::vector &records); void DumpStateByCommonEventRecord(const std::shared_ptr &record, std::string &dumpInfo); void DumpStateBySubscriberRecord(const std::shared_ptr &record, std::string &dumpInfo); - void DumpHistoryStateBySubscriberRecord(const History_event_record &record, std::string &dumpInfo); + void DumpHistoryStateBySubscriberRecord(const HistoryEventRecord &record, std::string &dumpInfo); - void DumpHistoryStateByCommonEventRecord(const History_event_record &record, std::string &dumpInfo); + void DumpHistoryStateByCommonEventRecord(const HistoryEventRecord &record, std::string &dumpInfo); - void EnqueueHistoryEventRecord(const std::shared_ptr &eventRecordPtr); + void EnqueueHistoryEventRecord(const std::shared_ptr &eventRecordPtr, bool hasLastSubscribe); private: std::shared_ptr handler_; std::shared_ptr handlerOrdered_; std::vector> orderedEventQueue_; std::vector> unorderedEventQueue_; - std::vector historyEventRecords_; + std::vector historyEventRecords_; bool pendingTimeoutMessage_; bool scheduled_; const int64_t TIMEOUT = 10000; // How long we allow a receiver to run before giving up on it. Unit: ms diff --git a/services/ces/include/history_event_record.h b/services/ces/include/history_event_record.h index d8211b3331c5aa2dac712ea2dd93a50e43cea055..0573f60e89e85f226d64d5b5044d47f73a06442e 100644 --- a/services/ces/include/history_event_record.h +++ b/services/ces/include/history_event_record.h @@ -34,13 +34,13 @@ struct HistorySubscriberRecord { {} }; -struct History_event_record { - enum EventState_ { +struct HistoryEventRecord { + enum EventState { IDLE = 0, RECEIVEING, RECEIVED, }; - enum DeliveryState_ { + enum DeliveryState { PENDING = 0, DELIVERED, SKIPPED, @@ -62,21 +62,21 @@ struct History_event_record { bool isSystemEvent; std::vector receivers; - sptr resultTo; + bool hasLastSubscribe; std::vector deliveryState; int64_t dispatchTime; int64_t receiverTime; int state; bool resultAbort; - History_event_record() + HistoryEventRecord() : code(0), sticky(false), ordered(false), pid(0), uid(0), isSystemEvent(false), - resultTo(nullptr), + hasLastSubscribe(false), dispatchTime(0), receiverTime(0), state(0), diff --git a/services/ces/include/ordered_event_record.h b/services/ces/include/ordered_event_record.h index c6b91e167edc2047d78a7d96759b9ab2caadfa8d..cdc7e365d0701423c459ef9d9819f7bdb30edeb5 100644 --- a/services/ces/include/ordered_event_record.h +++ b/services/ces/include/ordered_event_record.h @@ -22,13 +22,13 @@ namespace OHOS { namespace EventFwk { struct OrderedEventRecord : public CommonEventRecord { - enum EventState_ { + enum EventState { IDLE = 0, RECEIVEING, RECEIVED, }; - enum DeliveryState_ { + enum DeliveryState { PENDING = 0, DELIVERED, SKIPPED, diff --git a/services/ces/src/common_event_control_manager.cpp b/services/ces/src/common_event_control_manager.cpp index 0ebca62926553239791652f359cbecaa6d722d8b..514e4ebe61d52748eedbf7d0843788481f67bd9a 100644 --- a/services/ces/src/common_event_control_manager.cpp +++ b/services/ces/src/common_event_control_manager.cpp @@ -122,6 +122,10 @@ bool CommonEventControlManager::GetUnorderedEventHandler() bool CommonEventControlManager::NotifyUnorderedEvent(std::shared_ptr &eventRecord) { EVENT_LOGI("enter"); + if (!eventRecord) { + EVENT_LOGI("Invalid event record."); + return false; + } std::lock_guard lock(unorderedMutex_); EVENT_LOGI("event = %{public}s, receivers size = %{public}zu", eventRecord->commonEventData->GetWant().GetAction().c_str(), eventRecord->receivers.size()); @@ -149,7 +153,7 @@ bool CommonEventControlManager::NotifyUnorderedEvent(std::shared_ptr CommonEventControlManager::GetMatchingOrderedReceiver(sptr proxy) +std::shared_ptr CommonEventControlManager::GetMatchingOrderedReceiver( + const sptr &proxy) { EVENT_LOGI("enter"); @@ -290,7 +295,8 @@ bool CommonEventControlManager::EnqueueOrderedRecord(const std::shared_ptr &eventRecordPtr) +void CommonEventControlManager::EnqueueHistoryEventRecord( + const std::shared_ptr &eventRecordPtr, bool hasLastSubscribe) { EVENT_LOGI("enter"); @@ -299,7 +305,7 @@ void CommonEventControlManager::EnqueueHistoryEventRecord(const std::shared_ptr< return; } - History_event_record record; + HistoryEventRecord record; record.want = eventRecordPtr->commonEventData->GetWant(); record.code = eventRecordPtr->commonEventData->GetCode(); record.data = eventRecordPtr->commonEventData->GetData(); @@ -326,7 +332,7 @@ void CommonEventControlManager::EnqueueHistoryEventRecord(const std::shared_ptr< record.receivers.emplace_back(receiver); } - record.resultTo = eventRecordPtr->resultTo; + record.hasLastSubscribe = hasLastSubscribe; record.deliveryState = eventRecordPtr->deliveryState; record.dispatchTime = eventRecordPtr->dispatchTime; record.receiverTime = eventRecordPtr->receiverTime; @@ -439,6 +445,7 @@ void CommonEventControlManager::ProcessNextOrderedEvent(bool isSendMsg) if ((sp->receivers.size() == 0) || (sp->nextReceiver >= numReceivers) || sp->resultAbort || forceReceive) { // No more receivers for this ordered common event, then process the final result receiver + bool hasLastSubscribe = (sp->resultTo != nullptr) ? true : false; if (sp->resultTo != nullptr) { EVENT_LOGI("Process the final subscriber"); sptr receiver = iface_cast(sp->resultTo); @@ -447,11 +454,12 @@ void CommonEventControlManager::ProcessNextOrderedEvent(bool isSendMsg) return; } receiver->NotifyEvent(*(sp->commonEventData), true, sp->publishInfo->IsSticky()); + sp->resultTo = nullptr; } CancelTimeout(); - EnqueueHistoryEventRecord(sp); + EnqueueHistoryEventRecord(sp, hasLastSubscribe); orderedEventQueue_.erase(orderedEventQueue_.begin()); @@ -756,7 +764,7 @@ void CommonEventControlManager::GetOrderedEventRecords( } void CommonEventControlManager::GetHistoryEventRecords( - const std::string &event, std::vector &records) + const std::string &event, std::vector &records) { EVENT_LOGI("enter"); if (event.empty()) { @@ -870,7 +878,7 @@ void CommonEventControlManager::DumpStateByCommonEventRecord( } void CommonEventControlManager::DumpHistoryStateByCommonEventRecord( - const History_event_record &record, std::string &dumpInfo) + const HistoryEventRecord &record, std::string &dumpInfo) { EVENT_LOGI("enter"); @@ -940,7 +948,7 @@ void CommonEventControlManager::DumpHistoryStateByCommonEventRecord( std::string data = "\tData: " + record.data + "\n"; std::string lastSubscriber; - if (record.resultTo) { + if (record.hasLastSubscribe) { lastSubscriber = "\tHasLastSubscriber: true\n"; } else { lastSubscriber = "\tHasLastSubscriber: false\n"; @@ -1014,7 +1022,7 @@ void CommonEventControlManager::DumpStateBySubscriberRecord( } void CommonEventControlManager::DumpHistoryStateBySubscriberRecord( - const History_event_record &record, std::string &dumpInfo) + const HistoryEventRecord &record, std::string &dumpInfo) { EVENT_LOGI("enter"); @@ -1117,7 +1125,7 @@ void CommonEventControlManager::DumpHistoryState(const std::string &event, std:: { EVENT_LOGI("enter"); - std::vector records; + std::vector records; std::lock_guard lock(historyMutex_); GetHistoryEventRecords(event, records); diff --git a/services/test/unittest/common_event_dump_test.cpp b/services/test/unittest/common_event_dump_test.cpp index dd74f003d424d046a19a43116df31d89f1018de8..964d1324c9a91004d7fa4c7af2d7243526ff30c5 100644 --- a/services/test/unittest/common_event_dump_test.cpp +++ b/services/test/unittest/common_event_dump_test.cpp @@ -52,8 +52,6 @@ const std::string SCHEME2 = "com.ces.test.scheme2"; const std::string PERMISSION2 = "com.ces.test.permission2"; const std::string DEVICEDID2 = "deviceId2"; const std::string TYPE2 = "type2"; -const std::string BUNDLE2 = "BundleName"; -const std::string ABILITY2 = "AbilityName"; const int PRIORITY2 = 2; const int FLAG2 = 2; const int CODE2 = 2; @@ -75,8 +73,25 @@ const uid_t UID2 = 11; const int STATE_INDEX1 = 1; const int STATE_INDEX2 = 2; const int STATE_INDEX3 = 3; -const int DUMP_INFO_COUNT = 2; const int PUBLISH_COUNT = 60; +const int DUMP_SUBSCRIBER_COUNT_ONE = 1; +const int DUMP_SUBSCRIBER_COUNT_TWO = 2; +const int DUMP_SUBSCRIBER_COUNT_FOUR = 4; +const int DUMP_STICKY_COUNT_ONE = 1; +const int DUMP_STICKY_COUNT_TWO = 2; +const int DUMP_PENDING_COUNT_ONE = 1; +const int DUMP_HISTORY_COUNT_ONE = 1; +const int DUMP_HISTORY_COUNT_TWO = 2; +const int DUMP_HISTORY_COUNT_FOUR = 4; +const int DUMP_HISTORY_COUNT_SIX = 6; +const int DUMP_HISTORY_COUNT_NINE = 9; +const int DUMP_HISTORY_COUNT_TEN = 10; +const int DUMP_HISTORY_COUNT_ELEVEN = 11; +const int DUMP_HISTORY_COUNT_TWELVE = 12; +const int DUMP_HISTORY_COUNT_THIRTEEN = 13; +const int DUMP_HISTORY_COUNT_FOURTEEN = 14; +const int DUMP_HISTORY_COUNT_FIFTEEN = 15; +const int DUMP_HISTORY_COUNT_MAX = 100; static OHOS::sptr bundleObject = nullptr; OHOS::sptr commonEventListener; @@ -105,7 +120,7 @@ public: int desOrderedCount, int desHistoryCount); void SetPublishDataByOrdered(CommonEventData &data, CommonEventPublishInfo &publishInfo); void SetPublishDataByOrdered2(CommonEventData &data, CommonEventPublishInfo &publishInfo); - void SetPublishDataByOrdered3(CommonEventData &data, CommonEventPublishInfo &publishInfo); + void SetPublishDataByUnordered(CommonEventData &data, CommonEventPublishInfo &publishInfo); private: std::shared_ptr runner_; @@ -202,14 +217,15 @@ private: if (innerCommonEventManager_) { std::vector state; innerCommonEventManager_->DumpState("", state); - CommonEventDumpTest::dumpInfoCount(state, DUMP_INFO_COUNT, DUMP_INFO_COUNT, 1, 0); + CommonEventDumpTest::dumpInfoCount(state, + DUMP_SUBSCRIBER_COUNT_TWO, DUMP_STICKY_COUNT_TWO, DUMP_PENDING_COUNT_ONE, 0); } std::function asyncProcessFunc = std::bind(&SubscriberTest2::AsyncProcess, this, commonEventListener2); handler_->PostTask(asyncProcessFunc); } void ProcessSubscriberTest2Case2(CommonEventData data) { - GTEST_LOG_(INFO) << "ProcessSubscriberTest2Case1: start"; + GTEST_LOG_(INFO) << "ProcessSubscriberTest2Case2: start"; std::shared_ptr result = GoAsyncCommonEvent(); std::function asyncProcessFunc = std::bind(&SubscriberTest2::AsyncProcess, this, commonEventListener2); handler_->PostTask(asyncProcessFunc); @@ -234,7 +250,7 @@ public: handler_ = std::make_shared(EventRunner::Create()); }; - SubscriberTestLast(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + explicit SubscriberTestLast(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) { handler_ = std::make_shared(EventRunner::Create()); }; @@ -490,7 +506,7 @@ void CommonEventDumpTest::SetPublishDataByOrdered2(CommonEventData &data, Common publishInfo.SetOrdered(true); } -void CommonEventDumpTest::SetPublishDataByOrdered3(CommonEventData &data, CommonEventPublishInfo &publishInfo) +void CommonEventDumpTest::SetPublishDataByUnordered(CommonEventData &data, CommonEventPublishInfo &publishInfo) { // make a want Want want; @@ -514,20 +530,19 @@ void CommonEventDumpTest::SetPublishDataByOrdered3(CommonEventData &data, Common publishInfo.SetOrdered(false); } -static void SetMatchingSkills(MatchingSkills &matchingSkills) +static void SubscribeDoubleEvent( + int priority, const std::string &permission, const std::string &deviceId, CommonEventListener *&listener) { + MatchingSkills matchingSkills; matchingSkills.AddEvent(EVENT); matchingSkills.AddEvent(EVENT2); matchingSkills.AddEntity(ENTITY); matchingSkills.AddEntity(ENTITY2); -} -static void SetSubscribeInfo1(CommonEventListener *&listener, const MatchingSkills &matchingSkills) -{ CommonEventSubscribeInfo subscribeInfo(matchingSkills); - subscribeInfo.SetPriority(PRIORITY); - subscribeInfo.SetPermission(PERMISSION); - subscribeInfo.SetDeviceId(DEVICEDID); + subscribeInfo.SetPriority(priority); + subscribeInfo.SetPermission(permission); + subscribeInfo.SetDeviceId(deviceId); std::shared_ptr subscriber = std::make_shared(subscribeInfo); listener = new (std::nothrow) CommonEventListener(subscriber); @@ -536,26 +551,15 @@ static void SetSubscribeInfo1(CommonEventListener *&listener, const MatchingSkil subscribeInfo, listener->AsObject()); } -static void SetSubscribeInfo2(CommonEventListener *&listener, const MatchingSkills &matchingSkills) -{ - CommonEventSubscribeInfo subscribeInfo(matchingSkills); - subscribeInfo.SetPriority(PRIORITY2); - subscribeInfo.SetPermission(PERMISSION2); - subscribeInfo.SetDeviceId(DEVICEDID2); - std::shared_ptr subscriber = std::make_shared(subscribeInfo); - listener = new (std::nothrow) CommonEventListener(subscriber); - OHOS::DelayedSingleton::GetInstance()->SubscribeCommonEvent( - subscribeInfo, listener->AsObject()); -} - -static void Test0100Publish1() +static void PublishUnorderedEvent( + const std::string &event, const std::string &type, + const int code, const std::string &data, const std::string &permission) { Want want; - want.SetAction(EVENT); + want.SetAction(event); want.AddEntity(ENTITY); want.AddEntity(ENTITY2); - want.SetType(TYPE); - want.SetFlags(FLAG); + want.SetType(type); OHOS::AppExecFwk::ElementName element; element.SetBundleName(BUNDLE); @@ -564,64 +568,31 @@ static void Test0100Publish1() want.SetElement(element); // make common event data - CommonEventData data; - data.SetWant(want); - data.SetCode(CODE); - data.SetData(DATA); + CommonEventData eventData; + eventData.SetWant(want); + eventData.SetCode(code); + eventData.SetData(data); // make publish info CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(false); - std::vector permissions; - permissions.emplace_back(PERMISSION); + permissions.emplace_back(permission); publishInfo.SetSubscriberPermissions(permissions); - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); -} - -static void Test0100Publish2() -{ - Want want2; - want2.SetAction(EVENT2); - want2.AddEntity(ENTITY); - want2.AddEntity(ENTITY2); - want2.SetType(TYPE2); - want2.SetFlags(FLAG2); - - OHOS::AppExecFwk::ElementName element2; - element2.SetBundleName(BUNDLE); - element2.SetAbilityName(ABILITY); - element2.SetDeviceID(DEVICEDID); - want2.SetElement(element2); - - // make common event data - CommonEventData data2; - data2.SetWant(want2); - data2.SetCode(CODE2); - data2.SetData(DATA2); - - // make publish info - CommonEventPublishInfo publishInfo2; - - publishInfo2.SetSticky(false); - - std::vector permissions; - permissions.emplace_back(PERMISSION2); - publishInfo2.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data2, publishInfo2, nullptr); + OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent( + eventData, publishInfo, nullptr); } -static void Test0200Publish1() +static void PublishStickyEvent( + const std::string &event, const std::string &type, + const int code, const std::string &data, const std::string &permission) { Want want; - want.SetAction(EVENT); + want.SetAction(event); want.AddEntity(ENTITY); want.AddEntity(ENTITY2); - want.SetType(TYPE); - want.SetFlags(FLAG); + want.SetType(type); OHOS::AppExecFwk::ElementName element; element.SetBundleName(BUNDLE); @@ -630,86 +601,78 @@ static void Test0200Publish1() want.SetElement(element); // make common event data - CommonEventData data; - data.SetWant(want); - data.SetCode(CODE); - data.SetData(DATA); + CommonEventData eventData; + eventData.SetWant(want); + eventData.SetCode(code); + eventData.SetData(data); // make publish info CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(true); - std::vector permissions; - permissions.emplace_back(PERMISSION); + permissions.emplace_back(permission); publishInfo.SetSubscriberPermissions(permissions); - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); + OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent( + eventData, publishInfo, nullptr); } -static void Test0200Publish2() +static void PublishStickyEvent( + const std::string &event, const std::string &type, const int flag, const std::string &permission) { - Want want2; - want2.SetAction(EVENT2); - want2.AddEntity(ENTITY); - want2.AddEntity(ENTITY2); - want2.SetType(TYPE2); - want2.SetFlags(FLAG2); - - OHOS::AppExecFwk::ElementName element2; - element2.SetBundleName(BUNDLE); - element2.SetAbilityName(ABILITY); - element2.SetDeviceID(DEVICEDID); - want2.SetElement(element2); + Want want; + want.SetAction(event); + want.AddEntity(ENTITY); + want.AddEntity(ENTITY2); + want.SetType(type); + want.SetFlags(flag); + + OHOS::AppExecFwk::ElementName element; + element.SetBundleName(BUNDLE); + element.SetAbilityName(ABILITY); + element.SetDeviceID(DEVICEDID); + want.SetElement(element); // make common event data - CommonEventData data2; - data2.SetWant(want2); - data2.SetCode(CODE2); - data2.SetData(DATA2); + CommonEventData eventData; + eventData.SetWant(want); // make publish info - CommonEventPublishInfo publishInfo2; - - publishInfo2.SetSticky(true); - + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); std::vector permissions; - permissions.emplace_back(PERMISSION2); - publishInfo2.SetSubscriberPermissions(permissions); + permissions.emplace_back(permission); + publishInfo.SetSubscriberPermissions(permissions); - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data2, publishInfo2, nullptr); + OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent( + eventData, publishInfo, nullptr); } /* * @tc.number: CommonEventDumpTest_0100 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after publishing unordered events */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0100, Function | MediumTest | Level1) { /* Subscribe */ - MatchingSkills matchingSkills; CommonEventListener *listener = nullptr; CommonEventListener *listener2 = nullptr; - - SetMatchingSkills(matchingSkills); - - SetSubscribeInfo1(listener, matchingSkills); - - SetSubscribeInfo2(listener2, matchingSkills); + SubscribeDoubleEvent(PRIORITY, PERMISSION, DEVICEDID, listener); + SubscribeDoubleEvent(PRIORITY2, PERMISSION2, DEVICEDID2, listener2); + EXPECT_NE(nullptr, listener); + EXPECT_NE(nullptr, listener2); /* Publish */ - Test0100Publish1(); - - Test0100Publish2(); + PublishUnorderedEvent(EVENT, TYPE, CODE, DATA, PERMISSION); + PublishUnorderedEvent(EVENT2, TYPE2, CODE2, DATA2, PERMISSION2); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, DUMP_INFO_COUNT, 0, 0, 2); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_TWO, 0, 0, DUMP_HISTORY_COUNT_TWO); EXPECT_EQ("Sticky Events:\tNo information", state[STATE_INDEX2]); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); @@ -719,33 +682,28 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0100, Function | MediumTest | /* * @tc.number: CommonEventDumpTest_0200 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after publishing sticky events */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0200, Function | MediumTest | Level1) { /* Subscribe */ - MatchingSkills matchingSkills; CommonEventListener *listener = nullptr; CommonEventListener *listener2 = nullptr; - - SetMatchingSkills(matchingSkills); - - SetSubscribeInfo1(listener, matchingSkills); - - SetSubscribeInfo2(listener2, matchingSkills); + SubscribeDoubleEvent(PRIORITY, PERMISSION, DEVICEDID, listener); + SubscribeDoubleEvent(PRIORITY2, PERMISSION2, DEVICEDID2, listener2); + EXPECT_NE(nullptr, listener); + EXPECT_NE(nullptr, listener2); /* Publish */ - Test0200Publish1(); - - Test0200Publish2(); + PublishStickyEvent(EVENT, TYPE, CODE, DATA, PERMISSION); + PublishStickyEvent(EVENT2, TYPE2, CODE2, DATA2, PERMISSION2); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, DUMP_INFO_COUNT, DUMP_INFO_COUNT, 0, 4); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_TWO, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_FOUR); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener2->AsObject()); @@ -754,80 +712,27 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0200, Function | MediumTest | /* * @tc.number: CommonEventDumpTest_0300 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after updating sticky events */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0300, Function | MediumTest | Level1) { /* Publish */ - // make a want - Want want; - want.SetAction(EVENT); - want.AddEntity(ENTITY); - want.AddEntity(ENTITY2); - want.SetType(TYPE); - want.SetFlags(FLAG); - - OHOS::AppExecFwk::ElementName element; - element.SetBundleName(BUNDLE); - element.SetAbilityName(ABILITY); - element.SetDeviceID(DEVICEDID); - want.SetElement(element); - - // make common event data - CommonEventData data; - data.SetWant(want); - - // make publish info - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION); - publishInfo.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); - - // make a want - Want want2; - want2.SetAction(EVENT2); - want2.AddEntity(ENTITY); - want2.AddEntity(ENTITY2); - want2.SetType(TYPE2); - want2.SetFlags(FLAG2); - - OHOS::AppExecFwk::ElementName element2; - element2.SetBundleName(BUNDLE); - element2.SetAbilityName(ABILITY); - element2.SetDeviceID(DEVICEDID); - want2.SetElement(element2); - - // make common event data - CommonEventData data2; - data2.SetWant(want2); - - // make publish info - CommonEventPublishInfo publishInfo2; - publishInfo2.SetSticky(true); - - permissions.emplace_back(PERMISSION2); - publishInfo2.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data2, publishInfo2, nullptr); + PublishStickyEvent(EVENT, TYPE, FLAG, PERMISSION); + PublishStickyEvent(EVENT2, TYPE2, FLAG2, PERMISSION2); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 6); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_SIX); EXPECT_EQ("Subscribers:\tNo information", state[0]); } /* * @tc.number: CommonEventDumpTest_0400 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after subscribing */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0400, Function | MediumTest | Level1) { @@ -849,10 +754,9 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0400, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 1, DUMP_INFO_COUNT, 0, 6); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_ONE, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_SIX); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); } @@ -860,7 +764,7 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0400, Function | MediumTest | /* * @tc.number: CommonEventDumpTest_0500 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after subscribing */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0500, Function | MediumTest | Level1) { @@ -881,10 +785,9 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0500, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 1, DUMP_INFO_COUNT, 0, 6); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_ONE, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_SIX); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); } @@ -892,7 +795,7 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0500, Function | MediumTest | /* * @tc.number: CommonEventDumpTest_0600 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after subscribing */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0600, Function | MediumTest | Level1) { @@ -912,10 +815,9 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0600, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 1, DUMP_INFO_COUNT, 0, 6); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_ONE, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_SIX); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); } @@ -923,7 +825,7 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0600, Function | MediumTest | /* * @tc.number: CommonEventDumpTest_0700 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after subscribing */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0700, Function | MediumTest | Level1) { @@ -942,10 +844,9 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0700, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 1, DUMP_INFO_COUNT, 0, 6); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_ONE, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_SIX); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); } @@ -953,7 +854,7 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0700, Function | MediumTest | /* * @tc.number: CommonEventDumpTest_0800 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information after subscribing */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0800, Function | MediumTest | Level1) { @@ -971,10 +872,9 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0800, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 1, DUMP_INFO_COUNT, 0, 6); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_ONE, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_SIX); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); } @@ -982,7 +882,7 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0800, Function | MediumTest | /* * @tc.number: CommonEventDumpTest_0900 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for unpublished event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0900, Function | MediumTest | Level1) { @@ -1000,8 +900,7 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0900, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState(EVENT3, state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState(EVENT3, state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); dumpInfoCount(state, 0, 0, 0, 0); EXPECT_EQ("Subscribers:\tNo information", state[0]); @@ -1010,99 +909,31 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_0900, Function | MediumTest | OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); } -void Test100Publish1() -{ - Want want; - want.SetAction(EVENT); - want.AddEntity(ENTITY); - want.AddEntity(ENTITY2); - want.SetType(TYPE); - want.SetFlags(FLAG); - - OHOS::AppExecFwk::ElementName element; - element.SetBundleName(BUNDLE); - element.SetAbilityName(ABILITY); - element.SetDeviceID(DEVICEDID); - want.SetElement(element); - - // make common event data - CommonEventData data; - data.SetWant(want); - - // make publish info - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION); - publishInfo.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); -} - -void Test100Publish2() -{ - Want want2; - want2.SetAction(EVENT2); - want2.AddEntity(ENTITY); - want2.AddEntity(ENTITY2); - want2.SetType(TYPE2); - want2.SetFlags(FLAG2); - - OHOS::AppExecFwk::ElementName element2; - element2.SetBundleName(BUNDLE); - element2.SetAbilityName(ABILITY); - element2.SetDeviceID(DEVICEDID); - want2.SetElement(element2); - - // make common event data - CommonEventData data2; - data2.SetWant(want2); - - // make publish info - CommonEventPublishInfo publishInfo2; - - publishInfo2.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION2); - publishInfo2.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data2, publishInfo2, nullptr); -} - /* * @tc.number: CommonEventDumpTest_1000 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for specified event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1000, TestSize.Level1) { /* Subscribe */ - MatchingSkills matchingSkills; CommonEventListener *listener = nullptr; CommonEventListener *listener2 = nullptr; - - SetMatchingSkills(matchingSkills); - - SetSubscribeInfo1(listener, matchingSkills); - - SetSubscribeInfo2(listener2, matchingSkills); + SubscribeDoubleEvent(PRIORITY, PERMISSION, DEVICEDID, listener); + SubscribeDoubleEvent(PRIORITY2, PERMISSION2, DEVICEDID2, listener2); + EXPECT_NE(nullptr, listener); + EXPECT_NE(nullptr, listener2); /* Publish */ - // Publish1 - Test100Publish1(); - - // Publish1 - Test100Publish2(); + PublishStickyEvent(EVENT, TYPE, FLAG, PERMISSION); + PublishStickyEvent(EVENT2, TYPE2, FLAG2, PERMISSION2); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState(EVENT2, state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState(EVENT2, state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, DUMP_INFO_COUNT, 1, 0, 4); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_TWO, DUMP_STICKY_COUNT_ONE, 0, DUMP_HISTORY_COUNT_FOUR); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener->AsObject()); OHOS::DelayedSingleton::GetInstance()->UnsubscribeCommonEvent(listener2->AsObject()); @@ -1111,210 +942,97 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1000, TestSize.Level1) /* * @tc.number: CommonEventDumpTest_1100 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for sticky event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1100, Function | MediumTest | Level1) { /* Publish */ - // make a want - Want want; - want.SetAction(EVENT); - want.SetType(TYPE); - want.SetFlags(FLAG); - - OHOS::AppExecFwk::ElementName element; - element.SetBundleName(BUNDLE); - element.SetAbilityName(ABILITY); - element.SetDeviceID(DEVICEDID); - want.SetElement(element); - - // make common event data - CommonEventData data; - data.SetWant(want); - - // make publish info - CommonEventPublishInfo publishInfo; - - publishInfo.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION); - publishInfo.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); + PublishStickyEvent(EVENT, TYPE, FLAG, PERMISSION); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 9); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_NINE); } /* * @tc.number: CommonEventDumpTest_1200 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for sticky event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1200, Function | MediumTest | Level1) { /* Publish */ - // make a want - Want want; - want.SetAction(EVENT); - want.SetFlags(FLAG); - - OHOS::AppExecFwk::ElementName element; - element.SetBundleName(BUNDLE); - element.SetAbilityName(ABILITY); - element.SetDeviceID(DEVICEDID); - want.SetElement(element); - - // make common event data - CommonEventData data; - data.SetWant(want); - - // make publish info - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION); - publishInfo.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); + PublishStickyEvent(EVENT, "", FLAG, PERMISSION); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 10); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_TEN); } /* * @tc.number: CommonEventDumpTest_1300 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for sticky event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1300, Function | MediumTest | Level1) { /* Publish */ - // make a want - Want want; - want.SetAction(EVENT); - - OHOS::AppExecFwk::ElementName element; - element.SetBundleName(BUNDLE); - element.SetAbilityName(ABILITY); - element.SetDeviceID(DEVICEDID); - want.SetElement(element); - - // make common event data - CommonEventData data; - data.SetWant(want); - - // make publish info - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION); - publishInfo.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); + PublishStickyEvent(EVENT, "", 0, PERMISSION); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 11); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_ELEVEN); } /* * @tc.number: CommonEventDumpTest_1400 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for sticky event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1400, Function | MediumTest | Level1) { /* Publish */ - // make a want - Want want; - want.SetAction(EVENT); - OHOS::AppExecFwk::ElementName element; - element.SetAbilityName(ABILITY); - element.SetDeviceID(DEVICEDID); - want.SetElement(element); - - // make common event data - CommonEventData data; - data.SetWant(want); - - // make publish info - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION); - publishInfo.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); + PublishStickyEvent(EVENT, "", 0, PERMISSION); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 12); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_TWELVE); } /* * @tc.number: CommonEventDumpTest_1500 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for sticky event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1500, Function | MediumTest | Level1) { /* Publish */ - // make a want - Want want; - want.SetAction(EVENT); - OHOS::AppExecFwk::ElementName element; - element.SetDeviceID(DEVICEDID); - want.SetElement(element); - // make common event data - CommonEventData data; - data.SetWant(want); - - // make publish info - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(true); - - std::vector permissions; - permissions.emplace_back(PERMISSION); - publishInfo.SetSubscriberPermissions(permissions); - - OHOS::DelayedSingleton::GetInstance()->PublishCommonEvent(data, publishInfo, nullptr); + PublishStickyEvent(EVENT, "", 0, PERMISSION); sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 13); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_THIRTEEN); } /* * @tc.number: CommonEventDumpTest_1600 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for sticky event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1600, Function | MediumTest | Level1) { @@ -1339,16 +1057,15 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1600, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 14); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_FOURTEEN); } /* * @tc.number: CommonEventDumpTest_1700 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for sticky event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1700, Function | MediumTest | Level1) { @@ -1369,33 +1086,31 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1700, Function | MediumTest | sleep(1); std::vector state; - bool dumpResult = OHOS::DelayedSingleton::GetInstance()->DumpState("", state); - EXPECT_EQ(true, dumpResult); + EXPECT_EQ(true, OHOS::DelayedSingleton::GetInstance()->DumpState("", state)); GTEST_LOG_(INFO) << "get state size:" << state.size(); - dumpInfoCount(state, 0, DUMP_INFO_COUNT, 0, 15); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_FIFTEEN); } /* * @tc.number: CommonEventDumpTest_1800 * @tc.name: test dump - * @tc.desc: The ordered event is empty + * @tc.desc: Verify dump information when the peding ordered event is empty */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1800, TestSize.Level1) { std::vector state; - CommonEventDumpTest::getInnerCommonEventManager()->DumpState("", state); - CommonEventDumpTest::dumpInfoCount(state, 0, 2, 0, 0); + getInnerCommonEventManager()->DumpState("", state); + dumpInfoCount(state, 0, DUMP_STICKY_COUNT_TWO, 0, 0); EXPECT_EQ("Pending Events:\tNo information", state[STATE_INDEX3]); } /* * @tc.number: CommonEventDumpTest_1900 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for ordered event */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1900, TestSize.Level1) { - /* Subscribe */ // make matching skills MatchingSkills matchingSkills; @@ -1410,25 +1125,19 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1900, TestSize.Level1) std::shared_ptr subscriberTest = std::make_shared(subscribeInfo, getInnerCommonEventManager()); // subscribe a common event - bool subscribeResult = SubscribeCommonEvent(subscriberTest, UID, commonEventListener); - EXPECT_EQ(true, subscribeResult); - - // make another matching skills - MatchingSkills matchingSkillsAnother; - matchingSkillsAnother.AddEvent(EVENTCASE1); - matchingSkillsAnother.AddEntity(ENTITY); - matchingSkillsAnother.AddEntity(ENTITY2); + EXPECT_EQ(true, SubscribeCommonEvent(subscriberTest, UID, commonEventListener)); + sleep(1); + // make another subcriber info - CommonEventSubscribeInfo subscribeInfo2(matchingSkillsAnother); + CommonEventSubscribeInfo subscribeInfo2(matchingSkills); subscribeInfo2.SetPriority(0); subscribeInfo2.SetDeviceId(DEVICEDID2); // make another subcriber object std::shared_ptr subscriberTest2 = std::make_shared(subscribeInfo2, getInnerCommonEventManager()); - // subscribe another event - bool subscribeResult2 = SubscribeCommonEvent(subscriberTest2, UID2, commonEventListener2); - EXPECT_EQ(true, subscribeResult2); + EXPECT_EQ(true, SubscribeCommonEvent(subscriberTest2, UID2, commonEventListener2)); + sleep(1); std::shared_ptr subscriber = std::make_shared(); @@ -1437,28 +1146,29 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_1900, TestSize.Level1) CommonEventPublishInfo publishInfo; SetPublishDataByOrdered(data, publishInfo); - sleep(PUBLISH_SLEEP); - // publish order event - bool publishResult = PublishCommonEvent(data, publishInfo, subscriber, commonEventListener3); - EXPECT_EQ(true, publishResult); + EXPECT_EQ(true, PublishCommonEvent(data, publishInfo, subscriber, commonEventListener3)); sleep(PUBLISH_SLEEP); + + std::vector state; + getInnerCommonEventManager()->DumpState("", state); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_TWO, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_ONE); } /* * @tc.number: CommonEventDumpTest_2000 * @tc.name: test dump - * @tc.desc: Verify after subscribe can get subscriber info to do uid is not right + * @tc.desc: Verify dump information for maximum number of history events */ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_2000, TestSize.Level1) { - /* Subscribe */ // make matching skills MatchingSkills matchingSkills; matchingSkills.AddEvent(EVENTCASE2); matchingSkills.AddEntity(ENTITY); matchingSkills.AddEntity(ENTITY2); + // make subcriber info CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPriority(1); @@ -1467,25 +1177,19 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_2000, TestSize.Level1) std::shared_ptr subscriberTest = std::make_shared(subscribeInfo, getInnerCommonEventManager()); // subscribe a common event - bool subscribeResult = SubscribeCommonEvent(subscriberTest, UID, commonEventListener); - EXPECT_EQ(true, subscribeResult); - - // make another matching skills - MatchingSkills matchingSkillsAnother; - matchingSkillsAnother.AddEvent(EVENTCASE2); - matchingSkillsAnother.AddEntity(ENTITY); - matchingSkillsAnother.AddEntity(ENTITY2); + EXPECT_EQ(true, SubscribeCommonEvent(subscriberTest, UID, commonEventListener)); + sleep(1); + // make another subcriber info - CommonEventSubscribeInfo subscribeInfo2(matchingSkillsAnother); + CommonEventSubscribeInfo subscribeInfo2(matchingSkills); subscribeInfo2.SetPriority(0); subscribeInfo2.SetDeviceId(DEVICEDID2); // make another subcriber object std::shared_ptr subscriberTest2 = std::make_shared(subscribeInfo2, getInnerCommonEventManager()); - // subscribe another event - bool subscribeResult2 = SubscribeCommonEvent(subscriberTest2, UID2, commonEventListener2); - EXPECT_EQ(true, subscribeResult2); + EXPECT_EQ(true, SubscribeCommonEvent(subscriberTest2, UID2, commonEventListener2)); + sleep(1); std::shared_ptr subscriber = std::make_shared(); @@ -1493,23 +1197,23 @@ HWTEST_F(CommonEventDumpTest, CommonEventDumpTest_2000, TestSize.Level1) CommonEventData data; CommonEventPublishInfo publishInfo; - sleep(PUBLISH_SLEEP); int count = 0; while (count < PUBLISH_COUNT) { // publish order event SetPublishDataByOrdered2(data, publishInfo); - bool publishResult = PublishCommonEvent(data, publishInfo, subscriber, commonEventListener3); - EXPECT_EQ(true, publishResult); + EXPECT_EQ(true, PublishCommonEvent(data, publishInfo, subscriber, commonEventListener3)); + sleep(1); // publish unorder event - SetPublishDataByOrdered3(data, publishInfo); - publishResult = PublishCommonEvent(data, publishInfo, subscriber, commonEventListener3); - EXPECT_EQ(true, publishResult); + SetPublishDataByUnordered(data, publishInfo); + EXPECT_EQ(true, PublishCommonEvent(data, publishInfo, subscriber, commonEventListener3)); + sleep(1); count++; } sleep(PUBLISH_SLEEP); + std::vector state; getInnerCommonEventManager()->DumpState("", state); - CommonEventDumpTest::dumpInfoCount(state, 4, DUMP_INFO_COUNT, 0, 100); + dumpInfoCount(state, DUMP_SUBSCRIBER_COUNT_FOUR, DUMP_STICKY_COUNT_TWO, 0, DUMP_HISTORY_COUNT_MAX); } } // namespace diff --git a/services/test/unittest/common_event_publish_system_event_test.cpp b/services/test/unittest/common_event_publish_system_event_test.cpp index f37fe4e2ff71fbaf13def26cfb02914e903a6c97..0089c71c56b818a38fc5e6d1afe42b44743ebb66 100644 --- a/services/test/unittest/common_event_publish_system_event_test.cpp +++ b/services/test/unittest/common_event_publish_system_event_test.cpp @@ -32,6 +32,7 @@ using namespace OHOS::EventFwk; namespace { const int PID = 0; const int UID = 1000; // system app +const int PUBLISH_SLEEP = 5; } // namespace static OHOS::sptr bundleObject = nullptr; @@ -69,7 +70,7 @@ void CommonEventPublishSystemEventTest::TearDown(void) class SubscriberTest : public CommonEventSubscriber { public: - SubscriberTest(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + explicit SubscriberTest(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {} ~SubscriberTest() @@ -105,6 +106,7 @@ HWTEST_F(CommonEventPublishSystemEventTest, CommonEventPublishSystemEventTest_01 bool publishResult = innerCommonEventManager.PublishCommonEvent(data, publishInfo, nullptr, curTime, PID, UID, "bundlename"); EXPECT_EQ(true, publishResult); + sleep(PUBLISH_SLEEP); } /* @@ -133,4 +135,5 @@ HWTEST_F(CommonEventPublishSystemEventTest, CommonEventPublishSystemEventTest_02 bool publishResult = innerCommonEventManager.PublishCommonEvent(data, publishInfo, nullptr, curTime, PID, 0, "bundlename"); EXPECT_EQ(false, publishResult); + sleep(PUBLISH_SLEEP); } diff --git a/services/test/unittest/common_event_sticky_test.cpp b/services/test/unittest/common_event_sticky_test.cpp index d679f6e93cfc8ac97666682c510020f4eb80aa0e..dcd97632533c22743813482da83578e8760b2962 100644 --- a/services/test/unittest/common_event_sticky_test.cpp +++ b/services/test/unittest/common_event_sticky_test.cpp @@ -271,7 +271,7 @@ HWTEST_F(CommonEventStickyTest, CommonEventStickyTest_0500, Function | MediumTes * @tc.name: Find events of no subscriber info * @tc.desc: Get invalid return value. */ -HWTEST_F(CommonEventStickyTest, FindStickyEvents_0600, TestSize.Level0) +HWTEST_F(CommonEventStickyTest, FindStickyEvents_0600, TestSize.Level1) { // make a vector of records std::vector> records; @@ -289,7 +289,7 @@ HWTEST_F(CommonEventStickyTest, FindStickyEvents_0600, TestSize.Level0) * @tc.name: Fail to find events of subscriber info * @tc.desc: No event would be pushed into common event records. */ -HWTEST_F(CommonEventStickyTest, FindStickyEvents_0700, TestSize.Level0) +HWTEST_F(CommonEventStickyTest, FindStickyEvents_0700, TestSize.Level1) { // make matching skills MatchingSkills matchingSkills; @@ -315,7 +315,7 @@ HWTEST_F(CommonEventStickyTest, FindStickyEvents_0700, TestSize.Level0) * @tc.name: Succeed to find events of subscriber info * @tc.desc: Found events would be pushed into common event records. */ -HWTEST_F(CommonEventStickyTest, FindStickyEvents_0800, TestSize.Level0) +HWTEST_F(CommonEventStickyTest, FindStickyEvents_0800, TestSize.Level1) { // make matching skills MatchingSkills matchingSkills; @@ -369,7 +369,7 @@ HWTEST_F(CommonEventStickyTest, FindStickyEvents_0800, TestSize.Level0) * @tc.name: Update an unexisting record * @tc.desc: A new record would be added. */ -HWTEST_F(CommonEventStickyTest, UpdateStickyEvent_0900, TestSize.Level0) +HWTEST_F(CommonEventStickyTest, UpdateStickyEvent_0900, TestSize.Level1) { // make a want Want want; @@ -411,7 +411,7 @@ HWTEST_F(CommonEventStickyTest, UpdateStickyEvent_0900, TestSize.Level0) * @tc.name: Update an existing record * @tc.desc: The existing record would be updated. */ -HWTEST_F(CommonEventStickyTest, UpdateStickyEvent_1000, TestSize.Level0) +HWTEST_F(CommonEventStickyTest, UpdateStickyEvent_1000, TestSize.Level1) { // get common event sticky manager auto stickyManagerPtr = OHOS::DelayedSingleton::GetInstance(); diff --git a/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp b/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp index 65d84b8dd687de58579d815e8d460555b80e13c0..619930c14ffc21724f730591957e08d2abd15364 100755 --- a/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp +++ b/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp @@ -247,8 +247,7 @@ private: class SubscriberAnotherTest : public CommonEventSubscriber { public: - explicit SubscriberAnotherTest(const CommonEventSubscribeInfo &subscribeInfo) - : CommonEventSubscriber(subscribeInfo) + explicit SubscriberAnotherTest(const CommonEventSubscribeInfo &subscribeInfo) : CommonEventSubscriber(subscribeInfo) {} ~SubscriberAnotherTest() diff --git a/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp b/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp index d0f5655871b4900da720636a739310ccb1ef58f7..1ae349d4a15f10896853a6593e8649359a73a8c6 100755 --- a/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp +++ b/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp @@ -37,10 +37,11 @@ namespace OHOS { namespace EventFwk { namespace { std::mutex mtx_; +std::mutex mtx2_; const time_t TIME_OUT_SECONDS_LIMIT = 5; +const time_t TIME_OUT_SECONDS_TWO = 2; const time_t TIME_OUT_SECONDS_ = 3; -const time_t TIME_OUT_SECONDS_NINE = 9; -const time_t TIME_OUT_SECONDS_ELEVEN = 11; +const time_t TIME_OUT_SECONDS_TEN = 10; const time_t TIME_OUT_SECONDS_TWENTY = 20; const unsigned int SUBSCRIBER_MAX_SIZE = 200; const unsigned int SUBSCRIBER_MAX_SIZE_PLUS = 201; @@ -96,6 +97,7 @@ void CommonEventServicesSystemTestSubscriber::OnReceiveEvent(const CommonEventDa } else if (action == CompareStrFalse) { EXPECT_TRUE(data.GetCode() == g_CODE_COMPARE2); } + mtx2_.unlock(); } class CESPublishOrderTimeOutOne : public CommonEventSubscriber { @@ -160,15 +162,14 @@ void cesSystemTest::TearDown() */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0100, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "TESTEVENT_SUBSCRIBER"; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -178,15 +179,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0100, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0200, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "1"; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -196,15 +196,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0200, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0300, Function | MediumTest | Level1) { - bool result = false; std::string eventName = ""; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -214,15 +213,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0300, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0400, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "............."; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -232,15 +230,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0400, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0500, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "HELLO\0\0\0WORLD"; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -250,16 +247,15 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0500, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0600, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "TESTEVENT_SUBSCRIBER_SETPRIORITY"; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPriority(100); auto subscriberPtr = std::make_shared(subscribeInfo); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -269,17 +265,15 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0600, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0700, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "TESTEVENT_UNSUBSCRIBE_SETPRIORITY"; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPriority(100); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -289,32 +283,23 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0700, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0800, Function | MediumTest | Level1) { - std::string eventName1 = "TESTEVENT1"; - std::string eventName2 = "TESTEVENT1"; - std::string eventName3 = "TESTEVENT1"; - MatchingSkills matchingSkills1; - matchingSkills1.AddEvent(eventName1); - CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); - auto subscriberPtr1 = std::make_shared(subscribeInfo1); - bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1); - EXPECT_TRUE(result1); + std::string eventName = "TESTEVENT1"; + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); - MatchingSkills matchingSkills2; - matchingSkills2.AddEvent(eventName2); - CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); - auto subscriberPtr2 = std::make_shared(subscribeInfo2); - bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2); - EXPECT_TRUE(result2); + auto subscriberPtr1 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); - MatchingSkills matchingSkills3; - matchingSkills3.AddEvent(eventName3); - CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); - auto subscriberPtr3 = std::make_shared(subscribeInfo3); - bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3); - EXPECT_TRUE(result3); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); + auto subscriberPtr2 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + + auto subscriberPtr3 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -324,32 +309,23 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0800, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0900, Function | MediumTest | Level1) { - std::string eventName1 = ""; - std::string eventName2 = ""; - std::string eventName3 = ""; - MatchingSkills matchingSkills1; - matchingSkills1.AddEvent(eventName1); - CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); - auto subscriberPtr1 = std::make_shared(subscribeInfo1); - bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1); - EXPECT_TRUE(result1); + std::string eventName = ""; + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); - MatchingSkills matchingSkills2; - matchingSkills2.AddEvent(eventName2); - CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); - auto subscriberPtr2 = std::make_shared(subscribeInfo2); - bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2); - EXPECT_TRUE(result2); + auto subscriberPtr1 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); - MatchingSkills matchingSkills3; - matchingSkills3.AddEvent(eventName3); - CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); - auto subscriberPtr3 = std::make_shared(subscribeInfo3); - bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3); - EXPECT_TRUE(result3); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); + auto subscriberPtr2 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + + auto subscriberPtr3 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -359,32 +335,23 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_0900, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1000, Function | MediumTest | Level1) { - std::string eventName1 = "TESTEVENT1"; - std::string eventName2 = "TESTEVENT2"; - std::string eventName3 = "TESTEVENT3"; - MatchingSkills matchingSkills1; - matchingSkills1.AddEvent(eventName1); - CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); - auto subscriberPtr1 = std::make_shared(subscribeInfo1); - bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1); - EXPECT_TRUE(result1); + std::string eventName = "TESTEVENT3"; + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); - MatchingSkills matchingSkills2; - matchingSkills2.AddEvent(eventName2); - CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); - auto subscriberPtr2 = std::make_shared(subscribeInfo2); - bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2); - EXPECT_TRUE(result2); + auto subscriberPtr1 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); - MatchingSkills matchingSkills3; - matchingSkills3.AddEvent(eventName3); - CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); - auto subscriberPtr3 = std::make_shared(subscribeInfo3); - bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3); - EXPECT_TRUE(result3); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); + auto subscriberPtr2 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + + auto subscriberPtr3 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -396,21 +363,21 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1100, Function | MediumTest | Leve { std::string eventName1 = "TEST1"; std::string eventName2 = "TEST2"; + MatchingSkills matchingSkills1; matchingSkills1.AddEvent(eventName1); CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); auto subscriberPtr1 = std::make_shared(subscribeInfo1); - bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1); - EXPECT_TRUE(result1); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); MatchingSkills matchingSkills2; matchingSkills2.AddEvent(eventName2); CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); auto subscriberPtr2 = std::make_shared(subscribeInfo2); - bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2); - EXPECT_TRUE(result2); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); } /* @@ -423,29 +390,28 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1200, Function | MediumTest | Leve std::string eventName1 = "TESTEVENT1"; std::string eventName2 = "1"; std::string eventName3 = ""; + MatchingSkills matchingSkills1; matchingSkills1.AddEvent(eventName1); CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); auto subscriberPtr1 = std::make_shared(subscribeInfo1); - bool result1 = CommonEventManager::SubscribeCommonEvent(subscriberPtr1); - EXPECT_TRUE(result1); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); MatchingSkills matchingSkills2; matchingSkills2.AddEvent(eventName2); CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); auto subscriberPtr2 = std::make_shared(subscribeInfo2); - bool result2 = CommonEventManager::SubscribeCommonEvent(subscriberPtr2); - EXPECT_TRUE(result2); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); MatchingSkills matchingSkills3; matchingSkills3.AddEvent(eventName3); CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); auto subscriberPtr3 = std::make_shared(subscribeInfo3); - bool result3 = CommonEventManager::SubscribeCommonEvent(subscriberPtr3); - EXPECT_TRUE(result3); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -456,15 +422,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1200, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1300, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_UNSUBSCRIBE"; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -475,15 +440,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1300, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1400, Function | MediumTest | Level1) { std::string eventName = "2"; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -494,15 +458,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1400, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1500, Function | MediumTest | Level1) { std::string eventName = ""; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -513,15 +476,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1500, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1600, Function | MediumTest | Level1) { std::string eventName = ".................."; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -532,15 +494,14 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1600, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1700, Function | MediumTest | Level1) { std::string eventName = "HELLO\0\0\0WORLD"; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -553,35 +514,27 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1800, Function | MediumTest | Leve std::string eventName1 = "TESTEVENT4"; std::string eventName2 = "TESTEVENT5"; std::string eventName3 = "TESTEVENT6"; - bool result1 = false; + MatchingSkills matchingSkills1; matchingSkills1.AddEvent(eventName1); CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); auto subscriberPtr1 = std::make_shared(subscribeInfo1); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) { - result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - } - EXPECT_TRUE(result1); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); - bool result2 = false; MatchingSkills matchingSkills2; matchingSkills2.AddEvent(eventName2); CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); auto subscriberPtr2 = std::make_shared(subscribeInfo2); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) { - result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - } - EXPECT_TRUE(result2); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); - bool result3 = false; MatchingSkills matchingSkills3; matchingSkills3.AddEvent(eventName3); CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); auto subscriberPtr3 = std::make_shared(subscribeInfo3); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) { - result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); - } - EXPECT_TRUE(result3); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -594,25 +547,19 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_1900, Function | MediumTest | Leve std::string eventName1 = "TEST3"; std::string eventName2 = "TEST4"; - bool result1 = false; MatchingSkills matchingSkills1; matchingSkills1.AddEvent(eventName1); CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); auto subscriberPtr1 = std::make_shared(subscribeInfo1); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) { - result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - } - EXPECT_TRUE(result1); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); - bool result2 = false; MatchingSkills matchingSkills2; matchingSkills2.AddEvent(eventName2); CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); auto subscriberPtr2 = std::make_shared(subscribeInfo2); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) { - result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - } - EXPECT_TRUE(result2); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); } /* @@ -625,35 +572,27 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_2000, Function | MediumTest | Leve std::string eventName1 = "TESTEVENT7"; std::string eventName2 = "3"; std::string eventName3 = ""; - bool result1 = false; + MatchingSkills matchingSkills1; matchingSkills1.AddEvent(eventName1); CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); auto subscriberPtr1 = std::make_shared(subscribeInfo1); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) { - result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - } - EXPECT_TRUE(result1); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); - bool result2 = false; MatchingSkills matchingSkills2; matchingSkills2.AddEvent(eventName2); CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); auto subscriberPtr2 = std::make_shared(subscribeInfo2); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) { - result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - } - EXPECT_TRUE(result2); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); - bool result3 = false; MatchingSkills matchingSkills3; matchingSkills3.AddEvent(eventName3); CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); auto subscriberPtr3 = std::make_shared(subscribeInfo3); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) { - result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); - } - EXPECT_TRUE(result3); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -663,38 +602,23 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_2000, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_2100, Function | MediumTest | Level1) { - std::string eventName1 = "TESTEVENT4"; - std::string eventName2 = "TESTEVENT4"; - std::string eventName3 = "TESTEVENT4"; - MatchingSkills matchingSkills1; - matchingSkills1.AddEvent(eventName1); - CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); - bool result1 = false; - auto subscriberPtr1 = std::make_shared(subscribeInfo1); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) { - result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - } - EXPECT_TRUE(result1); + std::string eventName = "TESTEVENT4"; - MatchingSkills matchingSkills2; - matchingSkills2.AddEvent(eventName2); - CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); - bool result2 = false; - auto subscriberPtr2 = std::make_shared(subscribeInfo2); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) { - result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - } - EXPECT_TRUE(result2); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); - MatchingSkills matchingSkills3; - matchingSkills3.AddEvent(eventName3); - CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); - bool result3 = false; - auto subscriberPtr3 = std::make_shared(subscribeInfo3); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) { - result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); - } - EXPECT_TRUE(result3); + auto subscriberPtr1 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); + + auto subscriberPtr2 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); + + auto subscriberPtr3 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -704,38 +628,23 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_2100, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_2200, Function | MediumTest | Level1) { - std::string eventName1 = ""; - std::string eventName2 = ""; - std::string eventName3 = ""; - MatchingSkills matchingSkills1; - matchingSkills1.AddEvent(eventName1); - CommonEventSubscribeInfo subscribeInfo1(matchingSkills1); - bool result1 = false; - auto subscriberPtr1 = std::make_shared(subscribeInfo1); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) { - result1 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - } - EXPECT_TRUE(result1); + std::string eventName = ""; - MatchingSkills matchingSkills2; - matchingSkills2.AddEvent(eventName2); - CommonEventSubscribeInfo subscribeInfo2(matchingSkills2); - bool result2 = false; - auto subscriberPtr2 = std::make_shared(subscribeInfo2); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr2)) { - result2 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2); - } - EXPECT_TRUE(result2); + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); - MatchingSkills matchingSkills3; - matchingSkills3.AddEvent(eventName3); - CommonEventSubscribeInfo subscribeInfo3(matchingSkills3); - bool result3 = false; - auto subscriberPtr3 = std::make_shared(subscribeInfo3); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr3)) { - result3 = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3); - } - EXPECT_TRUE(result3); + auto subscriberPtr1 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); + + auto subscriberPtr2 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr2), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr2), true); + + auto subscriberPtr3 = std::make_shared(subscribeInfo); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr3), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr3), true); } /* @@ -745,21 +654,34 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEvent_2200, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SendEvent_0100, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ACTION"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION"; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -769,23 +691,36 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0100, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_0200, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ENTITY"; - std::string eventAction = "TESTEVENT_PUBLISH_ENTITY"; std::string entity = "ADDENTITY"; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -795,22 +730,35 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0200, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_0300, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_SCHEME"; - std::string eventAction = "TESTEVENT_PUBLISH_SCHEME"; std::string scheme = "SETSCHEME"; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -820,51 +768,77 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0300, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_0400, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_SCHEME_ENTITY"; - std::string eventAction = "TESTEVENT_PUBLISH_SCHEME_ENTITY"; std::string scheme = "SETSCHEME"; std::string entity = "ADDENTITY"; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); -} -/* + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } + } + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); +} + +/* * @tc.number: CES_SendEvent_0500 * @tc.name: SubscribeCommonEvent * @tc.desc: Verify set action with sticky is false */ HWTEST_F(cesSystemTest, CES_SendEvent_0500, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ACTION_INFO_FALSE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_INFO_FALSE"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -875,25 +849,24 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0500, Function | MediumTest | Level1) HWTEST_F(cesSystemTest, CES_SendEvent_0600, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_TRUE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_TRUE"; std::string entity = "ADDENTITY"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -903,26 +876,39 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0600, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_0700, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_FALSE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_INFO_FALSE"; std::string entity = "ADDENTITY"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -933,23 +919,22 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0700, Function | MediumTest | Level1) HWTEST_F(cesSystemTest, CES_SendEvent_0800, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_PUBLISH_ACTION_INFO_TRUE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_INFO_TRUE"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -960,24 +945,23 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0800, Function | MediumTest | Level1) HWTEST_F(cesSystemTest, CES_SendEvent_0900, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_TRUE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_TRUE"; std::string scheme = "SETSCHEME"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -987,25 +971,38 @@ HWTEST_F(cesSystemTest, CES_SendEvent_0900, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_1000, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_FALSE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SCHEME_INFO_FALSE"; std::string scheme = "SETSCHEME"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1016,26 +1013,25 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1000, Function | MediumTest | Level1) HWTEST_F(cesSystemTest, CES_SendEvent_1100, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_TRUE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_TRUE"; std::string entity = "ADDENTITY"; std::string scheme = "SETSCHEME"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1045,27 +1041,40 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1100, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_1200, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_FALSE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_ENTITY_SCHEME_INFO_FALSE"; std::string entity = "ADDENTITY"; std::string scheme = "SETSCHEME"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1075,24 +1084,37 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1200, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0100, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_STICHY_ACTION_INFO_FALSE"; - std::string eventAction = "TESTEVENT_STICHY_ACTION_INFO_FALSE"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1103,25 +1125,24 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0100, Function | MediumTest | HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0200, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_TRUE"; - std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_TRUE"; std::string entity = "ADDENTITY"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1131,26 +1152,39 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0200, Function | MediumTest | */ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0300, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_FALSE"; - std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_INFO_FALSE"; std::string entity = "ADDENTITY"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1161,23 +1195,22 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0300, Function | MediumTest | HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0400, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_STICKY_ACTION_INFO_TRUE"; - std::string eventAction = "TESTEVENT_STICKY_ACTION_INFO_TRUE"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1188,24 +1221,23 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0400, Function | MediumTest | HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0500, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_TRUE"; - std::string eventAction = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_TRUE"; std::string scheme = "SETSCHEME"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1215,25 +1247,38 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0500, Function | MediumTest | */ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0600, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_FALSE"; - std::string eventAction = "TESTEVENT_STICKY_ACTION_SCHEME_INFO_FALSE"; std::string scheme = "SETSCHEME"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1244,26 +1289,25 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0600, Function | MediumTest | HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0700, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_TRUE"; - std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_TRUE"; std::string entity = "ADDENTITY"; std::string scheme = "SETSCHEME"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1273,27 +1317,40 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0700, Function | MediumTest | */ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0800, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_FALSE"; - std::string eventAction = "TESTEVENT_STICKY_ACTION_ENTITY_SCHEME_INFO_FALSE"; std::string entity = "ADDENTITY"; std::string scheme = "SETSCHEME"; - bool stickty = false; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1304,29 +1361,27 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0800, Function | MediumTest | HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0900, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_GETSTICKY_"; - std::string eventAction = "TESTEVENT_GETSTICKY_"; std::string eventActionStr = "TESTEVENT_GETSTICKY_Str"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) && - CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) { - result = true; - } - EXPECT_TRUE(result); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); CommonEventData stickyData; - CommonEventManager::GetStickyCommonEvent(eventAction, stickyData); + CommonEventManager::GetStickyCommonEvent(eventName, stickyData); EXPECT_FALSE(eventActionStr == stickyData.GetWant().GetAction()); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1337,29 +1392,26 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_0900, Function | MediumTest | HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_1000, TestSize.Level2) { std::string eventName = "TESTEVENT_GETSTICKY_FALSE"; - std::string eventAction = "TESTEVENT_GETSTICKY_FALSE"; std::string actionTest = "CHECKTESTACTION"; - bool stickty = true; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) && - CommonEventManager::PublishCommonEvent(commonEventData, publishInfo)) { - result = true; - } - EXPECT_TRUE(result); + + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); CommonEventData stickyData; - bool stickyResult = CommonEventManager::GetStickyCommonEvent(actionTest, stickyData); - EXPECT_FALSE(stickyResult); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::GetStickyCommonEvent(actionTest, stickyData), false); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1370,12 +1422,13 @@ HWTEST_F(cesSystemTest, CES_SendEventSetViscosity_1000, TestSize.Level2) HWTEST_F(cesSystemTest, CES_ReceiveEvent_0100, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_RECEIVE_ACTIONReceiveEvent_0100"; - std::string eventAction = "TESTEVENT_RECEIVE_ACTIONReceiveEvent_0100"; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); @@ -1398,7 +1451,7 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0100, Function | MediumTest | Level1) // expect the subscriber could receive the event within 5 seconds. EXPECT_LT(seconds, TIME_OUT_SECONDS_LIMIT); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1408,16 +1461,17 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0100, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0200, Function | MediumTest | Level1) { + bool result = true; std::string eventName = "TESTEVENT_RECEIVE_ENTITYReceiveEvent_0200"; - std::string eventAction = "TESTEVENT_RECEIVE_ENTITYReceiveEvent_0200"; std::string entity = "ADDENTITY"; - bool result = true; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); @@ -1441,7 +1495,7 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0200, Function | MediumTest | Level1) // The publisher sets the Entity, the receiver must set it, otherwise the receiver will not receive the information EXPECT_FALSE(result); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1452,18 +1506,19 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0200, Function | MediumTest | Level1) HWTEST_F(cesSystemTest, CES_ReceiveEvent_0300, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_RECEIVE_ACTION_INFO_FALSE"; - std::string eventAction = "TESTEVENT_RECEIVE_ACTION_INFO_FALSE"; - bool stickty = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); @@ -1483,7 +1538,7 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0300, Function | MediumTest | Level1) // expect the subscriber could receive the event within 5 seconds. EXPECT_LT(seconds, TIME_OUT_SECONDS_LIMIT); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1493,20 +1548,21 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0300, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0400, Function | MediumTest | Level1) { - std::string eventName = "TESTEVENT_RECEIVE_ACTION_INFO_TRUEReceiveEvent_0400"; - std::string eventAction = "TESTEVENT_RECEIVE_ACTION_INFO_TRUEReceiveEvent_0400"; - bool stickty = true; bool result = true; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + std::string eventName = "TESTEVENT_RECEIVE_ACTION_INFO_TRUEReceiveEvent_0400"; + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); @@ -1527,7 +1583,7 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0400, Function | MediumTest | Level1) // expect the subscriber could receive the event within 5 seconds. EXPECT_FALSE(result); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1537,22 +1593,23 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0400, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0500, Function | MediumTest | Level1) { + bool result = true; std::string eventName = "TESTEVENT_RECEIVE_ENTITY_INFO_FALSE"; - std::string eventAction = "TESTEVENT_RECEIVE_ENTITY_INFO_FALSE"; std::string entity = "ADDENTITY"; - bool result = true; - bool stickty = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(false); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); @@ -1573,7 +1630,7 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0500, Function | MediumTest | Level1) // The publisher sets the Entity, the receiver must set it, otherwise the receiver will not receive the information EXPECT_FALSE(result); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1583,22 +1640,23 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0500, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0600, Function | MediumTest | Level1) { + bool result = true; std::string eventName = "testEventReceiveEntityInfoFalse"; - std::string eventAction = "testEventReceiveEntityInfoFalse"; std::string entity = "addEntity"; - bool result = true; - bool stickty = true; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); wantTest.AddEntity(entity); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; - publishInfo.SetSticky(stickty); auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + publishInfo.SetSticky(true); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); @@ -1619,7 +1677,7 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0600, Function | MediumTest | Level1) // The publisher sets the Entity, the receiver must set it, otherwise the receiver will not receive the information EXPECT_FALSE(result); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1629,15 +1687,14 @@ HWTEST_F(cesSystemTest, CES_ReceiveEvent_0600, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SubscriptionEventTheme_0100, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "TESTADDTHEME"; MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1653,12 +1710,11 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEventTheme_0200, Function | MediumTest | MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName1); matchingSkills.AddEvent(eventName2); - CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1669,19 +1725,13 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEventTheme_0200, Function | MediumTest | HWTEST_F(cesSystemTest, CES_SubscriptionEventTheme_0300, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_MATCHEVENTTEST"; - bool result = false; Want wantTest; wantTest.SetAction(eventName); MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); - CommonEventSubscribeInfo subscribeInfo(matchingSkills); - auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = matchingSkills.Match(wantTest); - } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(matchingSkills.Match(wantTest), true); } /* @@ -1693,19 +1743,13 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEventTheme_0400, Function | MediumTest | { std::string eventName = "TESTMATCHEVENTTOPICAL"; std::string eventNameCompare = "TESTMATCHEVENTTOPICAL_COMPARE"; - bool result = true; Want wantTest; wantTest.SetAction(eventNameCompare); MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); - CommonEventSubscribeInfo subscribeInfo(matchingSkills); - auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = matchingSkills.Match(wantTest); - } - EXPECT_FALSE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(matchingSkills.Match(wantTest), false); } /* @@ -1716,18 +1760,20 @@ HWTEST_F(cesSystemTest, CES_SubscriptionEventTheme_0400, Function | MediumTest | */ HWTEST_F(cesSystemTest, CES_SendEvent_1300, Function | MediumTest | Level1) { - std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_ADDED; - std::string eventAction = CommonEventSupport::COMMON_EVENT_ABILITY_ADDED; bool sysResult = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_ADDED; + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); // The publisher can send normally, but does not have permission to send system events @@ -1750,7 +1796,7 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1300, Function | MediumTest | Level1) // Unable to receive published system events, failed to send system events EXPECT_TRUE(sysResult); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1761,18 +1807,20 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1300, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_1400, Function | MediumTest | Level1) { - std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_REMOVED; - std::string eventAction = CommonEventSupport::COMMON_EVENT_ABILITY_REMOVED; bool sysResult = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_REMOVED; + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); // The publisher can send normally, but does not have permission to send system events @@ -1795,7 +1843,7 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1400, Function | MediumTest | Level1) // Unable to receive published system events, failed to send system events EXPECT_TRUE(sysResult); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1806,18 +1854,20 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1400, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_1500, Function | MediumTest | Level1) { - std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED; - std::string eventAction = CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED; bool sysResult = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + std::string eventName = CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED; + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); // The publisher can send normally, but does not have permission to send system events @@ -1840,7 +1890,7 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1500, Function | MediumTest | Level1) // Unable to receive published system events, failed to send system events EXPECT_TRUE(sysResult); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1850,18 +1900,20 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1500, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_1600, Function | MediumTest | Level1) { - std::string eventName = CommonEventSupport::COMMON_EVENT_ACCOUNT_DELETED; - std::string eventAction = CommonEventSupport::COMMON_EVENT_ACCOUNT_DELETED; bool result = true; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + std::string eventName = CommonEventSupport::COMMON_EVENT_ACCOUNT_DELETED; + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; auto subscriberPtr = std::make_shared(subscribeInfo); + CommonEventPublishInfo publishInfo; + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); @@ -1882,7 +1934,7 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1600, Function | MediumTest | Level1) // System events published by ordinary publishers, the publication fails, and the receiver cannot receive it EXPECT_FALSE(result); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1893,25 +1945,49 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1600, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_1700, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = CompareStr; - std::string eventAction = CompareStr; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); - commonEventData.SetCode(1); + commonEventData.SetCode(g_CODE_COMPARE1); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; auto subscriberPtr = std::make_shared(subscribeInfo); auto subscriberPtr1 = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr) && - CommonEventManager::SubscribeCommonEvent(subscriberPtr1)) { - CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr1), true); + mtx_.lock(); + mtx2_.lock(); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - sleep(1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + while (!mtx2_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } + } + + mtx_.unlock(); + mtx2_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr1), true); } /* @@ -1923,41 +1999,57 @@ HWTEST_F(cesSystemTest, CES_SendEvent_1700, Function | MediumTest | Level1) */ HWTEST_F(cesSystemTest, CES_SendEvent_1800, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = CompareStrFalse; - std::string eventAction = CompareStrFalse; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); - commonEventData.SetCode(200); + commonEventData.SetCode(g_CODE_COMPARE3); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - CommonEventPublishInfo publishInfo; auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + CommonEventPublishInfo publishInfo; + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - sleep(1); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* * @tc.number: CES_SetEventAuthority_0100 * @tc.name: SetPermission - * @tc.desc: Set permission for common event subscribers and verify successfully subscribe to common events + * @tc.desc: Set permission for common event subscribers and verify successfully subscribe to common events */ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0100, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_SUBSCRIBER_PERMISSION"; std::string permissin = "PERMISSION"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPermission(permissin); auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1970,15 +2062,16 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0200, Function | MediumTest | Leve { std::string eventName = "TESTEVENT_SUBSCRIBER_PERMISSION_PRIORITY"; std::string permissin = "PERMISSION"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPermission(permissin); subscribeInfo.SetPriority(1); auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -1992,6 +2085,7 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0300, Function | MediumTest | Leve std::string eventName = "TESTEVENT_SUBSCRIBER_PERMISSION_PRIORITY_D"; std::string permissin = "PERMISSION"; std::string deviceId = "deviceId"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); @@ -1999,9 +2093,9 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0300, Function | MediumTest | Leve subscribeInfo.SetPriority(1); subscribeInfo.SetDeviceId(deviceId); auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2013,16 +2107,15 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0400, Function | MediumTest | Leve { std::string eventName = "TESTEVENT_UNSUBSCRIBER_PERMISSION"; std::string permissin = "PERMISSION"; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPermission(permissin); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2035,17 +2128,16 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0500, Function | MediumTest | Leve { std::string eventName = "TESTEVENT_UNSUBSCRIBER_PERMISSION_PRIORITY"; std::string permissin = "PERMISSION"; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPermission(permissin); subscribeInfo.SetPriority(1); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2059,7 +2151,7 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0600, Function | MediumTest | Leve std::string eventName = "TESTEVENT_UNSUBSCRIBER_PERMISSION_PRIORITY_D"; std::string permissin = "PERMISSION"; std::string deviceId = "deviceId"; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); @@ -2067,10 +2159,9 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0600, Function | MediumTest | Leve subscribeInfo.SetPriority(1); subscribeInfo.SetDeviceId(deviceId); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2080,26 +2171,40 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0600, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0700, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ACTION_PERMISSION"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_PERMISSION"; std::string permissin = "PERMISSION"; - std::vector permissins; - permissins.emplace_back(permissin); - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); + auto subscriberPtr = std::make_shared(subscribeInfo); + + std::vector permissins; + permissins.emplace_back(permissin); CommonEventPublishInfo publishInfo; publishInfo.SetSubscriberPermissions(permissins); - auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData, publishInfo); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData, publishInfo), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2109,21 +2214,23 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0700, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0800, Function | MediumTest | Level1) { + bool result = false; std::string eventName = "TESTEVENT_PUBLISH_ACTION_PERMISSION_R"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_PERMISSION_R"; std::string permissin = "PERMISSION"; - bool result = false; - std::vector permissins; - permissins.emplace_back(permissin); - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); + auto subscriberPtr = std::make_shared(subscribeInfo); + + std::vector permissins; + permissins.emplace_back(permissin); CommonEventPublishInfo publishInfo; publishInfo.SetSubscriberPermissions(permissins); - auto subscriberPtr = std::make_shared(subscribeInfo); EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); mtx_.lock(); @@ -2144,7 +2251,7 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0800, Function | MediumTest | Leve } EXPECT_TRUE(result); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2155,14 +2262,15 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0800, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SetEventAuthority_0900, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_SUBSCRIBER_SETTHREADMODE"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::HANDLER); auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2173,16 +2281,15 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_0900, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SetEventAuthority_1000, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_UNSUBSCRIBER_SETTHREADMODE"; - bool result = false; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::HANDLER); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); - } - EXPECT_TRUE(result); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2192,22 +2299,35 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_1000, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SetEventAuthority_1100, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventName = "TESTEVENT_PUBLISH_ACTION_SETTHREADMODE"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SETTHREADMODE"; - bool result = false; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::HANDLER); auto subscriberPtr = std::make_shared(subscribeInfo); - if (CommonEventManager::SubscribeCommonEvent(subscriberPtr)) { - result = CommonEventManager::PublishCommonEvent(commonEventData); + + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtr), true); + mtx_.lock(); + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventData), true); + + struct tm doingTime = {0}; + int64_t seconds = 0; + while (!mtx_.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&doingTime), true); + seconds = OHOS::GetSecondsBetween(startTime, doingTime); + if (seconds >= TIME_OUT_SECONDS_TWO) { + break; + } } - EXPECT_TRUE(result); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2218,12 +2338,13 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_1100, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_SetEventAuthority_1200, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_PUBLISH_ACTION_SETHANDLER_HANDLER_STCES"; - std::string eventAction = "TESTEVENT_PUBLISH_ACTION_SETHANDLER_HANDLER_STCES"; - MatchingSkills matchingSkills; - matchingSkills.AddEvent(eventName); + Want wantTest; - wantTest.SetAction(eventAction); + wantTest.SetAction(eventName); CommonEventData commonEventData(wantTest); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetThreadMode(CommonEventSubscribeInfo::ThreadMode::POST); auto subscriberPtr = std::make_shared(subscribeInfo); @@ -2247,7 +2368,7 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_1200, Function | MediumTest | Leve // expect the subscriber could receive the event within 5 seconds. EXPECT_LT(seconds, TIME_OUT_SECONDS_LIMIT); mtx_.unlock(); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtr), true); } /* @@ -2258,15 +2379,13 @@ HWTEST_F(cesSystemTest, CES_SetEventAuthority_1200, Function | MediumTest | Leve HWTEST_F(cesSystemTest, CES_VerifyMatchingSkills_0100, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_GETMATCHINGSKILLS"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); MatchingSkills testMatching = subscribeInfo.GetMatchingSkills(); + EXPECT_EQ(testMatching.GetEvent(0), eventName); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); } /* @@ -2278,35 +2397,29 @@ HWTEST_F(cesSystemTest, CES_VerifyMatchingSkills_0200, Function | MediumTest | L { std::string eventName = "TESTEVENT_ADDENTITY_GETENTITY"; std::string entity = "entity"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); matchingSkills.AddEntity(entity); - CommonEventSubscribeInfo subscribeInfo(matchingSkills); - auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); + EXPECT_EQ(matchingSkills.GetEntity(0), entity); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); } /* * @tc.number: CES_VerifyMatchingSkills_0300 * @tc.name: HasEntity - * @tc.desc: verify that entity is in MatchingSkills + * @tc.desc: verify that entity is in MatchingSkills */ HWTEST_F(cesSystemTest, CES_VerifyMatchingSkills_0300, Function | MediumTest | Level1) { std::string eventName = "TESTEVENT_ADDENTITY_HASENTITY"; std::string entity = "entity"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); matchingSkills.AddEntity(entity); - CommonEventSubscribeInfo subscribeInfo(matchingSkills); - auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); + EXPECT_TRUE(matchingSkills.HasEntity(entity)); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); } /* @@ -2318,16 +2431,13 @@ HWTEST_F(cesSystemTest, CES_VerifyMatchingSkills_0400, Function | MediumTest | L { std::string eventName = "TESTEVENT_ADDENTITY_REMOVEENTITY"; std::string entity = "entity"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); matchingSkills.AddEntity(entity); matchingSkills.RemoveEntity(entity); - CommonEventSubscribeInfo subscribeInfo(matchingSkills); - auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); + EXPECT_FALSE(matchingSkills.HasEntity(entity)); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); } /* @@ -2339,15 +2449,12 @@ HWTEST_F(cesSystemTest, CES_VerifyMatchingSkills_0500, Function | MediumTest | L { std::string eventName = "TESTEVENT_ADDENTITY_ENTITYCOUNT"; std::string entity = "entity"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); matchingSkills.AddEntity(entity); - CommonEventSubscribeInfo subscribeInfo(matchingSkills); - auto subscriberPtr = std::make_shared(subscribeInfo); - bool result = CommonEventManager::SubscribeCommonEvent(subscriberPtr); - EXPECT_TRUE(result); + EXPECT_TRUE((matchingSkills.CountEntities() >= 1)); - CommonEventManager::UnSubscribeCommonEvent(subscriberPtr); } /* @@ -2357,22 +2464,20 @@ HWTEST_F(cesSystemTest, CES_VerifyMatchingSkills_0500, Function | MediumTest | L */ HWTEST_F(cesSystemTest, CES_SubscriberMaxSize_0100, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "TESTEVENT_SUBSCRIBER"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - std::vector> subscriberPtrs; + for (size_t i = 0; i < SUBSCRIBER_MAX_SIZE; i++) { auto subscriberPtr = std::make_shared(subscribeInfo); subscriberPtrs.push_back(subscriberPtr); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtrs.at(i)); - EXPECT_TRUE(result); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtrs.at(i)), true); } for (size_t i = 0; i < SUBSCRIBER_MAX_SIZE; i++) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtrs.at(i)); - EXPECT_TRUE(result); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtrs.at(i)), true); } } @@ -2384,26 +2489,24 @@ HWTEST_F(cesSystemTest, CES_SubscriberMaxSize_0100, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_SubscriberMaxSize_0200, Function | MediumTest | Level1) { - bool result = false; std::string eventName = "TESTEVENT_SUBSCRIBER_PLUS"; + MatchingSkills matchingSkills; matchingSkills.AddEvent(eventName); CommonEventSubscribeInfo subscribeInfo(matchingSkills); - std::vector> subscriberPtrs; + for (size_t i = 0; i < SUBSCRIBER_MAX_SIZE_PLUS - 1; i++) { auto subscriberPtr = std::make_shared(subscribeInfo); subscriberPtrs.push_back(subscriberPtr); - result = CommonEventManager::SubscribeCommonEvent(subscriberPtrs.at(i)); - EXPECT_TRUE(result); + EXPECT_EQ(CommonEventManager::SubscribeCommonEvent(subscriberPtrs.at(i)), true); } + auto subscriberPtr = std::make_shared(subscribeInfo); - subscriberPtrs.push_back(subscriberPtr); - EXPECT_FALSE(CommonEventManager::SubscribeCommonEvent(subscriberPtrs.at(SUBSCRIBER_MAX_SIZE_PLUS - 1))); + EXPECT_FALSE(CommonEventManager::SubscribeCommonEvent(subscriberPtr)); for (size_t i = 0; i < SUBSCRIBER_MAX_SIZE_PLUS - 1; i++) { - result = CommonEventManager::UnSubscribeCommonEvent(subscriberPtrs.at(i)); - EXPECT_TRUE(result); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberPtrs.at(i)), true); } } @@ -2414,31 +2517,33 @@ HWTEST_F(cesSystemTest, CES_SubscriberMaxSize_0200, Function | MediumTest | Leve */ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0100, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventNameTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT"; - std::string eventActionTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT"; - MatchingSkills matchingSkillsTimeOne; - matchingSkillsTimeOne.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoOne(matchingSkillsTimeOne); + + Want wantTimeOut; + wantTimeOut.SetAction(eventNameTimeOut); + CommonEventData commonEventDataTimeOut(wantTimeOut); + + CommonEventPublishInfo publishInfoTimeOut; + publishInfoTimeOut.SetOrdered(true); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventNameTimeOut); + + CommonEventSubscribeInfo subscribeInfoOne(matchingSkills); subscribeInfoOne.SetPriority(PRIORITY_HIGH); auto subscriberTimeOnePtr = std::make_shared(subscribeInfoOne); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr)); - MatchingSkills matchingSkillsTimeTwo; - matchingSkillsTimeTwo.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoTwo(matchingSkillsTimeOne); + CommonEventSubscribeInfo subscribeInfoTwo(matchingSkills); subscribeInfoTwo.SetPriority(PRIORITY_LOW); auto subscriberTimeTwoPtr = std::make_shared(subscribeInfoTwo); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr)); mtx_.lock(); - struct tm startTime = {0}; - Want wantTimeOut; - wantTimeOut.SetAction(eventActionTimeOut); - CommonEventData commonEventDataTimeOut(wantTimeOut); - CommonEventPublishInfo publishInfoTimeOut; - publishInfoTimeOut.SetOrdered(true); - EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); EXPECT_TRUE(CommonEventManager::PublishCommonEvent(commonEventDataTimeOut, publishInfoTimeOut)); + + EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); struct tm doingTime = {0}; int64_t seconds = 0; while (!mtx_.try_lock()) { @@ -2451,11 +2556,11 @@ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0100, Function | MediumTest | Le } // expect the subscriber could receive the event within 11 seconds. std::cout << "seconds: " << seconds << std::endl; - EXPECT_LT(TIME_OUT_SECONDS_NINE, seconds); - EXPECT_LT(seconds, TIME_OUT_SECONDS_ELEVEN); - CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr); - CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr); + EXPECT_GE(seconds, TIME_OUT_SECONDS_TEN); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeOnePtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeTwoPtr), true); } /* @@ -2465,29 +2570,30 @@ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0100, Function | MediumTest | Le */ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0200, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventNameTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT_SUBSCRIBER"; - std::string eventActionTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT_SUBSCRIBER"; - MatchingSkills matchingSkillsTimeOne; - matchingSkillsTimeOne.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoOne(matchingSkillsTimeOne); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventNameTimeOut); + + Want wantTimeOut; + wantTimeOut.SetAction(eventNameTimeOut); + CommonEventData commonEventDataTimeOut(wantTimeOut); + + CommonEventPublishInfo publishInfoTimeOut; + publishInfoTimeOut.SetOrdered(true); + + CommonEventSubscribeInfo subscribeInfoOne(matchingSkills); subscribeInfoOne.SetPriority(PRIORITY_HIGH); auto subscriberTimeOnePtr = std::make_shared(subscribeInfoOne); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr)); - MatchingSkills matchingSkillsTimeTwo; - matchingSkillsTimeTwo.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoTwo(matchingSkillsTimeOne); + CommonEventSubscribeInfo subscribeInfoTwo(matchingSkills); subscribeInfoTwo.SetPriority(PRIORITY_LOW); auto subscriberTimeTwoPtr = std::make_shared(subscribeInfoTwo); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr)); mtx_.lock(); - struct tm startTime = {0}; - Want wantTimeOut; - wantTimeOut.SetAction(eventActionTimeOut); - CommonEventData commonEventDataTimeOut(wantTimeOut); - CommonEventPublishInfo publishInfoTimeOut; - publishInfoTimeOut.SetOrdered(true); EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); EXPECT_TRUE( CommonEventManager::PublishCommonEvent(commonEventDataTimeOut, publishInfoTimeOut, subscriberTimeTwoPtr)); @@ -2503,11 +2609,10 @@ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0200, Function | MediumTest | Le } // expect the subscriber could receive the event within 11 seconds. std::cout << "seconds: " << seconds << std::endl; - EXPECT_LT(TIME_OUT_SECONDS_NINE, seconds); - EXPECT_LT(seconds, TIME_OUT_SECONDS_ELEVEN); - CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr); - CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr); + EXPECT_GE(seconds, TIME_OUT_SECONDS_TEN); mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeOnePtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeTwoPtr), true); } /* @@ -2518,27 +2623,28 @@ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0200, Function | MediumTest | Le */ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0300, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventNameTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT_NOPRIORITY"; - std::string eventActionTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT_NOPRIORITY"; - MatchingSkills matchingSkillsTimeOne; - matchingSkillsTimeOne.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoOne(matchingSkillsTimeOne); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventNameTimeOut); + + Want wantTimeOut; + wantTimeOut.SetAction(eventNameTimeOut); + CommonEventData commonEventDataTimeOut(wantTimeOut); + + CommonEventPublishInfo publishInfoTimeOut; + publishInfoTimeOut.SetOrdered(true); + + CommonEventSubscribeInfo subscribeInfoOne(matchingSkills); auto subscriberTimeOnePtr = std::make_shared(subscribeInfoOne); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr)); - MatchingSkills matchingSkillsTimeTwo; - matchingSkillsTimeTwo.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoTwo(matchingSkillsTimeOne); + CommonEventSubscribeInfo subscribeInfoTwo(matchingSkills); auto subscriberTimeTwoPtr = std::make_shared(subscribeInfoTwo); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr)); mtx_.lock(); - struct tm startTime = {0}; - Want wantTimeOut; - wantTimeOut.SetAction(eventActionTimeOut); - CommonEventData commonEventDataTimeOut(wantTimeOut); - CommonEventPublishInfo publishInfoTimeOut; - publishInfoTimeOut.SetOrdered(true); EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); EXPECT_TRUE(CommonEventManager::PublishCommonEvent(commonEventDataTimeOut, publishInfoTimeOut)); struct tm doingTime = {0}; @@ -2553,11 +2659,10 @@ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0300, Function | MediumTest | Le } // expect the subscriber could receive the event within 11 seconds. std::cout << "seconds: " << seconds << std::endl; - EXPECT_LT(TIME_OUT_SECONDS_NINE, seconds); - EXPECT_LT(seconds, TIME_OUT_SECONDS_ELEVEN); - CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr); - CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr); + EXPECT_GE(seconds, TIME_OUT_SECONDS_TEN); mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeOnePtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeTwoPtr), true); } /* @@ -2568,27 +2673,28 @@ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0300, Function | MediumTest | Le */ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0400, Function | MediumTest | Level1) { + struct tm startTime = {0}; std::string eventNameTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT_SUBSCRIBER_NOPRIORITY"; - std::string eventActionTimeOut = "TESTEVENT_PUBLISHORDER_TIMEOUT_SUBSCRIBER_NOPRIORITY"; - MatchingSkills matchingSkillsTimeOne; - matchingSkillsTimeOne.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoOne(matchingSkillsTimeOne); + + MatchingSkills matchingSkills; + matchingSkills.AddEvent(eventNameTimeOut); + + Want wantTimeOut; + wantTimeOut.SetAction(eventNameTimeOut); + CommonEventData commonEventDataTimeOut(wantTimeOut); + + CommonEventPublishInfo publishInfoTimeOut; + publishInfoTimeOut.SetOrdered(true); + + CommonEventSubscribeInfo subscribeInfoOne(matchingSkills); auto subscriberTimeOnePtr = std::make_shared(subscribeInfoOne); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr)); - MatchingSkills matchingSkillsTimeTwo; - matchingSkillsTimeTwo.AddEvent(eventNameTimeOut); - CommonEventSubscribeInfo subscribeInfoTwo(matchingSkillsTimeOne); + CommonEventSubscribeInfo subscribeInfoTwo(matchingSkills); auto subscriberTimeTwoPtr = std::make_shared(subscribeInfoTwo); EXPECT_TRUE(CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr)); mtx_.lock(); - struct tm startTime = {0}; - Want wantTimeOut; - wantTimeOut.SetAction(eventActionTimeOut); - CommonEventData commonEventDataTimeOut(wantTimeOut); - CommonEventPublishInfo publishInfoTimeOut; - publishInfoTimeOut.SetOrdered(true); EXPECT_EQ(OHOS::GetSystemCurrentTime(&startTime), true); EXPECT_TRUE( CommonEventManager::PublishCommonEvent(commonEventDataTimeOut, publishInfoTimeOut, subscriberTimeTwoPtr)); @@ -2604,11 +2710,11 @@ HWTEST_F(cesSystemTest, CES_PublishOrderTimeOut_0400, Function | MediumTest | Le } // expect the subscriber could receive the event within 11 seconds. std::cout << "seconds: " << seconds << std::endl; - EXPECT_LT(TIME_OUT_SECONDS_NINE, seconds); - EXPECT_LT(seconds, TIME_OUT_SECONDS_ELEVEN); - CommonEventManager::SubscribeCommonEvent(subscriberTimeOnePtr); - CommonEventManager::SubscribeCommonEvent(subscriberTimeTwoPtr); + EXPECT_GE(seconds, TIME_OUT_SECONDS_TEN); + mtx_.unlock(); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeOnePtr), true); + EXPECT_EQ(CommonEventManager::UnSubscribeCommonEvent(subscriberTimeTwoPtr), true); } /* @@ -2625,16 +2731,13 @@ HWTEST_F(cesSystemTest, CES_PermissionAndOrDefault_0100, Function | MediumTest | wantAnd.SetAction(eventAndN); CommonEventData commonEventDataAnd(wantAnd); CommonEventPublishInfo publishInfoAnd; - bool resultAnd = EventFwk::CommonEventManager::PublishCommonEvent(commonEventDataAnd, publishInfoAnd); - EXPECT_TRUE(resultAnd); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventDataAnd, publishInfoAnd), true); Want wantDefaultN; wantDefaultN.SetAction(eventDefaultN); CommonEventData commonEventDataDefaultN(wantDefaultN); CommonEventPublishInfo publishInfoDefaultN; - bool resultDefaultN = - EventFwk::CommonEventManager::PublishCommonEvent(commonEventDataDefaultN, publishInfoDefaultN); - EXPECT_TRUE(resultDefaultN); + EXPECT_EQ(CommonEventManager::PublishCommonEvent(commonEventDataDefaultN, publishInfoDefaultN), true); } } // namespace EventFwk } // namespace OHOS \ No newline at end of file