Files
ce_cdm/cdm/test/test_host.h
2020-07-24 14:30:03 -07:00

86 lines
2.6 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.
#ifndef WVCDM_CDM_TEST_TEST_HOST_H_
#define WVCDM_CDM_TEST_TEST_HOST_H_
#include <map>
#include <queue>
#include <string>
#include <vector>
#include "cdm.h"
#include "test_sleep.h"
// This provides a host environment for running CDM tests. It implements the
// IStorage, IClock and ITimer interfaces that a host would normally implement,
// while allowing them to be manipulated by the test.
class TestHost : public widevine::Cdm::IStorage,
public widevine::Cdm::IClock,
public widevine::Cdm::ITimer,
public wvcdm::TestSleep::CallBack {
public:
TestHost();
~TestHost();
void Reset();
// Used for manipulating and inspecting timer states during testing.
void ElapseTime(int64_t milliseconds) override;
int NumTimers() const;
// This should be called before trying to write the cert.bin file. This is
// used when testing device provisioning.
void SaveProvisioningInformation() { save_device_cert_ = true; }
// widevine::Cdm::IStorage
bool read(const std::string& name, std::string* data) override;
bool write(const std::string& name, const std::string& data) override;
bool exists(const std::string& name) override;
bool remove(const std::string& name) override;
int32_t size(const std::string& name) override;
bool list(std::vector<std::string>* names) override;
// widevine::Cdm::IClock
int64_t now() override;
// widevine::Cdm::ITimer
void setTimeout(int64_t delay_ms, IClient* client, void* context) override;
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;
extern std::string g_sandbox_id;
#endif // WVCDM_CDM_TEST_TEST_HOST_H_