// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine Master // License Agreement. // // TestSleep - Controls sleep and clock adjustment during tests. // #ifndef WVCDM_UTIL_TEST_SLEEP_H_ #define WVCDM_UTIL_TEST_SLEEP_H_ #include namespace wvcdm { class TestSleep { public: // The callback is called when the clock should be advanced. class CallBack { public: virtual void ElapseTime(int64_t milliseconds) = 0; protected: virtual ~CallBack(){}; }; // If real_sleep_ is true, then this sleeps for |seconds| of time. // If the callback exists, this calls the callback. static void Sleep(unsigned int seconds); // If we are using a real clock and a fake clock, then the real clock advances // a little while we are doing work, but the fake one only advances when we // sleep. This function advances the fake clock to be in sync with the real // clock. This function should be called to prevent a slow flaky test from // failing due to this drift. static void SyncFakeClock(); static void set_real_sleep(bool real_sleep) { real_sleep_ = real_sleep; } static void set_callback(CallBack* callback) { callback_ = callback; } private: // Controls if the test sleep should use real sleep. static bool real_sleep_; // Called when the clock should advance. static CallBack* callback_; }; } // namespace wvcdm #endif // WVCDM_UTIL_TEST_SLEEP_H_