Skip to content

Commit b557054

Browse files
fix platform audio tests
1 parent e5572f5 commit b557054

2 files changed

Lines changed: 42 additions & 37 deletions

File tree

‎src/tests/integration/test_platform_audio.cpp‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ class PlatformTrackCollectorDelegate : public RoomDelegate {
7373
PlatformTrackState& state_;
7474
};
7575

76-
/// Construct a PlatformAudio, or skip the calling test when the platform Audio
77-
/// Device Module is unavailable (headless CI runners have no audio hardware).
78-
std::unique_ptr<PlatformAudio> makePlatformAudioOrSkip() {
79-
try {
80-
return std::make_unique<PlatformAudio>();
81-
} catch (const PlatformAudioError& error) {
82-
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
83-
}
84-
return nullptr;
85-
}
86-
8776
} // namespace
8877

8978
class PlatformAudioIntegrationTest : public LiveKitTestBase {};
@@ -95,8 +84,12 @@ class PlatformAudioIntegrationTest : public LiveKitTestBase {};
9584
TEST_F(PlatformAudioIntegrationTest, PublishPlatformAudioTrackEndToEnd) {
9685
skipIfNotConfigured();
9786

98-
auto platform_audio = makePlatformAudioOrSkip();
99-
ASSERT_NE(platform_audio, nullptr);
87+
std::unique_ptr<PlatformAudio> platform_audio;
88+
try {
89+
platform_audio = std::make_unique<PlatformAudio>();
90+
} catch (const PlatformAudioError& error) {
91+
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
92+
}
10093

10194
RoomOptions options;
10295
options.auto_subscribe = true;
@@ -134,8 +127,12 @@ TEST_F(PlatformAudioIntegrationTest, PublishPlatformAudioTrackEndToEnd) {
134127
TEST_F(PlatformAudioIntegrationTest, UnpublishPlatformAudioTrackPropagates) {
135128
skipIfNotConfigured();
136129

137-
auto platform_audio = makePlatformAudioOrSkip();
138-
ASSERT_NE(platform_audio, nullptr);
130+
std::unique_ptr<PlatformAudio> platform_audio;
131+
try {
132+
platform_audio = std::make_unique<PlatformAudio>();
133+
} catch (const PlatformAudioError& error) {
134+
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
135+
}
139136

140137
RoomOptions options;
141138
options.auto_subscribe = true;
@@ -185,8 +182,12 @@ TEST_F(PlatformAudioIntegrationTest, UnpublishPlatformAudioTrackPropagates) {
185182
TEST_F(PlatformAudioIntegrationTest, MultipleSourcesFromOneManagerPublish) {
186183
skipIfNotConfigured();
187184

188-
auto platform_audio = makePlatformAudioOrSkip();
189-
ASSERT_NE(platform_audio, nullptr);
185+
std::unique_ptr<PlatformAudio> platform_audio;
186+
try {
187+
platform_audio = std::make_unique<PlatformAudio>();
188+
} catch (const PlatformAudioError& error) {
189+
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
190+
}
190191

191192
RoomOptions options;
192193
options.auto_subscribe = true;

‎src/tests/unit/test_platform_audio.cpp‎

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ class PlatformAudioTest : public ::testing::Test {
2727
protected:
2828
void SetUp() override { livekit::initialize(livekit::LogLevel::Info); }
2929
void TearDown() override { livekit::shutdown(); }
30-
31-
/// Construct a PlatformAudio, or skip the calling test when the platform
32-
/// Audio Device Module is unavailable (headless CI runners have no audio
33-
/// hardware). Returns nullptr after recording the skip.
34-
static std::unique_ptr<PlatformAudio> makePlatformAudioOrSkip() {
35-
try {
36-
return std::make_unique<PlatformAudio>();
37-
} catch (const PlatformAudioError& error) {
38-
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
39-
}
40-
return nullptr;
41-
}
4230
};
4331

4432
TEST_F(PlatformAudioTest, DefaultOptionsEnableVoiceProcessing) {
@@ -79,8 +67,12 @@ TEST_F(PlatformAudioTest, CreateSourceAndTrackWhenAvailable) {
7967
}
8068

8169
TEST_F(PlatformAudioTest, MovedFromManagerThrowsOnUseButCountsAreSafe) {
82-
auto platform_audio = makePlatformAudioOrSkip();
83-
ASSERT_NE(platform_audio, nullptr);
70+
std::unique_ptr<PlatformAudio> platform_audio;
71+
try {
72+
platform_audio = std::make_unique<PlatformAudio>();
73+
} catch (const PlatformAudioError& error) {
74+
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
75+
}
8476

8577
PlatformAudio moved_to = std::move(*platform_audio);
8678
PlatformAudio& moved_from = *platform_audio;
@@ -101,8 +93,12 @@ TEST_F(PlatformAudioTest, MovedFromManagerThrowsOnUseButCountsAreSafe) {
10193
}
10294

10395
TEST_F(PlatformAudioTest, CopySharesHandleStateAndOutlivesOriginal) {
104-
auto platform_audio = makePlatformAudioOrSkip();
105-
ASSERT_NE(platform_audio, nullptr);
96+
std::unique_ptr<PlatformAudio> platform_audio;
97+
try {
98+
platform_audio = std::make_unique<PlatformAudio>();
99+
} catch (const PlatformAudioError& error) {
100+
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
101+
}
106102

107103
// A copy shares the underlying handle, so the cached counts agree.
108104
PlatformAudio copy = *platform_audio;
@@ -120,8 +116,12 @@ TEST_F(PlatformAudioTest, CopySharesHandleStateAndOutlivesOriginal) {
120116
}
121117

122118
TEST_F(PlatformAudioTest, CreateSourceWithCustomOptions) {
123-
auto platform_audio = makePlatformAudioOrSkip();
124-
ASSERT_NE(platform_audio, nullptr);
119+
std::unique_ptr<PlatformAudio> platform_audio;
120+
try {
121+
platform_audio = std::make_unique<PlatformAudio>();
122+
} catch (const PlatformAudioError& error) {
123+
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
124+
}
125125

126126
PlatformAudioOptions options;
127127
options.echo_cancellation = false;
@@ -135,8 +135,12 @@ TEST_F(PlatformAudioTest, CreateSourceWithCustomOptions) {
135135
}
136136

137137
TEST_F(PlatformAudioTest, EnumerateDevicesAndSelectWhenAvailable) {
138-
auto platform_audio = makePlatformAudioOrSkip();
139-
ASSERT_NE(platform_audio, nullptr);
138+
std::unique_ptr<PlatformAudio> platform_audio;
139+
try {
140+
platform_audio = std::make_unique<PlatformAudio>();
141+
} catch (const PlatformAudioError& error) {
142+
GTEST_SKIP() << "PlatformAudio unavailable: " << error.what();
143+
}
140144

141145
// Enumeration must succeed even on headless runners (it may return empty).
142146
std::vector<AudioDeviceInfo> recording_devices;

0 commit comments

Comments
 (0)