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.h" | 8 #include "base/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 51 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.message_loop_proxy(), | 72 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
73 FROM_HERE, | 73 FROM_HERE, |
74 Bind(&ReturnFourtyTwo), | 74 Bind(&ReturnFourtyTwo), |
75 Bind(&StoreValue, &result)); | 75 Bind(&StoreValue, &result)); |
76 | 76 |
77 RunLoop().RunUntilIdle(); | 77 RunLoop().RunUntilIdle(); |
78 | 78 |
79 EXPECT_EQ(42, result); | 79 EXPECT_EQ(42, result); |
80 } | 80 } |
81 | 81 |
82 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultImplicitConvert) { | 82 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultImplicitConvert) { |
83 double result = 0; | 83 double result = 0; |
84 | 84 |
85 MessageLoop message_loop; | 85 MessageLoop message_loop; |
86 PostTaskAndReplyWithResult(message_loop.message_loop_proxy(), | 86 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
87 FROM_HERE, | 87 FROM_HERE, |
88 Bind(&ReturnFourtyTwo), | 88 Bind(&ReturnFourtyTwo), |
89 Bind(&StoreDoubleValue, &result)); | 89 Bind(&StoreDoubleValue, &result)); |
90 | 90 |
91 RunLoop().RunUntilIdle(); | 91 RunLoop().RunUntilIdle(); |
92 | 92 |
93 EXPECT_DOUBLE_EQ(42.0, result); | 93 EXPECT_DOUBLE_EQ(42.0, result); |
94 } | 94 } |
95 | 95 |
96 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { | 96 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { |
97 g_foo_destruct_count = 0; | 97 g_foo_destruct_count = 0; |
98 g_foo_free_count = 0; | 98 g_foo_free_count = 0; |
99 | 99 |
100 MessageLoop message_loop; | 100 MessageLoop message_loop; |
101 PostTaskAndReplyWithResult(message_loop.message_loop_proxy(), | 101 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
102 FROM_HERE, | 102 FROM_HERE, |
103 Bind(&CreateFoo), | 103 Bind(&CreateFoo), |
104 Bind(&ExpectFoo)); | 104 Bind(&ExpectFoo)); |
105 | 105 |
106 RunLoop().RunUntilIdle(); | 106 RunLoop().RunUntilIdle(); |
107 | 107 |
108 EXPECT_EQ(1, g_foo_destruct_count); | 108 EXPECT_EQ(1, g_foo_destruct_count); |
109 EXPECT_EQ(0, g_foo_free_count); | 109 EXPECT_EQ(0, g_foo_free_count); |
110 } | 110 } |
111 | 111 |
112 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassedFreeProc) { | 112 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassedFreeProc) { |
113 g_foo_destruct_count = 0; | 113 g_foo_destruct_count = 0; |
114 g_foo_free_count = 0; | 114 g_foo_free_count = 0; |
115 | 115 |
116 MessageLoop message_loop; | 116 MessageLoop message_loop; |
117 PostTaskAndReplyWithResult(message_loop.message_loop_proxy(), | 117 PostTaskAndReplyWithResult(message_loop.message_loop_proxy().get(), |
118 FROM_HERE, | 118 FROM_HERE, |
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 |