From c5c7b633c80095a696b179514aaee6eea83182d0 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Thu, 28 Dec 2023 14:01:48 +0100 Subject: [PATCH] test: simple template for categorizer test (to be extended) --- CMakeLists.txt | 1 + test/categorizer_test.cpp | 81 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 test/categorizer_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f4cf14c..a47b656d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -594,6 +594,7 @@ if(WITH_TESTS) list(APPEND DWARFS_TESTS badfs_test block_merger_test + categorizer_test chmod_transformer_test compat_test dwarfs_test diff --git a/test/categorizer_test.cpp b/test/categorizer_test.cpp new file mode 100644 index 00000000..03b384b9 --- /dev/null +++ b/test/categorizer_test.cpp @@ -0,0 +1,81 @@ +/* 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 . + */ + +#include + +#include + +#include + +#include "dwarfs/filesystem_v2.h" +#include "dwarfs_tool_main.h" + +#include "mmap_mock.h" +#include "test_helpers.h" +#include "test_logger.h" + +using namespace dwarfs; + +namespace fs = std::filesystem; +// namespace po = boost::program_options; + +namespace { + +auto test_dir = fs::path(TEST_DATA_DIR).make_preferred(); +auto audio_data_dir = test_dir / "pcmaudio"; + +} // namespace + +class categorizer_test : public testing::TestWithParam {}; + +TEST_P(categorizer_test, end_to_end) { + auto level = GetParam(); + + auto input = std::make_shared(); + + input->add("", {1, 040755, 1, 0, 0, 10, 42, 0, 0, 0}); + input->add_local_files(audio_data_dir); + input->add_file("random", 4096, true); + + test::test_iolayer iolayer(input); + + std::vector args{"mkdwarfs", "-i", "/", + "-o", "-", "--categorize"}; + + auto exit_code = mkdwarfs_main(args, iolayer.get()); + + EXPECT_EQ(exit_code, 0); + + auto fsimage = iolayer.out(); + + auto mm = std::make_shared(std::move(fsimage)); + + test::test_logger lgr; + filesystem_v2 fs(lgr, mm); + + auto iv16 = fs.find("/test8.aiff"); + auto iv32 = fs.find("/test8.caf"); + + EXPECT_TRUE(iv16); + EXPECT_TRUE(iv32); +} + +INSTANTIATE_TEST_SUITE_P(dwarfs, categorizer_test, ::testing::Values("debug"));