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 <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 namespace base { | 14 namespace base { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 int ReturnFourtyTwo() { | 18 int ReturnFourtyTwo() { |
(...skipping 16 matching lines...) Expand all Loading... |
33 ++g_foo_destruct_count; | 35 ++g_foo_destruct_count; |
34 } | 36 } |
35 }; | 37 }; |
36 | 38 |
37 scoped_ptr<Foo> CreateFoo() { | 39 scoped_ptr<Foo> CreateFoo() { |
38 return scoped_ptr<Foo>(new Foo); | 40 return scoped_ptr<Foo>(new Foo); |
39 } | 41 } |
40 | 42 |
41 void ExpectFoo(scoped_ptr<Foo> foo) { | 43 void ExpectFoo(scoped_ptr<Foo> foo) { |
42 EXPECT_TRUE(foo.get()); | 44 EXPECT_TRUE(foo.get()); |
43 scoped_ptr<Foo> local_foo(foo.Pass()); | 45 scoped_ptr<Foo> local_foo(std::move(foo)); |
44 EXPECT_TRUE(local_foo.get()); | 46 EXPECT_TRUE(local_foo.get()); |
45 EXPECT_FALSE(foo.get()); | 47 EXPECT_FALSE(foo.get()); |
46 } | 48 } |
47 | 49 |
48 struct FooDeleter { | 50 struct FooDeleter { |
49 void operator()(Foo* foo) const { | 51 void operator()(Foo* foo) const { |
50 ++g_foo_free_count; | 52 ++g_foo_free_count; |
51 delete foo; | 53 delete foo; |
52 }; | 54 }; |
53 }; | 55 }; |
54 | 56 |
55 scoped_ptr<Foo, FooDeleter> CreateScopedFoo() { | 57 scoped_ptr<Foo, FooDeleter> CreateScopedFoo() { |
56 return scoped_ptr<Foo, FooDeleter>(new Foo); | 58 return scoped_ptr<Foo, FooDeleter>(new Foo); |
57 } | 59 } |
58 | 60 |
59 void ExpectScopedFoo(scoped_ptr<Foo, FooDeleter> foo) { | 61 void ExpectScopedFoo(scoped_ptr<Foo, FooDeleter> foo) { |
60 EXPECT_TRUE(foo.get()); | 62 EXPECT_TRUE(foo.get()); |
61 scoped_ptr<Foo, FooDeleter> local_foo(foo.Pass()); | 63 scoped_ptr<Foo, FooDeleter> local_foo(std::move(foo)); |
62 EXPECT_TRUE(local_foo.get()); | 64 EXPECT_TRUE(local_foo.get()); |
63 EXPECT_FALSE(foo.get()); | 65 EXPECT_FALSE(foo.get()); |
64 } | 66 } |
65 | 67 |
66 } // namespace | 68 } // namespace |
67 | 69 |
68 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) { | 70 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) { |
69 int result = 0; | 71 int result = 0; |
70 | 72 |
71 MessageLoop message_loop; | 73 MessageLoop message_loop; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 PostTaskAndReplyWithResult(message_loop.task_runner().get(), FROM_HERE, | 115 PostTaskAndReplyWithResult(message_loop.task_runner().get(), FROM_HERE, |
114 Bind(&CreateScopedFoo), Bind(&ExpectScopedFoo)); | 116 Bind(&CreateScopedFoo), Bind(&ExpectScopedFoo)); |
115 | 117 |
116 RunLoop().RunUntilIdle(); | 118 RunLoop().RunUntilIdle(); |
117 | 119 |
118 EXPECT_EQ(1, g_foo_destruct_count); | 120 EXPECT_EQ(1, g_foo_destruct_count); |
119 EXPECT_EQ(1, g_foo_free_count); | 121 EXPECT_EQ(1, g_foo_free_count); |
120 } | 122 } |
121 | 123 |
122 } // namespace base | 124 } // namespace base |
OLD | NEW |