mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 03:49:44 -04:00
Add some pcmaudio categorizer tests
This commit is contained in:
parent
0f0505947c
commit
dbd5502f82
@ -569,6 +569,8 @@ if(WITH_TESTS)
|
||||
add_executable(dwarfs_utils_test test/utils_test.cpp)
|
||||
add_executable(dwarfs_pcm_sample_transformer_test
|
||||
test/pcm_sample_transformer_test.cpp)
|
||||
add_executable(dwarfs_pcmaudio_categorizer_test
|
||||
test/pcmaudio_categorizer_test.cpp)
|
||||
|
||||
target_link_libraries(dwarfs_test test_helpers gtest gtest_main)
|
||||
target_link_libraries(dwarfs_compat_test gtest gtest_main)
|
||||
@ -576,9 +578,12 @@ if(WITH_TESTS)
|
||||
target_link_libraries(dwarfs_tools_test test_helpers gtest gtest_main)
|
||||
target_link_libraries(dwarfs_utils_test gtest gtest_main)
|
||||
target_link_libraries(dwarfs_pcm_sample_transformer_test gtest gtest_main)
|
||||
target_link_libraries(dwarfs_pcmaudio_categorizer_test gtest gtest_main gmock_main
|
||||
"$<LINK_LIBRARY:WHOLE_ARCHIVE,dwarfs_categorizer>")
|
||||
|
||||
list(APPEND BINARY_TARGETS dwarfs_test dwarfs_compat_test dwarfs_badfs_test
|
||||
dwarfs_tools_test dwarfs_utils_test dwarfs_pcm_sample_transformer_test)
|
||||
dwarfs_tools_test dwarfs_utils_test dwarfs_pcm_sample_transformer_test
|
||||
dwarfs_pcmaudio_categorizer_test)
|
||||
|
||||
gtest_discover_tests(dwarfs_test DISCOVERY_TIMEOUT 120)
|
||||
gtest_discover_tests(dwarfs_compat_test DISCOVERY_TIMEOUT 120)
|
||||
@ -586,6 +591,7 @@ if(WITH_TESTS)
|
||||
gtest_discover_tests(dwarfs_tools_test DISCOVERY_TIMEOUT 120)
|
||||
gtest_discover_tests(dwarfs_utils_test DISCOVERY_TIMEOUT 120)
|
||||
gtest_discover_tests(dwarfs_pcm_sample_transformer_test DISCOVERY_TIMEOUT 120)
|
||||
gtest_discover_tests(dwarfs_pcmaudio_categorizer_test DISCOVERY_TIMEOUT 120)
|
||||
|
||||
if(FLAC_FOUND)
|
||||
add_executable(dwarfs_flac_compressor_test test/flac_compressor_test.cpp)
|
||||
@ -600,6 +606,9 @@ if(WITH_TESTS)
|
||||
target_compile_definitions(dwarfs_badfs_test
|
||||
PRIVATE TEST_DATA_DIR=\"${CMAKE_SOURCE_DIR}/test\")
|
||||
|
||||
target_compile_definitions(dwarfs_pcmaudio_categorizer_test
|
||||
PRIVATE TEST_DATA_DIR=\"${CMAKE_SOURCE_DIR}/test\")
|
||||
|
||||
target_compile_definitions(
|
||||
dwarfs_tools_test
|
||||
PRIVATE TEST_DATA_DIR=\"${CMAKE_SOURCE_DIR}/test\"
|
||||
|
122
test/pcmaudio_categorizer_test.cpp
Normal file
122
test/pcmaudio_categorizer_test.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/**
|
||||
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||
*
|
||||
* This file is part of dwarfs.
|
||||
*
|
||||
* dwarfs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* dwarfs is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <folly/String.h>
|
||||
|
||||
#include "dwarfs/categorizer.h"
|
||||
#include "dwarfs/mmap.h"
|
||||
|
||||
#include "test_logger.h"
|
||||
|
||||
using namespace dwarfs;
|
||||
using testing::MatchesRegex;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
auto test_dir = fs::path(TEST_DATA_DIR);
|
||||
|
||||
TEST(pcmaudio_categorizer, requirements) {
|
||||
test::test_logger logger(logger::INFO);
|
||||
boost::program_options::variables_map vm;
|
||||
auto& catreg = categorizer_registry::instance();
|
||||
auto catmgr = categorizer_manager(logger);
|
||||
|
||||
catmgr.add(catreg.create(logger, "pcmaudio", vm));
|
||||
|
||||
try {
|
||||
catmgr.set_metadata_requirements(
|
||||
catmgr.category_value("pcmaudio/metadata").value(),
|
||||
R"({"endianness": ["set", ["big"]], "bytes_per_sample": ["range", 2, 3]})");
|
||||
FAIL() << "expected std::runtime_error";
|
||||
} catch (std::runtime_error const& e) {
|
||||
EXPECT_STREQ(
|
||||
"unsupported metadata requirements: bytes_per_sample, endianness",
|
||||
e.what());
|
||||
} catch (...) {
|
||||
FAIL() << "unexpected exception: "
|
||||
<< folly::exceptionStr(std::current_exception());
|
||||
}
|
||||
|
||||
catmgr.set_metadata_requirements(
|
||||
catmgr.category_value("pcmaudio/waveform").value(),
|
||||
R"({"endianness": ["set", ["mixed"]], "bytes_per_sample": ["range", 2, 3]})");
|
||||
|
||||
auto wav = test_dir / "pcmaudio" / "test16.wav";
|
||||
auto mm = mmap(wav);
|
||||
|
||||
{
|
||||
auto job = catmgr.job(wav);
|
||||
job.set_total_size(mm.size());
|
||||
|
||||
EXPECT_TRUE(logger.empty());
|
||||
|
||||
job.categorize_random_access(mm.span());
|
||||
auto frag = job.result();
|
||||
|
||||
ASSERT_EQ(1, logger.get_log().size());
|
||||
auto const& ent = logger.get_log().front();
|
||||
EXPECT_EQ(logger::WARN, ent.level);
|
||||
EXPECT_THAT(
|
||||
ent.output,
|
||||
MatchesRegex(
|
||||
R"(^\[WAV\] ".*": endianness 'little' does not meet requirements$)"));
|
||||
|
||||
EXPECT_TRUE(frag.empty());
|
||||
|
||||
logger.clear();
|
||||
}
|
||||
|
||||
catmgr.set_metadata_requirements(
|
||||
catmgr.category_value("pcmaudio/waveform").value(),
|
||||
R"({"endianness": ["set", ["big", "little"]], "bytes_per_sample": ["range", 1, 4]})");
|
||||
|
||||
{
|
||||
auto job = catmgr.job(wav);
|
||||
job.set_total_size(mm.size());
|
||||
|
||||
EXPECT_TRUE(logger.empty());
|
||||
|
||||
job.categorize_random_access(mm.span());
|
||||
auto frag = job.result();
|
||||
|
||||
EXPECT_TRUE(logger.empty());
|
||||
|
||||
EXPECT_EQ(2, frag.size());
|
||||
|
||||
auto const& first = frag.span()[0];
|
||||
auto const& second = frag.span()[1];
|
||||
EXPECT_EQ("pcmaudio/metadata",
|
||||
catmgr.category_name(first.category().value()));
|
||||
EXPECT_EQ(44, first.size());
|
||||
EXPECT_EQ("pcmaudio/waveform",
|
||||
catmgr.category_name(second.category().value()));
|
||||
EXPECT_EQ(14, second.size());
|
||||
EXPECT_EQ(mm.size(), first.size() + second.size());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user