OLD | NEW |
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 |
11 #include "webrtc/base/asyncinvoker.h" | 11 #include "webrtc/base/asyncinvoker.h" |
12 #include "webrtc/base/asyncudpsocket.h" | 12 #include "webrtc/base/asyncudpsocket.h" |
13 #include "webrtc/base/event.h" | 13 #include "webrtc/base/event.h" |
14 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
15 #include "webrtc/base/physicalsocketserver.h" | 15 #include "webrtc/base/physicalsocketserver.h" |
| 16 #include "webrtc/base/sigslot.h" |
16 #include "webrtc/base/socketaddress.h" | 17 #include "webrtc/base/socketaddress.h" |
17 #include "webrtc/base/thread.h" | 18 #include "webrtc/base/thread.h" |
18 | 19 |
19 #if defined(WEBRTC_WIN) | 20 #if defined(WEBRTC_WIN) |
20 #include <comdef.h> // NOLINT | 21 #include <comdef.h> // NOLINT |
21 #endif | 22 #endif |
22 | 23 |
23 using namespace rtc; | 24 using namespace rtc; |
24 | 25 |
25 // Generates a sequence of numbers (collaboratively). | 26 // Generates a sequence of numbers (collaboratively). |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // Start the sequence A --(invoke)--> B --(async invoke)--> C --(invoke)--> A. | 371 // Start the sequence A --(invoke)--> B --(async invoke)--> C --(invoke)--> A. |
371 // Thread B returns when C receives the call and C should be blocked until A | 372 // Thread B returns when C receives the call and C should be blocked until A |
372 // starts to process messages. | 373 // starts to process messages. |
373 thread_b.Invoke<void>(Bind(&LocalFuncs::AsyncInvokeSetAndWait, | 374 thread_b.Invoke<void>(Bind(&LocalFuncs::AsyncInvokeSetAndWait, |
374 &thread_c, thread_a, &thread_a_called)); | 375 &thread_c, thread_a, &thread_a_called)); |
375 EXPECT_FALSE(thread_a_called.Get()); | 376 EXPECT_FALSE(thread_a_called.Get()); |
376 | 377 |
377 EXPECT_TRUE_WAIT(thread_a_called.Get(), 2000); | 378 EXPECT_TRUE_WAIT(thread_a_called.Get(), 2000); |
378 } | 379 } |
379 | 380 |
| 381 // Set the name on a thread when the underlying QueueDestroyed signal is |
| 382 // triggered. This causes an error if the object is already partially |
| 383 // destroyed. |
| 384 class SetNameOnSignalQueueDestroyedTester : public sigslot::has_slots<> { |
| 385 public: |
| 386 SetNameOnSignalQueueDestroyedTester(Thread* thread) : thread_(thread) { |
| 387 thread->SignalQueueDestroyed.connect( |
| 388 this, &SetNameOnSignalQueueDestroyedTester::OnQueueDestroyed); |
| 389 } |
| 390 |
| 391 void OnQueueDestroyed() { |
| 392 // Makes sure that if we access the Thread while it's being destroyed, that |
| 393 // it doesn't cause a problem because the vtable has been modified. |
| 394 thread_->SetName("foo", nullptr); |
| 395 } |
| 396 |
| 397 private: |
| 398 Thread* thread_; |
| 399 }; |
| 400 |
| 401 TEST(ThreadTest, SetNameOnSignalQueueDestroyed) { |
| 402 Thread* thread1 = new Thread(); |
| 403 SetNameOnSignalQueueDestroyedTester tester1(thread1); |
| 404 delete thread1; |
| 405 |
| 406 Thread* thread2 = new AutoThread(); |
| 407 SetNameOnSignalQueueDestroyedTester tester2(thread2); |
| 408 delete thread2; |
| 409 |
| 410 #if defined(WEBRTC_WIN) |
| 411 Thread* thread3 = new ComThread(); |
| 412 SetNameOnSignalQueueDestroyedTester tester3(thread3); |
| 413 delete thread3; |
| 414 #endif |
| 415 } |
| 416 |
380 class AsyncInvokeTest : public testing::Test { | 417 class AsyncInvokeTest : public testing::Test { |
381 public: | 418 public: |
382 void IntCallback(int value) { | 419 void IntCallback(int value) { |
383 EXPECT_EQ(expected_thread_, Thread::Current()); | 420 EXPECT_EQ(expected_thread_, Thread::Current()); |
384 int_value_ = value; | 421 int_value_ = value; |
385 } | 422 } |
386 void AsyncInvokeIntCallback(AsyncInvoker* invoker, Thread* thread) { | 423 void AsyncInvokeIntCallback(AsyncInvoker* invoker, Thread* thread) { |
387 expected_thread_ = thread; | 424 expected_thread_ = thread; |
388 invoker->AsyncInvoke(thread, FunctorC(), | 425 invoker->AsyncInvoke(thread, FunctorC(), |
389 &AsyncInvokeTest::IntCallback, | 426 &AsyncInvokeTest::IntCallback, |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 }; | 754 }; |
718 | 755 |
719 TEST_F(ComThreadTest, ComInited) { | 756 TEST_F(ComThreadTest, ComInited) { |
720 Thread* thread = new ComThread(); | 757 Thread* thread = new ComThread(); |
721 EXPECT_TRUE(thread->Start()); | 758 EXPECT_TRUE(thread->Start()); |
722 thread->Post(this, 0); | 759 thread->Post(this, 0); |
723 EXPECT_TRUE_WAIT(done_, 1000); | 760 EXPECT_TRUE_WAIT(done_, 1000); |
724 delete thread; | 761 delete thread; |
725 } | 762 } |
726 #endif | 763 #endif |
OLD | NEW |