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 |
8 #include "media/base/media_log.h" | 10 #include "media/base/media_log.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
10 | 12 |
| 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 |
11 namespace media { | 21 namespace media { |
12 | 22 |
13 class MockMediaLog : public MediaLog { | 23 class MockMediaLog : public MediaLog { |
14 public: | 24 public: |
15 MockMediaLog(); | 25 MockMediaLog(); |
16 | 26 |
17 MOCK_METHOD1(DoAddEventLogString, void(const std::string& event)); | 27 MOCK_METHOD1(DoAddEventLogString, void(const std::string& event)); |
18 | 28 |
19 // Trampoline method to workaround GMOCK problems with scoped_ptr<>. | 29 // Trampoline method to workaround GMOCK problems with scoped_ptr<>. |
20 // Also simplifies tests to be able to string match on the log string | 30 // Also simplifies tests to be able to string match on the log string |
21 // representation on the added event. | 31 // representation on the added event. |
22 void AddEvent(scoped_ptr<MediaLogEvent> event) override { | 32 void AddEvent(scoped_ptr<MediaLogEvent> event) override { |
23 DoAddEventLogString(MediaEventToLogString(*event)); | 33 DoAddEventLogString(MediaEventToLogString(*event)); |
24 } | 34 } |
25 | 35 |
26 protected: | 36 protected: |
27 virtual ~MockMediaLog(); | 37 virtual ~MockMediaLog(); |
28 | 38 |
29 private: | 39 private: |
30 DISALLOW_COPY_AND_ASSIGN(MockMediaLog); | 40 DISALLOW_COPY_AND_ASSIGN(MockMediaLog); |
31 }; | 41 }; |
32 | 42 |
33 } // namespace media | 43 } // namespace media |
34 | 44 |
35 #endif // MEDIA_BASE_MOCK_MEDIA_LOG_H_ | 45 #endif // MEDIA_BASE_MOCK_MEDIA_LOG_H_ |
OLD | NEW |