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..a8fcfe4dc776391431da54bdce351464d82135fb |
--- /dev/null |
+++ b/media/base/decoder_buffer_unittest.cc |
@@ -0,0 +1,76 @@ |
+// 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" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace media { |
+ |
+TEST(DecoderBufferTest, Constructors) { |
+ const int kTestSize = 10; |
+ |
+ scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); |
+ EXPECT_FALSE(buffer->GetData()); |
+ |
+ scoped_refptr<DecoderBuffer> buffer2(new DecoderBuffer(kTestSize)); |
+ ASSERT_TRUE(buffer2); |
+ EXPECT_EQ(kTestSize, buffer2->GetDataSize()); |
+} |
+ |
+TEST(DecoderBufferTest, PaddingAlignment) { |
+ scoped_refptr<DecoderBuffer> buffer = DecoderBuffer::CopyFrom(NULL, 0); |
+ EXPECT_FALSE(buffer->GetData()); |
+ |
+ const char kData[] = "hello"; |
+ const int kDataSize = arraysize(kData); |
+ 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.
|
+ reinterpret_cast<const uint8*>(&kData), kDataSize); |
+ ASSERT_TRUE(buffer2); |
+ EXPECT_EQ(buffer2->GetDataSize(), kDataSize); |
+ ASSERT_EQ(0, memcmp(buffer2->GetData(), kData, kDataSize)); |
+ |
+#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.
|
+ // If we're using FFmpeg, I should be able to poke past the end of the data by |
+ // FF_INPUT_BUFFER_PADDING_SIZE bytes without blowing up anything. |
+ 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.
|
+ buffer2->GetWritableData() + kDataSize, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
+ |
+ // 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 :
|
+#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>( |
+ 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 |