mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:18:11 +00:00
Tests: Refactor FLAC spec test to not use a TestCase subclass
The deallocation of the test cases at the very end happens through a NonnullRefPtr<TestCase>, meaning the deallocation will assume the wrong object size and trip up ASAN. Therefore, we cannot use a TestCase subclass. I also took this opportunity and made use of the new LoaderError formatter.
This commit is contained in:
parent
904a4dd314
commit
73a367a00a
1 changed files with 25 additions and 35 deletions
|
@ -9,47 +9,37 @@
|
|||
#include <LibCore/Directory.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
struct FlacTest : Test::TestCase {
|
||||
FlacTest(LexicalPath path)
|
||||
: Test::TestCase(
|
||||
DeprecatedString::formatted("flac_spec_test_{}", path.basename()), [this]() { run(); }, false)
|
||||
, m_path(move(path))
|
||||
{
|
||||
}
|
||||
|
||||
void run() const
|
||||
{
|
||||
auto result = Audio::FlacLoaderPlugin::create(m_path.string());
|
||||
if (result.is_error()) {
|
||||
FAIL(DeprecatedString::formatted("{} (at {})", result.error().description, result.error().index));
|
||||
return;
|
||||
}
|
||||
|
||||
auto loader = result.release_value();
|
||||
|
||||
while (true) {
|
||||
auto maybe_samples = loader->load_chunks(2 * MiB);
|
||||
if (maybe_samples.is_error()) {
|
||||
FAIL(DeprecatedString::formatted("{} (at {})", maybe_samples.error().description, maybe_samples.error().index));
|
||||
return;
|
||||
}
|
||||
maybe_samples.value().remove_all_matching([](auto& chunk) { return chunk.is_empty(); });
|
||||
if (maybe_samples.value().is_empty())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LexicalPath m_path;
|
||||
};
|
||||
|
||||
struct DiscoverFLACTestsHack {
|
||||
DiscoverFLACTestsHack()
|
||||
{
|
||||
// FIXME: Also run (our own) tests in this directory.
|
||||
(void)Core::Directory::for_each_entry("./SpecTests"sv, Core::DirIterator::Flags::SkipParentAndBaseDir, [](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> {
|
||||
auto path = LexicalPath::join(directory.path().string(), entry.name);
|
||||
if (path.extension() == "flac"sv)
|
||||
Test::add_test_case_to_suite(make_ref_counted<FlacTest>(path));
|
||||
if (path.extension() == "flac"sv) {
|
||||
Test::add_test_case_to_suite(adopt_ref(*new ::Test::TestCase(
|
||||
DeprecatedString::formatted("flac_spec_test_{}", path.basename()),
|
||||
[path = move(path)]() {
|
||||
auto result = Audio::FlacLoaderPlugin::create(path.string());
|
||||
if (result.is_error()) {
|
||||
FAIL(DeprecatedString::formatted("{}", result.error()));
|
||||
return;
|
||||
}
|
||||
|
||||
auto loader = result.release_value();
|
||||
|
||||
while (true) {
|
||||
auto maybe_samples = loader->load_chunks(2 * MiB);
|
||||
if (maybe_samples.is_error()) {
|
||||
FAIL(DeprecatedString::formatted("{}", maybe_samples.error()));
|
||||
return;
|
||||
}
|
||||
maybe_samples.value().remove_all_matching([](auto& chunk) { return chunk.is_empty(); });
|
||||
if (maybe_samples.value().is_empty())
|
||||
return;
|
||||
}
|
||||
},
|
||||
false)));
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue