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

Side by Side Diff: media/formats/webm/webm_parser_unittest.cc

Issue 1874413003: Convert media/formats to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 "media/formats/webm/webm_parser.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
7 9
10 #include <memory>
11
8 #include "base/macros.h" 12 #include "base/macros.h"
9 #include "media/formats/webm/cluster_builder.h" 13 #include "media/formats/webm/cluster_builder.h"
10 #include "media/formats/webm/webm_constants.h" 14 #include "media/formats/webm/webm_constants.h"
11 #include "media/formats/webm/webm_parser.h"
12 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
14 17
15 using ::testing::InSequence; 18 using ::testing::InSequence;
16 using ::testing::Return; 19 using ::testing::Return;
17 using ::testing::ReturnNull; 20 using ::testing::ReturnNull;
18 using ::testing::StrictMock; 21 using ::testing::StrictMock;
19 using ::testing::_; 22 using ::testing::_;
20 23
21 namespace media { 24 namespace media {
(...skipping 11 matching lines...) Expand all
33 MOCK_METHOD2(OnFloat, bool(int, double)); 36 MOCK_METHOD2(OnFloat, bool(int, double));
34 MOCK_METHOD3(OnBinary, bool(int, const uint8_t*, int)); 37 MOCK_METHOD3(OnBinary, bool(int, const uint8_t*, int));
35 MOCK_METHOD2(OnString, bool(int, const std::string&)); 38 MOCK_METHOD2(OnString, bool(int, const std::string&));
36 }; 39 };
37 40
38 class WebMParserTest : public testing::Test { 41 class WebMParserTest : public testing::Test {
39 protected: 42 protected:
40 StrictMock<MockWebMParserClient> client_; 43 StrictMock<MockWebMParserClient> client_;
41 }; 44 };
42 45
43 static scoped_ptr<Cluster> CreateCluster(int block_count) { 46 static std::unique_ptr<Cluster> CreateCluster(int block_count) {
44 ClusterBuilder cb; 47 ClusterBuilder cb;
45 cb.SetClusterTimecode(0); 48 cb.SetClusterTimecode(0);
46 49
47 for (int i = 0; i < block_count; i++) { 50 for (int i = 0; i < block_count; i++) {
48 uint8_t data[] = {0x00}; 51 uint8_t data[] = {0x00};
49 cb.AddSimpleBlock(0, i, 0, data, sizeof(data)); 52 cb.AddSimpleBlock(0, i, 0, data, sizeof(data));
50 } 53 }
51 54
52 return cb.Finish(); 55 return cb.Finish();
53 } 56 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 EXPECT_CALL(client_, OnListEnd(kWebMIdCluster)).WillOnce(Return(true)); 217 EXPECT_CALL(client_, OnListEnd(kWebMIdCluster)).WillOnce(Return(true));
215 EXPECT_CALL(client_, OnListEnd(kWebMIdSegment)).WillOnce(Return(true)); 218 EXPECT_CALL(client_, OnListEnd(kWebMIdSegment)).WillOnce(Return(true));
216 219
217 WebMListParser parser(kWebMIdSegment, &client_); 220 WebMListParser parser(kWebMIdSegment, &client_);
218 EXPECT_EQ(size, parser.Parse(kBuffer, size)); 221 EXPECT_EQ(size, parser.Parse(kBuffer, size));
219 EXPECT_TRUE(parser.IsParsingComplete()); 222 EXPECT_TRUE(parser.IsParsingComplete());
220 } 223 }
221 224
222 225
223 TEST_F(WebMParserTest, ParseListElementWithSingleCall) { 226 TEST_F(WebMParserTest, ParseListElementWithSingleCall) {
224 scoped_ptr<Cluster> cluster(CreateCluster(kBlockCount)); 227 std::unique_ptr<Cluster> cluster(CreateCluster(kBlockCount));
225 CreateClusterExpectations(kBlockCount, true, &client_); 228 CreateClusterExpectations(kBlockCount, true, &client_);
226 229
227 WebMListParser parser(kWebMIdCluster, &client_); 230 WebMListParser parser(kWebMIdCluster, &client_);
228 EXPECT_EQ(cluster->size(), parser.Parse(cluster->data(), cluster->size())); 231 EXPECT_EQ(cluster->size(), parser.Parse(cluster->data(), cluster->size()));
229 EXPECT_TRUE(parser.IsParsingComplete()); 232 EXPECT_TRUE(parser.IsParsingComplete());
230 } 233 }
231 234
232 TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) { 235 TEST_F(WebMParserTest, ParseListElementWithMultipleCalls) {
233 scoped_ptr<Cluster> cluster(CreateCluster(kBlockCount)); 236 std::unique_ptr<Cluster> cluster(CreateCluster(kBlockCount));
234 CreateClusterExpectations(kBlockCount, true, &client_); 237 CreateClusterExpectations(kBlockCount, true, &client_);
235 238
236 const uint8_t* data = cluster->data(); 239 const uint8_t* data = cluster->data();
237 int size = cluster->size(); 240 int size = cluster->size();
238 int default_parse_size = 3; 241 int default_parse_size = 3;
239 WebMListParser parser(kWebMIdCluster, &client_); 242 WebMListParser parser(kWebMIdCluster, &client_);
240 int parse_size = std::min(default_parse_size, size); 243 int parse_size = std::min(default_parse_size, size);
241 244
242 while (size > 0) { 245 while (size > 0) {
243 int result = parser.Parse(data, parse_size); 246 int result = parser.Parse(data, parse_size);
(...skipping 13 matching lines...) Expand all
257 data += result; 260 data += result;
258 size -= result; 261 size -= result;
259 262
260 EXPECT_EQ((size == 0), parser.IsParsingComplete()); 263 EXPECT_EQ((size == 0), parser.IsParsingComplete());
261 } 264 }
262 EXPECT_TRUE(parser.IsParsingComplete()); 265 EXPECT_TRUE(parser.IsParsingComplete());
263 } 266 }
264 267
265 TEST_F(WebMParserTest, Reset) { 268 TEST_F(WebMParserTest, Reset) {
266 InSequence s; 269 InSequence s;
267 scoped_ptr<Cluster> cluster(CreateCluster(kBlockCount)); 270 std::unique_ptr<Cluster> cluster(CreateCluster(kBlockCount));
268 271
269 // First expect all but the last block. 272 // First expect all but the last block.
270 CreateClusterExpectations(kBlockCount - 1, false, &client_); 273 CreateClusterExpectations(kBlockCount - 1, false, &client_);
271 274
272 // Now expect all blocks. 275 // Now expect all blocks.
273 CreateClusterExpectations(kBlockCount, true, &client_); 276 CreateClusterExpectations(kBlockCount, true, &client_);
274 277
275 WebMListParser parser(kWebMIdCluster, &client_); 278 WebMListParser parser(kWebMIdCluster, &client_);
276 279
277 // Send slightly less than the full cluster so all but the last block is 280 // Send slightly less than the full cluster so all but the last block is
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 EXPECT_CALL(client_, OnString(kWebMIdDocType, "a")).WillOnce(Return(true)); 404 EXPECT_CALL(client_, OnString(kWebMIdDocType, "a")).WillOnce(Return(true));
402 EXPECT_CALL(client_, OnString(kWebMIdDocType, "a")).WillOnce(Return(true)); 405 EXPECT_CALL(client_, OnString(kWebMIdDocType, "a")).WillOnce(Return(true));
403 EXPECT_CALL(client_, OnListEnd(kWebMIdEBMLHeader)).WillOnce(Return(true)); 406 EXPECT_CALL(client_, OnListEnd(kWebMIdEBMLHeader)).WillOnce(Return(true));
404 407
405 WebMListParser parser(kWebMIdEBMLHeader, &client_); 408 WebMListParser parser(kWebMIdEBMLHeader, &client_);
406 EXPECT_EQ(size, parser.Parse(kBuffer, size)); 409 EXPECT_EQ(size, parser.Parse(kBuffer, size));
407 EXPECT_TRUE(parser.IsParsingComplete()); 410 EXPECT_TRUE(parser.IsParsingComplete());
408 } 411 }
409 412
410 } // namespace media 413 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698