14
14
#include " api/task_queue/default_task_queue_factory.h"
15
15
#include " modules/audio_device/include/mock_audio_device.h"
16
16
#include " modules/audio_processing/include/mock_audio_processing.h"
17
+ #include " modules/utility/include/mock/mock_process_thread.h"
17
18
#include " test/gtest.h"
18
19
#include " test/mock_transport.h"
19
20
@@ -40,15 +41,20 @@ class VoipCoreTest : public ::testing::Test {
40
41
rtc::scoped_refptr<AudioProcessing> audio_processing =
41
42
new rtc::RefCountedObject<test::MockAudioProcessing>();
42
43
44
+ auto process_thread = std::make_unique<NiceMock<MockProcessThread>>();
45
+ // Hold the pointer to use for testing.
46
+ process_thread_ = process_thread.get ();
47
+
43
48
voip_core_ = std::make_unique<VoipCore>();
44
49
voip_core_->Init (std::move (encoder_factory), std::move (decoder_factory),
45
50
CreateDefaultTaskQueueFactory (), audio_device_,
46
- std::move (audio_processing));
51
+ std::move (audio_processing), std::move (process_thread) );
47
52
}
48
53
49
54
std::unique_ptr<VoipCore> voip_core_;
50
55
NiceMock<MockTransport> transport_;
51
56
rtc::scoped_refptr<test::MockAudioDeviceModule> audio_device_;
57
+ NiceMock<MockProcessThread>* process_thread_;
52
58
};
53
59
54
60
// Validate expected API calls that involves with VoipCore. Some verification is
@@ -176,5 +182,34 @@ TEST_F(VoipCoreTest, StopSendAndPlayoutWithoutStarting) {
176
182
voip_core_->ReleaseChannel (*channel);
177
183
}
178
184
185
+ // This tests correctness on ProcessThread usage where we expect the first/last
186
+ // channel creation/release triggers its Start/Stop method once only.
187
+ TEST_F (VoipCoreTest, TestProcessThreadOperation) {
188
+ EXPECT_CALL (*process_thread_, Start);
189
+ EXPECT_CALL (*process_thread_, RegisterModule).Times (2 );
190
+
191
+ auto channel_one = voip_core_->CreateChannel (&transport_, 0xdeadc0de );
192
+ auto channel_two = voip_core_->CreateChannel (&transport_, 0xdeadbeef );
193
+ EXPECT_TRUE (channel_one);
194
+ EXPECT_TRUE (channel_two);
195
+
196
+ EXPECT_CALL (*process_thread_, Stop);
197
+ EXPECT_CALL (*process_thread_, DeRegisterModule).Times (2 );
198
+
199
+ voip_core_->ReleaseChannel (*channel_one);
200
+ voip_core_->ReleaseChannel (*channel_two);
201
+
202
+ EXPECT_CALL (*process_thread_, Start);
203
+ EXPECT_CALL (*process_thread_, RegisterModule);
204
+
205
+ auto channel_three = voip_core_->CreateChannel (&transport_, absl::nullopt);
206
+ EXPECT_TRUE (channel_three);
207
+
208
+ EXPECT_CALL (*process_thread_, Stop);
209
+ EXPECT_CALL (*process_thread_, DeRegisterModule);
210
+
211
+ voip_core_->ReleaseChannel (*channel_three);
212
+ }
213
+
179
214
} // namespace
180
215
} // namespace webrtc
0 commit comments