summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2023-03-14 21:50:20 +0100
committerLinus Groh <mail@linusgroh.de>2023-03-19 14:15:35 +0000
commit73a367a00a74b7ddcbaa4114026bee97dffc17c8 (patch)
tree261da7391982eee78bc954e88a1b48306027a3cc /Tests
parent904a4dd314f81a9fa846809aa8cc409eb7135364 (diff)
downloadserenity-73a367a00a74b7ddcbaa4114026bee97dffc17c8.zip
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.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibAudio/TestFLACSpec.cpp60
1 files changed, 25 insertions, 35 deletions
diff --git a/Tests/LibAudio/TestFLACSpec.cpp b/Tests/LibAudio/TestFLACSpec.cpp
index 833e659152..cbecc3f815 100644
--- a/Tests/LibAudio/TestFLACSpec.cpp
+++ b/Tests/LibAudio/TestFLACSpec.cpp
@@ -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;
});
}