File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,5 +47,7 @@ namespace ECFMP::Event {
4747 * Compares events.
4848 */
4949 [[nodiscard]] auto operator ==(const class Event & event) const -> bool ;
50+
51+ // TODO: Event participants
5052 };
5153}// namespace ECFMP::Event
Original file line number Diff line number Diff line change 77
88namespace ECFMP ::EventBus {
99
10- template <typename EventType>
11- class EventStreamFactory ;
12-
1310 class EventBus
1411 {
1512 public:
@@ -48,6 +45,17 @@ namespace ECFMP::EventBus {
4845 GetStream<EventType>().SubscribeOnce (listener, filter);
4946 };
5047
48+ /* *
49+ * Checks whether a specified type of listener is registered for a specified type of event.
50+ *
51+ * Can be used for test assertions.
52+ */
53+ template <typename ListenerType, typename EventType>
54+ [[nodiscard]] auto HasListenerOfType () -> bool
55+ {
56+ return GetStream<EventType>().template HasListenerOfType <ListenerType>();
57+ }
58+
5159 private:
5260 template <typename EventType>
5361 auto GetStream () -> InternalEventStream<EventType>&
Original file line number Diff line number Diff line change @@ -34,5 +34,26 @@ namespace ECFMP::EventBus {
3434 this ->subscriptions .end ()
3535 );
3636 };
37+
38+ /* *
39+ * A method for testing only, shouldn't normally be used.
40+ */
41+ template <typename ListenerType>
42+ [[nodiscard]] auto HasListenerOfType () -> bool
43+ {
44+ auto guard = std::lock_guard (this ->mutex );
45+ return std::any_of (
46+ this ->subscriptions .begin (), this ->subscriptions .end (),
47+ [](const EventSubscription<EventType>& subscription) {
48+ try {
49+ static_cast <void >(dynamic_cast <const ListenerType&>(*subscription.listener ));
50+ return true ;
51+ }
52+ catch (std::bad_cast&) {
53+ return false ;
54+ }
55+ }
56+ );
57+ }
3758 };
3859}// namespace ECFMP::EventBus
Original file line number Diff line number Diff line change 11#include " ECFMP/SdkFactory.h"
22#include " ECFMP/EventListeners.h"
3+ #include " ECFMP/eventbus/EventBus.h"
4+ #include " api/ApiDataDownloadedEvent.h"
5+ #include " api/ApiDataParser.h"
36#include " mock/MockHttpClient.h"
47#include " mock/MockLogger.h"
58
@@ -64,4 +67,13 @@ namespace ECFMPTest::Plugin {
6467 ECFMP ::Plugin::SdkConfigurationException
6568 );
6669 }
70+
71+ TEST_F (SdkFactoryTest, ItRegistersApiDataParserForApiDataEvents)
72+ {
73+ const auto instance = ECFMP::Plugin::SdkFactory::Build ().WithHttpClient (std::move (http)).Instance ();
74+ auto hasListener =
75+ instance->EventBus ().HasListenerOfType <ECFMP ::Api::ApiDataParser, ECFMP ::Api::ApiDataDownloadedEvent>();
76+ EXPECT_TRUE (hasListener);
77+ instance->Destroy ();
78+ }
6779}// namespace ECFMPTest::Plugin
You can’t perform that action at this time.
0 commit comments