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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/callback_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/callback_util.h
diff --git a/media/base/callback_util.h b/media/base/callback_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..ab4deb93d5bc10085d809e621626e18d82819253
--- /dev/null
+++ b/media/base/callback_util.h
@@ -0,0 +1,112 @@
+// This file was GENERATED by command:
+// 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.
+// DO NOT EDIT BY HAND!!!
+
+
+// Copyright (c) 2012 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_CALLBACK_UTIL_H_
+#define MEDIA_BASE_CALLBACK_UTIL_H_
+
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace media {
+
+// Matchers for base::Callback and base::Closure.
+
+MATCHER(IsNullCallback, "a null callback") {
+ return (arg.is_null());
+}
+
+MATCHER(IsNotNullCallback, "a non-null callback") {
+ return (!arg.is_null());
+}
+
+// The RunClosure<N>() action invokes Run() method on the N-th (0-based)
+// argument of the mock function.
+
+ACTION_TEMPLATE(RunClosure,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_0_VALUE_PARAMS()) {
+ ::std::tr1::get<k>(args).Run();
+}
+
+// Various overloads for RunCallback<N>().
+//
+// The RunCallback<N>(p1, p2, ..., p_k) action invokes Run() method on the N-th
+// (0-based) argument of the mock function, with arguments p1, p2, ..., p_k.
+//
+// Notes:
+//
+// 1. The arguments are passed by value by default. If you need to
+// pass an argument by reference, wrap it inside ByRef(). For example,
+//
+// RunCallback<1>(5, string("Hello"), ByRef(foo))
+//
+// passes 5 and string("Hello") by value, and passes foo by reference.
+//
+// 2. If the callback takes an argument by reference but ByRef() is
+// not used, it will receive the reference to a copy of the value,
+// instead of the original value. For example, when the 0-th
+// argument of the callback takes a const string&, the action
+//
+// RunCallback<0>(string("Hello"))
+//
+// makes a copy of the temporary string("Hello") object and passes a
+// reference of the copy, instead of the original temporary object,
+// to the callback. This makes it easy for a user to define an
+// RunCallback action from temporary values and have it performed later.
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_0_VALUE_PARAMS()) {
+ return ::std::tr1::get<k>(args).Run();
+}
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_1_VALUE_PARAMS(p0)) {
+ return ::std::tr1::get<k>(args).Run(p0);
+}
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_2_VALUE_PARAMS(p0, p1)) {
+ return ::std::tr1::get<k>(args).Run(p0, p1);
+}
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_3_VALUE_PARAMS(p0, p1, p2)) {
+ return ::std::tr1::get<k>(args).Run(p0, p1, p2);
+}
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
+ return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3);
+}
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
+ return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4);
+}
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
+ return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5);
+}
+
+ACTION_TEMPLATE(RunCallback,
+ HAS_1_TEMPLATE_PARAMS(int, k),
+ AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
+ return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5, p6);
+}
+
+} // namespace media
+
+#endif // MEDIA_BASE_CALLBACK_UTIL_H_
« 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