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

Unified Diff: base/bind_unittest.cc

Issue 8949057: Revert 115441 - Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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 | « base/bind_internal.h.pump ('k') | base/callback.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_unittest.cc
===================================================================
--- base/bind_unittest.cc (revision 115443)
+++ base/bind_unittest.cc (working copy)
@@ -5,9 +5,6 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -105,7 +102,7 @@
(*copies_)++;
}
- // Probing for copies from coercion.
+ // Probing for copies from coerscion.
CopyCounter(const DerivedCopyCounter& other)
: copies_(other.copies_),
assigns_(other.assigns_) {
@@ -152,11 +149,6 @@
int* deletes_;
};
-template <typename T>
-T PassThru(T scoper) {
- return scoper.Pass();
-}
-
// Some test functions that we can Bind to.
template <typename T>
T PolymorphicIdentity(T t) {
@@ -676,8 +668,8 @@
// return the same value.
Callback<DeleteCounter*(void)> no_capture_cb =
Bind(&PolymorphicIdentity<DeleteCounter*>, Owned(counter));
- ASSERT_EQ(counter, no_capture_cb.Run());
- ASSERT_EQ(counter, no_capture_cb.Run());
+ EXPECT_EQ(counter, no_capture_cb.Run());
+ EXPECT_EQ(counter, no_capture_cb.Run());
EXPECT_EQ(0, deletes);
no_capture_cb.Reset(); // This should trigger a delete.
EXPECT_EQ(1, deletes);
@@ -692,60 +684,11 @@
EXPECT_EQ(1, deletes);
}
-// Passed() wrapper support.
-// - Passed() can be constructed from a pointer to scoper.
-// - Passed() can be constructed from a scoper rvalue.
-// - Using Passed() gives Callback Ownership.
-// - Ownership is transferred from Callback to callee on the first Run().
-// - Callback supports unbound arguments.
-TEST_F(BindTest, ScopedPtr) {
- int deletes = 0;
-
- // Tests the Passed() function's support for pointers.
- scoped_ptr<DeleteCounter> ptr(new DeleteCounter(&deletes));
- Callback<scoped_ptr<DeleteCounter>(void)> unused_callback =
- Bind(&PassThru<scoped_ptr<DeleteCounter> >, Passed(&ptr));
- EXPECT_FALSE(ptr.get());
- EXPECT_EQ(0, deletes);
-
- // If we never invoke the Callback, it retains ownership and deletes.
- unused_callback.Reset();
- EXPECT_EQ(1, deletes);
-
- // Tests the Passed() function's support for rvalues.
- deletes = 0;
- DeleteCounter* counter = new DeleteCounter(&deletes);
- Callback<scoped_ptr<DeleteCounter>(void)> callback =
- Bind(&PassThru<scoped_ptr<DeleteCounter> >,
- Passed(scoped_ptr<DeleteCounter>(counter)));
- EXPECT_FALSE(ptr.get());
- EXPECT_EQ(0, deletes);
-
- // Check that ownership can be transferred back out.
- scoped_ptr<DeleteCounter> result = callback.Run();
- ASSERT_EQ(counter, result.get());
- EXPECT_EQ(0, deletes);
-
- // Resetting does not delete since ownership was transferred.
- callback.Reset();
- EXPECT_EQ(0, deletes);
-
- // Ensure that we actually did get ownership.
- result.reset();
- EXPECT_EQ(1, deletes);
-
- // Test unbound argument forwarding.
- Callback<scoped_ptr<DeleteCounter>(scoped_ptr<DeleteCounter>)> cb_unbound =
- Bind(&PassThru<scoped_ptr<DeleteCounter> >);
- ptr.reset(new DeleteCounter(&deletes));
- cb_unbound.Run(ptr.Pass());
-}
-
// Argument Copy-constructor usage for non-reference parameters.
// - Bound arguments are only copied once.
// - Forwarded arguments are only copied once.
-// - Forwarded arguments with coercions are only copied twice (once for the
-// coercion, and one for the final dispatch).
+// - Forwarded arguments with coerscions are only copied twice (once for the
+// coerscion, and one for the final dispatch).
TEST_F(BindTest, ArgumentCopies) {
int copies = 0;
int assigns = 0;
« no previous file with comments | « base/bind_internal.h.pump ('k') | base/callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698