1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright (c) 2008-2009 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/data_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
using media::DataBuffer;
TEST(DataBufferTest, Basic) {
const char kData[] = "hello";
const size_t kDataSize = arraysize(kData);
const char kNewData[] = "chromium";
const size_t kNewDataSize = arraysize(kNewData);
const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337);
const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667);
const base::TimeDelta kTimestampB = base::TimeDelta::FromMicroseconds(1234);
const base::TimeDelta kDurationB = base::TimeDelta::FromMicroseconds(5678);
// Create our buffer and copy some data into it.
// Create a DataBuffer.
scoped_refptr<DataBuffer> buffer = new DataBuffer();
ASSERT_TRUE(buffer);
// Test StreamSample implementation.
buffer->SetTimestamp(kTimestampA);
buffer->SetDuration(kDurationA);
EXPECT_TRUE(kTimestampA == buffer->GetTimestamp());
EXPECT_TRUE(kDurationA == buffer->GetDuration());
EXPECT_FALSE(buffer->IsEndOfStream());
EXPECT_FALSE(buffer->IsDiscontinuous());
buffer->SetTimestamp(kTimestampB);
buffer->SetDuration(kDurationB);
EXPECT_TRUE(kTimestampB == buffer->GetTimestamp());
EXPECT_TRUE(kDurationB == buffer->GetDuration());
buffer->SetEndOfStream(true);
EXPECT_TRUE(buffer->IsEndOfStream());
buffer->SetEndOfStream(false);
EXPECT_FALSE(buffer->IsEndOfStream());
buffer->SetDiscontinuous(true);
EXPECT_TRUE(buffer->IsDiscontinuous());
buffer->SetDiscontinuous(false);
EXPECT_FALSE(buffer->IsDiscontinuous());
// Test WritableBuffer implementation.
EXPECT_FALSE(buffer->GetData());
uint8* data = buffer->GetWritableData(kDataSize);
ASSERT_TRUE(data);
ASSERT_EQ(buffer->GetDataSize(), kDataSize);
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));
data = buffer->GetWritableData(kNewDataSize + 10);
ASSERT_TRUE(data);
ASSERT_EQ(buffer->GetDataSize(), kNewDataSize + 10);
memcpy(data, kNewData, kNewDataSize);
read_only_data = buffer->GetData();
buffer->SetDataSize(kNewDataSize);
EXPECT_EQ(buffer->GetDataSize(), kNewDataSize);
ASSERT_EQ(data, read_only_data);
EXPECT_EQ(0, memcmp(read_only_data, kNewData, kNewDataSize));
}
|