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 #if !defined(OS_ANDROID) | |
8 #include "media/ffmpeg/ffmpeg_common.h" | |
9 #endif | |
10 | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace media { | |
14 | |
15 TEST(DecoderBufferTest, Constructors) { | |
scherkus (not reviewing)
2012/05/30 02:48:42
these tests use the 1-arg ctor out of convenience
| |
16 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); | |
17 EXPECT_TRUE(buffer->GetData()); | |
18 EXPECT_EQ(0, buffer->GetDataSize()); | |
19 EXPECT_FALSE(buffer->IsEndOfStream()); | |
20 | |
21 const int kTestSize = 10; | |
22 scoped_refptr<DecoderBuffer> buffer3(new DecoderBuffer(kTestSize)); | |
23 ASSERT_TRUE(buffer3); | |
24 EXPECT_EQ(kTestSize, buffer3->GetDataSize()); | |
25 } | |
26 | |
27 TEST(DecoderBufferTest, CreateEOSBuffer) { | |
28 scoped_refptr<DecoderBuffer> buffer(DecoderBuffer::CreateEOSBuffer()); | |
29 EXPECT_TRUE(buffer->IsEndOfStream()); | |
30 EXPECT_FALSE(buffer->GetData()); | |
31 EXPECT_EQ(0, buffer->GetDataSize()); | |
32 } | |
33 | |
34 TEST(DecoderBufferTest, CopyFrom) { | |
35 const uint8 kData[] = "hello"; | |
36 const int kDataSize = arraysize(kData); | |
37 scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom( | |
38 reinterpret_cast<const uint8*>(&kData), kDataSize)); | |
39 ASSERT_TRUE(buffer2); | |
40 EXPECT_NE(kData, buffer2->GetData()); | |
41 EXPECT_EQ(buffer2->GetDataSize(), kDataSize); | |
42 EXPECT_EQ(0, memcmp(buffer2->GetData(), kData, kDataSize)); | |
43 EXPECT_FALSE(buffer2->IsEndOfStream()); | |
44 } | |
45 | |
46 #if !defined(OS_ANDROID) | |
47 TEST(DecoderBufferTest, PaddingAlignment) { | |
48 const uint8 kData[] = "hello"; | |
49 const int kDataSize = arraysize(kData); | |
50 scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom( | |
51 reinterpret_cast<const uint8*>(&kData), kDataSize)); | |
52 ASSERT_TRUE(buffer2); | |
53 | |
54 // FFmpeg padding data should always be zeroed. | |
55 for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++) | |
56 EXPECT_EQ((buffer2->GetData() + kDataSize)[i], 0); | |
57 | |
58 // If the data is padded correctly we should be able to read and write past | |
59 // the end of the data by FF_INPUT_BUFFER_PADDING_SIZE bytes without crashing | |
60 // or Valgrind/ASAN throwing errors. | |
61 const uint8 kFillChar = 0xFF; | |
62 memset( | |
63 buffer2->GetWritableData() + kDataSize, kFillChar, | |
64 FF_INPUT_BUFFER_PADDING_SIZE); | |
65 for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++) | |
66 EXPECT_EQ((buffer2->GetData() + kDataSize)[i], kFillChar); | |
67 | |
68 // These alignments will need to be updated to match FFmpeg when it changes. | |
69 #if defined(ARCH_CPU_ARM_FAMILY) | |
70 // FFmpeg data should be aligned on a 16 byte boundary for ARM. | |
71 const int kDataAlignment = 16; | |
72 #else | |
73 // FFmpeg data should be aligned on a 32 byte boundary for x86. | |
74 const int kDataAlignment = 32; | |
75 #endif | |
76 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>( | |
77 buffer2->GetData()) & (kDataAlignment - 1)); | |
78 } | |
79 #endif | |
80 | |
81 TEST(DecoderBufferTest, ReadingWriting) { | |
82 const char kData[] = "hello"; | |
83 const int kDataSize = arraysize(kData); | |
84 | |
85 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(kDataSize)); | |
86 ASSERT_TRUE(buffer); | |
87 | |
88 uint8* data = buffer->GetWritableData(); | |
89 ASSERT_TRUE(data); | |
90 ASSERT_EQ(kDataSize, buffer->GetDataSize()); | |
91 memcpy(data, kData, kDataSize); | |
92 const uint8* read_only_data = buffer->GetData(); | |
93 ASSERT_EQ(data, read_only_data); | |
94 ASSERT_EQ(0, memcmp(read_only_data, kData, kDataSize)); | |
95 EXPECT_FALSE(buffer->IsEndOfStream()); | |
96 } | |
97 | |
98 TEST(DecoderBufferTest, GetDecryptConfig) { | |
99 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); | |
100 EXPECT_FALSE(buffer->GetDecryptConfig()); | |
101 } | |
102 | |
103 } // namespace media | |
OLD | NEW |