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

Side by Side Diff: media/filters/ffmpeg_demuxer_unittest.cc

Issue 8319010: Properly ref-count the EndOfStream buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Keep one change in r105647. Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <deque> 5 #include <deque>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "media/base/filters.h" 10 #include "media/base/filters.h"
(...skipping 18 matching lines...) Expand all
29 using ::testing::WithArgs; 29 using ::testing::WithArgs;
30 using ::testing::_; 30 using ::testing::_;
31 31
32 namespace media { 32 namespace media {
33 33
34 MATCHER(IsEndOfStreamBuffer, 34 MATCHER(IsEndOfStreamBuffer,
35 std::string(negation ? "isn't" : "is") + " end of stream") { 35 std::string(negation ? "isn't" : "is") + " end of stream") {
36 return arg->IsEndOfStream(); 36 return arg->IsEndOfStream();
37 } 37 }
38 38
39 ACTION(DeleteArg0Buffer) {
40 scoped_refptr<Buffer> buffer(arg0);
41 }
42
43 // Fixture class to facilitate writing tests. Takes care of setting up the 39 // Fixture class to facilitate writing tests. Takes care of setting up the
44 // FFmpeg, pipeline and filter host mocks. 40 // FFmpeg, pipeline and filter host mocks.
45 class FFmpegDemuxerTest : public testing::Test { 41 class FFmpegDemuxerTest : public testing::Test {
46 protected: 42 protected:
47 43
48 FFmpegDemuxerTest() { 44 FFmpegDemuxerTest() {
49 // Create an FFmpegDemuxer. 45 // Create an FFmpegDemuxer.
50 demuxer_ = new FFmpegDemuxer(&message_loop_); 46 demuxer_ = new FFmpegDemuxer(&message_loop_);
51 demuxer_->disable_first_seek_hack_for_testing(); 47 demuxer_->disable_first_seek_hack_for_testing();
52 48
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 396
401 // Expect all calls in sequence. 397 // Expect all calls in sequence.
402 InSequence s; 398 InSequence s;
403 399
404 // Create our mocked callback. The Callback created by base::Bind() will take 400 // Create our mocked callback. The Callback created by base::Bind() will take
405 // ownership of this pointer. 401 // ownership of this pointer.
406 StrictMock<MockReadCallback>* callback = new StrictMock<MockReadCallback>(); 402 StrictMock<MockReadCallback>* callback = new StrictMock<MockReadCallback>();
407 403
408 // The callback should be immediately deleted. We'll use a checkpoint to 404 // The callback should be immediately deleted. We'll use a checkpoint to
409 // verify that it has indeed been deleted. 405 // verify that it has indeed been deleted.
410 EXPECT_CALL(*callback, Run(IsEndOfStreamBuffer())) 406 EXPECT_CALL(*callback, Run(IsEndOfStreamBuffer()));
411 .WillOnce(DeleteArg0Buffer());
412 EXPECT_CALL(*callback, OnDelete()); 407 EXPECT_CALL(*callback, OnDelete());
413 EXPECT_CALL(*this, CheckPoint(1)); 408 EXPECT_CALL(*this, CheckPoint(1));
414 409
415 // Attempt the read... 410 // Attempt the read...
416 audio->Read(base::Bind(&MockReadCallback::Run, callback)); 411 audio->Read(base::Bind(&MockReadCallback::Run, callback));
417 412
418 message_loop_.RunAllPending(); 413 message_loop_.RunAllPending();
419 414
420 // ...and verify that |callback| was deleted. 415 // ...and verify that |callback| was deleted.
421 CheckPoint(1); 416 CheckPoint(1);
(...skipping 18 matching lines...) Expand all
440 435
441 // Expect all calls in sequence. 436 // Expect all calls in sequence.
442 InSequence s; 437 InSequence s;
443 438
444 // Create our mocked callback. The Callback created by base::Bind() will take 439 // Create our mocked callback. The Callback created by base::Bind() will take
445 // ownership of this pointer. 440 // ownership of this pointer.
446 StrictMock<MockReadCallback>* callback = new StrictMock<MockReadCallback>(); 441 StrictMock<MockReadCallback>* callback = new StrictMock<MockReadCallback>();
447 442
448 // The callback should be immediately deleted. We'll use a checkpoint to 443 // The callback should be immediately deleted. We'll use a checkpoint to
449 // verify that it has indeed been deleted. 444 // verify that it has indeed been deleted.
450 EXPECT_CALL(*callback, Run(IsEndOfStreamBuffer())) 445 EXPECT_CALL(*callback, Run(IsEndOfStreamBuffer()));
451 .WillOnce(DeleteArg0Buffer());
452 EXPECT_CALL(*callback, OnDelete()); 446 EXPECT_CALL(*callback, OnDelete());
453 EXPECT_CALL(*this, CheckPoint(1)); 447 EXPECT_CALL(*this, CheckPoint(1));
454 448
455 // Release the reference to the demuxer. This should also destroy it. 449 // Release the reference to the demuxer. This should also destroy it.
456 demuxer_ = NULL; 450 demuxer_ = NULL;
457 // |audio| now has a demuxer_ pointer to invalid memory. 451 // |audio| now has a demuxer_ pointer to invalid memory.
458 452
459 // Attempt the read... 453 // Attempt the read...
460 audio->Read(base::Bind(&MockReadCallback::Run, callback)); 454 audio->Read(base::Bind(&MockReadCallback::Run, callback));
461 455
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 message_loop_.RunAllPending(); 683 message_loop_.RunAllPending();
690 EXPECT_TRUE(reader->called()); 684 EXPECT_TRUE(reader->called());
691 ValidateBuffer(FROM_HERE, reader->buffer(), 1740, 2436000); 685 ValidateBuffer(FROM_HERE, reader->buffer(), 1740, 2436000);
692 686
693 // Manually release the last reference to the buffer and verify it was freed. 687 // Manually release the last reference to the buffer and verify it was freed.
694 reader->Reset(); 688 reader->Reset();
695 message_loop_.RunAllPending(); 689 message_loop_.RunAllPending();
696 } 690 }
697 691
698 } // namespace media 692 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698