Files
ce_cdm/cdm/test/test_host.h
Joey Parrish 0546ee6732 Source release v3.0.0-0-g8d3792b-ce + third_party
Change-Id: I399e71ddfffcd436171d1c60283c63ab4658e0b1
2015-06-19 15:13:49 -07:00

61 lines
1.6 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 "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;
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 int64_t now() OVERRIDE;
virtual void setTimeout(int64_t delay_ms,
IClient* client,
void* context) 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;
IClient* client;
void* context;
};
int64_t now_;
std::priority_queue<Timer> timers_;
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_