OLD | NEW |
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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 return scoped_ptr<Foo>(new Foo); | 38 return scoped_ptr<Foo>(new Foo); |
39 } | 39 } |
40 | 40 |
41 void ExpectFoo(scoped_ptr<Foo> foo) { | 41 void ExpectFoo(scoped_ptr<Foo> foo) { |
42 EXPECT_TRUE(foo.get()); | 42 EXPECT_TRUE(foo.get()); |
43 scoped_ptr<Foo> local_foo(foo.Pass()); | 43 scoped_ptr<Foo> local_foo(foo.Pass()); |
44 EXPECT_TRUE(local_foo.get()); | 44 EXPECT_TRUE(local_foo.get()); |
45 EXPECT_FALSE(foo.get()); | 45 EXPECT_FALSE(foo.get()); |
46 } | 46 } |
47 | 47 |
48 struct FreeFooFunctor { | 48 struct FooDeleter { |
49 void operator()(Foo* foo) const { | 49 void operator()(Foo* foo) const { |
50 ++g_foo_free_count; | 50 ++g_foo_free_count; |
51 delete foo; | 51 delete foo; |
52 }; | 52 }; |
53 }; | 53 }; |
54 | 54 |
55 scoped_ptr_malloc<Foo, FreeFooFunctor> CreateScopedFoo() { | 55 scoped_ptr<Foo, FooDeleter> CreateScopedFoo() { |
56 return scoped_ptr_malloc<Foo, FreeFooFunctor>(new Foo); | 56 return scoped_ptr<Foo, FooDeleter>(new Foo); |
57 } | 57 } |
58 | 58 |
59 void ExpectScopedFoo(scoped_ptr_malloc<Foo, FreeFooFunctor> foo) { | 59 void ExpectScopedFoo(scoped_ptr<Foo, FooDeleter> foo) { |
60 EXPECT_TRUE(foo.get()); | 60 EXPECT_TRUE(foo.get()); |
61 scoped_ptr_malloc<Foo, FreeFooFunctor> local_foo(foo.Pass()); | 61 scoped_ptr<Foo, FooDeleter> local_foo(foo.Pass()); |
62 EXPECT_TRUE(local_foo.get()); | 62 EXPECT_TRUE(local_foo.get()); |
63 EXPECT_FALSE(foo.get()); | 63 EXPECT_FALSE(foo.get()); |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) { | 68 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) { |
69 int result = 0; | 69 int result = 0; |
70 | 70 |
71 MessageLoop message_loop; | 71 MessageLoop message_loop; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 Bind(&CreateScopedFoo), | 119 Bind(&CreateScopedFoo), |
120 Bind(&ExpectScopedFoo)); | 120 Bind(&ExpectScopedFoo)); |
121 | 121 |
122 RunLoop().RunUntilIdle(); | 122 RunLoop().RunUntilIdle(); |
123 | 123 |
124 EXPECT_EQ(1, g_foo_destruct_count); | 124 EXPECT_EQ(1, g_foo_destruct_count); |
125 EXPECT_EQ(1, g_foo_free_count); | 125 EXPECT_EQ(1, g_foo_free_count); |
126 } | 126 } |
127 | 127 |
128 } // namespace base | 128 } // namespace base |
OLD | NEW |