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

Side by Side Diff: chromecast/base/bind_to_task_runner_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698