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 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // There's no easy way to verify the name was set properly at this time. | 236 // There's no easy way to verify the name was set properly at this time. |
237 TEST(ThreadTest, Names) { | 237 TEST(ThreadTest, Names) { |
238 // Default name | 238 // Default name |
239 Thread *thread; | 239 Thread *thread; |
240 thread = new Thread(); | 240 thread = new Thread(); |
241 EXPECT_TRUE(thread->Start()); | 241 EXPECT_TRUE(thread->Start()); |
242 thread->Stop(); | 242 thread->Stop(); |
243 delete thread; | 243 delete thread; |
244 thread = new Thread(); | 244 thread = new Thread(); |
245 // Name with no object parameter | 245 // Name with no object parameter |
246 EXPECT_TRUE(thread->SetName("No object", NULL)); | 246 EXPECT_TRUE(thread->SetName("No object", nullptr)); |
247 EXPECT_TRUE(thread->Start()); | 247 EXPECT_TRUE(thread->Start()); |
248 thread->Stop(); | 248 thread->Stop(); |
249 delete thread; | 249 delete thread; |
250 // Really long name | 250 // Really long name |
251 thread = new Thread(); | 251 thread = new Thread(); |
252 EXPECT_TRUE(thread->SetName("Abcdefghijklmnopqrstuvwxyz1234567890", this)); | 252 EXPECT_TRUE(thread->SetName("Abcdefghijklmnopqrstuvwxyz1234567890", this)); |
253 EXPECT_TRUE(thread->Start()); | 253 EXPECT_TRUE(thread->Start()); |
254 thread->Stop(); | 254 thread->Stop(); |
255 delete thread; | 255 delete thread; |
256 } | 256 } |
(...skipping 28 matching lines...) Expand all Loading... |
285 }; | 285 }; |
286 EXPECT_EQ(999, thread.Invoke<int>(RTC_FROM_HERE, &LocalFuncs::Func1)); | 286 EXPECT_EQ(999, thread.Invoke<int>(RTC_FROM_HERE, &LocalFuncs::Func1)); |
287 thread.Invoke<void>(RTC_FROM_HERE, &LocalFuncs::Func2); | 287 thread.Invoke<void>(RTC_FROM_HERE, &LocalFuncs::Func2); |
288 } | 288 } |
289 | 289 |
290 // Verifies that two threads calling Invoke on each other at the same time does | 290 // Verifies that two threads calling Invoke on each other at the same time does |
291 // not deadlock. | 291 // not deadlock. |
292 TEST(ThreadTest, TwoThreadsInvokeNoDeadlock) { | 292 TEST(ThreadTest, TwoThreadsInvokeNoDeadlock) { |
293 AutoThread thread; | 293 AutoThread thread; |
294 Thread* current_thread = Thread::Current(); | 294 Thread* current_thread = Thread::Current(); |
295 ASSERT_TRUE(current_thread != NULL); | 295 ASSERT_TRUE(current_thread != nullptr); |
296 | 296 |
297 Thread other_thread; | 297 Thread other_thread; |
298 other_thread.Start(); | 298 other_thread.Start(); |
299 | 299 |
300 struct LocalFuncs { | 300 struct LocalFuncs { |
301 static void Set(bool* out) { *out = true; } | 301 static void Set(bool* out) { *out = true; } |
302 static void InvokeSet(Thread* thread, bool* out) { | 302 static void InvokeSet(Thread* thread, bool* out) { |
303 thread->Invoke<void>(RTC_FROM_HERE, Bind(&Set, out)); | 303 thread->Invoke<void>(RTC_FROM_HERE, Bind(&Set, out)); |
304 } | 304 } |
305 }; | 305 }; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 436 } |
437 void SetExpectedThreadForIntCallback(Thread* thread) { | 437 void SetExpectedThreadForIntCallback(Thread* thread) { |
438 expected_thread_ = thread; | 438 expected_thread_ = thread; |
439 } | 439 } |
440 | 440 |
441 protected: | 441 protected: |
442 enum { kWaitTimeout = 1000 }; | 442 enum { kWaitTimeout = 1000 }; |
443 AsyncInvokeTest() | 443 AsyncInvokeTest() |
444 : int_value_(0), | 444 : int_value_(0), |
445 invoke_started_(true, false), | 445 invoke_started_(true, false), |
446 expected_thread_(NULL) {} | 446 expected_thread_(nullptr) {} |
447 | 447 |
448 int int_value_; | 448 int int_value_; |
449 Event invoke_started_; | 449 Event invoke_started_; |
450 Thread* expected_thread_; | 450 Thread* expected_thread_; |
451 }; | 451 }; |
452 | 452 |
453 TEST_F(AsyncInvokeTest, FireAndForget) { | 453 TEST_F(AsyncInvokeTest, FireAndForget) { |
454 AsyncInvoker invoker; | 454 AsyncInvoker invoker; |
455 // Create and start the thread. | 455 // Create and start the thread. |
456 Thread thread; | 456 Thread thread; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 EXPECT_FALSE(flag1.get()); | 781 EXPECT_FALSE(flag1.get()); |
782 EXPECT_TRUE(flag2.get()); | 782 EXPECT_TRUE(flag2.get()); |
783 } | 783 } |
784 | 784 |
785 #if defined(WEBRTC_WIN) | 785 #if defined(WEBRTC_WIN) |
786 class ComThreadTest : public testing::Test, public MessageHandler { | 786 class ComThreadTest : public testing::Test, public MessageHandler { |
787 public: | 787 public: |
788 ComThreadTest() : done_(false) {} | 788 ComThreadTest() : done_(false) {} |
789 protected: | 789 protected: |
790 virtual void OnMessage(Message* message) { | 790 virtual void OnMessage(Message* message) { |
791 HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); | 791 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); |
792 // S_FALSE means the thread was already inited for a multithread apartment. | 792 // S_FALSE means the thread was already inited for a multithread apartment. |
793 EXPECT_EQ(S_FALSE, hr); | 793 EXPECT_EQ(S_FALSE, hr); |
794 if (SUCCEEDED(hr)) { | 794 if (SUCCEEDED(hr)) { |
795 CoUninitialize(); | 795 CoUninitialize(); |
796 } | 796 } |
797 done_ = true; | 797 done_ = true; |
798 } | 798 } |
799 bool done_; | 799 bool done_; |
800 }; | 800 }; |
801 | 801 |
802 TEST_F(ComThreadTest, ComInited) { | 802 TEST_F(ComThreadTest, ComInited) { |
803 Thread* thread = new ComThread(); | 803 Thread* thread = new ComThread(); |
804 EXPECT_TRUE(thread->Start()); | 804 EXPECT_TRUE(thread->Start()); |
805 thread->Post(RTC_FROM_HERE, this, 0); | 805 thread->Post(RTC_FROM_HERE, this, 0); |
806 EXPECT_TRUE_WAIT(done_, 1000); | 806 EXPECT_TRUE_WAIT(done_, 1000); |
807 delete thread; | 807 delete thread; |
808 } | 808 } |
809 #endif | 809 #endif |
OLD | NEW |