summaryrefslogtreecommitdiffstats
path: root/base/bind_unittest.cc
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-24 02:02:17 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-24 02:02:17 +0000
commitc18b1056be790c55f10e407a1f6a3706bff7df03 (patch)
tree7ed333791fc8dfeaef29c07307e8efcfa1b44fba /base/bind_unittest.cc
parentb2e900f755ea4e66b5f41413716ecb55720e354d (diff)
downloadchromium_src-c18b1056be790c55f10e407a1f6a3706bff7df03.zip
chromium_src-c18b1056be790c55f10e407a1f6a3706bff7df03.tar.gz
chromium_src-c18b1056be790c55f10e407a1f6a3706bff7df03.tar.bz2
Callback support for unbound reference and array arguments.
Because the callback object uses const An& for the type of the Run() function in argument forwarding, the code breaks for An=T& or An=T[]. This CL adds in code to modify the parameter type to remove duplicate references, and other fun. BUG=35223 TEST=new unittests Review URL: http://codereview.chromium.org/6718021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79239 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind_unittest.cc')
-rw-r--r--base/bind_unittest.cc38
1 files changed, 36 insertions, 2 deletions
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc
index 061808b..b3e0160 100644
--- a/base/bind_unittest.cc
+++ b/base/bind_unittest.cc
@@ -174,6 +174,10 @@ int UnwrapNoRefParentConstRef(const NoRefParent& p) {
return p.value;
}
+void RefArgSet(int &n) {
+ n = 2;
+}
+
// Only useful in no-compile tests.
int UnwrapNoRefParentRef(Parent& p) {
return p.value;
@@ -351,6 +355,37 @@ TEST_F(BindTest, ArgumentBinding) {
EXPECT_EQ(8, bind_const_reference_promotes_cb.Run());
}
+// Unbound argument type support tests.
+// - Unbound value.
+// - Unbound pointer.
+// - Unbound reference.
+// - Unbound const reference.
+// - Unbound unsized array.
+// - Unbound sized array.
+// - Unbound array-of-arrays.
+TEST_F(BindTest, UnboundArgumentTypeSupport) {
+ Callback<void(int)> unbound_value_cb = Bind(&VoidPolymorphic1<int>);
+ Callback<void(int*)> unbound_pointer_cb = Bind(&VoidPolymorphic1<int*>);
+ Callback<void(int&)> unbound_ref_cb = Bind(&VoidPolymorphic1<int&>);
+ Callback<void(const int&)> unbound_const_ref_cb =
+ Bind(&VoidPolymorphic1<const int&>);
+ Callback<void(int[])> unbound_unsized_array_cb =
+ Bind(&VoidPolymorphic1<int[]>);
+ Callback<void(int[2])> unbound_sized_array_cb =
+ Bind(&VoidPolymorphic1<int[2]>);
+ Callback<void(int[][2])> unbound_array_of_arrays_cb =
+ Bind(&VoidPolymorphic1<int[][2]>);
+}
+
+// Function with unbound reference parameter.
+// - Original paraemter is modified by callback.
+TEST_F(BindTest, UnboundReferenceSupport) {
+ int n = 0;
+ Callback<void(int&)> unbound_ref_cb = Bind(&RefArgSet);
+ unbound_ref_cb.Run(n);
+ EXPECT_EQ(2, n);
+}
+
// Functions that take reference parameters.
// - Forced reference parameter type still stores a copy.
// - Forced const reference parameter type still stores a copy.
@@ -570,14 +605,13 @@ TEST_F(BindTest, NoCompile) {
//
// HasRef p[10];
// Callback<void(void)> method_bound_to_array_cb =
- // Bind(&HasRef::VoidConstMethod0, p);
+ // Bind(&HasRef::VoidConstMethod0, p);
// method_bound_to_array_cb.Run();
// - Refcounted types should not be bound as a raw pointer.
// HasRef for_raw_ptr;
// Callback<void(void)> ref_count_as_raw_ptr =
// Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr);
- // ASSERT_EQ(&for_raw_ptr, ref_count_as_raw_ptr.Run());
}