• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #ifndef TEST_UTILS_MOCK_CALLBACK_H_
9 #define TEST_UTILS_MOCK_CALLBACK_H_
10 
11 #include <cstdint>
12 
13 #include "gmock/gmock.h"
14 
15 #include "webm/callback.h"
16 #include "webm/dom_types.h"
17 #include "webm/reader.h"
18 #include "webm/status.h"
19 
20 namespace webm {
21 
22 // A simple version of Callback that can be used with Google Mock. By default,
23 // the mocked methods will call through to the corresponding Callback methods.
24 class MockCallback : public Callback {
25  public:
MockCallback()26   MockCallback() {
27     using testing::_;
28     using testing::Invoke;
29 
30     ON_CALL(*this, OnElementBegin(_, _))
31         .WillByDefault(Invoke(this, &MockCallback::OnElementBeginConcrete));
32     ON_CALL(*this, OnUnknownElement(_, _, _))
33         .WillByDefault(Invoke(this, &MockCallback::OnUnknownElementConcrete));
34     ON_CALL(*this, OnEbml(_, _))
35         .WillByDefault(Invoke(this, &MockCallback::OnEbmlConcrete));
36     ON_CALL(*this, OnVoid(_, _, _))
37         .WillByDefault(Invoke(this, &MockCallback::OnVoidConcrete));
38     ON_CALL(*this, OnSegmentBegin(_, _))
39         .WillByDefault(Invoke(this, &MockCallback::OnSegmentBeginConcrete));
40     ON_CALL(*this, OnSeek(_, _))
41         .WillByDefault(Invoke(this, &MockCallback::OnSeekConcrete));
42     ON_CALL(*this, OnInfo(_, _))
43         .WillByDefault(Invoke(this, &MockCallback::OnInfoConcrete));
44     ON_CALL(*this, OnClusterBegin(_, _, _))
45         .WillByDefault(Invoke(this, &MockCallback::OnClusterBeginConcrete));
46     ON_CALL(*this, OnSimpleBlockBegin(_, _, _))
47         .WillByDefault(Invoke(this, &MockCallback::OnSimpleBlockBeginConcrete));
48     ON_CALL(*this, OnSimpleBlockEnd(_, _))
49         .WillByDefault(Invoke(this, &MockCallback::OnSimpleBlockEndConcrete));
50     ON_CALL(*this, OnBlockGroupBegin(_, _))
51         .WillByDefault(Invoke(this, &MockCallback::OnBlockGroupBeginConcrete));
52     ON_CALL(*this, OnBlockBegin(_, _, _))
53         .WillByDefault(Invoke(this, &MockCallback::OnBlockBeginConcrete));
54     ON_CALL(*this, OnBlockEnd(_, _))
55         .WillByDefault(Invoke(this, &MockCallback::OnBlockEndConcrete));
56     ON_CALL(*this, OnBlockGroupEnd(_, _))
57         .WillByDefault(Invoke(this, &MockCallback::OnBlockGroupEndConcrete));
58     ON_CALL(*this, OnFrame(_, _, _))
59         .WillByDefault(Invoke(this, &MockCallback::OnFrameConcrete));
60     ON_CALL(*this, OnClusterEnd(_, _))
61         .WillByDefault(Invoke(this, &MockCallback::OnClusterEndConcrete));
62     ON_CALL(*this, OnTrackEntry(_, _))
63         .WillByDefault(Invoke(this, &MockCallback::OnTrackEntryConcrete));
64     ON_CALL(*this, OnCuePoint(_, _))
65         .WillByDefault(Invoke(this, &MockCallback::OnCuePointConcrete));
66     ON_CALL(*this, OnEditionEntry(_, _))
67         .WillByDefault(Invoke(this, &MockCallback::OnEditionEntryConcrete));
68     ON_CALL(*this, OnTag(_, _))
69         .WillByDefault(Invoke(this, &MockCallback::OnTagConcrete));
70     ON_CALL(*this, OnSegmentEnd(_))
71         .WillByDefault(Invoke(this, &MockCallback::OnSegmentEndConcrete));
72   }
73 
74   // Mocks for methods from Callback.
75   MOCK_METHOD2(OnElementBegin,
76                Status(const ElementMetadata& metadata, Action* action));
77 
78   MOCK_METHOD3(OnUnknownElement,
79                Status(const ElementMetadata& metadata, Reader* reader,
80                       std::uint64_t* bytes_remaining));
81 
82   MOCK_METHOD2(OnEbml,
83                Status(const ElementMetadata& metadata, const Ebml& ebml));
84 
85   MOCK_METHOD3(OnVoid, Status(const ElementMetadata& metadata, Reader* reader,
86                               std::uint64_t* bytes_remaining));
87 
88   MOCK_METHOD2(OnSegmentBegin,
89                Status(const ElementMetadata& metadata, Action* action));
90 
91   MOCK_METHOD2(OnSeek,
92                Status(const ElementMetadata& metadata, const Seek& seek));
93 
94   MOCK_METHOD2(OnInfo,
95                Status(const ElementMetadata& metadata, const Info& info));
96 
97   MOCK_METHOD3(OnClusterBegin, Status(const ElementMetadata& metadata,
98                                       const Cluster& cluster, Action* action));
99 
100   MOCK_METHOD3(OnSimpleBlockBegin,
101                Status(const ElementMetadata& metadata,
102                       const SimpleBlock& simple_block, Action* action));
103 
104   MOCK_METHOD2(OnSimpleBlockEnd, Status(const ElementMetadata& metadata,
105                                         const SimpleBlock& simple_block));
106 
107   MOCK_METHOD2(OnBlockGroupBegin,
108                Status(const ElementMetadata& metadata, Action* action));
109 
110   MOCK_METHOD3(OnBlockBegin, Status(const ElementMetadata& metadata,
111                                     const Block& block, Action* action));
112 
113   MOCK_METHOD2(OnBlockEnd,
114                Status(const ElementMetadata& metadata, const Block& block));
115 
116   MOCK_METHOD2(OnBlockGroupEnd, Status(const ElementMetadata& metadata,
117                                        const BlockGroup& block_group));
118 
119   MOCK_METHOD3(OnFrame, Status(const FrameMetadata& metadata, Reader* reader,
120                                std::uint64_t* bytes_remaining));
121 
122   MOCK_METHOD2(OnClusterEnd,
123                Status(const ElementMetadata& metadata, const Cluster& cluster));
124 
125   MOCK_METHOD2(OnTrackEntry, Status(const ElementMetadata& metadata,
126                                     const TrackEntry& track_entry));
127 
128   MOCK_METHOD2(OnCuePoint, Status(const ElementMetadata& metadata,
129                                   const CuePoint& cue_point));
130 
131   MOCK_METHOD2(OnEditionEntry, Status(const ElementMetadata& metadata,
132                                       const EditionEntry& edition_entry));
133 
134   MOCK_METHOD2(OnTag, Status(const ElementMetadata& metadata, const Tag& tag));
135 
136   MOCK_METHOD1(OnSegmentEnd, Status(const ElementMetadata& metadata));
137 
138   // Concrete implementations that the corresponding mocked method may call,
139   // provided for convenience. These methods just call through to the
140   // corrensponding methods in Callback, and provide an convenient way for the
141   // MockCallback to exhibit the same behavior as Callback.
OnElementBeginConcrete(const ElementMetadata & metadata,Action * action)142   Status OnElementBeginConcrete(const ElementMetadata& metadata,
143                                 Action* action) {
144     return Callback::OnElementBegin(metadata, action);
145   }
146 
OnUnknownElementConcrete(const ElementMetadata & metadata,Reader * reader,std::uint64_t * bytes_remaining)147   Status OnUnknownElementConcrete(const ElementMetadata& metadata,
148                                   Reader* reader,
149                                   std::uint64_t* bytes_remaining) {
150     return Callback::OnUnknownElement(metadata, reader, bytes_remaining);
151   }
152 
OnEbmlConcrete(const ElementMetadata & metadata,const Ebml & ebml)153   Status OnEbmlConcrete(const ElementMetadata& metadata, const Ebml& ebml) {
154     return Callback::OnEbml(metadata, ebml);
155   }
156 
OnVoidConcrete(const ElementMetadata & metadata,Reader * reader,std::uint64_t * bytes_remaining)157   Status OnVoidConcrete(const ElementMetadata& metadata, Reader* reader,
158                         std::uint64_t* bytes_remaining) {
159     return Callback::OnVoid(metadata, reader, bytes_remaining);
160   }
161 
OnSegmentBeginConcrete(const ElementMetadata & metadata,Action * action)162   Status OnSegmentBeginConcrete(const ElementMetadata& metadata,
163                                 Action* action) {
164     return Callback::OnSegmentBegin(metadata, action);
165   }
166 
OnSeekConcrete(const ElementMetadata & metadata,const Seek & seek)167   Status OnSeekConcrete(const ElementMetadata& metadata, const Seek& seek) {
168     return Callback::OnSeek(metadata, seek);
169   }
170 
OnInfoConcrete(const ElementMetadata & metadata,const Info & info)171   Status OnInfoConcrete(const ElementMetadata& metadata, const Info& info) {
172     return Callback::OnInfo(metadata, info);
173   }
174 
OnClusterBeginConcrete(const ElementMetadata & metadata,const Cluster & cluster,Action * action)175   Status OnClusterBeginConcrete(const ElementMetadata& metadata,
176                                 const Cluster& cluster, Action* action) {
177     return Callback::OnClusterBegin(metadata, cluster, action);
178   }
179 
OnSimpleBlockBeginConcrete(const ElementMetadata & metadata,const SimpleBlock & simple_block,Action * action)180   Status OnSimpleBlockBeginConcrete(const ElementMetadata& metadata,
181                                     const SimpleBlock& simple_block,
182                                     Action* action) {
183     return Callback::OnSimpleBlockBegin(metadata, simple_block, action);
184   }
185 
OnSimpleBlockEndConcrete(const ElementMetadata & metadata,const SimpleBlock & simple_block)186   Status OnSimpleBlockEndConcrete(const ElementMetadata& metadata,
187                                   const SimpleBlock& simple_block) {
188     return Callback::OnSimpleBlockEnd(metadata, simple_block);
189   }
190 
OnBlockGroupBeginConcrete(const ElementMetadata & metadata,Action * action)191   Status OnBlockGroupBeginConcrete(const ElementMetadata& metadata,
192                                    Action* action) {
193     return Callback::OnBlockGroupBegin(metadata, action);
194   }
195 
OnBlockBeginConcrete(const ElementMetadata & metadata,const Block & block,Action * action)196   Status OnBlockBeginConcrete(const ElementMetadata& metadata,
197                               const Block& block, Action* action) {
198     return Callback::OnBlockBegin(metadata, block, action);
199   }
200 
OnBlockEndConcrete(const ElementMetadata & metadata,const Block & block)201   Status OnBlockEndConcrete(const ElementMetadata& metadata,
202                             const Block& block) {
203     return Callback::OnBlockEnd(metadata, block);
204   }
205 
OnBlockGroupEndConcrete(const ElementMetadata & metadata,const BlockGroup & block_group)206   Status OnBlockGroupEndConcrete(const ElementMetadata& metadata,
207                                  const BlockGroup& block_group) {
208     return Callback::OnBlockGroupEnd(metadata, block_group);
209   }
210 
OnFrameConcrete(const FrameMetadata & metadata,Reader * reader,std::uint64_t * bytes_remaining)211   Status OnFrameConcrete(const FrameMetadata& metadata, Reader* reader,
212                          std::uint64_t* bytes_remaining) {
213     return Callback::OnFrame(metadata, reader, bytes_remaining);
214   }
215 
OnClusterEndConcrete(const ElementMetadata & metadata,const Cluster & cluster)216   Status OnClusterEndConcrete(const ElementMetadata& metadata,
217                               const Cluster& cluster) {
218     return Callback::OnClusterEnd(metadata, cluster);
219   }
220 
OnTrackEntryConcrete(const ElementMetadata & metadata,const TrackEntry & track_entry)221   Status OnTrackEntryConcrete(const ElementMetadata& metadata,
222                               const TrackEntry& track_entry) {
223     return Callback::OnTrackEntry(metadata, track_entry);
224   }
225 
OnCuePointConcrete(const ElementMetadata & metadata,const CuePoint & cue_point)226   Status OnCuePointConcrete(const ElementMetadata& metadata,
227                             const CuePoint& cue_point) {
228     return Callback::OnCuePoint(metadata, cue_point);
229   }
230 
OnEditionEntryConcrete(const ElementMetadata & metadata,const EditionEntry & edition_entry)231   Status OnEditionEntryConcrete(const ElementMetadata& metadata,
232                                 const EditionEntry& edition_entry) {
233     return Callback::OnEditionEntry(metadata, edition_entry);
234   }
235 
OnTagConcrete(const ElementMetadata & metadata,const Tag & tag)236   Status OnTagConcrete(const ElementMetadata& metadata, const Tag& tag) {
237     return Callback::OnTag(metadata, tag);
238   }
239 
OnSegmentEndConcrete(const ElementMetadata & metadata)240   Status OnSegmentEndConcrete(const ElementMetadata& metadata) {
241     return Callback::OnSegmentEnd(metadata);
242   }
243 };
244 
245 }  // namespace webm
246 
247 #endif  // TEST_UTILS_MOCK_CALLBACK_H_
248