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

Side by Side Diff: webrtc/modules/utility/source/process_thread_impl_unittest.cc

Issue 1785173002: Replace scoped_ptr with unique_ptr in webrtc/modules/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@up8
Patch Set: Created 4 years, 9 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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory>
11 #include <utility> 12 #include <utility>
12 13
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/modules/include/module.h" 16 #include "webrtc/modules/include/module.h"
16 #include "webrtc/modules/utility/source/process_thread_impl.h" 17 #include "webrtc/modules/utility/source/process_thread_impl.h"
17 #include "webrtc/system_wrappers/include/tick_util.h" 18 #include "webrtc/system_wrappers/include/tick_util.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 thread.Start(); 66 thread.Start();
66 thread.Stop(); 67 thread.Stop();
67 } 68 }
68 } 69 }
69 70
70 // Verifies that we get at least call back to Process() on the worker thread. 71 // Verifies that we get at least call back to Process() on the worker thread.
71 TEST(ProcessThreadImpl, ProcessCall) { 72 TEST(ProcessThreadImpl, ProcessCall) {
72 ProcessThreadImpl thread("ProcessThread"); 73 ProcessThreadImpl thread("ProcessThread");
73 thread.Start(); 74 thread.Start();
74 75
75 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 76 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
76 77
77 MockModule module; 78 MockModule module;
78 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 79 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
79 EXPECT_CALL(module, Process()) 80 EXPECT_CALL(module, Process())
80 .WillOnce(DoAll(SetEvent(event.get()), Return())) 81 .WillOnce(DoAll(SetEvent(event.get()), Return()))
81 .WillRepeatedly(Return()); 82 .WillRepeatedly(Return());
82 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 83 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
83 84
84 thread.RegisterModule(&module); 85 thread.RegisterModule(&module);
85 EXPECT_EQ(kEventSignaled, event->Wait(100)); 86 EXPECT_EQ(kEventSignaled, event->Wait(100));
86 87
87 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 88 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
88 thread.Stop(); 89 thread.Stop();
89 } 90 }
90 91
91 // Same as ProcessCall except the module is registered before the 92 // Same as ProcessCall except the module is registered before the
92 // call to Start(). 93 // call to Start().
93 TEST(ProcessThreadImpl, ProcessCall2) { 94 TEST(ProcessThreadImpl, ProcessCall2) {
94 ProcessThreadImpl thread("ProcessThread"); 95 ProcessThreadImpl thread("ProcessThread");
95 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 96 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
96 97
97 MockModule module; 98 MockModule module;
98 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 99 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
99 EXPECT_CALL(module, Process()) 100 EXPECT_CALL(module, Process())
100 .WillOnce(DoAll(SetEvent(event.get()), Return())) 101 .WillOnce(DoAll(SetEvent(event.get()), Return()))
101 .WillRepeatedly(Return()); 102 .WillRepeatedly(Return());
102 103
103 thread.RegisterModule(&module); 104 thread.RegisterModule(&module);
104 105
105 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 106 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
106 thread.Start(); 107 thread.Start();
107 EXPECT_EQ(kEventSignaled, event->Wait(100)); 108 EXPECT_EQ(kEventSignaled, event->Wait(100));
108 109
109 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 110 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
110 thread.Stop(); 111 thread.Stop();
111 } 112 }
112 113
113 // Tests setting up a module for callbacks and then unregister that module. 114 // Tests setting up a module for callbacks and then unregister that module.
114 // After unregistration, we should not receive any further callbacks. 115 // After unregistration, we should not receive any further callbacks.
115 TEST(ProcessThreadImpl, Deregister) { 116 TEST(ProcessThreadImpl, Deregister) {
116 ProcessThreadImpl thread("ProcessThread"); 117 ProcessThreadImpl thread("ProcessThread");
117 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 118 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
118 119
119 int process_count = 0; 120 int process_count = 0;
120 MockModule module; 121 MockModule module;
121 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 122 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
122 EXPECT_CALL(module, Process()) 123 EXPECT_CALL(module, Process())
123 .WillOnce(DoAll(SetEvent(event.get()), 124 .WillOnce(DoAll(SetEvent(event.get()),
124 Increment(&process_count), 125 Increment(&process_count),
125 Return())) 126 Return()))
126 .WillRepeatedly(DoAll(Increment(&process_count), Return())); 127 .WillRepeatedly(DoAll(Increment(&process_count), Return()));
127 128
(...skipping 16 matching lines...) Expand all
144 thread.Stop(); 145 thread.Stop();
145 } 146 }
146 147
147 // Helper function for testing receiving a callback after a certain amount of 148 // Helper function for testing receiving a callback after a certain amount of
148 // time. There's some variance of timing built into it to reduce chance of 149 // time. There's some variance of timing built into it to reduce chance of
149 // flakiness on bots. 150 // flakiness on bots.
150 void ProcessCallAfterAFewMs(int64_t milliseconds) { 151 void ProcessCallAfterAFewMs(int64_t milliseconds) {
151 ProcessThreadImpl thread("ProcessThread"); 152 ProcessThreadImpl thread("ProcessThread");
152 thread.Start(); 153 thread.Start();
153 154
154 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 155 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
155 156
156 MockModule module; 157 MockModule module;
157 int64_t start_time = 0; 158 int64_t start_time = 0;
158 int64_t called_time = 0; 159 int64_t called_time = 0;
159 EXPECT_CALL(module, TimeUntilNextProcess()) 160 EXPECT_CALL(module, TimeUntilNextProcess())
160 .WillOnce(DoAll(SetTimestamp(&start_time), 161 .WillOnce(DoAll(SetTimestamp(&start_time),
161 Return(milliseconds))) 162 Return(milliseconds)))
162 .WillRepeatedly(Return(milliseconds)); 163 .WillRepeatedly(Return(milliseconds));
163 EXPECT_CALL(module, Process()) 164 EXPECT_CALL(module, Process())
164 .WillOnce(DoAll(SetTimestamp(&called_time), 165 .WillOnce(DoAll(SetTimestamp(&called_time),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // (on average 1 callback every 20ms). On real hardware, we're usually pretty 210 // (on average 1 callback every 20ms). On real hardware, we're usually pretty
210 // close to that, but the test bots that run on virtual machines, will 211 // close to that, but the test bots that run on virtual machines, will
211 // typically be in the range 30-40 callbacks. 212 // typically be in the range 30-40 callbacks.
212 // DISABLED for now since this can take up to 2 seconds to run on the slowest 213 // DISABLED for now since this can take up to 2 seconds to run on the slowest
213 // build bots. 214 // build bots.
214 // TODO(tommi): Fix. 215 // TODO(tommi): Fix.
215 TEST(ProcessThreadImpl, DISABLED_Process50Times) { 216 TEST(ProcessThreadImpl, DISABLED_Process50Times) {
216 ProcessThreadImpl thread("ProcessThread"); 217 ProcessThreadImpl thread("ProcessThread");
217 thread.Start(); 218 thread.Start();
218 219
219 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 220 std::unique_ptr<EventWrapper> event(EventWrapper::Create());
220 221
221 MockModule module; 222 MockModule module;
222 int callback_count = 0; 223 int callback_count = 0;
223 // Ask for a callback after 20ms. 224 // Ask for a callback after 20ms.
224 EXPECT_CALL(module, TimeUntilNextProcess()) 225 EXPECT_CALL(module, TimeUntilNextProcess())
225 .WillRepeatedly(Return(20)); 226 .WillRepeatedly(Return(20));
226 EXPECT_CALL(module, Process()) 227 EXPECT_CALL(module, Process())
227 .WillRepeatedly(DoAll(Increment(&callback_count), 228 .WillRepeatedly(DoAll(Increment(&callback_count),
228 Return())); 229 Return()));
229 230
(...skipping 12 matching lines...) Expand all
242 EXPECT_GE(callback_count, 25); 243 EXPECT_GE(callback_count, 25);
243 EXPECT_LE(callback_count, 50); 244 EXPECT_LE(callback_count, 50);
244 } 245 }
245 246
246 // Tests that we can wake up the worker thread to give us a callback right 247 // Tests that we can wake up the worker thread to give us a callback right
247 // away when we know the thread is sleeping. 248 // away when we know the thread is sleeping.
248 TEST(ProcessThreadImpl, WakeUp) { 249 TEST(ProcessThreadImpl, WakeUp) {
249 ProcessThreadImpl thread("ProcessThread"); 250 ProcessThreadImpl thread("ProcessThread");
250 thread.Start(); 251 thread.Start();
251 252
252 rtc::scoped_ptr<EventWrapper> started(EventWrapper::Create()); 253 std::unique_ptr<EventWrapper> started(EventWrapper::Create());
253 rtc::scoped_ptr<EventWrapper> called(EventWrapper::Create()); 254 std::unique_ptr<EventWrapper> called(EventWrapper::Create());
254 255
255 MockModule module; 256 MockModule module;
256 int64_t start_time; 257 int64_t start_time;
257 int64_t called_time; 258 int64_t called_time;
258 259
259 // Ask for a callback after 1000ms. 260 // Ask for a callback after 1000ms.
260 // TimeUntilNextProcess will be called twice. 261 // TimeUntilNextProcess will be called twice.
261 // The first time we use it to get the thread into a waiting state. 262 // The first time we use it to get the thread into a waiting state.
262 // Then we wake the thread and there should not be another call made to 263 // Then we wake the thread and there should not be another call made to
263 // TimeUntilNextProcess before Process() is called. 264 // TimeUntilNextProcess before Process() is called.
(...skipping 22 matching lines...) Expand all
286 EXPECT_GE(called_time, start_time); 287 EXPECT_GE(called_time, start_time);
287 uint32_t diff = called_time - start_time; 288 uint32_t diff = called_time - start_time;
288 // We should have been called back much quicker than 1sec. 289 // We should have been called back much quicker than 1sec.
289 EXPECT_LE(diff, 100u); 290 EXPECT_LE(diff, 100u);
290 } 291 }
291 292
292 // Tests that we can post a task that gets run straight away on the worker 293 // Tests that we can post a task that gets run straight away on the worker
293 // thread. 294 // thread.
294 TEST(ProcessThreadImpl, PostTask) { 295 TEST(ProcessThreadImpl, PostTask) {
295 ProcessThreadImpl thread("ProcessThread"); 296 ProcessThreadImpl thread("ProcessThread");
296 rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create()); 297 std::unique_ptr<EventWrapper> task_ran(EventWrapper::Create());
297 rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); 298 std::unique_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get()));
298 thread.Start(); 299 thread.Start();
299 thread.PostTask(std::move(task)); 300 thread.PostTask(rtc::UniqueToScoped(std::move(task)));
300 EXPECT_EQ(kEventSignaled, task_ran->Wait(100)); 301 EXPECT_EQ(kEventSignaled, task_ran->Wait(100));
301 thread.Stop(); 302 thread.Stop();
302 } 303 }
303 304
304 } // namespace webrtc 305 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698