OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "media/base/mock_ffmpeg.h" | 7 #include "media/base/mock_ffmpeg.h" |
8 #include "media/base/mock_filters.h" | 8 #include "media/base/mock_filters.h" |
9 #include "media/ffmpeg/ffmpeg_common.h" | 9 #include "media/ffmpeg/ffmpeg_common.h" |
10 #include "media/filters/ffmpeg_glue.h" | 10 #include "media/filters/ffmpeg_glue.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( | 143 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( |
144 new StrictMock<Destroyable<MockProtocol> >()); | 144 new StrictMock<Destroyable<MockProtocol> >()); |
145 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); | 145 EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true)); |
146 std::string key = glue->AddProtocol(protocol.get()); | 146 std::string key = glue->AddProtocol(protocol.get()); |
147 | 147 |
148 // Prepare FFmpeg URLContext structure. | 148 // Prepare FFmpeg URLContext structure. |
149 URLContext context; | 149 URLContext context; |
150 memset(&context, 0, sizeof(context)); | 150 memset(&context, 0, sizeof(context)); |
151 | 151 |
152 // Test opening a URLContext with a protocol that doesn't exist. | 152 // Test opening a URLContext with a protocol that doesn't exist. |
153 EXPECT_EQ(AVERROR_IO, protocol_->url_open(&context, "foobar", 0)); | 153 EXPECT_EQ(AVERROR(EIO), protocol_->url_open(&context, "foobar", 0)); |
154 | 154 |
155 // Test opening a URLContext with our protocol. | 155 // Test opening a URLContext with our protocol. |
156 EXPECT_EQ(0, protocol_->url_open(&context, key.c_str(), 0)); | 156 EXPECT_EQ(0, protocol_->url_open(&context, key.c_str(), 0)); |
157 EXPECT_EQ(URL_RDONLY, context.flags); | 157 EXPECT_EQ(URL_RDONLY, context.flags); |
158 EXPECT_EQ(protocol.get(), context.priv_data); | 158 EXPECT_EQ(protocol.get(), context.priv_data); |
159 EXPECT_TRUE(context.is_streamed); | 159 EXPECT_TRUE(context.is_streamed); |
160 | 160 |
161 // We're going to remove references one by one until the last reference is | 161 // We're going to remove references one by one until the last reference is |
162 // held by FFmpeg. Once we close the URLContext, the protocol should be | 162 // held by FFmpeg. Once we close the URLContext, the protocol should be |
163 // destroyed. | 163 // destroyed. |
(...skipping 19 matching lines...) Expand all Loading... |
183 TEST_F(FFmpegGlueTest, Write) { | 183 TEST_F(FFmpegGlueTest, Write) { |
184 scoped_ptr<StrictMock<MockProtocol> > protocol( | 184 scoped_ptr<StrictMock<MockProtocol> > protocol( |
185 new StrictMock<MockProtocol>()); | 185 new StrictMock<MockProtocol>()); |
186 URLContext context; | 186 URLContext context; |
187 OpenContext(protocol.get(), &context); | 187 OpenContext(protocol.get(), &context); |
188 | 188 |
189 const int kBufferSize = 16; | 189 const int kBufferSize = 16; |
190 uint8 buffer[kBufferSize]; | 190 uint8 buffer[kBufferSize]; |
191 | 191 |
192 // Writing should always fail and never call the protocol. | 192 // Writing should always fail and never call the protocol. |
193 EXPECT_EQ(AVERROR_IO, protocol_->url_write(&context, NULL, 0)); | 193 EXPECT_EQ(AVERROR(EIO), protocol_->url_write(&context, NULL, 0)); |
194 EXPECT_EQ(AVERROR_IO, protocol_->url_write(&context, buffer, 0)); | 194 EXPECT_EQ(AVERROR(EIO), protocol_->url_write(&context, buffer, 0)); |
195 EXPECT_EQ(AVERROR_IO, protocol_->url_write(&context, buffer, kBufferSize)); | 195 EXPECT_EQ(AVERROR(EIO), protocol_->url_write(&context, buffer, kBufferSize)); |
196 | 196 |
197 // Destroy the protocol. | 197 // Destroy the protocol. |
198 protocol_->url_close(&context); | 198 protocol_->url_close(&context); |
199 } | 199 } |
200 | 200 |
201 TEST_F(FFmpegGlueTest, Read) { | 201 TEST_F(FFmpegGlueTest, Read) { |
202 scoped_ptr<StrictMock<MockProtocol> > protocol( | 202 scoped_ptr<StrictMock<MockProtocol> > protocol( |
203 new StrictMock<MockProtocol>()); | 203 new StrictMock<MockProtocol>()); |
204 URLContext context; | 204 URLContext context; |
205 OpenContext(protocol.get(), &context); | 205 OpenContext(protocol.get(), &context); |
206 | 206 |
207 const int kBufferSize = 16; | 207 const int kBufferSize = 16; |
208 uint8 buffer[kBufferSize]; | 208 uint8 buffer[kBufferSize]; |
209 | 209 |
210 // Reads are for the most part straight-through calls to Read(). | 210 // Reads are for the most part straight-through calls to Read(). |
211 InSequence s; | 211 InSequence s; |
212 EXPECT_CALL(*protocol, Read(0, buffer)) | 212 EXPECT_CALL(*protocol, Read(0, buffer)) |
213 .WillOnce(Return(0)); | 213 .WillOnce(Return(0)); |
214 EXPECT_CALL(*protocol, Read(kBufferSize, buffer)) | 214 EXPECT_CALL(*protocol, Read(kBufferSize, buffer)) |
215 .WillOnce(Return(kBufferSize)); | 215 .WillOnce(Return(kBufferSize)); |
216 EXPECT_CALL(*protocol, Read(kBufferSize, buffer)) | 216 EXPECT_CALL(*protocol, Read(kBufferSize, buffer)) |
217 .WillOnce(Return(DataSource::kReadError)); | 217 .WillOnce(Return(DataSource::kReadError)); |
218 | 218 |
219 EXPECT_EQ(0, protocol_->url_read(&context, buffer, 0)); | 219 EXPECT_EQ(0, protocol_->url_read(&context, buffer, 0)); |
220 EXPECT_EQ(kBufferSize, protocol_->url_read(&context, buffer, kBufferSize)); | 220 EXPECT_EQ(kBufferSize, protocol_->url_read(&context, buffer, kBufferSize)); |
221 EXPECT_EQ(AVERROR_IO, protocol_->url_read(&context, buffer, kBufferSize)); | 221 EXPECT_EQ(AVERROR(EIO), protocol_->url_read(&context, buffer, kBufferSize)); |
222 | 222 |
223 // Destroy the protocol. | 223 // Destroy the protocol. |
224 protocol_->url_close(&context); | 224 protocol_->url_close(&context); |
225 } | 225 } |
226 | 226 |
227 TEST_F(FFmpegGlueTest, Seek) { | 227 TEST_F(FFmpegGlueTest, Seek) { |
228 scoped_ptr<StrictMock<MockProtocol> > protocol( | 228 scoped_ptr<StrictMock<MockProtocol> > protocol( |
229 new StrictMock<MockProtocol>()); | 229 new StrictMock<MockProtocol>()); |
230 URLContext context; | 230 URLContext context; |
231 OpenContext(protocol.get(), &context); | 231 OpenContext(protocol.get(), &context); |
232 | 232 |
233 // SEEK_SET should be a straight-through call to SetPosition(), which when | 233 // SEEK_SET should be a straight-through call to SetPosition(), which when |
234 // successful will return the result from GetPosition(). | 234 // successful will return the result from GetPosition(). |
235 InSequence s; | 235 InSequence s; |
236 EXPECT_CALL(*protocol, SetPosition(-16)) | 236 EXPECT_CALL(*protocol, SetPosition(-16)) |
237 .WillOnce(Return(false)); | 237 .WillOnce(Return(false)); |
238 | 238 |
239 EXPECT_CALL(*protocol, SetPosition(16)) | 239 EXPECT_CALL(*protocol, SetPosition(16)) |
240 .WillOnce(Return(true)); | 240 .WillOnce(Return(true)); |
241 EXPECT_CALL(*protocol, GetPosition(_)) | 241 EXPECT_CALL(*protocol, GetPosition(_)) |
242 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 242 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); |
243 | 243 |
244 EXPECT_EQ(AVERROR_IO, protocol_->url_seek(&context, -16, SEEK_SET)); | 244 EXPECT_EQ(AVERROR(EIO), protocol_->url_seek(&context, -16, SEEK_SET)); |
245 EXPECT_EQ(8, protocol_->url_seek(&context, 16, SEEK_SET)); | 245 EXPECT_EQ(8, protocol_->url_seek(&context, 16, SEEK_SET)); |
246 | 246 |
247 // SEEK_CUR should call GetPosition() first, and if it succeeds add the offset | 247 // SEEK_CUR should call GetPosition() first, and if it succeeds add the offset |
248 // to the result then call SetPosition()+GetPosition(). | 248 // to the result then call SetPosition()+GetPosition(). |
249 EXPECT_CALL(*protocol, GetPosition(_)) | 249 EXPECT_CALL(*protocol, GetPosition(_)) |
250 .WillOnce(Return(false)); | 250 .WillOnce(Return(false)); |
251 | 251 |
252 EXPECT_CALL(*protocol, GetPosition(_)) | 252 EXPECT_CALL(*protocol, GetPosition(_)) |
253 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 253 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); |
254 EXPECT_CALL(*protocol, SetPosition(16)) | 254 EXPECT_CALL(*protocol, SetPosition(16)) |
255 .WillOnce(Return(false)); | 255 .WillOnce(Return(false)); |
256 | 256 |
257 EXPECT_CALL(*protocol, GetPosition(_)) | 257 EXPECT_CALL(*protocol, GetPosition(_)) |
258 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 258 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); |
259 EXPECT_CALL(*protocol, SetPosition(16)) | 259 EXPECT_CALL(*protocol, SetPosition(16)) |
260 .WillOnce(Return(true)); | 260 .WillOnce(Return(true)); |
261 EXPECT_CALL(*protocol, GetPosition(_)) | 261 EXPECT_CALL(*protocol, GetPosition(_)) |
262 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 262 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); |
263 | 263 |
264 EXPECT_EQ(AVERROR_IO, protocol_->url_seek(&context, 8, SEEK_CUR)); | 264 EXPECT_EQ(AVERROR(EIO), protocol_->url_seek(&context, 8, SEEK_CUR)); |
265 EXPECT_EQ(AVERROR_IO, protocol_->url_seek(&context, 8, SEEK_CUR)); | 265 EXPECT_EQ(AVERROR(EIO), protocol_->url_seek(&context, 8, SEEK_CUR)); |
266 EXPECT_EQ(16, protocol_->url_seek(&context, 8, SEEK_CUR)); | 266 EXPECT_EQ(16, protocol_->url_seek(&context, 8, SEEK_CUR)); |
267 | 267 |
268 // SEEK_END should call GetSize() first, and if it succeeds add the offset | 268 // SEEK_END should call GetSize() first, and if it succeeds add the offset |
269 // to the result then call SetPosition()+GetPosition(). | 269 // to the result then call SetPosition()+GetPosition(). |
270 EXPECT_CALL(*protocol, GetSize(_)) | 270 EXPECT_CALL(*protocol, GetSize(_)) |
271 .WillOnce(Return(false)); | 271 .WillOnce(Return(false)); |
272 | 272 |
273 EXPECT_CALL(*protocol, GetSize(_)) | 273 EXPECT_CALL(*protocol, GetSize(_)) |
274 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 274 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); |
275 EXPECT_CALL(*protocol, SetPosition(8)) | 275 EXPECT_CALL(*protocol, SetPosition(8)) |
276 .WillOnce(Return(false)); | 276 .WillOnce(Return(false)); |
277 | 277 |
278 EXPECT_CALL(*protocol, GetSize(_)) | 278 EXPECT_CALL(*protocol, GetSize(_)) |
279 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 279 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); |
280 EXPECT_CALL(*protocol, SetPosition(8)) | 280 EXPECT_CALL(*protocol, SetPosition(8)) |
281 .WillOnce(Return(true)); | 281 .WillOnce(Return(true)); |
282 EXPECT_CALL(*protocol, GetPosition(_)) | 282 EXPECT_CALL(*protocol, GetPosition(_)) |
283 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); | 283 .WillOnce(DoAll(SetArgumentPointee<0>(8), Return(true))); |
284 | 284 |
285 EXPECT_EQ(AVERROR_IO, protocol_->url_seek(&context, -8, SEEK_END)); | 285 EXPECT_EQ(AVERROR(EIO), protocol_->url_seek(&context, -8, SEEK_END)); |
286 EXPECT_EQ(AVERROR_IO, protocol_->url_seek(&context, -8, SEEK_END)); | 286 EXPECT_EQ(AVERROR(EIO), protocol_->url_seek(&context, -8, SEEK_END)); |
287 EXPECT_EQ(8, protocol_->url_seek(&context, -8, SEEK_END)); | 287 EXPECT_EQ(8, protocol_->url_seek(&context, -8, SEEK_END)); |
288 | 288 |
289 // AVSEEK_SIZE should be a straight-through call to GetSize(). | 289 // AVSEEK_SIZE should be a straight-through call to GetSize(). |
290 EXPECT_CALL(*protocol, GetSize(_)) | 290 EXPECT_CALL(*protocol, GetSize(_)) |
291 .WillOnce(Return(false)); | 291 .WillOnce(Return(false)); |
292 | 292 |
293 EXPECT_CALL(*protocol, GetSize(_)) | 293 EXPECT_CALL(*protocol, GetSize(_)) |
294 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); | 294 .WillOnce(DoAll(SetArgumentPointee<0>(16), Return(true))); |
295 | 295 |
296 EXPECT_EQ(AVERROR_IO, protocol_->url_seek(&context, 0, AVSEEK_SIZE)); | 296 EXPECT_EQ(AVERROR(EIO), protocol_->url_seek(&context, 0, AVSEEK_SIZE)); |
297 EXPECT_EQ(16, protocol_->url_seek(&context, 0, AVSEEK_SIZE)); | 297 EXPECT_EQ(16, protocol_->url_seek(&context, 0, AVSEEK_SIZE)); |
298 | 298 |
299 // Destroy the protocol. | 299 // Destroy the protocol. |
300 protocol_->url_close(&context); | 300 protocol_->url_close(&context); |
301 } | 301 } |
302 | 302 |
303 TEST_F(FFmpegGlueTest, Destroy) { | 303 TEST_F(FFmpegGlueTest, Destroy) { |
304 // Create our protocol and add them to the glue layer. | 304 // Create our protocol and add them to the glue layer. |
305 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( | 305 scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol( |
306 new StrictMock<Destroyable<MockProtocol> >()); | 306 new StrictMock<Destroyable<MockProtocol> >()); |
307 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol.get()); | 307 std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol.get()); |
308 | 308 |
309 // We should expect the protocol to get destroyed when the unit test | 309 // We should expect the protocol to get destroyed when the unit test |
310 // exits. | 310 // exits. |
311 InSequence s; | 311 InSequence s; |
312 EXPECT_CALL(mock_ffmpeg_, CheckPoint(0)); | 312 EXPECT_CALL(mock_ffmpeg_, CheckPoint(0)); |
313 EXPECT_CALL(*protocol, OnDestroy()); | 313 EXPECT_CALL(*protocol, OnDestroy()); |
314 | 314 |
315 // Remove our own reference, we shouldn't be destroyed yet. | 315 // Remove our own reference, we shouldn't be destroyed yet. |
316 mock_ffmpeg_.CheckPoint(0); | 316 mock_ffmpeg_.CheckPoint(0); |
317 protocol.reset(); | 317 protocol.reset(); |
318 | 318 |
319 // ~FFmpegGlue() will be called when this unit test finishes execution. By | 319 // ~FFmpegGlue() will be called when this unit test finishes execution. By |
320 // leaving something inside FFmpegGlue's map we get to test our cleanup code. | 320 // leaving something inside FFmpegGlue's map we get to test our cleanup code. |
321 } | 321 } |
322 | 322 |
323 } // namespace media | 323 } // namespace media |
OLD | NEW |