Files
oemcrypto/util/test/test_sleep.h
Fred Gylys-Colwell 2f232e2939 OEMCrypto v16.1 Documentation and Headers
This commit contains the updated v16.1 documentation dated Nov 12th,
as well has the headers and update ODK library.

Unit tests and reference code is partially implemented, but not yet
complete.
2019-11-15 15:45:18 -08:00

50 lines
1.5 KiB
C++

// 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 <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_