Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/string_util.h" | |
| 6 #include "media/base/decoder_buffer.h" | |
| 7 | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace media { | |
| 11 | |
| 12 TEST(DecoderBufferTest, Constructors) { | |
| 13 const int kTestSize = 10; | |
| 14 | |
| 15 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); | |
| 16 EXPECT_FALSE(buffer->GetData()); | |
| 17 | |
| 18 scoped_refptr<DecoderBuffer> buffer2(new DecoderBuffer(kTestSize)); | |
| 19 ASSERT_TRUE(buffer2); | |
| 20 EXPECT_EQ(kTestSize, buffer2->GetDataSize()); | |
| 21 } | |
| 22 | |
| 23 TEST(DecoderBufferTest, PaddingAlignment) { | |
| 24 scoped_refptr<DecoderBuffer> buffer = DecoderBuffer::CopyFrom(NULL, 0); | |
| 25 EXPECT_FALSE(buffer->GetData()); | |
| 26 | |
| 27 const char kData[] = "hello"; | |
| 28 const int kDataSize = arraysize(kData); | |
| 29 scoped_refptr<DecoderBuffer> buffer2 = DecoderBuffer::CopyFrom( | |
|
scherkus (not reviewing)
2012/05/26 01:36:32
it looks like these two CopyFrom() tests be in a s
DaleCurtis
2012/05/29 21:17:01
Done.
| |
| 30 reinterpret_cast<const uint8*>(&kData), kDataSize); | |
| 31 ASSERT_TRUE(buffer2); | |
| 32 EXPECT_EQ(buffer2->GetDataSize(), kDataSize); | |
| 33 ASSERT_EQ(0, memcmp(buffer2->GetData(), kData, kDataSize)); | |
| 34 | |
| 35 #if !defined(OS_ANDROID) | |
|
scherkus (not reviewing)
2012/05/26 01:36:32
then for a PaddingAlignment test I would #if the w
DaleCurtis
2012/05/29 21:17:01
Done.
| |
| 36 // If we're using FFmpeg, I should be able to poke past the end of the data by | |
| 37 // FF_INPUT_BUFFER_PADDING_SIZE bytes without blowing up anything. | |
| 38 memset( | |
|
scherkus (not reviewing)
2012/05/26 01:36:32
since the area past is supposed to be zeros and be
DaleCurtis
2012/05/29 21:17:01
Done.
| |
| 39 buffer2->GetWritableData() + kDataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE); | |
| 40 | |
| 41 // These alignments will need to be updated to match FFmpeg when it changes. | |
|
scherkus (not reviewing)
2012/05/26 01:36:32
OOC is it expected to change?
DaleCurtis
2012/05/29 21:17:01
Probably if we ever get 512bit SIMD instructions :
| |
| 42 #if defined(ARCH_CPU_ARM_FAMILY) | |
| 43 // FFmpeg data should be aligned on a 16 byte boundary for ARM. | |
| 44 const int kDataAlignment = 16; | |
| 45 #else | |
| 46 // FFmpeg data should be aligned on a 32 byte boundary for x86. | |
| 47 const int kDataAlignment = 32; | |
| 48 #endif | |
| 49 EXPECT_EQ(0U, reinterpret_cast<uintptr_t>( | |
| 50 buffer2->GetData()) & (kDataAlignment - 1)); | |
| 51 #endif | |
| 52 } | |
| 53 | |
| 54 TEST(DecoderBufferTest, ReadingWriting) { | |
| 55 const char kData[] = "hello"; | |
| 56 const int kDataSize = arraysize(kData); | |
| 57 | |
| 58 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(kDataSize)); | |
| 59 ASSERT_TRUE(buffer); | |
| 60 | |
| 61 uint8* data = buffer->GetWritableData(); | |
| 62 ASSERT_TRUE(data); | |
| 63 ASSERT_EQ(kDataSize, buffer->GetDataSize()); | |
| 64 memcpy(data, kData, kDataSize); | |
| 65 const uint8* read_only_data = buffer->GetData(); | |
| 66 ASSERT_EQ(data, read_only_data); | |
| 67 ASSERT_EQ(0, memcmp(read_only_data, kData, kDataSize)); | |
| 68 EXPECT_FALSE(buffer->IsEndOfStream()); | |
| 69 } | |
| 70 | |
| 71 TEST(DecoderBufferTest, GetDecryptConfig) { | |
| 72 scoped_refptr<DecoderBuffer> buffer = new DecoderBuffer(0); | |
| 73 EXPECT_FALSE(buffer->GetDecryptConfig()); | |
| 74 } | |
| 75 | |
| 76 } // namespace media | |
| OLD | NEW |