From b5800fad77f20252301f647a568c6c114b93648c Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Thu, 14 Sep 2017 09:23:29 -0700 Subject: [PATCH] Created Mock Input and Output Media Handlers Created media handlers that make testing a handler easier by providing methods to send messages from upstream and check messages downstream. Change-Id: I7b3ba3a51bcf0d73bcaacd46b2dcbc16f87d8694 --- .../media/base/media_handler_test_base.cc | 27 +++++++++++++++++++ packager/media/base/media_handler_test_base.h | 23 ++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/packager/media/base/media_handler_test_base.cc b/packager/media/base/media_handler_test_base.cc index f6997ec196..8ff42c4c90 100644 --- a/packager/media/base/media_handler_test_base.cc +++ b/packager/media/base/media_handler_test_base.cc @@ -59,6 +59,33 @@ const uint8_t kData[]{ namespace shaka { namespace media { +bool FakeInputMediaHandler::ValidateOutputStreamIndex(size_t index) const { + return true; +} + +Status FakeInputMediaHandler::InitializeInternal() { + return Status::OK; +} + +Status FakeInputMediaHandler::Process(std::unique_ptr stream_data) { + return Status::OK; +} + +Status MockOutputMediaHandler::InitializeInternal() { + return Status::OK; +} + +Status MockOutputMediaHandler::Process( + std::unique_ptr stream_data) { + OnProcess(stream_data.get()); + return Status::OK; +} + +Status MockOutputMediaHandler::OnFlushRequest(size_t index) { + OnFlush(index); + return Status::OK; +} + Status FakeMediaHandler::InitializeInternal() { return Status::OK; } diff --git a/packager/media/base/media_handler_test_base.h b/packager/media/base/media_handler_test_base.h index daedcc5b15..c7d432cd9e 100644 --- a/packager/media/base/media_handler_test_base.h +++ b/packager/media/base/media_handler_test_base.h @@ -74,6 +74,29 @@ MATCHER_P4(IsMediaSample, stream_index, timestamp, duration, encrypted, "") { arg->media_sample->is_encrypted() == encrypted; } +class FakeInputMediaHandler : public MediaHandler { + public: + using MediaHandler::Dispatch; + using MediaHandler::FlushAllDownstreams; + using MediaHandler::FlushDownstream; + + private: + bool ValidateOutputStreamIndex(size_t index) const override; + Status InitializeInternal() override; + Status Process(std::unique_ptr stream_data) override; +}; + +class MockOutputMediaHandler : public MediaHandler { + public: + MOCK_METHOD1(OnProcess, void(const StreamData*)); + MOCK_METHOD1(OnFlush, void(size_t index)); + + private: + Status InitializeInternal() override; + Status Process(std::unique_ptr stream_data) override; + Status OnFlushRequest(size_t index) override; +}; + // A fake media handler definition used for testing. class FakeMediaHandler : public MediaHandler { public: