Added IsVideoStreamInfo Test Matcher

Added a matcher for Video Streams. This will allow us to use a general
matcher in tests for video specific fields.

Change-Id: I91b9aebd66be37ec6d5f09b762263fafaef854c2
This commit is contained in:
Aaron Vaage 2018-06-19 09:53:50 -07:00
parent 26bb50640c
commit bf29257e48
2 changed files with 46 additions and 0 deletions

View File

@ -81,6 +81,21 @@ bool TryMatchStreamDataType(const StreamDataType& actual,
return true; return true;
} }
bool TryMatchStreamType(const StreamType& actual,
const StreamType& expected,
::testing::MatchResultListener* listener) {
if (actual != expected) {
std::string expected_as_string = StreamTypeToString(expected);
std::string actual_as_string = StreamTypeToString(actual);
*listener << "which is " << actual_as_string << " (expected "
<< expected_as_string << ")";
return false;
}
return true;
}
std::string ToPrettyString(const std::string& str) { std::string ToPrettyString(const std::string& str) {
std::string out; std::string out;

View File

@ -12,6 +12,7 @@
#include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_number_conversions.h"
#include "packager/media/base/media_handler.h" #include "packager/media/base/media_handler.h"
#include "packager/media/base/video_stream_info.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -23,6 +24,10 @@ bool TryMatchStreamDataType(const StreamDataType& actual,
const StreamDataType& expected, const StreamDataType& expected,
::testing::MatchResultListener* listener); ::testing::MatchResultListener* listener);
bool TryMatchStreamType(const StreamType& actual,
const StreamType& expected,
::testing::MatchResultListener* listener);
template <typename T, typename M> template <typename T, typename M>
bool TryMatch(const T& value, bool TryMatch(const T& value,
const M& matcher, const M& matcher,
@ -62,6 +67,32 @@ MATCHER_P4(IsStreamInfo, stream_index, time_scale, encrypted, language, "") {
"language"); "language");
} }
MATCHER_P3(IsVideoStream, stream_index, trick_play_factor, playback_rate, "") {
if (!TryMatchStreamDataType(arg->stream_data_type,
StreamDataType::kStreamInfo, result_listener)) {
return false;
}
if (!TryMatchStreamType(arg->stream_info->stream_type(), kStreamVideo,
result_listener)) {
return false;
}
const VideoStreamInfo* info =
static_cast<const VideoStreamInfo*>(arg->stream_info.get());
*result_listener << "which is (" << arg->stream_index << ", "
<< info->trick_play_factor() << ", " << info->playback_rate()
<< ")";
return TryMatch(arg->stream_index, stream_index, result_listener,
"stream_index") &&
TryMatch(info->trick_play_factor(), trick_play_factor, result_listener,
"trick_play_factor") &&
TryMatch(info->playback_rate(), playback_rate, result_listener,
"playback_rate");
}
MATCHER_P5(IsSegmentInfo, MATCHER_P5(IsSegmentInfo,
stream_index, stream_index,
start_timestamp, start_timestamp,