mirror of
https://github.com/zebrajr/ladybird.git
synced 2026-01-15 12:15:15 +00:00
This doesn't help to reproduce the potential UAF in the previous commit, but it doesn't hurt to include this nonetheless.
58 lines
2.0 KiB
C++
58 lines
2.0 KiB
C++
/*
|
|
* Copyright (c) 2023-2025, Gregory Bertilson <gregory@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Math.h>
|
|
#include <AK/MemoryStream.h>
|
|
#include <AK/WeakPtr.h>
|
|
#include <LibCore/EventLoop.h>
|
|
#include <LibCore/System.h>
|
|
#include <LibMedia/Audio/PlaybackStream.h>
|
|
#include <LibTest/TestSuite.h>
|
|
|
|
#if defined(HAVE_PULSEAUDIO)
|
|
# include <LibMedia/Audio/PulseAudioWrappers.h>
|
|
#endif
|
|
|
|
// We are unable to create a playback stream on windows without an audio output device, so this would fail in CI
|
|
#if !defined(AK_OS_WINDOWS)
|
|
|
|
TEST_CASE(create_and_destroy_playback_stream)
|
|
{
|
|
Core::EventLoop event_loop;
|
|
|
|
bool has_implementation = false;
|
|
# if defined(HAVE_PULSEAUDIO) || defined(AK_OS_MACOS)
|
|
has_implementation = true;
|
|
# endif
|
|
|
|
{
|
|
auto stream_result = Audio::PlaybackStream::create(Audio::OutputState::Playing, 100, [](Audio::SampleSpecification) {}, [](Span<float> buffer) -> ReadonlySpan<float> { return buffer.trim(0); });
|
|
if (has_implementation) {
|
|
auto stream = stream_result.release_value();
|
|
EXPECT_EQ(stream->total_time_played(), AK::Duration::zero());
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
stream->resume()->when_rejected([](Error const&) { VERIFY_NOT_REACHED(); });
|
|
stream->drain_buffer_and_suspend()->when_rejected([](Error const&) { VERIFY_NOT_REACHED(); });
|
|
}
|
|
} else {
|
|
EXPECT(stream_result.is_error());
|
|
dbgln("Failed to create playback stream: {}", stream_result.error());
|
|
}
|
|
}
|
|
|
|
# if defined(HAVE_PULSEAUDIO)
|
|
// The PulseAudio context is kept alive by the PlaybackStream's control thread, which blocks on
|
|
// some operations, so it won't necessarily be destroyed immediately.
|
|
auto wait_start = MonotonicTime::now_coarse();
|
|
while (Audio::PulseAudioContext::is_connected()) {
|
|
if (MonotonicTime::now_coarse() - wait_start > AK::Duration::from_milliseconds(100))
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
# endif
|
|
}
|
|
#endif
|