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

Side by Side Diff: webrtc/base/thread_unittest.cc

Issue 1920043002: Replace scoped_ptr with unique_ptr in webrtc/base/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 7 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 | « webrtc/base/thread_checker_unittest.cc ('k') | webrtc/base/virtualsocket_unittest.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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 invoke_started_(true, false), 582 invoke_started_(true, false),
583 expected_thread_(nullptr) {} 583 expected_thread_(nullptr) {}
584 584
585 int int_value_; 585 int int_value_;
586 Event invoke_started_; 586 Event invoke_started_;
587 Thread* expected_thread_; 587 Thread* expected_thread_;
588 }; 588 };
589 589
590 // Functor for creating an invoker. 590 // Functor for creating an invoker.
591 struct CreateInvoker { 591 struct CreateInvoker {
592 CreateInvoker(scoped_ptr<GuardedAsyncInvoker>* invoker) : invoker_(invoker) {} 592 CreateInvoker(std::unique_ptr<GuardedAsyncInvoker>* invoker)
593 : invoker_(invoker) {}
593 void operator()() { invoker_->reset(new GuardedAsyncInvoker()); } 594 void operator()() { invoker_->reset(new GuardedAsyncInvoker()); }
594 scoped_ptr<GuardedAsyncInvoker>* invoker_; 595 std::unique_ptr<GuardedAsyncInvoker>* invoker_;
595 }; 596 };
596 597
597 // Test that we can call AsyncInvoke<void>() after the thread died. 598 // Test that we can call AsyncInvoke<void>() after the thread died.
598 TEST_F(GuardedAsyncInvokeTest, KillThreadFireAndForget) { 599 TEST_F(GuardedAsyncInvokeTest, KillThreadFireAndForget) {
599 // Create and start the thread. 600 // Create and start the thread.
600 scoped_ptr<Thread> thread(new Thread()); 601 std::unique_ptr<Thread> thread(new Thread());
601 thread->Start(); 602 thread->Start();
602 scoped_ptr<GuardedAsyncInvoker> invoker; 603 std::unique_ptr<GuardedAsyncInvoker> invoker;
603 // Create the invoker on |thread|. 604 // Create the invoker on |thread|.
604 thread->Invoke<void>(CreateInvoker(&invoker)); 605 thread->Invoke<void>(CreateInvoker(&invoker));
605 // Kill |thread|. 606 // Kill |thread|.
606 thread = nullptr; 607 thread = nullptr;
607 // Try calling functor. 608 // Try calling functor.
608 AtomicBool called; 609 AtomicBool called;
609 EXPECT_FALSE(invoker->AsyncInvoke<void>(FunctorB(&called))); 610 EXPECT_FALSE(invoker->AsyncInvoke<void>(FunctorB(&called)));
610 // With thread gone, nothing should happen. 611 // With thread gone, nothing should happen.
611 WAIT(called.get(), kWaitTimeout); 612 WAIT(called.get(), kWaitTimeout);
612 EXPECT_FALSE(called.get()); 613 EXPECT_FALSE(called.get());
613 } 614 }
614 615
615 // Test that we can call AsyncInvoke with callback after the thread died. 616 // Test that we can call AsyncInvoke with callback after the thread died.
616 TEST_F(GuardedAsyncInvokeTest, KillThreadWithCallback) { 617 TEST_F(GuardedAsyncInvokeTest, KillThreadWithCallback) {
617 // Create and start the thread. 618 // Create and start the thread.
618 scoped_ptr<Thread> thread(new Thread()); 619 std::unique_ptr<Thread> thread(new Thread());
619 thread->Start(); 620 thread->Start();
620 scoped_ptr<GuardedAsyncInvoker> invoker; 621 std::unique_ptr<GuardedAsyncInvoker> invoker;
621 // Create the invoker on |thread|. 622 // Create the invoker on |thread|.
622 thread->Invoke<void>(CreateInvoker(&invoker)); 623 thread->Invoke<void>(CreateInvoker(&invoker));
623 // Kill |thread|. 624 // Kill |thread|.
624 thread = nullptr; 625 thread = nullptr;
625 // Try calling functor. 626 // Try calling functor.
626 EXPECT_FALSE( 627 EXPECT_FALSE(
627 invoker->AsyncInvoke(FunctorC(), &GuardedAsyncInvokeTest::IntCallback, 628 invoker->AsyncInvoke(FunctorC(), &GuardedAsyncInvokeTest::IntCallback,
628 static_cast<GuardedAsyncInvokeTest*>(this))); 629 static_cast<GuardedAsyncInvokeTest*>(this)));
629 // With thread gone, callback should be cancelled. 630 // With thread gone, callback should be cancelled.
630 Thread::Current()->ProcessMessages(kWaitTimeout); 631 Thread::Current()->ProcessMessages(kWaitTimeout);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 }; 755 };
755 756
756 TEST_F(ComThreadTest, ComInited) { 757 TEST_F(ComThreadTest, ComInited) {
757 Thread* thread = new ComThread(); 758 Thread* thread = new ComThread();
758 EXPECT_TRUE(thread->Start()); 759 EXPECT_TRUE(thread->Start());
759 thread->Post(this, 0); 760 thread->Post(this, 0);
760 EXPECT_TRUE_WAIT(done_, 1000); 761 EXPECT_TRUE_WAIT(done_, 1000);
761 delete thread; 762 delete thread;
762 } 763 }
763 #endif 764 #endif
OLDNEW
« no previous file with comments | « webrtc/base/thread_checker_unittest.cc ('k') | webrtc/base/virtualsocket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698