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

Unified Diff: base/task_runner_util_unittest.cc

Issue 10344012: For types that support Pass(), e.g. scoped_ptr and friends, use Passed in PostTaskAndReplyWithResul… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 8 months 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/task_runner_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_runner_util_unittest.cc
diff --git a/base/task_runner_util_unittest.cc b/base/task_runner_util_unittest.cc
index 4c5882629f44d9aafa5c6a6da254a604b9891d60..daed77016c3f0e69b035842ed508de8e7cd80f0d 100644
--- a/base/task_runner_util_unittest.cc
+++ b/base/task_runner_util_unittest.cc
@@ -20,9 +20,28 @@ void StoreValue(int* destination, int value) {
*destination = value;
}
+int g_foo_destruct_count = 0;
+
+struct Foo {
+ ~Foo() {
+ ++g_foo_destruct_count;
+ }
+};
+
+scoped_ptr<Foo> CreateFoo() {
+ return scoped_ptr<Foo>(new Foo);
+}
+
+void ExpectFoo(scoped_ptr<Foo> foo) {
+ EXPECT_TRUE(foo.get());
+ scoped_ptr<Foo> local_foo(foo.Pass());
+ EXPECT_TRUE(local_foo.get());
+ EXPECT_FALSE(foo.get());
+}
+
} // namespace
-TEST(TaskRunnerHelpersTest, PostAndReplyWithStatus) {
+TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) {
MessageLoop message_loop;
int result = 0;
@@ -37,4 +56,20 @@ TEST(TaskRunnerHelpersTest, PostAndReplyWithStatus) {
EXPECT_EQ(42, result);
}
+TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) {
+ g_foo_destruct_count = 0;
+
+ MessageLoop message_loop;
+
+ PostTaskAndReplyWithResult(
+ message_loop.message_loop_proxy(),
+ FROM_HERE,
+ Bind(&CreateFoo),
+ Bind(&ExpectFoo));
+
+ message_loop.RunAllPending();
+
+ EXPECT_EQ(1, g_foo_destruct_count);
+}
+
} // namespace base
« no previous file with comments | « base/task_runner_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698