Define Text Sample Matchers and Test Functions

This change create some matchers and text functions that
will be used by the upcoming webvtt work.

Change-Id: I2d7931d1bdabd761f74e8aee7524d5ecfb7cfdc4
This commit is contained in:
Aaron Vaage 2017-09-18 08:47:00 -07:00
parent 8067fd4818
commit 23a2893a35
2 changed files with 40 additions and 3 deletions

View File

@ -7,6 +7,7 @@
#include "packager/media/base/media_handler_test_base.h"
#include "packager/media/base/audio_stream_info.h"
#include "packager/media/base/text_stream_info.h"
#include "packager/media/base/video_stream_info.h"
#include "packager/status_test_util.h"
@ -186,11 +187,31 @@ std::unique_ptr<SegmentInfo> MediaHandlerTestBase::GetSegmentInfo(
return info;
}
std::unique_ptr<StreamInfo> MediaHandlerTestBase::GetTextStreamInfo() const {
// None of this information is actually used by the text out handler.
// The stream info is just needed to signal the start of the stream.
return std::unique_ptr<StreamInfo>(
new TextStreamInfo(0, 0, 0, kUnknownCodec, "", "", 0, 0, ""));
}
std::unique_ptr<TextSample> MediaHandlerTestBase::GetTextSample(
const std::string& id,
uint64_t start,
uint64_t end,
const std::string& payload) const {
std::unique_ptr<TextSample> sample(new TextSample);
sample->set_id(id);
sample->SetTime(start, end);
sample->AppendPayload(payload);
return sample;
}
MediaHandlerGraphTestBase::MediaHandlerGraphTestBase()
: next_handler_(new FakeMediaHandler),
some_handler_(new FakeMediaHandler) {}
void MediaHandlerGraphTestBase::SetUpGraph(size_t num_inputs,
void MediaHandlerGraphTestBase::SetUpGraph(
size_t num_inputs,
size_t num_outputs,
std::shared_ptr<MediaHandler> handler) {
// Input handler is not really used anywhere but just to satisfy one input

View File

@ -74,6 +74,15 @@ MATCHER_P4(IsMediaSample, stream_index, timestamp, duration, encrypted, "") {
arg->media_sample->is_encrypted() == encrypted;
}
MATCHER_P5(IsTextSample, id, start_time, end_time, settings, payload, "") {
return arg->stream_data_type == StreamDataType::kTextSample &&
arg->text_sample->id() == id &&
arg->text_sample->start_time() == start_time &&
arg->text_sample->EndTime() == end_time &&
arg->text_sample->settings() == settings &&
arg->text_sample->payload() == payload;
}
class FakeInputMediaHandler : public MediaHandler {
public:
using MediaHandler::Dispatch;
@ -155,6 +164,13 @@ class MediaHandlerTestBase : public ::testing::Test {
int64_t duration,
bool is_subsegment) const;
std::unique_ptr<StreamInfo> GetTextStreamInfo() const;
std::unique_ptr<TextSample> GetTextSample(const std::string& id,
uint64_t start,
uint64_t end,
const std::string& payload) const;
private:
MediaHandlerTestBase(const MediaHandlerTestBase&) = delete;
MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete;