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

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

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