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

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

Issue 1703833002: Remove ignored return code from modules. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase 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
(...skipping 10 matching lines...) Expand all
21 using ::testing::_; 21 using ::testing::_;
22 using ::testing::DoAll; 22 using ::testing::DoAll;
23 using ::testing::InSequence; 23 using ::testing::InSequence;
24 using ::testing::Invoke; 24 using ::testing::Invoke;
25 using ::testing::Return; 25 using ::testing::Return;
26 using ::testing::SetArgPointee; 26 using ::testing::SetArgPointee;
27 27
28 class MockModule : public Module { 28 class MockModule : public Module {
29 public: 29 public:
30 MOCK_METHOD0(TimeUntilNextProcess, int64_t()); 30 MOCK_METHOD0(TimeUntilNextProcess, int64_t());
31 MOCK_METHOD0(Process, int32_t()); 31 MOCK_METHOD0(Process, void());
32 MOCK_METHOD1(ProcessThreadAttached, void(ProcessThread*)); 32 MOCK_METHOD1(ProcessThreadAttached, void(ProcessThread*));
33 }; 33 };
34 34
35 class RaiseEventTask : public ProcessTask { 35 class RaiseEventTask : public ProcessTask {
36 public: 36 public:
37 RaiseEventTask(EventWrapper* event) : event_(event) {} 37 RaiseEventTask(EventWrapper* event) : event_(event) {}
38 void Run() override { event_->Set(); } 38 void Run() override { event_->Set(); }
39 39
40 private: 40 private:
41 EventWrapper* event_; 41 EventWrapper* event_;
(...skipping 28 matching lines...) Expand all
70 // Verifies that we get at least call back to Process() on the worker thread. 70 // Verifies that we get at least call back to Process() on the worker thread.
71 TEST(ProcessThreadImpl, ProcessCall) { 71 TEST(ProcessThreadImpl, ProcessCall) {
72 ProcessThreadImpl thread("ProcessThread"); 72 ProcessThreadImpl thread("ProcessThread");
73 thread.Start(); 73 thread.Start();
74 74
75 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 75 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
76 76
77 MockModule module; 77 MockModule module;
78 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 78 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
79 EXPECT_CALL(module, Process()) 79 EXPECT_CALL(module, Process())
80 .WillOnce(DoAll(SetEvent(event.get()), Return(0))) 80 .WillOnce(DoAll(SetEvent(event.get()), Return()))
81 .WillRepeatedly(Return(0)); 81 .WillRepeatedly(Return());
82 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 82 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
83 83
84 thread.RegisterModule(&module); 84 thread.RegisterModule(&module);
85 EXPECT_EQ(kEventSignaled, event->Wait(100)); 85 EXPECT_EQ(kEventSignaled, event->Wait(100));
86 86
87 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 87 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
88 thread.Stop(); 88 thread.Stop();
89 } 89 }
90 90
91 // Same as ProcessCall except the module is registered before the 91 // Same as ProcessCall except the module is registered before the
92 // call to Start(). 92 // call to Start().
93 TEST(ProcessThreadImpl, ProcessCall2) { 93 TEST(ProcessThreadImpl, ProcessCall2) {
94 ProcessThreadImpl thread("ProcessThread"); 94 ProcessThreadImpl thread("ProcessThread");
95 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 95 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
96 96
97 MockModule module; 97 MockModule module;
98 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 98 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
99 EXPECT_CALL(module, Process()) 99 EXPECT_CALL(module, Process())
100 .WillOnce(DoAll(SetEvent(event.get()), Return(0))) 100 .WillOnce(DoAll(SetEvent(event.get()), Return()))
101 .WillRepeatedly(Return(0)); 101 .WillRepeatedly(Return());
102 102
103 thread.RegisterModule(&module); 103 thread.RegisterModule(&module);
104 104
105 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 105 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
106 thread.Start(); 106 thread.Start();
107 EXPECT_EQ(kEventSignaled, event->Wait(100)); 107 EXPECT_EQ(kEventSignaled, event->Wait(100));
108 108
109 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 109 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
110 thread.Stop(); 110 thread.Stop();
111 } 111 }
112 112
113 // Tests setting up a module for callbacks and then unregister that module. 113 // Tests setting up a module for callbacks and then unregister that module.
114 // After unregistration, we should not receive any further callbacks. 114 // After unregistration, we should not receive any further callbacks.
115 TEST(ProcessThreadImpl, Deregister) { 115 TEST(ProcessThreadImpl, Deregister) {
116 ProcessThreadImpl thread("ProcessThread"); 116 ProcessThreadImpl thread("ProcessThread");
117 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 117 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
118 118
119 int process_count = 0; 119 int process_count = 0;
120 MockModule module; 120 MockModule module;
121 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 121 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
122 EXPECT_CALL(module, Process()) 122 EXPECT_CALL(module, Process())
123 .WillOnce(DoAll(SetEvent(event.get()), 123 .WillOnce(DoAll(SetEvent(event.get()),
124 Increment(&process_count), 124 Increment(&process_count),
125 Return(0))) 125 Return()))
126 .WillRepeatedly(DoAll(Increment(&process_count), Return(0))); 126 .WillRepeatedly(DoAll(Increment(&process_count), Return()));
127 127
128 thread.RegisterModule(&module); 128 thread.RegisterModule(&module);
129 129
130 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 130 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
131 thread.Start(); 131 thread.Start();
132 132
133 EXPECT_EQ(kEventSignaled, event->Wait(100)); 133 EXPECT_EQ(kEventSignaled, event->Wait(100));
134 134
135 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 135 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
136 thread.DeRegisterModule(&module); 136 thread.DeRegisterModule(&module);
(...skipping 19 matching lines...) Expand all
156 MockModule module; 156 MockModule module;
157 int64_t start_time = 0; 157 int64_t start_time = 0;
158 int64_t called_time = 0; 158 int64_t called_time = 0;
159 EXPECT_CALL(module, TimeUntilNextProcess()) 159 EXPECT_CALL(module, TimeUntilNextProcess())
160 .WillOnce(DoAll(SetTimestamp(&start_time), 160 .WillOnce(DoAll(SetTimestamp(&start_time),
161 Return(milliseconds))) 161 Return(milliseconds)))
162 .WillRepeatedly(Return(milliseconds)); 162 .WillRepeatedly(Return(milliseconds));
163 EXPECT_CALL(module, Process()) 163 EXPECT_CALL(module, Process())
164 .WillOnce(DoAll(SetTimestamp(&called_time), 164 .WillOnce(DoAll(SetTimestamp(&called_time),
165 SetEvent(event.get()), 165 SetEvent(event.get()),
166 Return(0))) 166 Return()))
167 .WillRepeatedly(Return(0)); 167 .WillRepeatedly(Return());
168 168
169 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 169 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
170 thread.RegisterModule(&module); 170 thread.RegisterModule(&module);
171 171
172 // Add a buffer of 50ms due to slowness of some trybots 172 // Add a buffer of 50ms due to slowness of some trybots
173 // (e.g. win_drmemory_light) 173 // (e.g. win_drmemory_light)
174 EXPECT_EQ(kEventSignaled, event->Wait(milliseconds + 50)); 174 EXPECT_EQ(kEventSignaled, event->Wait(milliseconds + 50));
175 175
176 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 176 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
177 thread.Stop(); 177 thread.Stop();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 219 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
220 220
221 MockModule module; 221 MockModule module;
222 int callback_count = 0; 222 int callback_count = 0;
223 // Ask for a callback after 20ms. 223 // Ask for a callback after 20ms.
224 EXPECT_CALL(module, TimeUntilNextProcess()) 224 EXPECT_CALL(module, TimeUntilNextProcess())
225 .WillRepeatedly(Return(20)); 225 .WillRepeatedly(Return(20));
226 EXPECT_CALL(module, Process()) 226 EXPECT_CALL(module, Process())
227 .WillRepeatedly(DoAll(Increment(&callback_count), 227 .WillRepeatedly(DoAll(Increment(&callback_count),
228 Return(0))); 228 Return()));
229 229
230 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 230 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
231 thread.RegisterModule(&module); 231 thread.RegisterModule(&module);
232 232
233 EXPECT_EQ(kEventTimeout, event->Wait(1000)); 233 EXPECT_EQ(kEventTimeout, event->Wait(1000));
234 234
235 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 235 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
236 thread.Stop(); 236 thread.Stop();
237 237
238 printf("Callback count: %i\n", callback_count); 238 printf("Callback count: %i\n", callback_count);
(...skipping 23 matching lines...) Expand all
262 // Then we wake the thread and there should not be another call made to 262 // Then we wake the thread and there should not be another call made to
263 // TimeUntilNextProcess before Process() is called. 263 // TimeUntilNextProcess before Process() is called.
264 // The second time TimeUntilNextProcess is then called, is after Process 264 // The second time TimeUntilNextProcess is then called, is after Process
265 // has been called and we don't expect any more calls. 265 // has been called and we don't expect any more calls.
266 EXPECT_CALL(module, TimeUntilNextProcess()) 266 EXPECT_CALL(module, TimeUntilNextProcess())
267 .WillOnce(DoAll(SetTimestamp(&start_time), 267 .WillOnce(DoAll(SetTimestamp(&start_time),
268 SetEvent(started.get()), 268 SetEvent(started.get()),
269 Return(1000))) 269 Return(1000)))
270 .WillOnce(Return(1000)); 270 .WillOnce(Return(1000));
271 EXPECT_CALL(module, Process()) 271 EXPECT_CALL(module, Process())
272 .WillOnce(DoAll(SetTimestamp(&called_time), 272 .WillOnce(
273 SetEvent(called.get()), 273 DoAll(SetTimestamp(&called_time), SetEvent(called.get()), Return()))
274 Return(0))) 274 .WillRepeatedly(Return());
275 .WillRepeatedly(Return(0));
276 275
277 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 276 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
278 thread.RegisterModule(&module); 277 thread.RegisterModule(&module);
279 278
280 EXPECT_EQ(kEventSignaled, started->Wait(100)); 279 EXPECT_EQ(kEventSignaled, started->Wait(100));
281 thread.WakeUp(&module); 280 thread.WakeUp(&module);
282 EXPECT_EQ(kEventSignaled, called->Wait(100)); 281 EXPECT_EQ(kEventSignaled, called->Wait(100));
283 282
284 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 283 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
285 thread.Stop(); 284 thread.Stop();
(...skipping 10 matching lines...) Expand all
296 ProcessThreadImpl thread("ProcessThread"); 295 ProcessThreadImpl thread("ProcessThread");
297 rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create()); 296 rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create());
298 rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); 297 rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get()));
299 thread.Start(); 298 thread.Start();
300 thread.PostTask(std::move(task)); 299 thread.PostTask(std::move(task));
301 EXPECT_EQ(kEventSignaled, task_ran->Wait(100)); 300 EXPECT_EQ(kEventSignaled, task_ran->Wait(100));
302 thread.Stop(); 301 thread.Stop();
303 } 302 }
304 303
305 } // namespace webrtc 304 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc ('k') | webrtc/modules/video_capture/video_capture_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698