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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/task_runner_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_runner_util.h" 5 #include "base/task_runner_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 namespace { 13 namespace {
14 14
15 int ReturnFourtyTwo() { 15 int ReturnFourtyTwo() {
16 return 42; 16 return 42;
17 } 17 }
18 18
19 void StoreValue(int* destination, int value) { 19 void StoreValue(int* destination, int value) {
20 *destination = value; 20 *destination = value;
21 } 21 }
22 22
23 int g_foo_destruct_count = 0;
24
25 struct Foo {
26 ~Foo() {
27 ++g_foo_destruct_count;
28 }
29 };
30
31 scoped_ptr<Foo> CreateFoo() {
32 return scoped_ptr<Foo>(new Foo);
33 }
34
35 void ExpectFoo(scoped_ptr<Foo> foo) {
36 EXPECT_TRUE(foo.get());
37 scoped_ptr<Foo> local_foo(foo.Pass());
38 EXPECT_TRUE(local_foo.get());
39 EXPECT_FALSE(foo.get());
40 }
41
23 } // namespace 42 } // namespace
24 43
25 TEST(TaskRunnerHelpersTest, PostAndReplyWithStatus) { 44 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) {
26 MessageLoop message_loop; 45 MessageLoop message_loop;
27 int result = 0; 46 int result = 0;
28 47
29 PostTaskAndReplyWithResult( 48 PostTaskAndReplyWithResult(
30 message_loop.message_loop_proxy(), 49 message_loop.message_loop_proxy(),
31 FROM_HERE, 50 FROM_HERE,
32 Bind(&ReturnFourtyTwo), 51 Bind(&ReturnFourtyTwo),
33 Bind(&StoreValue, &result)); 52 Bind(&StoreValue, &result));
34 53
35 message_loop.RunAllPending(); 54 message_loop.RunAllPending();
36 55
37 EXPECT_EQ(42, result); 56 EXPECT_EQ(42, result);
38 } 57 }
39 58
59 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) {
60 g_foo_destruct_count = 0;
61
62 MessageLoop message_loop;
63
64 PostTaskAndReplyWithResult(
65 message_loop.message_loop_proxy(),
66 FROM_HERE,
67 Bind(&CreateFoo),
68 Bind(&ExpectFoo));
69
70 message_loop.RunAllPending();
71
72 EXPECT_EQ(1, g_foo_destruct_count);
73 }
74
40 } // namespace base 75 } // namespace base
OLDNEW
« 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