Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: media/base/bind_to_current_loop_unittest.cc

Issue 1544313002: Convert Pass()→std::move() in //media (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_current_loop.h" 5 #include "media/base/bind_to_current_loop.h"
6 6
7 #include <utility>
8
7 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
8 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace media { 13 namespace media {
12 14
13 void BoundBoolSet(bool* var, bool val) { 15 void BoundBoolSet(bool* var, bool val) {
14 *var = val; 16 *var = val;
15 } 17 }
16 18
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 EXPECT_FALSE(bool_val); 76 EXPECT_FALSE(bool_val);
75 loop_.RunUntilIdle(); 77 loop_.RunUntilIdle();
76 EXPECT_TRUE(bool_val); 78 EXPECT_TRUE(bool_val);
77 } 79 }
78 80
79 TEST_F(BindToCurrentLoopTest, PassedScopedPtrBool) { 81 TEST_F(BindToCurrentLoopTest, PassedScopedPtrBool) {
80 bool bool_val = false; 82 bool bool_val = false;
81 scoped_ptr<bool> scoped_ptr_bool(new bool(true)); 83 scoped_ptr<bool> scoped_ptr_bool(new bool(true));
82 base::Callback<void(scoped_ptr<bool>)> cb = BindToCurrentLoop(base::Bind( 84 base::Callback<void(scoped_ptr<bool>)> cb = BindToCurrentLoop(base::Bind(
83 &BoundBoolSetFromScopedPtr, &bool_val)); 85 &BoundBoolSetFromScopedPtr, &bool_val));
84 cb.Run(scoped_ptr_bool.Pass()); 86 cb.Run(std::move(scoped_ptr_bool));
85 EXPECT_FALSE(bool_val); 87 EXPECT_FALSE(bool_val);
86 loop_.RunUntilIdle(); 88 loop_.RunUntilIdle();
87 EXPECT_TRUE(bool_val); 89 EXPECT_TRUE(bool_val);
88 } 90 }
89 91
90 TEST_F(BindToCurrentLoopTest, BoundScopedArrayBool) { 92 TEST_F(BindToCurrentLoopTest, BoundScopedArrayBool) {
91 bool bool_val = false; 93 bool bool_val = false;
92 scoped_ptr<bool[]> scoped_array_bool(new bool[1]); 94 scoped_ptr<bool[]> scoped_array_bool(new bool[1]);
93 scoped_array_bool[0] = true; 95 scoped_array_bool[0] = true;
94 base::Closure cb = BindToCurrentLoop(base::Bind( 96 base::Closure cb = BindToCurrentLoop(base::Bind(
95 &BoundBoolSetFromScopedArray, &bool_val, 97 &BoundBoolSetFromScopedArray, &bool_val,
96 base::Passed(&scoped_array_bool))); 98 base::Passed(&scoped_array_bool)));
97 cb.Run(); 99 cb.Run();
98 EXPECT_FALSE(bool_val); 100 EXPECT_FALSE(bool_val);
99 loop_.RunUntilIdle(); 101 loop_.RunUntilIdle();
100 EXPECT_TRUE(bool_val); 102 EXPECT_TRUE(bool_val);
101 } 103 }
102 104
103 TEST_F(BindToCurrentLoopTest, PassedScopedArrayBool) { 105 TEST_F(BindToCurrentLoopTest, PassedScopedArrayBool) {
104 bool bool_val = false; 106 bool bool_val = false;
105 scoped_ptr<bool[]> scoped_array_bool(new bool[1]); 107 scoped_ptr<bool[]> scoped_array_bool(new bool[1]);
106 scoped_array_bool[0] = true; 108 scoped_array_bool[0] = true;
107 base::Callback<void(scoped_ptr<bool[]>)> cb = BindToCurrentLoop(base::Bind( 109 base::Callback<void(scoped_ptr<bool[]>)> cb = BindToCurrentLoop(base::Bind(
108 &BoundBoolSetFromScopedArray, &bool_val)); 110 &BoundBoolSetFromScopedArray, &bool_val));
109 cb.Run(scoped_array_bool.Pass()); 111 cb.Run(std::move(scoped_array_bool));
110 EXPECT_FALSE(bool_val); 112 EXPECT_FALSE(bool_val);
111 loop_.RunUntilIdle(); 113 loop_.RunUntilIdle();
112 EXPECT_TRUE(bool_val); 114 EXPECT_TRUE(bool_val);
113 } 115 }
114 116
115 TEST_F(BindToCurrentLoopTest, BoundScopedPtrFreeDeleterBool) { 117 TEST_F(BindToCurrentLoopTest, BoundScopedPtrFreeDeleterBool) {
116 bool bool_val = false; 118 bool bool_val = false;
117 scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool( 119 scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool(
118 static_cast<bool*>(malloc(sizeof(bool)))); 120 static_cast<bool*>(malloc(sizeof(bool))));
119 *scoped_ptr_free_deleter_bool = true; 121 *scoped_ptr_free_deleter_bool = true;
120 base::Closure cb = BindToCurrentLoop(base::Bind( 122 base::Closure cb = BindToCurrentLoop(base::Bind(
121 &BoundBoolSetFromScopedPtrFreeDeleter, &bool_val, 123 &BoundBoolSetFromScopedPtrFreeDeleter, &bool_val,
122 base::Passed(&scoped_ptr_free_deleter_bool))); 124 base::Passed(&scoped_ptr_free_deleter_bool)));
123 cb.Run(); 125 cb.Run();
124 EXPECT_FALSE(bool_val); 126 EXPECT_FALSE(bool_val);
125 loop_.RunUntilIdle(); 127 loop_.RunUntilIdle();
126 EXPECT_TRUE(bool_val); 128 EXPECT_TRUE(bool_val);
127 } 129 }
128 130
129 TEST_F(BindToCurrentLoopTest, PassedScopedPtrFreeDeleterBool) { 131 TEST_F(BindToCurrentLoopTest, PassedScopedPtrFreeDeleterBool) {
130 bool bool_val = false; 132 bool bool_val = false;
131 scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool( 133 scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool(
132 static_cast<bool*>(malloc(sizeof(bool)))); 134 static_cast<bool*>(malloc(sizeof(bool))));
133 *scoped_ptr_free_deleter_bool = true; 135 *scoped_ptr_free_deleter_bool = true;
134 base::Callback<void(scoped_ptr<bool, base::FreeDeleter>)> cb = 136 base::Callback<void(scoped_ptr<bool, base::FreeDeleter>)> cb =
135 BindToCurrentLoop(base::Bind(&BoundBoolSetFromScopedPtrFreeDeleter, 137 BindToCurrentLoop(base::Bind(&BoundBoolSetFromScopedPtrFreeDeleter,
136 &bool_val)); 138 &bool_val));
137 cb.Run(scoped_ptr_free_deleter_bool.Pass()); 139 cb.Run(std::move(scoped_ptr_free_deleter_bool));
138 EXPECT_FALSE(bool_val); 140 EXPECT_FALSE(bool_val);
139 loop_.RunUntilIdle(); 141 loop_.RunUntilIdle();
140 EXPECT_TRUE(bool_val); 142 EXPECT_TRUE(bool_val);
141 } 143 }
142 144
143 TEST_F(BindToCurrentLoopTest, BoolConstRef) { 145 TEST_F(BindToCurrentLoopTest, BoolConstRef) {
144 bool bool_var = false; 146 bool bool_var = false;
145 bool true_var = true; 147 bool true_var = true;
146 const bool& true_ref = true_var; 148 const bool& true_ref = true_var;
147 base::Closure cb = BindToCurrentLoop(base::Bind( 149 base::Closure cb = BindToCurrentLoop(base::Bind(
(...skipping 11 matching lines...) Expand all
159 &BoundIntegersSet, &a, &b)); 161 &BoundIntegersSet, &a, &b));
160 cb.Run(1, -1); 162 cb.Run(1, -1);
161 EXPECT_EQ(a, 0); 163 EXPECT_EQ(a, 0);
162 EXPECT_EQ(b, 0); 164 EXPECT_EQ(b, 0);
163 loop_.RunUntilIdle(); 165 loop_.RunUntilIdle();
164 EXPECT_EQ(a, 1); 166 EXPECT_EQ(a, 1);
165 EXPECT_EQ(b, -1); 167 EXPECT_EQ(b, -1);
166 } 168 }
167 169
168 } // namespace media 170 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_video_metadata_extractor_unittest.cc ('k') | media/base/cdm_promise_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698