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

Side by Side Diff: base/task_runner_util_unittest.cc

Issue 10382088: Fix a leak following r135955 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Separate tests 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 | « no previous file | tools/heapcheck/suppressions.txt » ('j') | 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
(...skipping 25 matching lines...) Expand all
36 void ExpectFoo(scoped_ptr<Foo> foo) { 36 void ExpectFoo(scoped_ptr<Foo> foo) {
37 EXPECT_TRUE(foo.get()); 37 EXPECT_TRUE(foo.get());
38 scoped_ptr<Foo> local_foo(foo.Pass()); 38 scoped_ptr<Foo> local_foo(foo.Pass());
39 EXPECT_TRUE(local_foo.get()); 39 EXPECT_TRUE(local_foo.get());
40 EXPECT_FALSE(foo.get()); 40 EXPECT_FALSE(foo.get());
41 } 41 }
42 42
43 struct FreeFooFunctor { 43 struct FreeFooFunctor {
44 void operator()(Foo* foo) const { 44 void operator()(Foo* foo) const {
45 ++g_foo_free_count; 45 ++g_foo_free_count;
46 delete foo;
46 }; 47 };
47 }; 48 };
48 49
49 scoped_ptr_malloc<Foo, FreeFooFunctor> CreateScopedFoo() { 50 scoped_ptr_malloc<Foo, FreeFooFunctor> CreateScopedFoo() {
50 return scoped_ptr_malloc<Foo, FreeFooFunctor>(new Foo); 51 return scoped_ptr_malloc<Foo, FreeFooFunctor>(new Foo);
51 } 52 }
52 53
53 void ExpectScopedFoo(scoped_ptr_malloc<Foo, FreeFooFunctor> foo) { 54 void ExpectScopedFoo(scoped_ptr_malloc<Foo, FreeFooFunctor> foo) {
54 EXPECT_TRUE(foo.get()); 55 EXPECT_TRUE(foo.get());
55 scoped_ptr_malloc<Foo, FreeFooFunctor> local_foo(foo.Pass()); 56 scoped_ptr_malloc<Foo, FreeFooFunctor> local_foo(foo.Pass());
(...skipping 27 matching lines...) Expand all
83 PostTaskAndReplyWithResult( 84 PostTaskAndReplyWithResult(
84 message_loop.message_loop_proxy(), 85 message_loop.message_loop_proxy(),
85 FROM_HERE, 86 FROM_HERE,
86 Bind(&CreateFoo), 87 Bind(&CreateFoo),
87 Bind(&ExpectFoo)); 88 Bind(&ExpectFoo));
88 89
89 message_loop.RunAllPending(); 90 message_loop.RunAllPending();
90 91
91 EXPECT_EQ(1, g_foo_destruct_count); 92 EXPECT_EQ(1, g_foo_destruct_count);
92 EXPECT_EQ(0, g_foo_free_count); 93 EXPECT_EQ(0, g_foo_free_count);
94 }
95
96 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassedFreeProc) {
97 g_foo_destruct_count = 0;
98 g_foo_free_count = 0;
99
100 MessageLoop message_loop;
93 101
94 PostTaskAndReplyWithResult( 102 PostTaskAndReplyWithResult(
95 message_loop.message_loop_proxy(), 103 message_loop.message_loop_proxy(),
96 FROM_HERE, 104 FROM_HERE,
97 Bind(&CreateScopedFoo), 105 Bind(&CreateScopedFoo),
98 Bind(&ExpectScopedFoo)); 106 Bind(&ExpectScopedFoo));
99 107
100 message_loop.RunAllPending(); 108 message_loop.RunAllPending();
101 109
102 EXPECT_EQ(1, g_foo_destruct_count); 110 EXPECT_EQ(1, g_foo_destruct_count);
103 EXPECT_EQ(1, g_foo_free_count); 111 EXPECT_EQ(1, g_foo_free_count);
104 } 112 }
105 113
106 } // namespace base 114 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698