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

Side by Side Diff: media/formats/mp4/box_reader_unittest.cc

Issue 1306783003: Revert of MSE: Verify MediaLog events created by existing MP4 unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@more_mockmedialog_testing_webm
Patch Set: Created 5 years, 3 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
« no previous file with comments | « media/formats/mp4/aac_unittest.cc ('k') | media/formats/mp4/mp4_stream_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/mock_media_log.h"
11 #include "media/formats/mp4/box_reader.h" 10 #include "media/formats/mp4/box_reader.h"
12 #include "media/formats/mp4/rcheck.h" 11 #include "media/formats/mp4/rcheck.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
15 13
16 using ::testing::HasSubstr;
17 using ::testing::StrictMock;
18
19 namespace media { 14 namespace media {
20 namespace mp4 { 15 namespace mp4 {
21 16
22 static const uint8 kSkipBox[] = { 17 static const uint8 kSkipBox[] = {
23 // Top-level test box containing three children 18 // Top-level test box containing three children
24 0x00, 0x00, 0x00, 0x40, 's', 'k', 'i', 'p', 19 0x00, 0x00, 0x00, 0x40, 's', 'k', 'i', 'p',
25 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 20 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
26 0xf9, 0x0a, 0x0b, 0x0c, 0xfd, 0x0e, 0x0f, 0x10, 21 0xf9, 0x0a, 0x0b, 0x0c, 0xfd, 0x0e, 0x0f, 0x10,
27 // Ordinary (8-byte header) child box 22 // Ordinary (8-byte header) child box
28 0x00, 0x00, 0x00, 0x0c, 'p', 's', 's', 'h', 0xde, 0xad, 0xbe, 0xef, 23 0x00, 0x00, 0x00, 0x0c, 'p', 's', 's', 'h', 0xde, 0xad, 0xbe, 0xef,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 FourCC BoxType() const override { return FOURCC_SKIP; } 69 FourCC BoxType() const override { return FOURCC_SKIP; }
75 70
76 SkipBox(); 71 SkipBox();
77 ~SkipBox() override; 72 ~SkipBox() override;
78 }; 73 };
79 74
80 SkipBox::SkipBox() {} 75 SkipBox::SkipBox() {}
81 SkipBox::~SkipBox() {} 76 SkipBox::~SkipBox() {}
82 77
83 class BoxReaderTest : public testing::Test { 78 class BoxReaderTest : public testing::Test {
84 public:
85 BoxReaderTest() : media_log_(new StrictMock<MockMediaLog>()) {}
86
87 protected: 79 protected:
88 std::vector<uint8> GetBuf() { 80 std::vector<uint8> GetBuf() {
89 return std::vector<uint8>(kSkipBox, kSkipBox + sizeof(kSkipBox)); 81 return std::vector<uint8>(kSkipBox, kSkipBox + sizeof(kSkipBox));
90 } 82 }
91
92 void TestTopLevelBox(const uint8* data, int size, uint32 fourCC) {
93 std::vector<uint8> buf(data, data + size);
94
95 bool err;
96 scoped_ptr<BoxReader> reader(
97 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), media_log_, &err));
98
99 EXPECT_FALSE(err);
100 EXPECT_TRUE(reader);
101 EXPECT_EQ(fourCC, reader->type());
102 EXPECT_EQ(reader->size(), size);
103 }
104
105 scoped_refptr<StrictMock<MockMediaLog>> media_log_;
106 }; 83 };
107 84
108 TEST_F(BoxReaderTest, ExpectedOperationTest) { 85 TEST_F(BoxReaderTest, ExpectedOperationTest) {
109 std::vector<uint8> buf = GetBuf(); 86 std::vector<uint8> buf = GetBuf();
110 bool err; 87 bool err;
111 scoped_ptr<BoxReader> reader( 88 scoped_ptr<BoxReader> reader(
112 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), media_log_, &err)); 89 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), new MediaLog(), &err));
113 EXPECT_FALSE(err); 90 EXPECT_FALSE(err);
114 EXPECT_TRUE(reader.get()); 91 EXPECT_TRUE(reader.get());
115 92
116 SkipBox box; 93 SkipBox box;
117 EXPECT_TRUE(box.Parse(reader.get())); 94 EXPECT_TRUE(box.Parse(reader.get()));
118 EXPECT_EQ(0x01, reader->version()); 95 EXPECT_EQ(0x01, reader->version());
119 EXPECT_EQ(0x020304u, reader->flags()); 96 EXPECT_EQ(0x020304u, reader->flags());
120 EXPECT_EQ(0x05, box.a); 97 EXPECT_EQ(0x05, box.a);
121 EXPECT_EQ(0x06, box.b); 98 EXPECT_EQ(0x06, box.b);
122 EXPECT_EQ(0x0708, box.c); 99 EXPECT_EQ(0x0708, box.c);
123 EXPECT_EQ(static_cast<int32>(0xf90a0b0c), box.d); 100 EXPECT_EQ(static_cast<int32>(0xf90a0b0c), box.d);
124 EXPECT_EQ(static_cast<int32>(0xfd0e0f10), box.e); 101 EXPECT_EQ(static_cast<int32>(0xfd0e0f10), box.e);
125 102
126 EXPECT_EQ(2u, box.kids.size()); 103 EXPECT_EQ(2u, box.kids.size());
127 EXPECT_EQ(0xdeadbeef, box.kids[0].val); 104 EXPECT_EQ(0xdeadbeef, box.kids[0].val);
128 EXPECT_EQ(0xfacecafe, box.kids[1].val); 105 EXPECT_EQ(0xfacecafe, box.kids[1].val);
129 106
130 // Accounting for the extra byte outside of the box above 107 // Accounting for the extra byte outside of the box above
131 EXPECT_EQ(buf.size(), static_cast<uint64>(reader->size() + 1)); 108 EXPECT_EQ(buf.size(), static_cast<uint64>(reader->size() + 1));
132 } 109 }
133 110
134 TEST_F(BoxReaderTest, OuterTooShortTest) { 111 TEST_F(BoxReaderTest, OuterTooShortTest) {
135 std::vector<uint8> buf = GetBuf(); 112 std::vector<uint8> buf = GetBuf();
136 bool err; 113 bool err;
137 114
138 // Create a soft failure by truncating the outer box. 115 // Create a soft failure by truncating the outer box.
139 scoped_ptr<BoxReader> r( 116 scoped_ptr<BoxReader> r(BoxReader::ReadTopLevelBox(&buf[0], buf.size() - 2,
140 BoxReader::ReadTopLevelBox(&buf[0], buf.size() - 2, media_log_, &err)); 117 new MediaLog(), &err));
141 118
142 EXPECT_FALSE(err); 119 EXPECT_FALSE(err);
143 EXPECT_FALSE(r.get()); 120 EXPECT_FALSE(r.get());
144 } 121 }
145 122
146 TEST_F(BoxReaderTest, InnerTooLongTest) { 123 TEST_F(BoxReaderTest, InnerTooLongTest) {
147 std::vector<uint8> buf = GetBuf(); 124 std::vector<uint8> buf = GetBuf();
148 bool err; 125 bool err;
149 126
150 // Make an inner box too big for its outer box. 127 // Make an inner box too big for its outer box.
151 buf[25] = 1; 128 buf[25] = 1;
152 scoped_ptr<BoxReader> reader( 129 scoped_ptr<BoxReader> reader(
153 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), media_log_, &err)); 130 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), new MediaLog(), &err));
154 131
155 SkipBox box; 132 SkipBox box;
156 EXPECT_FALSE(box.Parse(reader.get())); 133 EXPECT_FALSE(box.Parse(reader.get()));
157 } 134 }
158 135
159 TEST_F(BoxReaderTest, WrongFourCCTest) { 136 TEST_F(BoxReaderTest, WrongFourCCTest) {
160 std::vector<uint8> buf = GetBuf(); 137 std::vector<uint8> buf = GetBuf();
161 bool err; 138 bool err;
162 139
163 // Set an unrecognized top-level FourCC. 140 // Set an unrecognized top-level FourCC.
164 buf[5] = 1; 141 buf[5] = 1;
165
166 EXPECT_MEDIA_LOG(HasSubstr("Unrecognized top-level box type s\\u0001ip"));
167
168 scoped_ptr<BoxReader> reader( 142 scoped_ptr<BoxReader> reader(
169 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), media_log_, &err)); 143 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), new MediaLog(), &err));
170 EXPECT_FALSE(reader.get()); 144 EXPECT_FALSE(reader.get());
171 EXPECT_TRUE(err); 145 EXPECT_TRUE(err);
172 } 146 }
173 147
174 TEST_F(BoxReaderTest, ScanChildrenTest) { 148 TEST_F(BoxReaderTest, ScanChildrenTest) {
175 std::vector<uint8> buf = GetBuf(); 149 std::vector<uint8> buf = GetBuf();
176 bool err; 150 bool err;
177 scoped_ptr<BoxReader> reader( 151 scoped_ptr<BoxReader> reader(
178 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), media_log_, &err)); 152 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), new MediaLog(), &err));
179 153
180 EXPECT_TRUE(reader->SkipBytes(16) && reader->ScanChildren()); 154 EXPECT_TRUE(reader->SkipBytes(16) && reader->ScanChildren());
181 155
182 FreeBox free; 156 FreeBox free;
183 EXPECT_TRUE(reader->ReadChild(&free)); 157 EXPECT_TRUE(reader->ReadChild(&free));
184 EXPECT_FALSE(reader->ReadChild(&free)); 158 EXPECT_FALSE(reader->ReadChild(&free));
185 EXPECT_TRUE(reader->MaybeReadChild(&free)); 159 EXPECT_TRUE(reader->MaybeReadChild(&free));
186 160
187 std::vector<PsshBox> kids; 161 std::vector<PsshBox> kids;
188 162
189 EXPECT_TRUE(reader->ReadChildren(&kids)); 163 EXPECT_TRUE(reader->ReadChildren(&kids));
190 EXPECT_EQ(2u, kids.size()); 164 EXPECT_EQ(2u, kids.size());
191 kids.clear(); 165 kids.clear();
192 EXPECT_FALSE(reader->ReadChildren(&kids)); 166 EXPECT_FALSE(reader->ReadChildren(&kids));
193 EXPECT_TRUE(reader->MaybeReadChildren(&kids)); 167 EXPECT_TRUE(reader->MaybeReadChildren(&kids));
194 } 168 }
195 169
196 TEST_F(BoxReaderTest, ReadAllChildrenTest) { 170 TEST_F(BoxReaderTest, ReadAllChildrenTest) {
197 std::vector<uint8> buf = GetBuf(); 171 std::vector<uint8> buf = GetBuf();
198 // Modify buffer to exclude its last 'free' box 172 // Modify buffer to exclude its last 'free' box
199 buf[3] = 0x38; 173 buf[3] = 0x38;
200 bool err; 174 bool err;
201 scoped_ptr<BoxReader> reader( 175 scoped_ptr<BoxReader> reader(
202 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), media_log_, &err)); 176 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), new MediaLog(), &err));
203 177
204 std::vector<PsshBox> kids; 178 std::vector<PsshBox> kids;
205 EXPECT_TRUE(reader->SkipBytes(16) && reader->ReadAllChildren(&kids)); 179 EXPECT_TRUE(reader->SkipBytes(16) && reader->ReadAllChildren(&kids));
206 EXPECT_EQ(2u, kids.size()); 180 EXPECT_EQ(2u, kids.size());
207 EXPECT_EQ(kids[0].val, 0xdeadbeef); // Ensure order is preserved 181 EXPECT_EQ(kids[0].val, 0xdeadbeef); // Ensure order is preserved
208 } 182 }
209 183
184 static void TestTopLevelBox(const uint8* data, int size, uint32 fourCC) {
185
186 std::vector<uint8> buf(data, data + size);
187
188 bool err;
189 scoped_ptr<BoxReader> reader(
190 BoxReader::ReadTopLevelBox(&buf[0], buf.size(), new MediaLog(), &err));
191
192 EXPECT_FALSE(err);
193 EXPECT_TRUE(reader);
194 EXPECT_EQ(fourCC, reader->type());
195 EXPECT_EQ(reader->size(), size);
196 }
197
210 TEST_F(BoxReaderTest, SkippingBloc) { 198 TEST_F(BoxReaderTest, SkippingBloc) {
211 static const uint8 kData[] = { 199 static const uint8 kData[] = {
212 0x00, 0x00, 0x00, 0x09, 'b', 'l', 'o', 'c', 0x00 200 0x00, 0x00, 0x00, 0x09, 'b', 'l', 'o', 'c', 0x00
213 }; 201 };
214 202
215 TestTopLevelBox(kData, sizeof(kData), FOURCC_BLOC); 203 TestTopLevelBox(kData, sizeof(kData), FOURCC_BLOC);
216 } 204 }
217 205
218 TEST_F(BoxReaderTest, SkippingEmsg) { 206 TEST_F(BoxReaderTest, SkippingEmsg) {
219 static const uint8 kData[] = { 207 static const uint8 kData[] = {
(...skipping 18 matching lines...) Expand all
238 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 226 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
239 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, // usertype 227 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, // usertype
240 0x00, 228 0x00,
241 }; 229 };
242 230
243 TestTopLevelBox(kData, sizeof(kData), FOURCC_UUID); 231 TestTopLevelBox(kData, sizeof(kData), FOURCC_UUID);
244 } 232 }
245 233
246 } // namespace mp4 234 } // namespace mp4
247 } // namespace media 235 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/mp4/aac_unittest.cc ('k') | media/formats/mp4/mp4_stream_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698