Serenity Operating System
at master 58 lines 2.1 kB view raw
1/* 2 * Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/LexicalPath.h> 8#include <LibAudio/FlacLoader.h> 9#include <LibCore/Directory.h> 10#include <LibTest/TestCase.h> 11 12struct FlacTest : Test::TestCase { 13 FlacTest(LexicalPath path) 14 : Test::TestCase( 15 DeprecatedString::formatted("flac_spec_test_{}", path.basename()), [this]() { run(); }, false) 16 , m_path(move(path)) 17 { 18 } 19 20 void run() const 21 { 22 auto result = Audio::FlacLoaderPlugin::create(m_path.string()); 23 if (result.is_error()) { 24 FAIL(DeprecatedString::formatted("{} (at {})", result.error().description, result.error().index)); 25 return; 26 } 27 28 auto loader = result.release_value(); 29 30 while (true) { 31 auto maybe_samples = loader->load_chunks(2 * MiB); 32 if (maybe_samples.is_error()) { 33 FAIL(DeprecatedString::formatted("{} (at {})", maybe_samples.error().description, maybe_samples.error().index)); 34 return; 35 } 36 maybe_samples.value().remove_all_matching([](auto& chunk) { return chunk.is_empty(); }); 37 if (maybe_samples.value().is_empty()) 38 return; 39 } 40 } 41 42 LexicalPath m_path; 43}; 44 45struct DiscoverFLACTestsHack { 46 DiscoverFLACTestsHack() 47 { 48 // FIXME: Also run (our own) tests in this directory. 49 (void)Core::Directory::for_each_entry("./SpecTests"sv, Core::DirIterator::Flags::SkipParentAndBaseDir, [](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> { 50 auto path = LexicalPath::join(directory.path().string(), entry.name); 51 if (path.extension() == "flac"sv) 52 Test::add_test_case_to_suite(make_ref_counted<FlacTest>(path)); 53 return IterationDecision::Continue; 54 }); 55 } 56}; 57// Hack taken from TEST_CASE; the above constructor will run as part of global initialization before the tests are actually executed 58static struct DiscoverFLACTestsHack hack;