OEMCrypto and OPK v20 prerelease initial commit
This commit is contained in:
@@ -5,11 +5,14 @@
|
||||
// Clock - A fake clock just for running tests. This is used when running
|
||||
// OEMCrypto unit tests. It is not used when tests include the CE CDM source
|
||||
// code because that uses the clock in cdm/test_host.cpp instead.
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "clock.h"
|
||||
#include "test_sleep.h"
|
||||
#include "wv_duration.h"
|
||||
#include "wv_timestamp.h"
|
||||
|
||||
namespace wvutil {
|
||||
|
||||
@@ -19,16 +22,19 @@ class FakeClock : public TestSleep::CallBack {
|
||||
public:
|
||||
FakeClock() {
|
||||
auto now = std::chrono::system_clock().now();
|
||||
now_ = now.time_since_epoch() / std::chrono::milliseconds(1);
|
||||
now_ = Timestamp::FromUnixMilliseconds(
|
||||
std::chrono::floor<Milliseconds>(now.time_since_epoch()));
|
||||
TestSleep::AddCallback(this);
|
||||
}
|
||||
~FakeClock() { TestSleep::RemoveCallback(this); }
|
||||
void ElapseTime(int64_t milliseconds) { now_ += milliseconds; }
|
||||
void ElapseTime(int64_t milliseconds) override {
|
||||
now_ += Duration::FromMilliseconds(milliseconds);
|
||||
}
|
||||
|
||||
int64_t now() const { return now_; }
|
||||
Timestamp now() const { return now_; }
|
||||
|
||||
private:
|
||||
int64_t now_;
|
||||
Timestamp now_;
|
||||
};
|
||||
|
||||
FakeClock* g_fake_clock = nullptr;
|
||||
@@ -38,7 +44,12 @@ FakeClock* g_fake_clock = nullptr;
|
||||
int64_t Clock::GetCurrentTime() {
|
||||
TestSleep::SyncFakeClock();
|
||||
if (g_fake_clock == nullptr) g_fake_clock = new FakeClock();
|
||||
return g_fake_clock->now() / 1000;
|
||||
return static_cast<int64_t>(g_fake_clock->now().epoch_seconds().count());
|
||||
}
|
||||
|
||||
Timestamp Clock::GetCurrentTimestamp() {
|
||||
TestSleep::SyncFakeClock();
|
||||
if (g_fake_clock == nullptr) g_fake_clock = new FakeClock();
|
||||
return g_fake_clock->now();
|
||||
}
|
||||
} // namespace wvutil
|
||||
|
||||
Reference in New Issue
Block a user