OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MEDIA_BASE_MOCK_MEDIA_LOG_H_ | 5 #ifndef MEDIA_BASE_MOCK_MEDIA_LOG_H_ |
6 #define MEDIA_BASE_MOCK_MEDIA_LOG_H_ | 6 #define MEDIA_BASE_MOCK_MEDIA_LOG_H_ |
7 | 7 |
8 #include <string> | |
9 | |
10 #include "media/base/media_log.h" | 8 #include "media/base/media_log.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
12 | 10 |
13 // Helper macros to reduce boilerplate when verifying media log entries. | |
14 // |outer| is the std::string searched for substring |sub|. | |
15 #define CONTAINS_STRING(outer, sub) (std::string::npos != (outer).find(sub)) | |
16 | |
17 // "media_log_" is expected to be a scoped_refptr<MockMediaLog>, optionally a | |
18 // StrictMock, in scope of the usage of this macro. | |
19 #define EXPECT_MEDIA_LOG(x) EXPECT_CALL(*media_log_, DoAddEventLogString((x))) | |
20 | |
21 namespace media { | 11 namespace media { |
22 | 12 |
23 class MockMediaLog : public MediaLog { | 13 class MockMediaLog : public MediaLog { |
24 public: | 14 public: |
25 MockMediaLog(); | 15 MockMediaLog(); |
26 | 16 |
27 MOCK_METHOD1(DoAddEventLogString, void(const std::string& event)); | 17 MOCK_METHOD1(DoAddEventLogString, void(const std::string& event)); |
28 | 18 |
29 // Trampoline method to workaround GMOCK problems with scoped_ptr<>. | 19 // Trampoline method to workaround GMOCK problems with scoped_ptr<>. |
30 // Also simplifies tests to be able to string match on the log string | 20 // Also simplifies tests to be able to string match on the log string |
31 // representation on the added event. | 21 // representation on the added event. |
32 void AddEvent(scoped_ptr<MediaLogEvent> event) override { | 22 void AddEvent(scoped_ptr<MediaLogEvent> event) override { |
33 DoAddEventLogString(MediaEventToLogString(*event)); | 23 DoAddEventLogString(MediaEventToLogString(*event)); |
34 } | 24 } |
35 | 25 |
36 protected: | 26 protected: |
37 virtual ~MockMediaLog(); | 27 virtual ~MockMediaLog(); |
38 | 28 |
39 private: | 29 private: |
40 DISALLOW_COPY_AND_ASSIGN(MockMediaLog); | 30 DISALLOW_COPY_AND_ASSIGN(MockMediaLog); |
41 }; | 31 }; |
42 | 32 |
43 } // namespace media | 33 } // namespace media |
44 | 34 |
45 #endif // MEDIA_BASE_MOCK_MEDIA_LOG_H_ | 35 #endif // MEDIA_BASE_MOCK_MEDIA_LOG_H_ |
OLD | NEW |