Chromium Code Reviews| Index: media/base/decoder_buffer_unittest.cc |
| diff --git a/media/base/decoder_buffer_unittest.cc b/media/base/decoder_buffer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d98a0ed60795d145c0081339083822f3e30cda34 |
| --- /dev/null |
| +++ b/media/base/decoder_buffer_unittest.cc |
| @@ -0,0 +1,110 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/string_util.h" |
| +#include "media/base/decoder_buffer.h" |
| +#if !defined(OS_ANDROID) |
| +#include "media/ffmpeg/ffmpeg_common.h" |
| +#endif |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace media { |
| + |
| +TEST(DecoderBufferTest, Constructors) { |
| + scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); |
| + EXPECT_TRUE(buffer->GetData()); |
| + EXPECT_EQ(0, buffer->GetDataSize()); |
| + EXPECT_FALSE(buffer->IsEndOfStream()); |
| + |
| + scoped_refptr<DecoderBuffer> buffer2(new DecoderBuffer(-1)); |
| + EXPECT_FALSE(buffer2->GetData()); |
| + EXPECT_EQ(0, buffer2->GetDataSize()); |
| + EXPECT_TRUE(buffer2->IsEndOfStream()); |
| + |
| + const int kTestSize = 10; |
| + scoped_refptr<DecoderBuffer> buffer3(new DecoderBuffer(kTestSize)); |
| + ASSERT_TRUE(buffer3); |
| + EXPECT_EQ(kTestSize, buffer3->GetDataSize()); |
| +} |
| + |
| +TEST(DecoderBufferTest, CreateEOSBuffer) { |
| + scoped_refptr<DecoderBuffer> buffer(DecoderBuffer::CreateEOSBuffer()); |
| + EXPECT_TRUE(buffer->IsEndOfStream()); |
|
scherkus (not reviewing)
2012/05/30 00:45:19
what about the other methods?
DaleCurtis
2012/05/30 02:28:25
Added checks for GetData() and GetDataSize().
|
| +} |
| + |
| +TEST(DecoderBufferTest, CopyFrom) { |
| + scoped_refptr<DecoderBuffer> buffer(DecoderBuffer::CopyFrom(NULL, 0)); |
|
scherkus (not reviewing)
2012/05/30 00:45:19
does production code use CopyFrom(NULL, 0) today?
DaleCurtis
2012/05/30 02:28:25
I've changed FFmpegDemuxer::StreamHasEnded() so th
|
| + EXPECT_FALSE(buffer->GetData()); |
| + EXPECT_TRUE(buffer->IsEndOfStream()); |
| + |
| + const uint8 kData[] = "hello"; |
| + const int kDataSize = arraysize(kData); |
| + scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom( |
| + reinterpret_cast<const uint8*>(&kData), kDataSize)); |
| + ASSERT_TRUE(buffer2); |
| + EXPECT_NE(kData, buffer2->GetData()); |
| + EXPECT_EQ(buffer2->GetDataSize(), kDataSize); |
| + EXPECT_EQ(0, memcmp(buffer2->GetData(), kData, kDataSize)); |
| + EXPECT_FALSE(buffer2->IsEndOfStream()); |
| +} |
| + |
| +#if !defined(OS_ANDROID) |
| +TEST(DecoderBufferTest, PaddingAlignment) { |
| + const uint8 kData[] = "hello"; |
| + const int kDataSize = arraysize(kData); |
| + scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom( |
| + reinterpret_cast<const uint8*>(&kData), kDataSize)); |
| + ASSERT_TRUE(buffer2); |
| + |
| + // If the data is padded correctly we should be able to poke past the end of |
| + // the data by FF_INPUT_BUFFER_PADDING_SIZE bytes without blowing up anything. |
| + |
| + // FFmpeg padding data should always be zeroed. |
| + for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++) |
| + EXPECT_EQ((buffer2->GetData() + kDataSize)[i], 0); |
|
scherkus (not reviewing)
2012/05/30 00:45:19
fix indent
DaleCurtis
2012/05/30 02:28:25
Done.
|
| + |
| + const uint8 kFillChar = 0xFF; |
|
scherkus (not reviewing)
2012/05/30 00:45:19
I'd comment here that we're attempting to write he
DaleCurtis
2012/05/30 02:28:25
Done.
|
| + memset( |
| + buffer2->GetWritableData() + kDataSize, kFillChar, |
| + FF_INPUT_BUFFER_PADDING_SIZE); |
| + for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++) |
| + EXPECT_EQ((buffer2->GetData() + kDataSize)[i], kFillChar); |
|
scherkus (not reviewing)
2012/05/30 00:45:19
fix indent
DaleCurtis
2012/05/30 02:28:25
Done.
|
| + |
| + // These alignments will need to be updated to match FFmpeg when it changes. |
| +#if defined(ARCH_CPU_ARM_FAMILY) |
| + // FFmpeg data should be aligned on a 16 byte boundary for ARM. |
| + const int kDataAlignment = 16; |
| +#else |
| + // FFmpeg data should be aligned on a 32 byte boundary for x86. |
| + const int kDataAlignment = 32; |
| +#endif |
| + EXPECT_EQ(0U, reinterpret_cast<uintptr_t>( |
|
scherkus (not reviewing)
2012/05/30 00:45:19
nit: most (all?) of our code uses lower-case suffi
DaleCurtis
2012/05/30 02:28:25
Done.
|
| + buffer2->GetData()) & (kDataAlignment - 1)); |
| +} |
| +#endif |
| + |
| +TEST(DecoderBufferTest, ReadingWriting) { |
| + const char kData[] = "hello"; |
| + const int kDataSize = arraysize(kData); |
| + |
| + scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(kDataSize)); |
| + ASSERT_TRUE(buffer); |
| + |
| + uint8* data = buffer->GetWritableData(); |
| + ASSERT_TRUE(data); |
| + ASSERT_EQ(kDataSize, buffer->GetDataSize()); |
| + memcpy(data, kData, kDataSize); |
| + const uint8* read_only_data = buffer->GetData(); |
| + ASSERT_EQ(data, read_only_data); |
| + ASSERT_EQ(0, memcmp(read_only_data, kData, kDataSize)); |
| + EXPECT_FALSE(buffer->IsEndOfStream()); |
| +} |
| + |
| +TEST(DecoderBufferTest, GetDecryptConfig) { |
| + scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); |
| + EXPECT_FALSE(buffer->GetDecryptConfig()); |
| +} |
| + |
| +} // namespace media |