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

Side by Side Diff: media/base/callback_util.h

Issue 11359100: Add RunCallback to invoke a callback parameter in unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/callback_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // This file was GENERATED by command:
2 // pump.py callback_util.h.pump
scherkus (not reviewing) 2012/11/12 17:26:03 I don't see us checking in the .pump file -- is th
xhwang 2012/11/12 18:30:34 Done.
3 // DO NOT EDIT BY HAND!!!
4
5
6 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file.
9
10 #ifndef MEDIA_BASE_CALLBACK_UTIL_H_
11 #define MEDIA_BASE_CALLBACK_UTIL_H_
12
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 namespace media {
16
17 // Matchers for base::Callback and base::Closure.
18
19 MATCHER(IsNullCallback, "a null callback") {
20 return (arg.is_null());
21 }
22
23 MATCHER(IsNotNullCallback, "a non-null callback") {
24 return (!arg.is_null());
25 }
26
27 // The RunClosure<N>() action invokes Run() method on the N-th (0-based)
28 // argument of the mock function.
29
30 ACTION_TEMPLATE(RunClosure,
31 HAS_1_TEMPLATE_PARAMS(int, k),
32 AND_0_VALUE_PARAMS()) {
33 ::std::tr1::get<k>(args).Run();
34 }
35
36 // Various overloads for RunCallback<N>().
37 //
38 // The RunCallback<N>(p1, p2, ..., p_k) action invokes Run() method on the N-th
39 // (0-based) argument of the mock function, with arguments p1, p2, ..., p_k.
40 //
41 // Notes:
42 //
43 // 1. The arguments are passed by value by default. If you need to
44 // pass an argument by reference, wrap it inside ByRef(). For example,
45 //
46 // RunCallback<1>(5, string("Hello"), ByRef(foo))
47 //
48 // passes 5 and string("Hello") by value, and passes foo by reference.
49 //
50 // 2. If the callback takes an argument by reference but ByRef() is
51 // not used, it will receive the reference to a copy of the value,
52 // instead of the original value. For example, when the 0-th
53 // argument of the callback takes a const string&, the action
54 //
55 // RunCallback<0>(string("Hello"))
56 //
57 // makes a copy of the temporary string("Hello") object and passes a
58 // reference of the copy, instead of the original temporary object,
59 // to the callback. This makes it easy for a user to define an
60 // RunCallback action from temporary values and have it performed later.
61
62 ACTION_TEMPLATE(RunCallback,
63 HAS_1_TEMPLATE_PARAMS(int, k),
64 AND_0_VALUE_PARAMS()) {
65 return ::std::tr1::get<k>(args).Run();
66 }
67
68 ACTION_TEMPLATE(RunCallback,
69 HAS_1_TEMPLATE_PARAMS(int, k),
70 AND_1_VALUE_PARAMS(p0)) {
71 return ::std::tr1::get<k>(args).Run(p0);
72 }
73
74 ACTION_TEMPLATE(RunCallback,
75 HAS_1_TEMPLATE_PARAMS(int, k),
76 AND_2_VALUE_PARAMS(p0, p1)) {
77 return ::std::tr1::get<k>(args).Run(p0, p1);
78 }
79
80 ACTION_TEMPLATE(RunCallback,
81 HAS_1_TEMPLATE_PARAMS(int, k),
82 AND_3_VALUE_PARAMS(p0, p1, p2)) {
83 return ::std::tr1::get<k>(args).Run(p0, p1, p2);
84 }
85
86 ACTION_TEMPLATE(RunCallback,
87 HAS_1_TEMPLATE_PARAMS(int, k),
88 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
89 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3);
90 }
91
92 ACTION_TEMPLATE(RunCallback,
93 HAS_1_TEMPLATE_PARAMS(int, k),
94 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
95 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4);
96 }
97
98 ACTION_TEMPLATE(RunCallback,
99 HAS_1_TEMPLATE_PARAMS(int, k),
100 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
101 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5);
102 }
103
104 ACTION_TEMPLATE(RunCallback,
105 HAS_1_TEMPLATE_PARAMS(int, k),
106 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
107 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5, p6);
108 }
109
110 } // namespace media
111
112 #endif // MEDIA_BASE_CALLBACK_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/callback_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698