Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: media/base/decoder_buffer_unittest.cc

Issue 10447035: Introducing DecoderBuffer and general Buffer cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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) {
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 scoped_refptr<DecoderBuffer> buffer2(new DecoderBuffer(-1));
22 EXPECT_FALSE(buffer2->GetData());
23 EXPECT_EQ(0, buffer2->GetDataSize());
24 EXPECT_TRUE(buffer2->IsEndOfStream());
25
26 const int kTestSize = 10;
27 scoped_refptr<DecoderBuffer> buffer3(new DecoderBuffer(kTestSize));
28 ASSERT_TRUE(buffer3);
29 EXPECT_EQ(kTestSize, buffer3->GetDataSize());
30 }
31
32 TEST(DecoderBufferTest, CreateEOSBuffer) {
33 scoped_refptr<DecoderBuffer> buffer(DecoderBuffer::CreateEOSBuffer());
34 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().
35 }
36
37 TEST(DecoderBufferTest, CopyFrom) {
38 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
39 EXPECT_FALSE(buffer->GetData());
40 EXPECT_TRUE(buffer->IsEndOfStream());
41
42 const uint8 kData[] = "hello";
43 const int kDataSize = arraysize(kData);
44 scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom(
45 reinterpret_cast<const uint8*>(&kData), kDataSize));
46 ASSERT_TRUE(buffer2);
47 EXPECT_NE(kData, buffer2->GetData());
48 EXPECT_EQ(buffer2->GetDataSize(), kDataSize);
49 EXPECT_EQ(0, memcmp(buffer2->GetData(), kData, kDataSize));
50 EXPECT_FALSE(buffer2->IsEndOfStream());
51 }
52
53 #if !defined(OS_ANDROID)
54 TEST(DecoderBufferTest, PaddingAlignment) {
55 const uint8 kData[] = "hello";
56 const int kDataSize = arraysize(kData);
57 scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom(
58 reinterpret_cast<const uint8*>(&kData), kDataSize));
59 ASSERT_TRUE(buffer2);
60
61 // If the data is padded correctly we should be able to poke past the end of
62 // the data by FF_INPUT_BUFFER_PADDING_SIZE bytes without blowing up anything.
63
64 // FFmpeg padding data should always be zeroed.
65 for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++)
66 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.
67
68 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.
69 memset(
70 buffer2->GetWritableData() + kDataSize, kFillChar,
71 FF_INPUT_BUFFER_PADDING_SIZE);
72 for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++)
73 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.
74
75 // These alignments will need to be updated to match FFmpeg when it changes.
76 #if defined(ARCH_CPU_ARM_FAMILY)
77 // FFmpeg data should be aligned on a 16 byte boundary for ARM.
78 const int kDataAlignment = 16;
79 #else
80 // FFmpeg data should be aligned on a 32 byte boundary for x86.
81 const int kDataAlignment = 32;
82 #endif
83 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.
84 buffer2->GetData()) & (kDataAlignment - 1));
85 }
86 #endif
87
88 TEST(DecoderBufferTest, ReadingWriting) {
89 const char kData[] = "hello";
90 const int kDataSize = arraysize(kData);
91
92 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(kDataSize));
93 ASSERT_TRUE(buffer);
94
95 uint8* data = buffer->GetWritableData();
96 ASSERT_TRUE(data);
97 ASSERT_EQ(kDataSize, buffer->GetDataSize());
98 memcpy(data, kData, kDataSize);
99 const uint8* read_only_data = buffer->GetData();
100 ASSERT_EQ(data, read_only_data);
101 ASSERT_EQ(0, memcmp(read_only_data, kData, kDataSize));
102 EXPECT_FALSE(buffer->IsEndOfStream());
103 }
104
105 TEST(DecoderBufferTest, GetDecryptConfig) {
106 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0));
107 EXPECT_FALSE(buffer->GetDecryptConfig());
108 }
109
110 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698