Update V8 to version 4.7.56.
[chromium-blink-merge.git] / media / formats / common / offset_byte_queue_unittest.cc
blobee5914d3e41809119cf7c0c12824fcc914e88ac0
1 // Copyright 2014 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 <string.h>
7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "media/formats/common/offset_byte_queue.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace media {
14 class OffsetByteQueueTest : public testing::Test {
15 public:
16 void SetUp() override {
17 uint8 buf[256];
18 for (int i = 0; i < 256; i++) {
19 buf[i] = i;
21 queue_.reset(new OffsetByteQueue);
22 queue_->Push(buf, sizeof(buf));
23 queue_->Push(buf, sizeof(buf));
24 queue_->Pop(384);
26 // Queue will start with 128 bytes of data and an offset of 384 bytes.
27 // These values are used throughout the test.
30 protected:
31 scoped_ptr<OffsetByteQueue> queue_;
34 TEST_F(OffsetByteQueueTest, SetUp) {
35 EXPECT_EQ(384, queue_->head());
36 EXPECT_EQ(512, queue_->tail());
38 const uint8* buf;
39 int size;
41 queue_->Peek(&buf, &size);
42 EXPECT_EQ(128, size);
43 EXPECT_EQ(128, buf[0]);
44 EXPECT_EQ(255, buf[size-1]);
47 TEST_F(OffsetByteQueueTest, PeekAt) {
48 const uint8* buf;
49 int size;
51 queue_->PeekAt(400, &buf, &size);
52 EXPECT_EQ(queue_->tail() - 400, size);
53 EXPECT_EQ(400 - 256, buf[0]);
55 queue_->PeekAt(512, &buf, &size);
56 EXPECT_EQ(NULL, buf);
57 EXPECT_EQ(0, size);
60 TEST_F(OffsetByteQueueTest, Trim) {
61 EXPECT_TRUE(queue_->Trim(128));
62 EXPECT_TRUE(queue_->Trim(384));
63 EXPECT_EQ(384, queue_->head());
64 EXPECT_EQ(512, queue_->tail());
66 EXPECT_TRUE(queue_->Trim(400));
67 EXPECT_EQ(400, queue_->head());
68 EXPECT_EQ(512, queue_->tail());
70 const uint8* buf;
71 int size;
72 queue_->PeekAt(400, &buf, &size);
73 EXPECT_EQ(queue_->tail() - 400, size);
74 EXPECT_EQ(400 - 256, buf[0]);
76 // Trimming to the exact end of the buffer should return 'true'. This
77 // accomodates EOS cases.
78 EXPECT_TRUE(queue_->Trim(512));
79 EXPECT_EQ(512, queue_->head());
80 queue_->Peek(&buf, &size);
81 EXPECT_EQ(NULL, buf);
83 // Trimming past the end of the buffer should return 'false'; we haven't seen
84 // the preceeding bytes.
85 EXPECT_FALSE(queue_->Trim(513));
87 // However, doing that shouldn't affect the EOS case. Only adding new data
88 // should alter this behavior.
89 EXPECT_TRUE(queue_->Trim(512));
92 } // namespace media