Some misc cleanup

- Replace DCHECK_EQ with DCHECK for compatiblity
- Add ASSERT_FILE_CONTAINS
- Remove unnecessary release on unique_ptrs

Change-Id: I2ec22c52e47cb451479ae9a59818b9df20f62e63
This commit is contained in:
Kongqun Yang 2016-09-06 15:13:42 -07:00
parent c3d1dc1733
commit 90e3ec3f9a
6 changed files with 22 additions and 60 deletions

View File

@ -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();
}

View File

@ -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<base::Value> root(
base::JSONReader::Read(raw_response).release());
std::unique_ptr<base::Value> 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<base::Value> root(base::JSONReader::Read(response).release());
std::unique_ptr<base::Value> root(base::JSONReader::Read(response));
if (!root) {
LOG(ERROR) << "'" << response << "' is not in JSON format.";
return false;

View File

@ -7,6 +7,9 @@
#ifndef MEDIA_FILE_FILE_TEST_UTIL_H_
#define MEDIA_FILE_FILE_TEST_UTIL_H_
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>
#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<const char*>(array), sizeof(array)))); \
} while (false)
} // namespace media
} // namespace shaka
#endif // MEDIA_FILE_FILE_TEST_UTIL_H_

View File

@ -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

View File

@ -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.

View File

@ -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