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 thread_->SetName("foo", nullptr); | |
pthatcher1
2016/02/04 00:50:38
Can you leave a comment here, perhaps something li
joachim
2016/02/04 01:00:09
Done.
| |
393 } | |
394 | |
395 private: | |
396 Thread* thread_; | |
397 }; | |
398 | |
399 TEST(ThreadTest, SetNameOnSignalQueueDestroyed) { | |
400 Thread* thread1 = new Thread(); | |
401 SetNameOnSignalQueueDestroyedTester tester1(thread1); | |
402 delete thread1; | |
403 | |
404 Thread* thread2 = new AutoThread(); | |
405 SetNameOnSignalQueueDestroyedTester tester2(thread2); | |
406 delete thread2; | |
407 | |
408 #if defined(WEBRTC_WIN) | |
409 Thread* thread3 = new ComThread(); | |
410 SetNameOnSignalQueueDestroyedTester tester3(thread3); | |
411 delete thread3; | |
412 #endif | |
413 } | |
414 | |
380 class AsyncInvokeTest : public testing::Test { | 415 class AsyncInvokeTest : public testing::Test { |
381 public: | 416 public: |
382 void IntCallback(int value) { | 417 void IntCallback(int value) { |
383 EXPECT_EQ(expected_thread_, Thread::Current()); | 418 EXPECT_EQ(expected_thread_, Thread::Current()); |
384 int_value_ = value; | 419 int_value_ = value; |
385 } | 420 } |
386 void AsyncInvokeIntCallback(AsyncInvoker* invoker, Thread* thread) { | 421 void AsyncInvokeIntCallback(AsyncInvoker* invoker, Thread* thread) { |
387 expected_thread_ = thread; | 422 expected_thread_ = thread; |
388 invoker->AsyncInvoke(thread, FunctorC(), | 423 invoker->AsyncInvoke(thread, FunctorC(), |
389 &AsyncInvokeTest::IntCallback, | 424 &AsyncInvokeTest::IntCallback, |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 }; | 752 }; |
718 | 753 |
719 TEST_F(ComThreadTest, ComInited) { | 754 TEST_F(ComThreadTest, ComInited) { |
720 Thread* thread = new ComThread(); | 755 Thread* thread = new ComThread(); |
721 EXPECT_TRUE(thread->Start()); | 756 EXPECT_TRUE(thread->Start()); |
722 thread->Post(this, 0); | 757 thread->Post(this, 0); |
723 EXPECT_TRUE_WAIT(done_, 1000); | 758 EXPECT_TRUE_WAIT(done_, 1000); |
724 delete thread; | 759 delete thread; |
725 } | 760 } |
726 #endif | 761 #endif |
OLD | NEW |