BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / media / base / gmock_callback_support.h
blob22f4c10ad4f352f922baee36be27e8890c6dfe36
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_GMOCK_CALLBACK_SUPPORT_H_
6 #define MEDIA_BASE_GMOCK_CALLBACK_SUPPORT_H_
8 #include "testing/gmock/include/gmock/gmock.h"
10 namespace media {
12 // Matchers for base::Callback and base::Closure.
14 MATCHER(IsNullCallback, "a null callback") {
15 return (arg.is_null());
18 MATCHER(IsNotNullCallback, "a non-null callback") {
19 return (!arg.is_null());
22 // The RunClosure<N>() action invokes Run() method on the N-th (0-based)
23 // argument of the mock function.
25 ACTION_TEMPLATE(RunClosure,
26 HAS_1_TEMPLATE_PARAMS(int, k),
27 AND_0_VALUE_PARAMS()) {
28 ::std::tr1::get<k>(args).Run();
31 // Various overloads for RunCallback<N>().
33 // The RunCallback<N>(p1, p2, ..., p_k) action invokes Run() method on the N-th
34 // (0-based) argument of the mock function, with arguments p1, p2, ..., p_k.
36 // Notes:
38 // 1. The arguments are passed by value by default. If you need to
39 // pass an argument by reference, wrap it inside ByRef(). For example,
41 // RunCallback<1>(5, string("Hello"), ByRef(foo))
43 // passes 5 and string("Hello") by value, and passes foo by reference.
45 // 2. If the callback takes an argument by reference but ByRef() is
46 // not used, it will receive the reference to a copy of the value,
47 // instead of the original value. For example, when the 0-th
48 // argument of the callback takes a const string&, the action
50 // RunCallback<0>(string("Hello"))
52 // makes a copy of the temporary string("Hello") object and passes a
53 // reference of the copy, instead of the original temporary object,
54 // to the callback. This makes it easy for a user to define an
55 // RunCallback action from temporary values and have it performed later.
57 ACTION_TEMPLATE(RunCallback,
58 HAS_1_TEMPLATE_PARAMS(int, k),
59 AND_0_VALUE_PARAMS()) {
60 return ::std::tr1::get<k>(args).Run();
63 ACTION_TEMPLATE(RunCallback,
64 HAS_1_TEMPLATE_PARAMS(int, k),
65 AND_1_VALUE_PARAMS(p0)) {
66 return ::std::tr1::get<k>(args).Run(p0);
69 ACTION_TEMPLATE(RunCallback,
70 HAS_1_TEMPLATE_PARAMS(int, k),
71 AND_2_VALUE_PARAMS(p0, p1)) {
72 return ::std::tr1::get<k>(args).Run(p0, p1);
75 ACTION_TEMPLATE(RunCallback,
76 HAS_1_TEMPLATE_PARAMS(int, k),
77 AND_3_VALUE_PARAMS(p0, p1, p2)) {
78 return ::std::tr1::get<k>(args).Run(p0, p1, p2);
81 ACTION_TEMPLATE(RunCallback,
82 HAS_1_TEMPLATE_PARAMS(int, k),
83 AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
84 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3);
87 ACTION_TEMPLATE(RunCallback,
88 HAS_1_TEMPLATE_PARAMS(int, k),
89 AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
90 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4);
93 ACTION_TEMPLATE(RunCallback,
94 HAS_1_TEMPLATE_PARAMS(int, k),
95 AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
96 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5);
99 ACTION_TEMPLATE(RunCallback,
100 HAS_1_TEMPLATE_PARAMS(int, k),
101 AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
102 return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5, p6);
105 } // namespace media
107 #endif // MEDIA_BASE_GMOCK_CALLBACK_SUPPORT_H_