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

Side by Side Diff: media/base/audio_video_metadata_extractor_unittest.cc

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: . 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/base/audio_video_metadata_extractor.h"
6
7 #include <memory>
8
5 #include "base/logging.h" 9 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/sha1.h" 10 #include "base/sha1.h"
8 #include "build/build_config.h" 11 #include "build/build_config.h"
9 #include "media/base/audio_video_metadata_extractor.h"
10 #include "media/base/test_data_util.h" 12 #include "media/base/test_data_util.h"
11 #include "media/filters/file_data_source.h" 13 #include "media/filters/file_data_source.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 namespace media { 16 namespace media {
15 17
16 scoped_ptr<AudioVideoMetadataExtractor> GetExtractor( 18 std::unique_ptr<AudioVideoMetadataExtractor> GetExtractor(
17 const std::string& filename, 19 const std::string& filename,
18 bool extract_attached_images, 20 bool extract_attached_images,
19 bool expected_result, 21 bool expected_result,
20 double expected_duration, 22 double expected_duration,
21 int expected_width, 23 int expected_width,
22 int expected_height) { 24 int expected_height) {
23 FileDataSource source; 25 FileDataSource source;
24 EXPECT_TRUE(source.Initialize(GetTestDataFilePath(filename))); 26 EXPECT_TRUE(source.Initialize(GetTestDataFilePath(filename)));
25 27
26 scoped_ptr<AudioVideoMetadataExtractor> extractor( 28 std::unique_ptr<AudioVideoMetadataExtractor> extractor(
27 new AudioVideoMetadataExtractor); 29 new AudioVideoMetadataExtractor);
28 bool extracted = extractor->Extract(&source, extract_attached_images); 30 bool extracted = extractor->Extract(&source, extract_attached_images);
29 EXPECT_EQ(expected_result, extracted); 31 EXPECT_EQ(expected_result, extracted);
30 32
31 if (!extracted) 33 if (!extracted)
32 return extractor; 34 return extractor;
33 35
34 EXPECT_EQ(expected_duration, extractor->duration()); 36 EXPECT_EQ(expected_duration, extractor->duration());
35 37
36 EXPECT_EQ(expected_width, extractor->width()); 38 EXPECT_EQ(expected_width, extractor->width());
37 EXPECT_EQ(expected_height, extractor->height()); 39 EXPECT_EQ(expected_height, extractor->height());
38 40
39 return extractor; 41 return extractor;
40 } 42 }
41 43
42 const std::string GetTagValue( 44 const std::string GetTagValue(
43 const media::AudioVideoMetadataExtractor::TagDictionary& tags, 45 const media::AudioVideoMetadataExtractor::TagDictionary& tags,
44 const char* tag_name) { 46 const char* tag_name) {
45 auto tag_data = tags.find(tag_name); 47 auto tag_data = tags.find(tag_name);
46 return tag_data == tags.end() ? "" : tag_data->second; 48 return tag_data == tags.end() ? "" : tag_data->second;
47 } 49 }
48 50
49 TEST(AudioVideoMetadataExtractorTest, InvalidFile) { 51 TEST(AudioVideoMetadataExtractorTest, InvalidFile) {
50 GetExtractor("ten_byte_file", true, false, 0, -1, -1); 52 GetExtractor("ten_byte_file", true, false, 0, -1, -1);
51 } 53 }
52 54
53 TEST(AudioVideoMetadataExtractorTest, AudioOGG) { 55 TEST(AudioVideoMetadataExtractorTest, AudioOGG) {
54 scoped_ptr<AudioVideoMetadataExtractor> extractor = 56 std::unique_ptr<AudioVideoMetadataExtractor> extractor =
55 GetExtractor("9ch.ogg", true, true, 0, -1, -1); 57 GetExtractor("9ch.ogg", true, true, 0, -1, -1);
56 EXPECT_EQ("Processed by SoX", extractor->comment()); 58 EXPECT_EQ("Processed by SoX", extractor->comment());
57 59
58 EXPECT_EQ("ogg", extractor->stream_infos()[0].type); 60 EXPECT_EQ("ogg", extractor->stream_infos()[0].type);
59 EXPECT_EQ(2u, extractor->stream_infos().size()); 61 EXPECT_EQ(2u, extractor->stream_infos().size());
60 62
61 EXPECT_EQ(0u, extractor->stream_infos()[0].tags.size()); 63 EXPECT_EQ(0u, extractor->stream_infos()[0].tags.size());
62 64
63 EXPECT_EQ(1u, extractor->stream_infos()[1].tags.size()); 65 EXPECT_EQ(1u, extractor->stream_infos()[1].tags.size());
64 EXPECT_EQ("vorbis", extractor->stream_infos()[1].type); 66 EXPECT_EQ("vorbis", extractor->stream_infos()[1].type);
65 EXPECT_EQ("Processed by SoX", 67 EXPECT_EQ("Processed by SoX",
66 GetTagValue(extractor->stream_infos()[1].tags, "COMMENT")); 68 GetTagValue(extractor->stream_infos()[1].tags, "COMMENT"));
67 69
68 EXPECT_EQ(0u, extractor->attached_images_bytes().size()); 70 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
69 } 71 }
70 72
71 TEST(AudioVideoMetadataExtractorTest, AudioWAV) { 73 TEST(AudioVideoMetadataExtractorTest, AudioWAV) {
72 scoped_ptr<AudioVideoMetadataExtractor> extractor = 74 std::unique_ptr<AudioVideoMetadataExtractor> extractor =
73 GetExtractor("sfx_u8.wav", true, true, 0, -1, -1); 75 GetExtractor("sfx_u8.wav", true, true, 0, -1, -1);
74 EXPECT_EQ("Lavf54.37.100", extractor->encoder()); 76 EXPECT_EQ("Lavf54.37.100", extractor->encoder());
75 EXPECT_EQ("Amadeus Pro", extractor->encoded_by()); 77 EXPECT_EQ("Amadeus Pro", extractor->encoded_by());
76 78
77 EXPECT_EQ("wav", extractor->stream_infos()[0].type); 79 EXPECT_EQ("wav", extractor->stream_infos()[0].type);
78 EXPECT_EQ(2u, extractor->stream_infos().size()); 80 EXPECT_EQ(2u, extractor->stream_infos().size());
79 81
80 EXPECT_EQ(2u, extractor->stream_infos()[0].tags.size()); 82 EXPECT_EQ(2u, extractor->stream_infos()[0].tags.size());
81 EXPECT_EQ("Lavf54.37.100", 83 EXPECT_EQ("Lavf54.37.100",
82 GetTagValue(extractor->stream_infos()[0].tags, "encoder")); 84 GetTagValue(extractor->stream_infos()[0].tags, "encoder"));
83 EXPECT_EQ("Amadeus Pro", 85 EXPECT_EQ("Amadeus Pro",
84 GetTagValue(extractor->stream_infos()[0].tags, "encoded_by")); 86 GetTagValue(extractor->stream_infos()[0].tags, "encoded_by"));
85 87
86 EXPECT_EQ("pcm_u8", extractor->stream_infos()[1].type); 88 EXPECT_EQ("pcm_u8", extractor->stream_infos()[1].type);
87 EXPECT_EQ(0u, extractor->stream_infos()[1].tags.size()); 89 EXPECT_EQ(0u, extractor->stream_infos()[1].tags.size());
88 90
89 EXPECT_EQ(0u, extractor->attached_images_bytes().size()); 91 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
90 } 92 }
91 93
92 TEST(AudioVideoMetadataExtractorTest, VideoWebM) { 94 TEST(AudioVideoMetadataExtractorTest, VideoWebM) {
93 scoped_ptr<AudioVideoMetadataExtractor> extractor = 95 std::unique_ptr<AudioVideoMetadataExtractor> extractor =
94 GetExtractor("bear-320x240-multitrack.webm", true, true, 2, 320, 240); 96 GetExtractor("bear-320x240-multitrack.webm", true, true, 2, 320, 240);
95 EXPECT_EQ("Lavf53.9.0", extractor->encoder()); 97 EXPECT_EQ("Lavf53.9.0", extractor->encoder());
96 98
97 EXPECT_EQ(6u, extractor->stream_infos().size()); 99 EXPECT_EQ(6u, extractor->stream_infos().size());
98 100
99 EXPECT_EQ("matroska,webm", extractor->stream_infos()[0].type); 101 EXPECT_EQ("matroska,webm", extractor->stream_infos()[0].type);
100 EXPECT_EQ(1u, extractor->stream_infos()[0].tags.size()); 102 EXPECT_EQ(1u, extractor->stream_infos()[0].tags.size());
101 EXPECT_EQ("Lavf53.9.0", 103 EXPECT_EQ("Lavf53.9.0",
102 GetTagValue(extractor->stream_infos()[0].tags, "ENCODER")); 104 GetTagValue(extractor->stream_infos()[0].tags, "ENCODER"));
103 105
(...skipping 12 matching lines...) Expand all
116 EXPECT_EQ("pcm_s16le", extractor->stream_infos()[5].type); 118 EXPECT_EQ("pcm_s16le", extractor->stream_infos()[5].type);
117 EXPECT_EQ(1u, extractor->stream_infos()[5].tags.size()); 119 EXPECT_EQ(1u, extractor->stream_infos()[5].tags.size());
118 EXPECT_EQ("Lavc52.32.0", 120 EXPECT_EQ("Lavc52.32.0",
119 GetTagValue(extractor->stream_infos()[5].tags, "ENCODER")); 121 GetTagValue(extractor->stream_infos()[5].tags, "ENCODER"));
120 122
121 EXPECT_EQ(0u, extractor->attached_images_bytes().size()); 123 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
122 } 124 }
123 125
124 #if defined(USE_PROPRIETARY_CODECS) 126 #if defined(USE_PROPRIETARY_CODECS)
125 TEST(AudioVideoMetadataExtractorTest, AndroidRotatedMP4Video) { 127 TEST(AudioVideoMetadataExtractorTest, AndroidRotatedMP4Video) {
126 scoped_ptr<AudioVideoMetadataExtractor> extractor = 128 std::unique_ptr<AudioVideoMetadataExtractor> extractor =
127 GetExtractor("90rotation.mp4", true, true, 0, 1920, 1080); 129 GetExtractor("90rotation.mp4", true, true, 0, 1920, 1080);
128 130
129 EXPECT_EQ(90, extractor->rotation()); 131 EXPECT_EQ(90, extractor->rotation());
130 132
131 EXPECT_EQ(3u, extractor->stream_infos().size()); 133 EXPECT_EQ(3u, extractor->stream_infos().size());
132 134
133 EXPECT_EQ("mov,mp4,m4a,3gp,3g2,mj2", extractor->stream_infos()[0].type); 135 EXPECT_EQ("mov,mp4,m4a,3gp,3g2,mj2", extractor->stream_infos()[0].type);
134 EXPECT_EQ(4u, extractor->stream_infos()[0].tags.size()); 136 EXPECT_EQ(4u, extractor->stream_infos()[0].tags.size());
135 EXPECT_EQ("isom3gp4", GetTagValue(extractor->stream_infos()[0].tags, 137 EXPECT_EQ("isom3gp4", GetTagValue(extractor->stream_infos()[0].tags,
136 "compatible_brands")); 138 "compatible_brands"));
(...skipping 18 matching lines...) Expand all
155 EXPECT_EQ("2014-02-11 00:39:25", 157 EXPECT_EQ("2014-02-11 00:39:25",
156 GetTagValue(extractor->stream_infos()[2].tags, "creation_time")); 158 GetTagValue(extractor->stream_infos()[2].tags, "creation_time"));
157 EXPECT_EQ("SoundHandle", 159 EXPECT_EQ("SoundHandle",
158 GetTagValue(extractor->stream_infos()[2].tags, "handler_name")); 160 GetTagValue(extractor->stream_infos()[2].tags, "handler_name"));
159 EXPECT_EQ("eng", GetTagValue(extractor->stream_infos()[2].tags, "language")); 161 EXPECT_EQ("eng", GetTagValue(extractor->stream_infos()[2].tags, "language"));
160 162
161 EXPECT_EQ(0u, extractor->attached_images_bytes().size()); 163 EXPECT_EQ(0u, extractor->attached_images_bytes().size());
162 } 164 }
163 165
164 TEST(AudioVideoMetadataExtractorTest, AudioMP3) { 166 TEST(AudioVideoMetadataExtractorTest, AudioMP3) {
165 scoped_ptr<AudioVideoMetadataExtractor> extractor = 167 std::unique_ptr<AudioVideoMetadataExtractor> extractor =
166 GetExtractor("id3_png_test.mp3", true, true, 1, -1, -1); 168 GetExtractor("id3_png_test.mp3", true, true, 1, -1, -1);
167 169
168 EXPECT_EQ("Airbag", extractor->title()); 170 EXPECT_EQ("Airbag", extractor->title());
169 EXPECT_EQ("Radiohead", extractor->artist()); 171 EXPECT_EQ("Radiohead", extractor->artist());
170 EXPECT_EQ("OK Computer", extractor->album()); 172 EXPECT_EQ("OK Computer", extractor->album());
171 EXPECT_EQ(1, extractor->track()); 173 EXPECT_EQ(1, extractor->track());
172 EXPECT_EQ("Alternative", extractor->genre()); 174 EXPECT_EQ("Alternative", extractor->genre());
173 EXPECT_EQ("1997", extractor->date()); 175 EXPECT_EQ("1997", extractor->date());
174 EXPECT_EQ("Lavf54.4.100", extractor->encoder()); 176 EXPECT_EQ("Lavf54.4.100", extractor->encoder());
175 177
(...skipping 27 matching lines...) Expand all
203 extractor->attached_images_bytes()[0].substr(0, 8)); 205 extractor->attached_images_bytes()[0].substr(0, 8));
204 EXPECT_EQ("IEND\xae\x42\x60\x82", 206 EXPECT_EQ("IEND\xae\x42\x60\x82",
205 extractor->attached_images_bytes()[0].substr( 207 extractor->attached_images_bytes()[0].substr(
206 extractor->attached_images_bytes()[0].size() - 8, 8)); 208 extractor->attached_images_bytes()[0].size() - 8, 8));
207 EXPECT_EQ("\xF3\xED\x8F\xC7\xC7\x98\xB9V|p\xC0u!\xB5\x82\xCF\x95\xF0\xCD\xCE", 209 EXPECT_EQ("\xF3\xED\x8F\xC7\xC7\x98\xB9V|p\xC0u!\xB5\x82\xCF\x95\xF0\xCD\xCE",
208 base::SHA1HashString(extractor->attached_images_bytes()[0])); 210 base::SHA1HashString(extractor->attached_images_bytes()[0]));
209 } 211 }
210 #endif 212 #endif
211 213
212 } // namespace media 214 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698