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.
5 #include "base/string_util.h"
6 #include "media/base/buffers.h"
7 #include "testing/gtest/include/gtest/gtest.h"
13 // Simple implementation of Buffer to test base class functionality.
14 class TestBuffer
: public Buffer
{
17 : Buffer(base::TimeDelta(), base::TimeDelta()) {
20 // Sets |data_| and |size_| members for testing purposes. Does not take
21 // ownership of |data|.
22 TestBuffer(const uint8
* data
, int size
)
23 : Buffer(base::TimeDelta(), base::TimeDelta()),
28 // Buffer implementation.
29 virtual const uint8
* GetData() const OVERRIDE
{ return data_
; }
30 virtual int GetDataSize() const OVERRIDE
{ return size_
; }
33 virtual ~TestBuffer() {}
39 DISALLOW_COPY_AND_ASSIGN(TestBuffer
);
44 TEST(BufferTest
, Timestamp
) {
45 const base::TimeDelta kZero
;
46 const base::TimeDelta kTimestampA
= base::TimeDelta::FromMicroseconds(1337);
47 const base::TimeDelta kTimestampB
= base::TimeDelta::FromMicroseconds(1234);
49 scoped_refptr
<TestBuffer
> buffer
= new TestBuffer();
50 EXPECT_TRUE(buffer
->GetTimestamp() == kZero
);
52 buffer
->SetTimestamp(kTimestampA
);
53 EXPECT_TRUE(buffer
->GetTimestamp() == kTimestampA
);
55 buffer
->SetTimestamp(kTimestampB
);
56 EXPECT_TRUE(buffer
->GetTimestamp() == kTimestampB
);
59 TEST(BufferTest
, Duration
) {
60 const base::TimeDelta kZero
;
61 const base::TimeDelta kDurationA
= base::TimeDelta::FromMicroseconds(1337);
62 const base::TimeDelta kDurationB
= base::TimeDelta::FromMicroseconds(1234);
64 scoped_refptr
<TestBuffer
> buffer
= new TestBuffer();
65 EXPECT_TRUE(buffer
->GetDuration() == kZero
);
67 buffer
->SetDuration(kDurationA
);
68 EXPECT_TRUE(buffer
->GetDuration() == kDurationA
);
70 buffer
->SetDuration(kDurationB
);
71 EXPECT_TRUE(buffer
->GetDuration() == kDurationB
);
74 TEST(BufferTest
, IsEndOfStream
) {
75 const uint8 kData
[] = { 0x00, 0xFF };
76 const int kDataSize
= arraysize(kData
);
78 scoped_refptr
<TestBuffer
> buffer
= new TestBuffer(NULL
, 0);
79 EXPECT_TRUE(buffer
->IsEndOfStream());
81 buffer
= new TestBuffer(kData
, kDataSize
);
82 EXPECT_FALSE(buffer
->IsEndOfStream());
85 TEST(BufferTest
, GetDecryptConfig
) {
86 scoped_refptr
<TestBuffer
> buffer
= new TestBuffer();
87 EXPECT_FALSE(buffer
->GetDecryptConfig());