From 90e3ec3f9a26bbfc8783d631479aaaa2cf365d77 Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Tue, 6 Sep 2016 15:13:42 -0700 Subject: [PATCH] Some misc cleanup - Replace DCHECK_EQ with DCHECK for compatiblity - Add ASSERT_FILE_CONTAINS - Remove unnecessary release on unique_ptrs Change-Id: I2ec22c52e47cb451479ae9a59818b9df20f62e63 --- packager/hls/base/media_playlist.cc | 4 ++-- packager/media/base/widevine_key_source.cc | 7 ++----- packager/media/file/file_test_util.h | 13 +++++++++++- .../webm/encrypted_segmenter_unittest.cc | 19 ++---------------- .../webm/multi_segment_segmenter_unittest.cc | 19 ++---------------- .../webm/single_segment_segmenter_unittest.cc | 20 ++----------------- 6 files changed, 22 insertions(+), 60 deletions(-) diff --git a/packager/hls/base/media_playlist.cc b/packager/hls/base/media_playlist.cc index 87ad00b279..03f25eed63 100644 --- a/packager/hls/base/media_playlist.cc +++ b/packager/hls/base/media_playlist.cc @@ -232,7 +232,7 @@ void MediaPlaylist::RemoveOldestSegment() { auto entries_itr = entries_.begin(); ++entries_itr; if ((*entries_itr)->type() == HlsEntry::EntryType::kExtInf) { - DCHECK_EQ((*entries_itr)->type(), HlsEntry::EntryType::kExtInf); + DCHECK((*entries_itr)->type() == HlsEntry::EntryType::kExtInf); entries_.erase(entries_itr); return; } @@ -240,7 +240,7 @@ void MediaPlaylist::RemoveOldestSegment() { ++entries_itr; // This assumes that there is a segment between 2 EXT-X-KEY entries. // Which should be the case due to logic in AddEncryptionInfo(). - DCHECK_EQ((*entries_itr)->type(), HlsEntry::EntryType::kExtInf); + DCHECK((*entries_itr)->type() == HlsEntry::EntryType::kExtInf); entries_.erase(entries_itr); entries_.pop_front(); } diff --git a/packager/media/base/widevine_key_source.cc b/packager/media/base/widevine_key_source.cc index 7e3eb2ba2e..e0574e4e57 100644 --- a/packager/media/base/widevine_key_source.cc +++ b/packager/media/base/widevine_key_source.cc @@ -461,9 +461,7 @@ bool WidevineKeySource::DecodeResponse( DCHECK(response); // Extract base64 formatted response from JSON formatted raw response. - // TODO(kqyang): Remove ".release()" when base is updated to use unique_ptr. - std::unique_ptr root( - base::JSONReader::Read(raw_response).release()); + std::unique_ptr root(base::JSONReader::Read(raw_response)); if (!root) { LOG(ERROR) << "'" << raw_response << "' is not in JSON format."; return false; @@ -485,8 +483,7 @@ bool WidevineKeySource::ExtractEncryptionKey( DCHECK(transient_error); *transient_error = false; - // TODO(kqyang): Remove ".release()" when base is updated to use unique_ptr. - std::unique_ptr root(base::JSONReader::Read(response).release()); + std::unique_ptr root(base::JSONReader::Read(response)); if (!root) { LOG(ERROR) << "'" << response << "' is not in JSON format."; return false; diff --git a/packager/media/file/file_test_util.h b/packager/media/file/file_test_util.h index d5f9947364..697beb41d9 100644 --- a/packager/media/file/file_test_util.h +++ b/packager/media/file/file_test_util.h @@ -7,6 +7,9 @@ #ifndef MEDIA_FILE_FILE_TEST_UTIL_H_ #define MEDIA_FILE_FILE_TEST_UTIL_H_ +#include +#include + #include #include "packager/media/file/file.h" @@ -22,8 +25,16 @@ namespace media { ASSERT_EQ(std::string(array_ptr, arraysize(array)), temp_data); \ } while (false) +#define ASSERT_FILE_ENDS_WITH(file_name, array) \ + do { \ + std::string temp_data; \ + ASSERT_TRUE(File::ReadFileToString((file_name), &temp_data)); \ + EXPECT_THAT(temp_data, \ + ::testing::EndsWith(std::string( \ + reinterpret_cast(array), sizeof(array)))); \ + } while (false) + } // namespace media } // namespace shaka #endif // MEDIA_FILE_FILE_TEST_UTIL_H_ - diff --git a/packager/media/formats/webm/encrypted_segmenter_unittest.cc b/packager/media/formats/webm/encrypted_segmenter_unittest.cc index 7e0a537d26..8af360d76f 100644 --- a/packager/media/formats/webm/encrypted_segmenter_unittest.cc +++ b/packager/media/formats/webm/encrypted_segmenter_unittest.cc @@ -20,22 +20,7 @@ const std::string kIv = "0123456789012345"; const std::string kKey = "01234567890123456789012345678901"; const std::string kPsshData = ""; const uint8_t kBasicSupportData[] = { - // ID: EBML Header, Payload Size: 31 - 0x1a, 0x45, 0xdf, 0xa3, 0x9f, - // EBMLVersion: 1 - 0x42, 0x86, 0x81, 0x01, - // EBMLReadVersion: 1 - 0x42, 0xf7, 0x81, 0x01, - // EBMLMaxIDLength: 4 - 0x42, 0xf2, 0x81, 0x04, - // EBMLMaxSizeLength: 8 - 0x42, 0xf3, 0x81, 0x08, - // DocType: 'webm' - 0x42, 0x82, 0x84, 0x77, 0x65, 0x62, 0x6d, - // DocTypeVersion: 2 - 0x42, 0x87, 0x81, 0x02, - // DocTypeReadVersion: 2 - 0x42, 0x85, 0x81, 0x02, + // ID: EBML Header omitted. // ID: Segment, Payload Size: 432 0x18, 0x53, 0x80, 0x67, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb0, // ID: SeekHead, Payload Size: 58 @@ -239,7 +224,7 @@ TEST_F(EncrypedSegmenterTest, BasicSupport) { } ASSERT_OK(segmenter_->Finalize()); - ASSERT_FILE_EQ(OutputFileName().c_str(), kBasicSupportData); + ASSERT_FILE_ENDS_WITH(OutputFileName().c_str(), kBasicSupportData); } } // namespace media diff --git a/packager/media/formats/webm/multi_segment_segmenter_unittest.cc b/packager/media/formats/webm/multi_segment_segmenter_unittest.cc index fe08e1a410..ec3ad2fa6e 100644 --- a/packager/media/formats/webm/multi_segment_segmenter_unittest.cc +++ b/packager/media/formats/webm/multi_segment_segmenter_unittest.cc @@ -15,22 +15,7 @@ namespace { const uint64_t kDuration = 1000; const uint8_t kBasicSupportDataInit[] = { - // ID: EBML Header, Payload Size: 31 - 0x1a, 0x45, 0xdf, 0xa3, 0x9f, - // EBMLVersion: 1 - 0x42, 0x86, 0x81, 0x01, - // EBMLReadVersion: 1 - 0x42, 0xf7, 0x81, 0x01, - // EBMLMaxIDLength: 4 - 0x42, 0xf2, 0x81, 0x04, - // EBMLMaxSizeLength: 8 - 0x42, 0xf3, 0x81, 0x08, - // DocType: 'webm' - 0x42, 0x82, 0x84, 0x77, 0x65, 0x62, 0x6d, - // DocTypeVersion: 2 - 0x42, 0x87, 0x81, 0x02, - // DocTypeReadVersion: 2 - 0x42, 0x85, 0x81, 0x02, + // ID: EBML Header omitted. // ID: Segment, Payload Size: Unknown 0x18, 0x53, 0x80, 0x67, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // ID: Void, Payload Size: 87 @@ -134,7 +119,7 @@ TEST_F(MultiSegmentSegmenterTest, BasicSupport) { ASSERT_OK(segmenter_->Finalize()); // Verify the resulting data. - ASSERT_FILE_EQ(OutputFileName().c_str(), kBasicSupportDataInit); + ASSERT_FILE_ENDS_WITH(OutputFileName().c_str(), kBasicSupportDataInit); ASSERT_FILE_EQ(TemplateFileName(0).c_str(), kBasicSupportDataSegment); // There is no second segment. diff --git a/packager/media/formats/webm/single_segment_segmenter_unittest.cc b/packager/media/formats/webm/single_segment_segmenter_unittest.cc index c30c1a9285..f24bda7630 100644 --- a/packager/media/formats/webm/single_segment_segmenter_unittest.cc +++ b/packager/media/formats/webm/single_segment_segmenter_unittest.cc @@ -16,22 +16,7 @@ namespace { const uint64_t kDuration = 1000; const uint8_t kBasicSupportData[] = { - // ID: EBML Header, Payload Size: 31 - 0x1a, 0x45, 0xdf, 0xa3, 0x9f, - // EBMLVersion: 1 - 0x42, 0x86, 0x81, 0x01, - // EBMLReadVersion: 1 - 0x42, 0xf7, 0x81, 0x01, - // EBMLMaxIDLength: 4 - 0x42, 0xf2, 0x81, 0x04, - // EBMLMaxSizeLength: 8 - 0x42, 0xf3, 0x81, 0x08, - // DocType: 'webm' - 0x42, 0x82, 0x84, 0x77, 0x65, 0x62, 0x6d, - // DocTypeVersion: 2 - 0x42, 0x87, 0x81, 0x02, - // DocTypeReadVersion: 2 - 0x42, 0x85, 0x81, 0x02, + // ID: EBML Header omitted. // ID: Segment, Payload Size: 343 0x18, 0x53, 0x80, 0x67, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x57, // ID: SeekHead, Payload Size: 57 @@ -187,7 +172,7 @@ TEST_P(SingleSegmentSegmenterTest, BasicSupport) { } ASSERT_OK(segmenter_->Finalize()); - ASSERT_FILE_EQ(OutputFileName().c_str(), kBasicSupportData); + ASSERT_FILE_ENDS_WITH(OutputFileName().c_str(), kBasicSupportData); } TEST_P(SingleSegmentSegmenterTest, SplitsClustersOnSegmentDuration) { @@ -263,4 +248,3 @@ INSTANTIATE_TEST_CASE_P(TrueIsTwoPass, } // namespace media } // namespace shaka -