Chromium Code Reviews| 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 <string.h> | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "media/mp4/offset_byte_queue.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 class OffsetByteQueueTest : public testing::Test { | |
| 15 public: | |
| 16 virtual void SetUp() OVERRIDE { | |
| 17 uint8 buf[256]; | |
| 18 for (uint32 i = 0; i < 256; i++) { | |
|
acolwell GONE FROM CHROMIUM
2012/06/07 19:44:02
use int
strobe_
2012/06/07 22:04:22
Done.
| |
| 19 buf[i] = i; | |
| 20 } | |
| 21 queue_.reset(new OffsetByteQueue); | |
| 22 queue_->Push(buf, sizeof(buf)); | |
| 23 queue_->Push(buf, sizeof(buf)); | |
| 24 queue_->Pop(384); | |
| 25 | |
| 26 // Queue will start with 128 bytes of data and an offset of 384 bytes. | |
| 27 // These values are used throughout the test. | |
| 28 } | |
| 29 | |
| 30 protected: | |
| 31 scoped_ptr<OffsetByteQueue> queue_; | |
| 32 }; | |
| 33 | |
| 34 TEST_F(OffsetByteQueueTest, TestSetUp) { | |
| 35 EXPECT_EQ(384u, queue_->head()); | |
| 36 EXPECT_EQ(512u, queue_->tail()); | |
| 37 | |
| 38 const uint8* buf; | |
| 39 size_t size; | |
| 40 | |
| 41 queue_->Peek(&buf, &size); | |
| 42 EXPECT_EQ(128u, size); | |
| 43 EXPECT_EQ(128u, buf[0]); | |
| 44 EXPECT_EQ(255u, buf[size-1]); | |
| 45 } | |
| 46 | |
| 47 TEST_F(OffsetByteQueueTest, TestPeekAt) { | |
| 48 const uint8* buf; | |
| 49 size_t size; | |
| 50 | |
| 51 queue_->PeekAt(128u, &buf, &size); | |
| 52 EXPECT_EQ(NULL, buf); | |
| 53 EXPECT_EQ(0u, size); | |
| 54 | |
| 55 queue_->PeekAt(400u, &buf, &size); | |
| 56 EXPECT_EQ(queue_->tail() - 400u, size); | |
| 57 EXPECT_EQ(400u - 256u, buf[0]); | |
| 58 | |
| 59 queue_->PeekAt(512u, &buf, &size); | |
| 60 EXPECT_EQ(NULL, buf); | |
| 61 EXPECT_EQ(0u, size); | |
| 62 } | |
| 63 | |
| 64 TEST_F(OffsetByteQueueTest, TestTrim) { | |
| 65 EXPECT_TRUE(queue_->Trim(128)); | |
| 66 EXPECT_TRUE(queue_->Trim(384)); | |
| 67 EXPECT_EQ(384u, queue_->head()); | |
| 68 EXPECT_EQ(512u, queue_->tail()); | |
| 69 | |
| 70 EXPECT_TRUE(queue_->Trim(400)); | |
| 71 EXPECT_EQ(400u, queue_->head()); | |
| 72 EXPECT_EQ(512u, queue_->tail()); | |
| 73 | |
| 74 const uint8* buf; | |
| 75 size_t size; | |
| 76 queue_->PeekAt(400, &buf, &size); | |
| 77 EXPECT_EQ(queue_->tail() - 400u, size); | |
| 78 EXPECT_EQ(400u - 256u, buf[0]); | |
| 79 | |
| 80 // Trimming to the exact end of the buffer should return 'true'. This | |
| 81 // accomodates EOS cases. | |
| 82 EXPECT_TRUE(queue_->Trim(512)); | |
| 83 EXPECT_EQ(512u, queue_->head()); | |
| 84 queue_->Peek(&buf, &size); | |
| 85 EXPECT_EQ(NULL, buf); | |
| 86 | |
| 87 // Trimming past the end of the buffer should return 'false'; we haven't seen | |
| 88 // the preceeding bytes. | |
| 89 EXPECT_FALSE(queue_->Trim(513)); | |
| 90 | |
| 91 // However, doing that shouldn't affect the EOS case. Only adding new data | |
| 92 // should alter this behavior. | |
| 93 EXPECT_TRUE(queue_->Trim(512)); | |
| 94 } | |
| 95 | |
| 96 } // namespace media | |
| OLD | NEW |