Files
android/libwvdrmengine/cdm/util/test/test_clock.cpp
Alex Dale 8977119d05 Small fixes leftover from V16 merge.
[ 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
2020-02-06 17:44:45 -08:00

41 lines
980 B
C++

// Copyright 2019 Google Inc. All Rights Reserved.
//
// Clock - A fake clock just for running tests.
#include "clock.h"
#include <chrono>
#include "test_sleep.h"
namespace wvcdm {
namespace {
// A fake clock that only advances when TestSleep::Sleep is called.
class FakeClock : public wvcdm::TestSleep::CallBack {
public:
FakeClock() {
auto now = std::chrono::steady_clock().now();
now_ = now.time_since_epoch() / std::chrono::milliseconds(1);
TestSleep::set_callback(this);
}
~FakeClock() { TestSleep::set_callback(nullptr); }
void ElapseTime(int64_t milliseconds) { now_ += milliseconds; }
int64_t now() const { return now_; }
private:
int64_t now_;
};
FakeClock* g_fake_clock = nullptr;
} // namespace
// On devices running a fake OEMCrypto, we can use a fake sleep and fake time.
int64_t Clock::GetCurrentTime() {
if (g_fake_clock == nullptr) g_fake_clock = new FakeClock();
return g_fake_clock->now() / 1000;
}
} // namespace wvcdm