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

Side by Side Diff: media/mp4/offset_byte_queue_unittest.cc

Issue 10823069: Make peeking before the head of OffsetByteQueue a hard error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string.h> 5 #include <string.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "media/mp4/offset_byte_queue.h" 9 #include "media/mp4/offset_byte_queue.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 26 matching lines...) Expand all
37 37
38 const uint8* buf; 38 const uint8* buf;
39 int size; 39 int size;
40 40
41 queue_->Peek(&buf, &size); 41 queue_->Peek(&buf, &size);
42 EXPECT_EQ(128, size); 42 EXPECT_EQ(128, size);
43 EXPECT_EQ(128, buf[0]); 43 EXPECT_EQ(128, buf[0]);
44 EXPECT_EQ(255, buf[size-1]); 44 EXPECT_EQ(255, buf[size-1]);
45 } 45 }
46 46
47 TEST_F(OffsetByteQueueTest, TestPeekAt) { 47 TEST_F(OffsetByteQueueTest, PeekAtDeathTest) {
48 const uint8* buf; 48 const uint8* buf;
49 int size; 49 int size;
50 50
51 queue_->PeekAt(128, &buf, &size);
52 EXPECT_EQ(NULL, buf);
53 EXPECT_EQ(0, size);
54
55 queue_->PeekAt(400, &buf, &size); 51 queue_->PeekAt(400, &buf, &size);
56 EXPECT_EQ(queue_->tail() - 400, size); 52 EXPECT_EQ(queue_->tail() - 400, size);
57 EXPECT_EQ(400 - 256, buf[0]); 53 EXPECT_EQ(400 - 256, buf[0]);
58 54
59 queue_->PeekAt(512, &buf, &size); 55 queue_->PeekAt(512, &buf, &size);
60 EXPECT_EQ(NULL, buf); 56 EXPECT_EQ(NULL, buf);
61 EXPECT_EQ(0, size); 57 EXPECT_EQ(0, size);
58
59 // Peeking before current head should be an error
60 ASSERT_DEATH(queue_->PeekAt(128, &buf, &size), "offset >= head");
acolwell GONE FROM CHROMIUM 2012/07/31 19:27:44 Remove this since you said this situation only hap
62 } 61 }
63 62
64 TEST_F(OffsetByteQueueTest, TestTrim) { 63 TEST_F(OffsetByteQueueTest, TestTrim) {
65 EXPECT_TRUE(queue_->Trim(128)); 64 EXPECT_TRUE(queue_->Trim(128));
66 EXPECT_TRUE(queue_->Trim(384)); 65 EXPECT_TRUE(queue_->Trim(384));
67 EXPECT_EQ(384, queue_->head()); 66 EXPECT_EQ(384, queue_->head());
68 EXPECT_EQ(512, queue_->tail()); 67 EXPECT_EQ(512, queue_->tail());
69 68
70 EXPECT_TRUE(queue_->Trim(400)); 69 EXPECT_TRUE(queue_->Trim(400));
71 EXPECT_EQ(400, queue_->head()); 70 EXPECT_EQ(400, queue_->head());
(...skipping 15 matching lines...) Expand all
87 // Trimming past the end of the buffer should return 'false'; we haven't seen 86 // Trimming past the end of the buffer should return 'false'; we haven't seen
88 // the preceeding bytes. 87 // the preceeding bytes.
89 EXPECT_FALSE(queue_->Trim(513)); 88 EXPECT_FALSE(queue_->Trim(513));
90 89
91 // However, doing that shouldn't affect the EOS case. Only adding new data 90 // However, doing that shouldn't affect the EOS case. Only adding new data
92 // should alter this behavior. 91 // should alter this behavior.
93 EXPECT_TRUE(queue_->Trim(512)); 92 EXPECT_TRUE(queue_->Trim(512));
94 } 93 }
95 94
96 } // namespace media 95 } // namespace media
OLDNEW
« media/mp4/offset_byte_queue.cc ('K') | « media/mp4/offset_byte_queue.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698