[ Merge of http://go/wvgerrit/93505 ] During the merge process there were a few CL comments (ag/10122083) that were not able to be addressed. Most changes in the CL are spelling / grammar corrections. Bug: 148907684 Bug: 141247171 Test: CDM unit tests Change-Id: I9a8648525bbe5ed319521ebf01741a958ab69ae2
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
// Copyright 2019 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 <stdint.h>
|
|
|
|
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_
|