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 <memory> |
| 12 |
11 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
12 #include "webrtc/base/signalthread.h" | 14 #include "webrtc/base/signalthread.h" |
13 #include "webrtc/base/thread.h" | 15 #include "webrtc/base/thread.h" |
14 | 16 |
15 using namespace rtc; | 17 using namespace rtc; |
16 | 18 |
17 class SignalThreadTest : public testing::Test, public sigslot::has_slots<> { | 19 class SignalThreadTest : public testing::Test, public sigslot::has_slots<> { |
18 public: | 20 public: |
19 class SlowSignalThread : public SignalThread { | 21 class SlowSignalThread : public SignalThread { |
20 public: | 22 public: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 SignalThreadTest* harness_; | 130 SignalThreadTest* harness_; |
129 bool has_run_; | 131 bool has_run_; |
130 RTC_DISALLOW_COPY_AND_ASSIGN(OwnerThread); | 132 RTC_DISALLOW_COPY_AND_ASSIGN(OwnerThread); |
131 }; | 133 }; |
132 | 134 |
133 // Test for when the main thread goes away while the | 135 // Test for when the main thread goes away while the |
134 // signal thread is still working. This may happen | 136 // signal thread is still working. This may happen |
135 // when shutting down the process. | 137 // when shutting down the process. |
136 TEST_F(SignalThreadTest, OwnerThreadGoesAway) { | 138 TEST_F(SignalThreadTest, OwnerThreadGoesAway) { |
137 { | 139 { |
138 scoped_ptr<OwnerThread> owner(new OwnerThread(this)); | 140 std::unique_ptr<OwnerThread> owner(new OwnerThread(this)); |
139 main_thread_ = owner.get(); | 141 main_thread_ = owner.get(); |
140 owner->Start(); | 142 owner->Start(); |
141 while (!owner->has_run()) { | 143 while (!owner->has_run()) { |
142 Thread::Current()->socketserver()->Wait(10, false); | 144 Thread::Current()->socketserver()->Wait(10, false); |
143 } | 145 } |
144 } | 146 } |
145 // At this point the main thread has gone away. | 147 // At this point the main thread has gone away. |
146 // Give the SignalThread a little time to do its callback, | 148 // Give the SignalThread a little time to do its callback, |
147 // which will crash if the signal thread doesn't handle | 149 // which will crash if the signal thread doesn't handle |
148 // this situation well. | 150 // this situation well. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 TEST_F(SignalThreadTest, DeferredDestroyedThreadCleansUp) { | 191 TEST_F(SignalThreadTest, DeferredDestroyedThreadCleansUp) { |
190 thread_->Start(); | 192 thread_->Start(); |
191 EXPECT_STATE(1, 0, 0, 0, 0); | 193 EXPECT_STATE(1, 0, 0, 0, 0); |
192 thread_->Destroy(false); | 194 thread_->Destroy(false); |
193 EXPECT_STATE(1, 0, 0, 1, 0); | 195 EXPECT_STATE(1, 0, 0, 1, 0); |
194 Thread::SleepMs(500); | 196 Thread::SleepMs(500); |
195 EXPECT_STATE(1, 0, 0, 1, 0); | 197 EXPECT_STATE(1, 0, 0, 1, 0); |
196 Thread::Current()->ProcessMessages(0); | 198 Thread::Current()->ProcessMessages(0); |
197 EXPECT_STATE(1, 1, 0, 1, 1); | 199 EXPECT_STATE(1, 1, 0, 1, 1); |
198 } | 200 } |
OLD | NEW |