simple_test_clock.h 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2012 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_SIMPLE_TEST_CLOCK_H_
  5. #define BASE_TEST_SIMPLE_TEST_CLOCK_H_
  6. #include "base/compiler_specific.h"
  7. #include "base/synchronization/lock.h"
  8. #include "base/time/clock.h"
  9. #include "base/time/time.h"
  10. namespace base {
  11. // SimpleTestClock is a Clock implementation that gives control over
  12. // the returned Time objects. All methods may be called from any
  13. // thread.
  14. class SimpleTestClock : public Clock {
  15. public:
  16. // Starts off with a clock set to Time().
  17. SimpleTestClock();
  18. ~SimpleTestClock() override;
  19. Time Now() const override;
  20. // Advances the clock by |delta|.
  21. void Advance(TimeDelta delta);
  22. // Sets the clock to the given time.
  23. void SetNow(Time now);
  24. private:
  25. // Protects |now_|.
  26. mutable Lock lock_;
  27. Time now_;
  28. };
  29. } // namespace base
  30. #endif // BASE_TEST_SIMPLE_TEST_CLOCK_H_