| 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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 int ReturnFourtyTwo() { | 15 int ReturnFourtyTwo() { |
| 16 return 42; | 16 return 42; |
| 17 } | 17 } |
| 18 | 18 |
| 19 void StoreValue(int* destination, int value) { | 19 void StoreValue(int* destination, int value) { |
| 20 *destination = value; | 20 *destination = value; |
| 21 } | 21 } |
| 22 | 22 |
| 23 void StoreDoubleValue(double* destination, double value) { |
| 24 *destination = value; |
| 25 } |
| 26 |
| 23 int g_foo_destruct_count = 0; | 27 int g_foo_destruct_count = 0; |
| 24 int g_foo_free_count = 0; | 28 int g_foo_free_count = 0; |
| 25 | 29 |
| 26 struct Foo { | 30 struct Foo { |
| 27 ~Foo() { | 31 ~Foo() { |
| 28 ++g_foo_destruct_count; | 32 ++g_foo_destruct_count; |
| 29 } | 33 } |
| 30 }; | 34 }; |
| 31 | 35 |
| 32 scoped_ptr<Foo> CreateFoo() { | 36 scoped_ptr<Foo> CreateFoo() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 message_loop.message_loop_proxy(), | 72 message_loop.message_loop_proxy(), |
| 69 FROM_HERE, | 73 FROM_HERE, |
| 70 Bind(&ReturnFourtyTwo), | 74 Bind(&ReturnFourtyTwo), |
| 71 Bind(&StoreValue, &result)); | 75 Bind(&StoreValue, &result)); |
| 72 | 76 |
| 73 message_loop.RunUntilIdle(); | 77 message_loop.RunUntilIdle(); |
| 74 | 78 |
| 75 EXPECT_EQ(42, result); | 79 EXPECT_EQ(42, result); |
| 76 } | 80 } |
| 77 | 81 |
| 82 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultImplicitConvert) { |
| 83 MessageLoop message_loop; |
| 84 double result = 0; |
| 85 |
| 86 PostTaskAndReplyWithResult( |
| 87 message_loop.message_loop_proxy(), |
| 88 FROM_HERE, |
| 89 Bind(&ReturnFourtyTwo), |
| 90 Bind(&StoreDoubleValue, &result)); |
| 91 |
| 92 message_loop.RunUntilIdle(); |
| 93 |
| 94 EXPECT_DOUBLE_EQ(42.0, result); |
| 95 } |
| 96 |
| 78 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { | 97 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { |
| 79 g_foo_destruct_count = 0; | 98 g_foo_destruct_count = 0; |
| 80 g_foo_free_count = 0; | 99 g_foo_free_count = 0; |
| 81 | 100 |
| 82 MessageLoop message_loop; | 101 MessageLoop message_loop; |
| 83 | 102 |
| 84 PostTaskAndReplyWithResult( | 103 PostTaskAndReplyWithResult( |
| 85 message_loop.message_loop_proxy(), | 104 message_loop.message_loop_proxy(), |
| 86 FROM_HERE, | 105 FROM_HERE, |
| 87 Bind(&CreateFoo), | 106 Bind(&CreateFoo), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 105 Bind(&CreateScopedFoo), | 124 Bind(&CreateScopedFoo), |
| 106 Bind(&ExpectScopedFoo)); | 125 Bind(&ExpectScopedFoo)); |
| 107 | 126 |
| 108 message_loop.RunUntilIdle(); | 127 message_loop.RunUntilIdle(); |
| 109 | 128 |
| 110 EXPECT_EQ(1, g_foo_destruct_count); | 129 EXPECT_EQ(1, g_foo_destruct_count); |
| 111 EXPECT_EQ(1, g_foo_free_count); | 130 EXPECT_EQ(1, g_foo_free_count); |
| 112 } | 131 } |
| 113 | 132 |
| 114 } // namespace base | 133 } // namespace base |
| OLD | NEW |