CppUtils::UnitTest::EventWatcher<String::Hasher eventName, class... Args>
CLASSThread-safe RAII observer for monitoring emitted events and collecting payloads.
Description
Section titled “Description”Subscribes to the designated event upon construction and unsubscribes automatically upon destruction. Provides blocking synchronization utilities (waitForEvent, waitForOccurrences) and thread-safe inspection of occurrence counts and captured payloads.
| Template parameter | Description |
|---|---|
eventName | Compile-time hashed string identifying the event. |
Args | Types of the event payload arguments. |
Public types
Section titled “Public types”Payload
Section titled “Payload”using CppUtils::UnitTest::EventWatcher<eventName, Args>::Payload = std::conditional_t<sizeof...(Args) == 0, std::monostate, std::conditional_t<sizeof...(Args) == 1, std::tuple_element_t<0, std::tuple<Args..., void>>, std::tuple<Args...>>>;Public methods
Section titled “Public methods”Subscribes the watcher to the specified event emitter.
| Parameter | Description |
|---|---|
emitter | Reference to the event emitter to monitor. |
Returns the total number of times the monitored event has been fired.
Returns: Event occurrence count.
Checks if the monitored event has occurred at least once.
Returns: True if count() > 0.
template <Chrono::Duration TimeoutDuration = std::chrono::milliseconds>auto EventWatcher::waitForOccurrences(std::size_t targetCount, TimeoutDuration timeout = std::chrono::milliseconds{1000}) -> bool;Blocks until the event has been fired at least targetCount times or timeout expires.
| Template parameter | Description |
|---|---|
TimeoutDuration | Duration type (defaults to std::chrono::milliseconds). |
| Parameter | Description |
|---|---|
targetCount | Number of occurrences to wait for. |
timeout | Maximum duration to wait before giving up. |
Returns: True if the target occurrence count was reached before the timeout expired.
template <Chrono::Duration TimeoutDuration = std::chrono::milliseconds>auto EventWatcher::waitForEvent(TimeoutDuration timeout = std::chrono::milliseconds{1000}) -> bool;Blocks until the event occurs at least once or timeout expires.
| Template parameter | Description |
|---|---|
TimeoutDuration | Duration type (defaults to std::chrono::milliseconds). |
| Parameter | Description |
|---|---|
timeout | Maximum duration to wait before giving up. |
Returns: True if the event occurred before the timeout expired.
Acquires exclusive locked access to the recorded state and payloads.
Returns: Unique accessor locking the internal state.