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