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

Unified Diff: media/base/mock_filters.h

Issue 149423: Converted remaining tests to use gmock and deleted all old mocking code. (Closed)
Patch Set: Fix again Created 11 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/mock_ffmpeg.cc ('k') | media/base/mock_media_filters.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/mock_filters.h
diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h
index bef46a7d9c6699d39c0cee643a0f4708e47a50f4..bffba6ff9cad7c703a8a4ab8e17e32b5deb6c531 100644
--- a/media/base/mock_filters.h
+++ b/media/base/mock_filters.h
@@ -19,6 +19,27 @@
namespace media {
+// Use this template to test for object destruction by setting expectations on
+// the method OnDestroy().
+//
+// TODO(scherkus): not sure about the naming... perhaps contribute this back
+// to gmock itself!
+template<class MockClass>
+class Destroyable : public MockClass {
+ public:
+ Destroyable() {}
+
+ MOCK_METHOD0(OnDestroy, void());
+
+ protected:
+ virtual ~Destroyable() {
+ OnDestroy();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Destroyable);
+};
+
class MockDataSource : public DataSource {
public:
MockDataSource() {}
@@ -71,6 +92,12 @@ class MockDemuxerStream : public DemuxerStream {
public:
MockDemuxerStream() {}
+ // Sets the mime type of this object's media format, which is usually checked
+ // to determine the type of decoder to create.
+ explicit MockDemuxerStream(const std::string& mime_type) {
+ media_format_.SetAsString(MediaFormat::kMimeType, mime_type);
+ }
+
// DemuxerStream implementation.
const MediaFormat& media_format() { return media_format_; }
MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
@@ -175,7 +202,8 @@ class MockAudioRenderer : public AudioRenderer {
class MockFilterFactory : public FilterFactory {
public:
MockFilterFactory()
- : data_source_(new MockDataSource()),
+ : creation_successful_(true),
+ data_source_(new MockDataSource()),
demuxer_(new MockDemuxer()),
video_decoder_(new MockVideoDecoder()),
audio_decoder_(new MockAudioDecoder()),
@@ -185,6 +213,11 @@ class MockFilterFactory : public FilterFactory {
virtual ~MockFilterFactory() {}
+ // Controls whether the Create() method is successful or not.
+ void set_creation_successful(bool creation_successful) {
+ creation_successful_ = creation_successful;
+ }
+
// Mock accessors.
MockDataSource* data_source() const { return data_source_; }
MockDemuxer* demuxer() const { return demuxer_; }
@@ -195,6 +228,10 @@ class MockFilterFactory : public FilterFactory {
protected:
MediaFilter* Create(FilterType filter_type, const MediaFormat& media_format) {
+ if (!creation_successful_) {
+ return NULL;
+ }
+
switch (filter_type) {
case FILTER_DATA_SOURCE:
return data_source_;
@@ -215,6 +252,7 @@ class MockFilterFactory : public FilterFactory {
}
private:
+ bool creation_successful_;
scoped_refptr<MockDataSource> data_source_;
scoped_refptr<MockDemuxer> demuxer_;
scoped_refptr<MockVideoDecoder> video_decoder_;
@@ -225,6 +263,17 @@ class MockFilterFactory : public FilterFactory {
DISALLOW_COPY_AND_ASSIGN(MockFilterFactory);
};
+// Helper gmock action that calls InitializationComplete() on behalf of the
+// provided filter.
+ACTION_P(InitializationComplete, filter) {
+ filter->host()->InitializationComplete();
+}
+
+// Helper gmock action that calls Error() on behalf of the provided filter.
+ACTION_P2(Error, filter, error) {
+ filter->host()->Error(error);
+}
+
} // namespace media
#endif // MEDIA_BASE_MOCK_FILTERS_H_
« no previous file with comments | « media/base/mock_ffmpeg.cc ('k') | media/base/mock_media_filters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698