diff --git a/packager/media/event/mpd_notify_muxer_listener_unittest.cc b/packager/media/event/mpd_notify_muxer_listener_unittest.cc index 05813873b0..5c1f0ee02f 100644 --- a/packager/media/event/mpd_notify_muxer_listener_unittest.cc +++ b/packager/media/event/mpd_notify_muxer_listener_unittest.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -92,7 +93,8 @@ class MpdNotifyMuxerListenerTest : public ::testing::TestWithParam { MATCHER_P(ExpectMediaInfoEq, expected_text_format, "") { const MediaInfo expected = ConvertToMediaInfo(expected_text_format); - return MediaInfoEqual(expected, arg); + *result_listener << arg.ShortDebugString(); + return ::google::protobuf::util::MessageDifferencer::Equals(arg, expected); } TEST_F(MpdNotifyMuxerListenerTest, VodClearContent) { diff --git a/packager/media/event/muxer_listener_test_helper.cc b/packager/media/event/muxer_listener_test_helper.cc index 8a1b5f8c87..e053201dc9 100644 --- a/packager/media/event/muxer_listener_test_helper.cc +++ b/packager/media/event/muxer_listener_test_helper.cc @@ -110,19 +110,5 @@ std::vector GetDefaultKeySystemInfo() { return key_system_info; } -void ExpectMediaInfoEqual(const MediaInfo& expect, const MediaInfo& actual) { - ASSERT_TRUE(MediaInfoEqual(expect, actual)); -} - -bool MediaInfoEqual(const MediaInfo& expect, const MediaInfo& actual) { - // I found out here - // https://groups.google.com/forum/#!msg/protobuf/5sOExQkB2eQ/ZSBNZI0K54YJ - // that the best way to check equality is to serialize and check equality. - std::string expect_serialized = expect.SerializeAsString(); - std::string actual_serialized = actual.SerializeAsString(); - EXPECT_EQ(expect_serialized, actual_serialized); - return expect_serialized == actual_serialized; -} - } // namespace media } // namespace shaka diff --git a/packager/media/event/muxer_listener_test_helper.h b/packager/media/event/muxer_listener_test_helper.h index fa4c2d25db..aa484a992b 100644 --- a/packager/media/event/muxer_listener_test_helper.h +++ b/packager/media/event/muxer_listener_test_helper.h @@ -100,12 +100,6 @@ std::vector GetDefaultKeySystemInfo(); // Sets "default" values for muxer_options for testing. void SetDefaultMuxerOptions(MuxerOptions* muxer_options); -// Expect that expect and actual are equal. -void ExpectMediaInfoEqual(const MediaInfo& expect, const MediaInfo& actual); - -// Returns true if expect and actual are equal. -bool MediaInfoEqual(const MediaInfo& expect, const MediaInfo& actual); - } // namespace media } // namespace shaka diff --git a/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc b/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc index 2c570c6557..9e74b19113 100644 --- a/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc +++ b/packager/media/event/vod_media_info_dump_muxer_listener_unittest.cc @@ -4,7 +4,9 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +#include #include +#include #include #include @@ -39,19 +41,22 @@ namespace media { namespace { -void ExpectTextFormatMediaInfoEqual(const std::string& expect, - const std::string& actual) { - MediaInfo expect_media_info; +MATCHER_P(FileContentEqualsProto, expected_protobuf, "") { + std::string temp_file_media_info_str; + CHECK(File::ReadFileToString(arg.c_str(), &temp_file_media_info_str)); + CHECK(!temp_file_media_info_str.empty()); + + MediaInfo expected_media_info; MediaInfo actual_media_info; typedef ::google::protobuf::TextFormat TextFormat; - ASSERT_TRUE(TextFormat::ParseFromString(expect, &expect_media_info)) - << "Failed to parse " << std::endl << expect; - ASSERT_TRUE(TextFormat::ParseFromString(actual, &actual_media_info)) - << "Failed to parse " << std::endl << actual; - ASSERT_NO_FATAL_FAILURE( - ExpectMediaInfoEqual(expect_media_info, actual_media_info)) - << "Expect:" << std::endl << expect << std::endl - << "Actual:" << std::endl << actual; + CHECK(TextFormat::ParseFromString(expected_protobuf, &expected_media_info)); + CHECK(TextFormat::ParseFromString(temp_file_media_info_str, + &actual_media_info)); + + *result_listener << actual_media_info.ShortDebugString(); + + return ::google::protobuf::util::MessageDifferencer::Equals( + actual_media_info, expected_media_info); } } // namespace @@ -103,16 +108,6 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test { listener_->OnMediaEnd(params.media_ranges, params.duration_seconds); } - void ExpectTempFileToEqual(const std::string& expected_protobuf) { - std::string temp_file_media_info_str; - ASSERT_TRUE(File::ReadFileToString(temp_file_path_.AsUTF8Unsafe().c_str(), - &temp_file_media_info_str)); - ASSERT_TRUE(!temp_file_media_info_str.empty()); - - ASSERT_NO_FATAL_FAILURE((ExpectTextFormatMediaInfoEqual( - expected_protobuf, temp_file_media_info_str))); - } - protected: base::FilePath temp_file_path_; std::unique_ptr listener_; @@ -151,7 +146,8 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal) { "container_type: 1\n" "media_file_name: 'test_output_file_name.mp4'\n" "media_duration_seconds: 10.5\n"; - ASSERT_NO_FATAL_FAILURE(ExpectTempFileToEqual(kExpectedProtobufOutput)); + EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), + FileContentEqualsProto(kExpectedProtobufOutput)); } TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) { @@ -194,7 +190,8 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) { " protection_scheme: 'cenc'\n" "}\n"; - ASSERT_NO_FATAL_FAILURE(ExpectTempFileToEqual(kExpectedProtobufOutput)); + EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), + FileContentEqualsProto(kExpectedProtobufOutput)); } // Verify that VideoStreamInfo with non-0 pixel_{width,height} is set in the @@ -231,7 +228,8 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckPixelWidthAndHeightSet) { "container_type: 1\n" "media_file_name: 'test_output_file_name.mp4'\n" "media_duration_seconds: 10.5\n"; - ASSERT_NO_FATAL_FAILURE(ExpectTempFileToEqual(kExpectedProtobufOutput)); + EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), + FileContentEqualsProto(kExpectedProtobufOutput)); } TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckBandwidth) { @@ -272,7 +270,8 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckBandwidth) { "container_type: 1\n" "media_file_name: 'test_output_file_name.mp4'\n" "media_duration_seconds: 10.5\n"; - ASSERT_NO_FATAL_FAILURE(ExpectTempFileToEqual(kExpectedProtobufOutput)); + EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), + FileContentEqualsProto(kExpectedProtobufOutput)); } } // namespace media