74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
// Copyright 2015 Google Inc. All Rights Reserved.
|
|
#ifndef WVCDM_CDM_TEST_TEST_HOST_H_
|
|
#define WVCDM_CDM_TEST_TEST_HOST_H_
|
|
|
|
#include <queue>
|
|
#include <vector>
|
|
|
|
#include "cdm.h"
|
|
#include "override.h"
|
|
|
|
class TestHost : public widevine::Cdm::IStorage,
|
|
public widevine::Cdm::IClock,
|
|
public widevine::Cdm::ITimer {
|
|
public:
|
|
TestHost();
|
|
void Reset();
|
|
|
|
void ElapseTime(int64_t milliseconds);
|
|
int NumTimers() const;
|
|
|
|
void SaveProvisioningInformation() { save_device_cert_ = true; }
|
|
|
|
virtual bool read(const std::string& name,
|
|
std::string* data) OVERRIDE;
|
|
virtual bool write(const std::string& name,
|
|
const std::string& data) OVERRIDE;
|
|
virtual bool exists(const std::string& name) OVERRIDE;
|
|
virtual bool remove(const std::string& name) OVERRIDE;
|
|
virtual int32_t size(const std::string& name) OVERRIDE;
|
|
virtual bool list(std::vector<std::string>* names) OVERRIDE;
|
|
|
|
virtual int64_t now() OVERRIDE;
|
|
|
|
virtual void setTimeout(int64_t delay_ms,
|
|
IClient* client,
|
|
void* context) OVERRIDE;
|
|
virtual void cancel(IClient* client) OVERRIDE;
|
|
|
|
private:
|
|
struct Timer {
|
|
Timer(int64_t expiry_time, IClient* client, void* context)
|
|
: expiry_time_(expiry_time), client_(client), context_(context) {}
|
|
|
|
bool operator<(const Timer& other) const {
|
|
// We want to reverse the order so that the smallest expiry times go to
|
|
// the top of the priority queue.
|
|
return expiry_time_ > other.expiry_time_;
|
|
}
|
|
|
|
int64_t expiry_time() { return expiry_time_; }
|
|
IClient* client() { return client_; }
|
|
void* context() { return context_; }
|
|
|
|
private:
|
|
int64_t expiry_time_;
|
|
IClient* client_;
|
|
void* context_;
|
|
};
|
|
|
|
int64_t now_;
|
|
std::priority_queue<Timer> timers_;
|
|
|
|
std::string device_cert_;
|
|
bool save_device_cert_;
|
|
|
|
typedef std::map<std::string, std::string> StorageMap;
|
|
StorageMap files_;
|
|
};
|
|
|
|
// Owned and managed by the test runner.
|
|
extern TestHost* g_host;
|
|
|
|
#endif // WVCDM_CDM_TEST_TEST_HOST_H_
|