blob: 3b26df9eccdb30785d480f2576c84c95307eb002 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BASE_MOCK_CALLBACK_H_
#define MEDIA_BASE_MOCK_CALLBACK_H_
#include "base/callback.h"
#include "media/base/pipeline_status.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace media {
// Helper class used to test that callbacks are executed.
//
// In most cases NewExpectedCallback() can be used but if need be you can
// manually set expectations on an MockCallback object:
//
// StrictMock<MockCallback>* callback =
// new StrictMock<MockCallback>();
// EXPECT_CALL(*callback, RunWithParams(_));
// EXPECT_CALL(*callback, Destructor());
//
// ...or the equivalent and less verbose:
// StrictMock<MockCallback>* callback =
// new StrictMock<MockCallback>();
// callback->ExpectRunAndDelete();
//
// ...or if you don't care about verifying callback deletion:
//
// NiceMock<MockCallback>* callback =
// new NiceMock<MockCallback>();
// EXPECT_CALL(*callback, RunWithParams(_));
class MockCallback : public CallbackRunner<Tuple0> {
public:
MockCallback();
virtual ~MockCallback();
MOCK_METHOD1(RunWithParams, void(const Tuple0& params));
// Can be used to verify the object is destroyed.
MOCK_METHOD0(Destructor, void());
// Convenience function to set expectations for the callback to execute and
// deleted.
void ExpectRunAndDelete();
private:
DISALLOW_COPY_AND_ASSIGN(MockCallback);
};
// Helper class similar to MockCallback but is used where a
// PipelineStatusCallback is needed.
class MockStatusCallback : public CallbackRunner<Tuple1<PipelineStatus> > {
public:
MockStatusCallback();
virtual ~MockStatusCallback();
MOCK_METHOD1(RunWithParams, void(const Tuple1<PipelineStatus>& params));
// Can be used to verify the object is destroyed.
MOCK_METHOD0(Destructor, void());
// Convenience function to set expectations for the callback to execute and
// deleted.
void ExpectRunAndDelete(PipelineStatus status);
private:
DISALLOW_COPY_AND_ASSIGN(MockStatusCallback);
};
// Convenience functions that automatically create and set an expectation for
// the callback to run.
MockCallback* NewExpectedCallback();
MockStatusCallback* NewExpectedStatusCallback(PipelineStatus status);
base::Callback<void(PipelineStatus)> NewExpectedStatusCB(PipelineStatus status);
} // namespace media
#endif // MEDIA_BASE_MOCK_CALLBACK_H_
|