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 "media/base/bind_to_loop.h" | 5 #include "media/base/bind_to_loop.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 TEST_F(BindToLoopTest, Bool) { | 52 TEST_F(BindToLoopTest, Bool) { |
53 bool bool_var = false; | 53 bool bool_var = false; |
54 base::Callback<void(bool)> cb = BindToLoop(proxy_, base::Bind( | 54 base::Callback<void(bool)> cb = BindToLoop(proxy_, base::Bind( |
55 &BoundBoolSet, &bool_var)); | 55 &BoundBoolSet, &bool_var)); |
56 cb.Run(true); | 56 cb.Run(true); |
57 EXPECT_FALSE(bool_var); | 57 EXPECT_FALSE(bool_var); |
58 loop_.RunUntilIdle(); | 58 loop_.RunUntilIdle(); |
59 EXPECT_TRUE(bool_var); | 59 EXPECT_TRUE(bool_var); |
60 } | 60 } |
61 | 61 |
62 TEST_F(BindToLoopTest, ScopedPtrBool) { | 62 TEST_F(BindToLoopTest, BoundScopedPtrBool) { |
63 bool bool_val = false; | 63 bool bool_val = false; |
64 scoped_ptr<bool> scoped_ptr_bool(new bool(true)); | 64 scoped_ptr<bool> scoped_ptr_bool(new bool(true)); |
65 base::Closure cb = BindToLoop(proxy_, base::Bind( | 65 base::Closure cb = BindToLoop(proxy_, base::Bind( |
66 &BoundBoolSetFromScopedPtr, &bool_val, base::Passed(&scoped_ptr_bool))); | 66 &BoundBoolSetFromScopedPtr, &bool_val, base::Passed(&scoped_ptr_bool))); |
67 cb.Run(); | 67 cb.Run(); |
68 EXPECT_FALSE(bool_val); | 68 EXPECT_FALSE(bool_val); |
69 loop_.RunUntilIdle(); | 69 loop_.RunUntilIdle(); |
70 EXPECT_TRUE(bool_val); | 70 EXPECT_TRUE(bool_val); |
71 } | 71 } |
72 | 72 |
| 73 TEST_F(BindToLoopTest, PassedScopedPtrBool) { |
| 74 bool bool_val = false; |
| 75 scoped_ptr<bool> scoped_ptr_bool(new bool(true)); |
| 76 base::Callback<void(scoped_ptr<bool>)> cb = BindToLoop(proxy_, base::Bind( |
| 77 &BoundBoolSetFromScopedPtr, &bool_val)); |
| 78 cb.Run(scoped_ptr_bool.Pass()); |
| 79 EXPECT_FALSE(bool_val); |
| 80 loop_.RunUntilIdle(); |
| 81 EXPECT_TRUE(bool_val); |
| 82 } |
| 83 |
73 TEST_F(BindToLoopTest, BoolConstRef) { | 84 TEST_F(BindToLoopTest, BoolConstRef) { |
74 bool bool_var = false; | 85 bool bool_var = false; |
75 bool true_var = true; | 86 bool true_var = true; |
76 const bool& true_ref = true_var; | 87 const bool& true_ref = true_var; |
77 base::Closure cb = BindToLoop(proxy_, base::Bind( | 88 base::Closure cb = BindToLoop(proxy_, base::Bind( |
78 &BoundBoolSetFromConstRef, &bool_var, true_ref)); | 89 &BoundBoolSetFromConstRef, &bool_var, true_ref)); |
79 cb.Run(); | 90 cb.Run(); |
80 EXPECT_FALSE(bool_var); | 91 EXPECT_FALSE(bool_var); |
81 loop_.RunUntilIdle(); | 92 loop_.RunUntilIdle(); |
82 EXPECT_TRUE(bool_var); | 93 EXPECT_TRUE(bool_var); |
83 } | 94 } |
84 | 95 |
85 TEST_F(BindToLoopTest, Integers) { | 96 TEST_F(BindToLoopTest, Integers) { |
86 int a = 0; | 97 int a = 0; |
87 int b = 0; | 98 int b = 0; |
88 base::Callback<void(int, int)> cb = BindToLoop(proxy_, base::Bind( | 99 base::Callback<void(int, int)> cb = BindToLoop(proxy_, base::Bind( |
89 &BoundIntegersSet, &a, &b)); | 100 &BoundIntegersSet, &a, &b)); |
90 cb.Run(1, -1); | 101 cb.Run(1, -1); |
91 EXPECT_EQ(a, 0); | 102 EXPECT_EQ(a, 0); |
92 EXPECT_EQ(b, 0); | 103 EXPECT_EQ(b, 0); |
93 loop_.RunUntilIdle(); | 104 loop_.RunUntilIdle(); |
94 EXPECT_EQ(a, 1); | 105 EXPECT_EQ(a, 1); |
95 EXPECT_EQ(b, -1); | 106 EXPECT_EQ(b, -1); |
96 } | 107 } |
97 | 108 |
98 } // namespace media | 109 } // namespace media |
OLD | NEW |