Created Test Handler CachingMediaHandler

Renamed "FakeMediaHandler" to "CachingMediaHandler" so that it
is easier to differentiate from "FakeInputMediaHandler". It will
be used as the single method to verify media handler output.

This is part of an effort to find a cleaner way to test media handlers.

Change-Id: Ie391fe23ee3389d13b012ae3093744a453106c19
This commit is contained in:
Aaron Vaage 2018-06-20 16:13:15 -07:00
parent 33792ca2da
commit 60df64705b
2 changed files with 20 additions and 19 deletions

View File

@ -152,20 +152,20 @@ Status MockOutputMediaHandler::OnFlushRequest(size_t index) {
return Status::OK; return Status::OK;
} }
Status FakeMediaHandler::InitializeInternal() { Status CachingMediaHandler::InitializeInternal() {
return Status::OK; return Status::OK;
} }
Status FakeMediaHandler::Process(std::unique_ptr<StreamData> stream_data) { Status CachingMediaHandler::Process(std::unique_ptr<StreamData> stream_data) {
stream_data_vector_.push_back(std::move(stream_data)); stream_data_vector_.push_back(std::move(stream_data));
return Status::OK; return Status::OK;
} }
Status FakeMediaHandler::OnFlushRequest(size_t input_stream_index) { Status CachingMediaHandler::OnFlushRequest(size_t input_stream_index) {
return Status::OK; return Status::OK;
} }
bool FakeMediaHandler::ValidateOutputStreamIndex(size_t stream_index) const { bool CachingMediaHandler::ValidateOutputStreamIndex(size_t stream_index) const {
return true; return true;
} }
@ -346,16 +346,16 @@ MockOutputMediaHandler* MediaHandlerTestBase::Output(size_t index) {
} }
MediaHandlerGraphTestBase::MediaHandlerGraphTestBase() MediaHandlerGraphTestBase::MediaHandlerGraphTestBase()
: next_handler_(new FakeMediaHandler), : next_handler_(new CachingMediaHandler),
some_handler_(new FakeMediaHandler) {} some_handler_(new CachingMediaHandler) {}
void MediaHandlerGraphTestBase::SetUpGraph( void MediaHandlerGraphTestBase::SetUpGraph(
size_t num_inputs, size_t num_inputs,
size_t num_outputs, size_t num_outputs,
std::shared_ptr<MediaHandler> handler) { std::shared_ptr<MediaHandler> handler) {
// Input handler is not really used anywhere but just to satisfy one input // Input handler is not really used anywhere else except to validate number of
// one output restriction for the encryption handler. // allowed inputs for the handler to be tested.
auto input_handler = std::make_shared<FakeMediaHandler>(); auto input_handler = std::make_shared<CachingMediaHandler>();
for (size_t i = 0; i < num_inputs; ++i) for (size_t i = 0; i < num_inputs; ++i)
ASSERT_OK(input_handler->SetHandler(i, handler)); ASSERT_OK(input_handler->SetHandler(i, handler));
// All outputs are routed to |next_handler_|. // All outputs are routed to |next_handler_|.
@ -365,11 +365,11 @@ void MediaHandlerGraphTestBase::SetUpGraph(
const std::vector<std::unique_ptr<StreamData>>& const std::vector<std::unique_ptr<StreamData>>&
MediaHandlerGraphTestBase::GetOutputStreamDataVector() const { MediaHandlerGraphTestBase::GetOutputStreamDataVector() const {
return next_handler_->stream_data_vector(); return next_handler_->Cache();
} }
void MediaHandlerGraphTestBase::ClearOutputStreamDataVector() { void MediaHandlerGraphTestBase::ClearOutputStreamDataVector() {
next_handler_->clear_stream_data_vector(); next_handler_->Clear();
} }
} // namespace media } // namespace media

View File

@ -270,16 +270,17 @@ class MockOutputMediaHandler : public MediaHandler {
Status OnFlushRequest(size_t index) override; Status OnFlushRequest(size_t index) override;
}; };
// TODO(vaage) : Remove this test handler and convert other tests to use class CachingMediaHandler : public MediaHandler {
// FakeInputMediaHandler and MockOutputMediaHandler.
class FakeMediaHandler : public MediaHandler {
public: public:
const std::vector<std::unique_ptr<StreamData>>& stream_data_vector() const { const std::vector<std::unique_ptr<StreamData>>& Cache() const {
return stream_data_vector_; return stream_data_vector_;
} }
void clear_stream_data_vector() { stream_data_vector_.clear(); }
protected: // TODO(vaage) : Remove the use of clear in our tests as it can make flow
// of the test harder to understand.
void Clear() { stream_data_vector_.clear(); }
private:
Status InitializeInternal() override; Status InitializeInternal() override;
Status Process(std::unique_ptr<StreamData> stream_data) override; Status Process(std::unique_ptr<StreamData> stream_data) override;
Status OnFlushRequest(size_t input_stream_index) override; Status OnFlushRequest(size_t input_stream_index) override;
@ -381,7 +382,7 @@ class MediaHandlerGraphTestBase : public MediaHandlerTestBase {
std::shared_ptr<MediaHandler> some_handler() { return some_handler_; } std::shared_ptr<MediaHandler> some_handler() { return some_handler_; }
/// @return some a downstream handler that can be used for connecting. /// @return some a downstream handler that can be used for connecting.
std::shared_ptr<FakeMediaHandler> next_handler() { return next_handler_; } std::shared_ptr<CachingMediaHandler> next_handler() { return next_handler_; }
private: private:
MediaHandlerGraphTestBase(const MediaHandlerGraphTestBase&) = delete; MediaHandlerGraphTestBase(const MediaHandlerGraphTestBase&) = delete;
@ -389,7 +390,7 @@ class MediaHandlerGraphTestBase : public MediaHandlerTestBase {
delete; delete;
// Downstream handler used in testing graph. // Downstream handler used in testing graph.
std::shared_ptr<FakeMediaHandler> next_handler_; std::shared_ptr<CachingMediaHandler> next_handler_;
// Some random handler which can be used for testing. // Some random handler which can be used for testing.
std::shared_ptr<MediaHandler> some_handler_; std::shared_ptr<MediaHandler> some_handler_;
}; };