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

Side by Side Diff: base/message_loop/message_loop_task_runner_unittest.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 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 | « base/message_loop/message_loop.cc ('k') | base/message_loop/message_loop_test.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 (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 "base/message_loop/message_loop_task_runner.h" 5 #include "base/message_loop/message_loop_task_runner.h"
6 6
7 #include <memory>
8
7 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 10 #include "base/bind.h"
9 #include "base/debug/leak_annotations.h" 11 #include "base/debug/leak_annotations.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_task_runner.h" 13 #include "base/message_loop/message_loop_task_runner.h"
13 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
14 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h" 18 #include "testing/platform_test.h"
18 19
19 namespace base { 20 namespace base {
20 21
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 recorder->RecordRun(); 82 recorder->RecordRun();
82 MessageLoop::current()->QuitWhenIdle(); 83 MessageLoop::current()->QuitWhenIdle();
83 } 84 }
84 85
85 void UnblockTaskThread() { thread_sync_.Signal(); } 86 void UnblockTaskThread() { thread_sync_.Signal(); }
86 87
87 void BlockTaskThreadHelper() { thread_sync_.Wait(); } 88 void BlockTaskThreadHelper() { thread_sync_.Wait(); }
88 89
89 static StaticAtomicSequenceNumber g_order; 90 static StaticAtomicSequenceNumber g_order;
90 91
91 scoped_ptr<MessageLoop> current_loop_; 92 std::unique_ptr<MessageLoop> current_loop_;
92 Thread task_thread_; 93 Thread task_thread_;
93 94
94 private: 95 private:
95 base::WaitableEvent thread_sync_; 96 base::WaitableEvent thread_sync_;
96 }; 97 };
97 98
98 StaticAtomicSequenceNumber MessageLoopTaskRunnerTest::g_order; 99 StaticAtomicSequenceNumber MessageLoopTaskRunnerTest::g_order;
99 100
100 TEST_F(MessageLoopTaskRunnerTest, PostTaskAndReply_Basic) { 101 TEST_F(MessageLoopTaskRunnerTest, PostTaskAndReply_Basic) {
101 MessageLoop* task_run_on = NULL; 102 MessageLoop* task_run_on = NULL;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 297
297 ~DeletedOnFile() { 298 ~DeletedOnFile() {
298 test_->AssertOnFileThread(); 299 test_->AssertOnFileThread();
299 test_->Quit(); 300 test_->Quit();
300 } 301 }
301 302
302 private: 303 private:
303 MessageLoopTaskRunnerThreadingTest* test_; 304 MessageLoopTaskRunnerThreadingTest* test_;
304 }; 305 };
305 306
306 scoped_ptr<Thread> io_thread_; 307 std::unique_ptr<Thread> io_thread_;
307 scoped_ptr<Thread> file_thread_; 308 std::unique_ptr<Thread> file_thread_;
308 309
309 private: 310 private:
310 mutable MessageLoop loop_; 311 mutable MessageLoop loop_;
311 }; 312 };
312 313
313 TEST_F(MessageLoopTaskRunnerThreadingTest, Release) { 314 TEST_F(MessageLoopTaskRunnerThreadingTest, Release) {
314 EXPECT_TRUE(io_thread_->task_runner()->ReleaseSoon(FROM_HERE, this)); 315 EXPECT_TRUE(io_thread_->task_runner()->ReleaseSoon(FROM_HERE, this));
315 MessageLoop::current()->Run(); 316 MessageLoop::current()->Run();
316 } 317 }
317 318
318 TEST_F(MessageLoopTaskRunnerThreadingTest, Delete) { 319 TEST_F(MessageLoopTaskRunnerThreadingTest, Delete) {
319 DeletedOnFile* deleted_on_file = new DeletedOnFile(this); 320 DeletedOnFile* deleted_on_file = new DeletedOnFile(this);
320 EXPECT_TRUE( 321 EXPECT_TRUE(
321 file_thread_->task_runner()->DeleteSoon(FROM_HERE, deleted_on_file)); 322 file_thread_->task_runner()->DeleteSoon(FROM_HERE, deleted_on_file));
322 MessageLoop::current()->Run(); 323 MessageLoop::current()->Run();
323 } 324 }
324 325
325 TEST_F(MessageLoopTaskRunnerThreadingTest, PostTask) { 326 TEST_F(MessageLoopTaskRunnerThreadingTest, PostTask) {
326 EXPECT_TRUE(file_thread_->task_runner()->PostTask( 327 EXPECT_TRUE(file_thread_->task_runner()->PostTask(
327 FROM_HERE, Bind(&MessageLoopTaskRunnerThreadingTest::BasicFunction, 328 FROM_HERE, Bind(&MessageLoopTaskRunnerThreadingTest::BasicFunction,
328 Unretained(this)))); 329 Unretained(this))));
329 MessageLoop::current()->Run(); 330 MessageLoop::current()->Run();
330 } 331 }
331 332
332 TEST_F(MessageLoopTaskRunnerThreadingTest, PostTaskAfterThreadExits) { 333 TEST_F(MessageLoopTaskRunnerThreadingTest, PostTaskAfterThreadExits) {
333 scoped_ptr<Thread> test_thread( 334 std::unique_ptr<Thread> test_thread(
334 new Thread("MessageLoopTaskRunnerThreadingTest_Dummy")); 335 new Thread("MessageLoopTaskRunnerThreadingTest_Dummy"));
335 test_thread->Start(); 336 test_thread->Start();
336 scoped_refptr<SingleThreadTaskRunner> task_runner = 337 scoped_refptr<SingleThreadTaskRunner> task_runner =
337 test_thread->task_runner(); 338 test_thread->task_runner();
338 test_thread->Stop(); 339 test_thread->Stop();
339 340
340 bool ret = task_runner->PostTask( 341 bool ret = task_runner->PostTask(
341 FROM_HERE, Bind(&MessageLoopTaskRunnerThreadingTest::AssertNotRun)); 342 FROM_HERE, Bind(&MessageLoopTaskRunnerThreadingTest::AssertNotRun));
342 EXPECT_FALSE(ret); 343 EXPECT_FALSE(ret);
343 } 344 }
344 345
345 TEST_F(MessageLoopTaskRunnerThreadingTest, PostTaskAfterThreadIsDeleted) { 346 TEST_F(MessageLoopTaskRunnerThreadingTest, PostTaskAfterThreadIsDeleted) {
346 scoped_refptr<SingleThreadTaskRunner> task_runner; 347 scoped_refptr<SingleThreadTaskRunner> task_runner;
347 { 348 {
348 scoped_ptr<Thread> test_thread( 349 std::unique_ptr<Thread> test_thread(
349 new Thread("MessageLoopTaskRunnerThreadingTest_Dummy")); 350 new Thread("MessageLoopTaskRunnerThreadingTest_Dummy"));
350 test_thread->Start(); 351 test_thread->Start();
351 task_runner = test_thread->task_runner(); 352 task_runner = test_thread->task_runner();
352 } 353 }
353 bool ret = task_runner->PostTask( 354 bool ret = task_runner->PostTask(
354 FROM_HERE, Bind(&MessageLoopTaskRunnerThreadingTest::AssertNotRun)); 355 FROM_HERE, Bind(&MessageLoopTaskRunnerThreadingTest::AssertNotRun));
355 EXPECT_FALSE(ret); 356 EXPECT_FALSE(ret);
356 } 357 }
357 358
358 } // namespace base 359 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | base/message_loop/message_loop_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698