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/location.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" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 int ReturnFourtyTwo() { | 16 int ReturnFourtyTwo() { |
17 return 42; | 17 return 42; |
18 } | 18 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
72 PostTaskAndReplyWithResult(message_loop.task_runner().get(), FROM_HERE, | 72 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
| 73 FROM_HERE, |
73 Bind(&ReturnFourtyTwo), | 74 Bind(&ReturnFourtyTwo), |
74 Bind(&StoreValue, &result)); | 75 Bind(&StoreValue, &result)); |
75 | 76 |
76 RunLoop().RunUntilIdle(); | 77 RunLoop().RunUntilIdle(); |
77 | 78 |
78 EXPECT_EQ(42, result); | 79 EXPECT_EQ(42, result); |
79 } | 80 } |
80 | 81 |
81 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultImplicitConvert) { | 82 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultImplicitConvert) { |
82 double result = 0; | 83 double result = 0; |
83 | 84 |
84 MessageLoop message_loop; | 85 MessageLoop message_loop; |
85 PostTaskAndReplyWithResult(message_loop.task_runner().get(), FROM_HERE, | 86 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
| 87 FROM_HERE, |
86 Bind(&ReturnFourtyTwo), | 88 Bind(&ReturnFourtyTwo), |
87 Bind(&StoreDoubleValue, &result)); | 89 Bind(&StoreDoubleValue, &result)); |
88 | 90 |
89 RunLoop().RunUntilIdle(); | 91 RunLoop().RunUntilIdle(); |
90 | 92 |
91 EXPECT_DOUBLE_EQ(42.0, result); | 93 EXPECT_DOUBLE_EQ(42.0, result); |
92 } | 94 } |
93 | 95 |
94 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { | 96 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { |
95 g_foo_destruct_count = 0; | 97 g_foo_destruct_count = 0; |
96 g_foo_free_count = 0; | 98 g_foo_free_count = 0; |
97 | 99 |
98 MessageLoop message_loop; | 100 MessageLoop message_loop; |
99 PostTaskAndReplyWithResult(message_loop.task_runner().get(), FROM_HERE, | 101 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
100 Bind(&CreateFoo), Bind(&ExpectFoo)); | 102 FROM_HERE, |
| 103 Bind(&CreateFoo), |
| 104 Bind(&ExpectFoo)); |
101 | 105 |
102 RunLoop().RunUntilIdle(); | 106 RunLoop().RunUntilIdle(); |
103 | 107 |
104 EXPECT_EQ(1, g_foo_destruct_count); | 108 EXPECT_EQ(1, g_foo_destruct_count); |
105 EXPECT_EQ(0, g_foo_free_count); | 109 EXPECT_EQ(0, g_foo_free_count); |
106 } | 110 } |
107 | 111 |
108 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassedFreeProc) { | 112 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassedFreeProc) { |
109 g_foo_destruct_count = 0; | 113 g_foo_destruct_count = 0; |
110 g_foo_free_count = 0; | 114 g_foo_free_count = 0; |
111 | 115 |
112 MessageLoop message_loop; | 116 MessageLoop message_loop; |
113 PostTaskAndReplyWithResult(message_loop.task_runner().get(), FROM_HERE, | 117 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
114 Bind(&CreateScopedFoo), Bind(&ExpectScopedFoo)); | 118 FROM_HERE, |
| 119 Bind(&CreateScopedFoo), |
| 120 Bind(&ExpectScopedFoo)); |
115 | 121 |
116 RunLoop().RunUntilIdle(); | 122 RunLoop().RunUntilIdle(); |
117 | 123 |
118 EXPECT_EQ(1, g_foo_destruct_count); | 124 EXPECT_EQ(1, g_foo_destruct_count); |
119 EXPECT_EQ(1, g_foo_free_count); | 125 EXPECT_EQ(1, g_foo_free_count); |
120 } | 126 } |
121 | 127 |
122 } // namespace base | 128 } // namespace base |
OLD | NEW |