test_waitable_event.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_TEST_TEST_WAITABLE_EVENT_H_
  5. #define BASE_TEST_TEST_WAITABLE_EVENT_H_
  6. #include "base/synchronization/waitable_event.h"
  7. #include "build/build_config.h"
  8. #if BUILDFLAG(IS_WIN)
  9. #include "base/win/scoped_handle.h"
  10. #endif
  11. namespace base {
  12. // A WaitableEvent for use in tests, it has the same API as WaitableEvent with
  13. // the following two distinctions:
  14. // 1) ScopedAllowBaseSyncPrimitivesForTesting is not required to block on it.
  15. // 2) It doesn't instantiate a ScopedBlockingCallWithBaseSyncPrimitives in
  16. // Wait() (important in some //base tests that are thrown off when the
  17. // WaitableEvents used to drive the test add additional ScopedBlockingCalls
  18. // to the mix of monitored calls).
  19. class TestWaitableEvent : public WaitableEvent {
  20. public:
  21. TestWaitableEvent(ResetPolicy reset_policy = ResetPolicy::MANUAL,
  22. InitialState initial_state = InitialState::NOT_SIGNALED);
  23. #if BUILDFLAG(IS_WIN)
  24. explicit TestWaitableEvent(win::ScopedHandle event_handle);
  25. #endif
  26. };
  27. static_assert(sizeof(TestWaitableEvent) == sizeof(WaitableEvent),
  28. "WaitableEvent is non-virtual, TestWaitableEvent must be usable "
  29. "interchangeably.");
  30. } // namespace base
  31. #endif // BASE_TEST_TEST_WAITABLE_EVENT_H_