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

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

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: . Created 4 years, 8 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 <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/memory/free_deleter.h" 10 #include "base/memory/free_deleter.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 void BoundBoolSet(bool* var, bool val) { 17 void BoundBoolSet(bool* var, bool val) {
17 *var = val; 18 *var = val;
18 } 19 }
19 20
20 void BoundBoolSetFromScopedPtr(bool* var, scoped_ptr<bool> val) { 21 void BoundBoolSetFromScopedPtr(bool* var, std::unique_ptr<bool> val) {
21 *var = *val; 22 *var = *val;
22 } 23 }
23 24
24 void BoundBoolSetFromScopedPtrFreeDeleter( 25 void BoundBoolSetFromScopedPtrFreeDeleter(
25 bool* var, 26 bool* var,
26 scoped_ptr<bool, base::FreeDeleter> val) { 27 std::unique_ptr<bool, base::FreeDeleter> val) {
27 *var = *val; 28 *var = *val;
28 } 29 }
29 30
30 void BoundBoolSetFromScopedArray(bool* var, scoped_ptr<bool[]> val) { 31 void BoundBoolSetFromScopedArray(bool* var, std::unique_ptr<bool[]> val) {
31 *var = val[0]; 32 *var = val[0];
32 } 33 }
33 34
34 void BoundBoolSetFromConstRef(bool* var, const bool& val) { 35 void BoundBoolSetFromConstRef(bool* var, const bool& val) {
35 *var = val; 36 *var = val;
36 } 37 }
37 38
38 void BoundIntegersSet(int* a_var, int* b_var, int a_val, int b_val) { 39 void BoundIntegersSet(int* a_var, int* b_var, int a_val, int b_val) {
39 *a_var = a_val; 40 *a_var = a_val;
40 *b_var = b_val; 41 *b_var = b_val;
(...skipping 22 matching lines...) Expand all
63 base::Callback<void(bool)> cb = BindToCurrentLoop(base::Bind( 64 base::Callback<void(bool)> cb = BindToCurrentLoop(base::Bind(
64 &BoundBoolSet, &bool_var)); 65 &BoundBoolSet, &bool_var));
65 cb.Run(true); 66 cb.Run(true);
66 EXPECT_FALSE(bool_var); 67 EXPECT_FALSE(bool_var);
67 loop_.RunUntilIdle(); 68 loop_.RunUntilIdle();
68 EXPECT_TRUE(bool_var); 69 EXPECT_TRUE(bool_var);
69 } 70 }
70 71
71 TEST_F(BindToCurrentLoopTest, BoundScopedPtrBool) { 72 TEST_F(BindToCurrentLoopTest, BoundScopedPtrBool) {
72 bool bool_val = false; 73 bool bool_val = false;
73 scoped_ptr<bool> scoped_ptr_bool(new bool(true)); 74 std::unique_ptr<bool> scoped_ptr_bool(new bool(true));
74 base::Closure cb = BindToCurrentLoop(base::Bind( 75 base::Closure cb = BindToCurrentLoop(base::Bind(
75 &BoundBoolSetFromScopedPtr, &bool_val, base::Passed(&scoped_ptr_bool))); 76 &BoundBoolSetFromScopedPtr, &bool_val, base::Passed(&scoped_ptr_bool)));
76 cb.Run(); 77 cb.Run();
77 EXPECT_FALSE(bool_val); 78 EXPECT_FALSE(bool_val);
78 loop_.RunUntilIdle(); 79 loop_.RunUntilIdle();
79 EXPECT_TRUE(bool_val); 80 EXPECT_TRUE(bool_val);
80 } 81 }
81 82
82 TEST_F(BindToCurrentLoopTest, PassedScopedPtrBool) { 83 TEST_F(BindToCurrentLoopTest, PassedScopedPtrBool) {
83 bool bool_val = false; 84 bool bool_val = false;
84 scoped_ptr<bool> scoped_ptr_bool(new bool(true)); 85 std::unique_ptr<bool> scoped_ptr_bool(new bool(true));
85 base::Callback<void(scoped_ptr<bool>)> cb = BindToCurrentLoop(base::Bind( 86 base::Callback<void(std::unique_ptr<bool>)> cb =
86 &BoundBoolSetFromScopedPtr, &bool_val)); 87 BindToCurrentLoop(base::Bind(&BoundBoolSetFromScopedPtr, &bool_val));
87 cb.Run(std::move(scoped_ptr_bool)); 88 cb.Run(std::move(scoped_ptr_bool));
88 EXPECT_FALSE(bool_val); 89 EXPECT_FALSE(bool_val);
89 loop_.RunUntilIdle(); 90 loop_.RunUntilIdle();
90 EXPECT_TRUE(bool_val); 91 EXPECT_TRUE(bool_val);
91 } 92 }
92 93
93 TEST_F(BindToCurrentLoopTest, BoundScopedArrayBool) { 94 TEST_F(BindToCurrentLoopTest, BoundScopedArrayBool) {
94 bool bool_val = false; 95 bool bool_val = false;
95 scoped_ptr<bool[]> scoped_array_bool(new bool[1]); 96 std::unique_ptr<bool[]> scoped_array_bool(new bool[1]);
96 scoped_array_bool[0] = true; 97 scoped_array_bool[0] = true;
97 base::Closure cb = BindToCurrentLoop(base::Bind( 98 base::Closure cb = BindToCurrentLoop(base::Bind(
98 &BoundBoolSetFromScopedArray, &bool_val, 99 &BoundBoolSetFromScopedArray, &bool_val,
99 base::Passed(&scoped_array_bool))); 100 base::Passed(&scoped_array_bool)));
100 cb.Run(); 101 cb.Run();
101 EXPECT_FALSE(bool_val); 102 EXPECT_FALSE(bool_val);
102 loop_.RunUntilIdle(); 103 loop_.RunUntilIdle();
103 EXPECT_TRUE(bool_val); 104 EXPECT_TRUE(bool_val);
104 } 105 }
105 106
106 TEST_F(BindToCurrentLoopTest, PassedScopedArrayBool) { 107 TEST_F(BindToCurrentLoopTest, PassedScopedArrayBool) {
107 bool bool_val = false; 108 bool bool_val = false;
108 scoped_ptr<bool[]> scoped_array_bool(new bool[1]); 109 std::unique_ptr<bool[]> scoped_array_bool(new bool[1]);
109 scoped_array_bool[0] = true; 110 scoped_array_bool[0] = true;
110 base::Callback<void(scoped_ptr<bool[]>)> cb = BindToCurrentLoop(base::Bind( 111 base::Callback<void(std::unique_ptr<bool[]>)> cb =
111 &BoundBoolSetFromScopedArray, &bool_val)); 112 BindToCurrentLoop(base::Bind(&BoundBoolSetFromScopedArray, &bool_val));
112 cb.Run(std::move(scoped_array_bool)); 113 cb.Run(std::move(scoped_array_bool));
113 EXPECT_FALSE(bool_val); 114 EXPECT_FALSE(bool_val);
114 loop_.RunUntilIdle(); 115 loop_.RunUntilIdle();
115 EXPECT_TRUE(bool_val); 116 EXPECT_TRUE(bool_val);
116 } 117 }
117 118
118 TEST_F(BindToCurrentLoopTest, BoundScopedPtrFreeDeleterBool) { 119 TEST_F(BindToCurrentLoopTest, BoundScopedPtrFreeDeleterBool) {
119 bool bool_val = false; 120 bool bool_val = false;
120 scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool( 121 std::unique_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool(
121 static_cast<bool*>(malloc(sizeof(bool)))); 122 static_cast<bool*>(malloc(sizeof(bool))));
122 *scoped_ptr_free_deleter_bool = true; 123 *scoped_ptr_free_deleter_bool = true;
123 base::Closure cb = BindToCurrentLoop(base::Bind( 124 base::Closure cb = BindToCurrentLoop(base::Bind(
124 &BoundBoolSetFromScopedPtrFreeDeleter, &bool_val, 125 &BoundBoolSetFromScopedPtrFreeDeleter, &bool_val,
125 base::Passed(&scoped_ptr_free_deleter_bool))); 126 base::Passed(&scoped_ptr_free_deleter_bool)));
126 cb.Run(); 127 cb.Run();
127 EXPECT_FALSE(bool_val); 128 EXPECT_FALSE(bool_val);
128 loop_.RunUntilIdle(); 129 loop_.RunUntilIdle();
129 EXPECT_TRUE(bool_val); 130 EXPECT_TRUE(bool_val);
130 } 131 }
131 132
132 TEST_F(BindToCurrentLoopTest, PassedScopedPtrFreeDeleterBool) { 133 TEST_F(BindToCurrentLoopTest, PassedScopedPtrFreeDeleterBool) {
133 bool bool_val = false; 134 bool bool_val = false;
134 scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool( 135 std::unique_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool(
135 static_cast<bool*>(malloc(sizeof(bool)))); 136 static_cast<bool*>(malloc(sizeof(bool))));
136 *scoped_ptr_free_deleter_bool = true; 137 *scoped_ptr_free_deleter_bool = true;
137 base::Callback<void(scoped_ptr<bool, base::FreeDeleter>)> cb = 138 base::Callback<void(std::unique_ptr<bool, base::FreeDeleter>)> cb =
138 BindToCurrentLoop(base::Bind(&BoundBoolSetFromScopedPtrFreeDeleter, 139 BindToCurrentLoop(
139 &bool_val)); 140 base::Bind(&BoundBoolSetFromScopedPtrFreeDeleter, &bool_val));
140 cb.Run(std::move(scoped_ptr_free_deleter_bool)); 141 cb.Run(std::move(scoped_ptr_free_deleter_bool));
141 EXPECT_FALSE(bool_val); 142 EXPECT_FALSE(bool_val);
142 loop_.RunUntilIdle(); 143 loop_.RunUntilIdle();
143 EXPECT_TRUE(bool_val); 144 EXPECT_TRUE(bool_val);
144 } 145 }
145 146
146 TEST_F(BindToCurrentLoopTest, BoolConstRef) { 147 TEST_F(BindToCurrentLoopTest, BoolConstRef) {
147 bool bool_var = false; 148 bool bool_var = false;
148 bool true_var = true; 149 bool true_var = true;
149 const bool& true_ref = true_var; 150 const bool& true_ref = true_var;
(...skipping 12 matching lines...) Expand all
162 &BoundIntegersSet, &a, &b)); 163 &BoundIntegersSet, &a, &b));
163 cb.Run(1, -1); 164 cb.Run(1, -1);
164 EXPECT_EQ(a, 0); 165 EXPECT_EQ(a, 0);
165 EXPECT_EQ(b, 0); 166 EXPECT_EQ(b, 0);
166 loop_.RunUntilIdle(); 167 loop_.RunUntilIdle();
167 EXPECT_EQ(a, 1); 168 EXPECT_EQ(a, 1);
168 EXPECT_EQ(b, -1); 169 EXPECT_EQ(b, -1);
169 } 170 }
170 171
171 } // namespace media 172 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698