From 82ead48fa866254fb34d072a11404de93d9acf88 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 31 Aug 2024 08:27:23 -0500 Subject: [PATCH] updated build system --- support/include/utils/file.hpp | 206 ++---------------- .../include/utils/types/file/i_directory.hpp | 79 +++++++ support/include/utils/types/file/i_file.hpp | 93 ++++++++ .../include/utils/types/file/i_fs_item.hpp | 111 ++++++++++ support/src/utils/file.cpp | 3 +- support/test/include/test.hpp | 2 + support/test/src/test.cpp | 22 +- support/test/src/utils/file_test.cpp | 38 ++++ 8 files changed, 360 insertions(+), 194 deletions(-) create mode 100644 support/include/utils/types/file/i_directory.hpp create mode 100644 support/include/utils/types/file/i_file.hpp create mode 100644 support/include/utils/types/file/i_fs_item.hpp diff --git a/support/include/utils/file.hpp b/support/include/utils/file.hpp index b8dc2ed1..d40ffea4 100644 --- a/support/include/utils/file.hpp +++ b/support/include/utils/file.hpp @@ -25,50 +25,28 @@ #include "utils/config.hpp" #include "utils/path.hpp" +#include "utils/types/file/i_directory.hpp" +#include "utils/types/file/i_file.hpp" +#include "utils/types/file/i_fs_item.hpp" namespace repertory::utils::file { -enum class time_type { - accessed, - created, - modified, - written, -}; - -struct file_times final { - std::uint64_t accessed{}; - std::uint64_t created{}; - std::uint64_t modified{}; - std::uint64_t written{}; - - [[nodiscard]] auto get(time_type type) const -> std::uint64_t { - switch (type) { - case time_type::accessed: - return accessed; - case time_type::created: - return created; - case time_type::modified: - return modified; - case time_type::written: - return written; - } - - throw std::runtime_error("type_type not supported"); - } -}; - [[nodiscard]] auto change_to_process_directory() -> bool; +// INFO: has test [[nodiscard]] inline auto directory_exists_in_path(std::string_view path, std::string_view sub_directory) -> bool; +// INFO: has test [[nodiscard]] inline auto directory_exists_in_path(std::wstring_view path, std::wstring_view sub_directory) -> bool; +// INFO: has test [[nodiscard]] inline auto file_exists_in_path(std::string_view path, std::string_view file_name) -> bool; +// INFO: has test [[nodiscard]] inline auto file_exists_in_path(std::wstring_view path, std::wstring_view file_name) -> bool; @@ -102,12 +80,15 @@ get_total_drive_space(std::wstring_view path) -> std::optional; smb_create_and_validate_relative_path(std::string_view smb_path, std::string_view rel_path) -> std::string; +// INFO: has test [[nodiscard]] auto smb_create_relative_path(std::string_view smb_path) -> std::string; +// INFO: has test [[nodiscard]] auto smb_create_search_path(std::string_view smb_path) -> std::string; +// INFO: has test [[nodiscard]] auto smb_create_smb_path(std::string_view smb_path, std::string_view rel_path) -> std::string; @@ -125,129 +106,18 @@ smb_get_parent_path(std::string_view smb_path) -> std::string; std::string_view user, std::string_view password) -> std::string; +// INFO: has test [[nodiscard]] auto smb_parent_is_same(std::string_view smb_path1, std::string_view smb_path2) -> bool; #endif // defined(PROJECT_ENABLE_LIBDSM) -struct i_fs_item { - using fs_item_t = std::unique_ptr; - - virtual ~i_fs_item() = default; - - [[nodiscard]] virtual auto copy_to(std::string_view to_path, - bool overwrite) const -> bool = 0; - - [[nodiscard]] virtual auto copy_to(std::wstring_view new_path, - bool overwrite) -> bool { - return copy_to(utils::string::to_utf8(new_path), overwrite); - } - - [[nodiscard]] virtual auto exists() const -> bool = 0; - - [[nodiscard]] virtual auto get_path() const -> std::string = 0; - - [[nodiscard]] virtual auto - get_time(time_type type) const -> std::optional; - - [[nodiscard]] virtual auto is_directory_item() const -> bool = 0; - - [[nodiscard]] auto is_file_item() const -> bool { - return not is_directory_item(); - } - - [[nodiscard]] virtual auto is_symlink() const -> bool = 0; - - [[nodiscard]] virtual auto move_to(std::string_view new_path) -> bool = 0; - - [[nodiscard]] virtual auto move_to(std::wstring_view new_path) -> bool { - return move_to(utils::string::to_utf8(new_path)); - } - - [[nodiscard]] virtual auto remove() -> bool = 0; - -public: - [[nodiscard]] virtual operator bool() const = 0; - -protected: - i_fs_item() noexcept = default; - - i_fs_item(const i_fs_item &) noexcept = default; - - i_fs_item(i_fs_item &&) noexcept = default; - - auto operator=(i_fs_item &&) noexcept -> i_fs_item & = default; - - auto operator=(const i_fs_item &) noexcept -> i_fs_item & = default; -}; - -struct i_file : public i_fs_item { - using fs_file_t = std::unique_ptr; - - virtual ~i_file() = default; - - virtual void close() = 0; - - virtual void flush() const = 0; - - [[nodiscard]] virtual auto get_handle() const -> native_handle = 0; - - [[nodiscard]] virtual auto get_read_buffer_size() const -> std::uint32_t = 0; - - [[nodiscard]] auto is_directory_item() const -> bool override { - return false; - } - - [[nodiscard]] virtual auto is_read_only() const -> bool = 0; - - [[nodiscard]] virtual auto read(data_buffer &data, std::uint64_t offset, - std::size_t *total_read = nullptr) -> bool { - return read(data.data(), data.size(), offset, total_read); - } - - [[nodiscard]] virtual auto - read(unsigned char *data, std::size_t to_read, std::uint64_t offset, - std::size_t *total_read = nullptr) -> bool = 0; - - [[nodiscard]] virtual auto - read_all(data_buffer &data, std::uint64_t offset, - std::size_t *total_read = nullptr) -> bool; - - virtual auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t = 0; - - [[nodiscard]] virtual auto size() const -> std::optional = 0; - - [[nodiscard]] virtual auto truncate() -> bool { return truncate(0U); } - - [[nodiscard]] virtual auto truncate(std::size_t size) -> bool = 0; - - [[nodiscard]] virtual auto - write(const data_buffer &data, std::uint64_t offset, - std::size_t *total_written = nullptr) -> bool { - return write(data.data(), data.size(), offset, total_written); - } - - [[nodiscard]] virtual auto - write(const unsigned char *data, std::size_t to_write, std::size_t offset, - std::size_t *total_written = nullptr) -> bool = 0; - -protected: - i_file() noexcept = default; - - i_file(const i_file &) noexcept = default; - - i_file(i_file &&) noexcept = default; - - auto operator=(i_file &&) noexcept -> i_file & = default; - - auto operator=(const i_file &) noexcept -> i_file & = default; -}; - class file final : public i_file { public: // [[nodiscard]] static auto // attach_file(native_handle handle, // bool read_only = false) -> fs_file_t; + // INFO: has test [[nodiscard]] static auto open_file(std::string_view path, bool read_only = false) -> fs_file_t; @@ -256,6 +126,7 @@ public: return open_file(utils::string::to_utf8(path), read_only); } + // INFO: has test [[nodiscard]] static auto open_or_create_file(std::string_view path, bool read_only = false) -> fs_file_t; @@ -578,53 +449,6 @@ public: } }; -struct i_directory : public i_fs_item { - using fs_directory_t = std::unique_ptr; - using fs_file_t = i_file::fs_file_t; - - virtual ~i_directory() = default; - - [[nodiscard]] virtual auto - count(bool recursive = false) const -> std::uint64_t = 0; - - [[nodiscard]] virtual auto - create_directory(std::string_view path = "") const -> fs_directory_t = 0; - - [[nodiscard]] virtual auto create_file(std::string_view file_name, - bool read_only) const -> fs_file_t = 0; - - [[nodiscard]] auto is_directory_item() const -> bool override { return true; } - - [[nodiscard]] virtual auto - get_directory(std::string_view path) const -> fs_directory_t = 0; - - [[nodiscard]] virtual auto - get_directories() const -> std::vector = 0; - - [[nodiscard]] virtual auto - get_file(std::string_view path) const -> fs_file_t = 0; - - [[nodiscard]] virtual auto get_files() const -> std::vector = 0; - - [[nodiscard]] virtual auto get_items() const -> std::vector = 0; - - [[nodiscard]] virtual auto remove_recursively() -> bool = 0; - - [[nodiscard]] virtual auto - size(bool recursive = false) const -> std::uint64_t = 0; - -protected: - i_directory() noexcept = default; - - i_directory(const i_directory &) noexcept = default; - - i_directory(i_directory &&) noexcept = default; - - auto operator=(i_directory &&) noexcept -> i_directory & = default; - - auto operator=(const i_directory &) noexcept -> i_directory & = default; -}; - class directory final : public i_directory { public: using directory_t = std::unique_ptr; @@ -936,6 +760,7 @@ public: read_json_file(std::string_view path, nlohmann::json &data, std::optional password = std::nullopt) -> bool; +// INFO: has test [[nodiscard]] auto read_json_file( std::wstring_view path, nlohmann::json &data, std::optional password = std::nullopt) -> bool; @@ -944,16 +769,19 @@ read_json_file(std::string_view path, nlohmann::json &data, std::string_view path, const nlohmann::json &data, std::optional password = std::nullopt) -> bool; +// INFO: has test [[nodiscard]] auto write_json_file( std::wstring_view path, const nlohmann::json &data, std::optional password = std::nullopt) -> bool; #else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) +// INFO: has test [[nodiscard]] auto read_json_file(std::string_view path, nlohmann::json &data) -> bool; [[nodiscard]] auto read_json_file(std::wstring_view path, nlohmann::json &data) -> bool; +// INFO: has test [[nodiscard]] auto write_json_file(std::string_view path, const nlohmann::json &data) -> bool; diff --git a/support/include/utils/types/file/i_directory.hpp b/support/include/utils/types/file/i_directory.hpp new file mode 100644 index 00000000..8a9d6337 --- /dev/null +++ b/support/include/utils/types/file/i_directory.hpp @@ -0,0 +1,79 @@ +/* + Copyright <2018-2024> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#ifndef FIFTHGRID_INCLUDE_TYPES_FILE_I_DIRECTORY_HPP_ +#define FIFTHGRID_INCLUDE_TYPES_FILE_I_DIRECTORY_HPP_ + +#include "utils/config.hpp" + +#include "utils/types/file/i_file.hpp" +#include "utils/types/file/i_fs_item.hpp" + +namespace fifthgrid::utils::file { +struct i_directory : public i_fs_item { + using fs_directory_t = std::unique_ptr; + using fs_file_t = i_file::fs_file_t; + + virtual ~i_directory() = default; + + [[nodiscard]] virtual auto + count(bool recursive = false) const -> std::uint64_t = 0; + + [[nodiscard]] virtual auto + create_directory(std::string_view path = "") const -> fs_directory_t = 0; + + [[nodiscard]] virtual auto create_file(std::string_view file_name, + bool read_only) const -> fs_file_t = 0; + + [[nodiscard]] auto is_directory_item() const -> bool override { return true; } + + [[nodiscard]] virtual auto + get_directory(std::string_view path) const -> fs_directory_t = 0; + + [[nodiscard]] virtual auto + get_directories() const -> std::vector = 0; + + [[nodiscard]] virtual auto + get_file(std::string_view path) const -> fs_file_t = 0; + + [[nodiscard]] virtual auto get_files() const -> std::vector = 0; + + [[nodiscard]] virtual auto get_items() const -> std::vector = 0; + + [[nodiscard]] virtual auto remove_recursively() -> bool = 0; + + [[nodiscard]] virtual auto + size(bool recursive = false) const -> std::uint64_t = 0; + +protected: + i_directory() noexcept = default; + + i_directory(const i_directory &) noexcept = default; + + i_directory(i_directory &&) noexcept = default; + + auto operator=(i_directory &&) noexcept -> i_directory & = default; + + auto operator=(const i_directory &) noexcept -> i_directory & = default; +}; +} // namespace fifthgrid::utils::file + +#endif // FIFTHGRID_INCLUDE_TYPES_FILE_I_DIRECTORY_HPP_ diff --git a/support/include/utils/types/file/i_file.hpp b/support/include/utils/types/file/i_file.hpp new file mode 100644 index 00000000..17548006 --- /dev/null +++ b/support/include/utils/types/file/i_file.hpp @@ -0,0 +1,93 @@ +/* + Copyright <2018-2024> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#ifndef FIFTHGRID_INCLUDE_TYPES_FILE_I_FILE_HPP_ +#define FIFTHGRID_INCLUDE_TYPES_FILE_I_FILE_HPP_ + +#include "utils/config.hpp" + +#include "utils/types/file/i_fs_item.hpp" + +namespace fifthgrid::utils::file { +struct i_file : public i_fs_item { + using fs_file_t = std::unique_ptr; + + virtual ~i_file() = default; + + virtual void close() = 0; + + virtual void flush() const = 0; + + [[nodiscard]] virtual auto get_handle() const -> native_handle = 0; + + [[nodiscard]] virtual auto get_read_buffer_size() const -> std::uint32_t = 0; + + [[nodiscard]] auto is_directory_item() const -> bool override { + return false; + } + + [[nodiscard]] virtual auto is_read_only() const -> bool = 0; + + [[nodiscard]] virtual auto read(data_buffer &data, std::uint64_t offset, + std::size_t *total_read = nullptr) -> bool { + return read(data.data(), data.size(), offset, total_read); + } + + [[nodiscard]] virtual auto + read(unsigned char *data, std::size_t to_read, std::uint64_t offset, + std::size_t *total_read = nullptr) -> bool = 0; + + [[nodiscard]] virtual auto + read_all(data_buffer &data, std::uint64_t offset, + std::size_t *total_read = nullptr) -> bool; + + virtual auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t = 0; + + [[nodiscard]] virtual auto size() const -> std::optional = 0; + + [[nodiscard]] virtual auto truncate() -> bool { return truncate(0U); } + + [[nodiscard]] virtual auto truncate(std::size_t size) -> bool = 0; + + [[nodiscard]] virtual auto + write(const data_buffer &data, std::uint64_t offset, + std::size_t *total_written = nullptr) -> bool { + return write(data.data(), data.size(), offset, total_written); + } + + [[nodiscard]] virtual auto + write(const unsigned char *data, std::size_t to_write, std::size_t offset, + std::size_t *total_written = nullptr) -> bool = 0; + +protected: + i_file() noexcept = default; + + i_file(const i_file &) noexcept = default; + + i_file(i_file &&) noexcept = default; + + auto operator=(i_file &&) noexcept -> i_file & = default; + + auto operator=(const i_file &) noexcept -> i_file & = default; +}; +} // namespace fifthgrid::utils::file + +#endif // FIFTHGRID_INCLUDE_TYPES_FILE_I_FILE_HPP_ diff --git a/support/include/utils/types/file/i_fs_item.hpp b/support/include/utils/types/file/i_fs_item.hpp new file mode 100644 index 00000000..fd6878cf --- /dev/null +++ b/support/include/utils/types/file/i_fs_item.hpp @@ -0,0 +1,111 @@ +/* + Copyright <2018-2024> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#ifndef FIFTHGRID_INCLUDE_TYPES_FILE_I_FS_ITEM_HPP_ +#define FIFTHGRID_INCLUDE_TYPES_FILE_I_FS_ITEM_HPP_ + +#include "utils/config.hpp" + +#include "utils/string.hpp" + +namespace fifthgrid::utils::file { +enum class time_type { + accessed, + created, + modified, + written, +}; + +struct file_times final { + std::uint64_t accessed{}; + std::uint64_t created{}; + std::uint64_t modified{}; + std::uint64_t written{}; + + [[nodiscard]] auto get(time_type type) const -> std::uint64_t { + switch (type) { + case time_type::accessed: + return accessed; + case time_type::created: + return created; + case time_type::modified: + return modified; + case time_type::written: + return written; + } + + throw std::runtime_error("type_type not supported"); + } +}; + +struct i_fs_item { + using fs_item_t = std::unique_ptr; + + virtual ~i_fs_item() = default; + + [[nodiscard]] virtual auto copy_to(std::string_view to_path, + bool overwrite) const -> bool = 0; + + [[nodiscard]] virtual auto copy_to(std::wstring_view new_path, + bool overwrite) -> bool { + return copy_to(utils::string::to_utf8(new_path), overwrite); + } + + [[nodiscard]] virtual auto exists() const -> bool = 0; + + [[nodiscard]] virtual auto get_path() const -> std::string = 0; + + [[nodiscard]] virtual auto + get_time(time_type type) const -> std::optional; + + [[nodiscard]] virtual auto is_directory_item() const -> bool = 0; + + [[nodiscard]] auto is_file_item() const -> bool { + return not is_directory_item(); + } + + [[nodiscard]] virtual auto is_symlink() const -> bool = 0; + + [[nodiscard]] virtual auto move_to(std::string_view new_path) -> bool = 0; + + [[nodiscard]] virtual auto move_to(std::wstring_view new_path) -> bool { + return move_to(utils::string::to_utf8(new_path)); + } + + [[nodiscard]] virtual auto remove() -> bool = 0; + +public: + [[nodiscard]] virtual operator bool() const = 0; + +protected: + i_fs_item() noexcept = default; + + i_fs_item(const i_fs_item &) noexcept = default; + + i_fs_item(i_fs_item &&) noexcept = default; + + auto operator=(i_fs_item &&) noexcept -> i_fs_item & = default; + + auto operator=(const i_fs_item &) noexcept -> i_fs_item & = default; +}; +} // namespace fifthgrid::utils::file + +#endif // FIFTHGRID_INCLUDE_TYPES_FILE_I_FS_ITEM_HPP_ diff --git a/support/src/utils/file.cpp b/support/src/utils/file.cpp index 8145a1bc..b9f7b04d 100644 --- a/support/src/utils/file.cpp +++ b/support/src/utils/file.cpp @@ -83,7 +83,8 @@ auto get_free_drive_space(std::string_view path) try { #if defined(_WIN32) ULARGE_INTEGER li{}; - if (not ::GetDiskFreeSpaceEx(path.c_str(), &li, nullptr, nullptr)) { + if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr, + nullptr)) { throw std::runtime_error("failed to get free disk space|" + std::string{path} + '|' + std::to_string(utils::get_last_error_code())); diff --git a/support/test/include/test.hpp b/support/test/include/test.hpp index 9ad4e232..df9498e9 100644 --- a/support/test/include/test.hpp +++ b/support/test/include/test.hpp @@ -53,6 +53,8 @@ static void decrypt_and_verify(const buffer_t &buffer, std::string_view token, } #endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) +auto generate_test_directory() -> utils::file::i_directory &; + [[nodiscard]] auto get_test_input_dir() -> std::string; [[nodiscard]] auto get_test_output_dir() -> std::string; diff --git a/support/test/src/test.cpp b/support/test/src/test.cpp index 1536a5e0..42bcf44d 100644 --- a/support/test/src/test.cpp +++ b/support/test/src/test.cpp @@ -24,7 +24,7 @@ namespace { static std::recursive_mutex file_mtx{}; -static std::vector> +static std::vector> generated_files{}; static void delete_generated_files() { @@ -32,8 +32,7 @@ static void delete_generated_files() { std::optional parent_path; for (auto &&path : generated_files) { if (parent_path->empty()) { - parent_path = - repertory::utils::path::get_parent_path(path->get_path()); + parent_path = repertory::utils::path::get_parent_path(path->get_path()); } [[maybe_unused]] auto removed = path->remove(); @@ -73,10 +72,25 @@ auto create_random_file(std::size_t size) -> utils::file::i_file & { } generated_files.emplace_back(std::move(file)); - return *generated_files.back(); + return *dynamic_cast(generated_files.back().get()); } #endif // defined(PROJECT_ENABLE_LIBSODIUM) +auto generate_test_directory() -> utils::file::i_directory & { + recur_mutex_lock lock{file_mtx}; + + auto path = utils::path::combine( + get_test_output_dir(), + { + std::string{"test_dir"} + std::to_string(generated_files.size()), + }); + generated_files.emplace_back(std::unique_ptr( + new utils::file::directory{path})); + + return *dynamic_cast( + generated_files.back().get()); +} + auto generate_test_file_name(std::string_view file_name_no_extension) -> std::string { recur_mutex_lock lock{file_mtx}; diff --git a/support/test/src/utils/file_test.cpp b/support/test/src/utils/file_test.cpp index c991c57f..330898b6 100644 --- a/support/test/src/utils/file_test.cpp +++ b/support/test/src/utils/file_test.cpp @@ -262,4 +262,42 @@ TEST(utils_file, smb_parent_is_not_same) { EXPECT_FALSE(utils::file::smb_parent_is_same(path1, path2)); } #endif // defined(PROJECT_ENABLE_LIBDSM) + +TEST(util_file, directory_exists_in_path) { + auto &test_dir = test::generate_test_directory(); + auto sub_dir = test_dir.create_directory("moose"); + EXPECT_TRUE(sub_dir != nullptr); + if (sub_dir) { + EXPECT_TRUE( + utils::file::directory_exists_in_path(test_dir.get_path(), "moose")); + + EXPECT_FALSE( + utils::file::file_exists_in_path(test_dir.get_path(), "moose")); + + EXPECT_TRUE(utils::file::directory_exists_in_path( + utils::string::from_utf8(test_dir.get_path()), L"moose")); + + EXPECT_FALSE(utils::file::file_exists_in_path( + utils::string::from_utf8(test_dir.get_path()), L"moose")); + } +} + +TEST(util_file, file_exists_in_path) { + auto &test_dir = test::generate_test_directory(); + auto sub_file = test_dir.create_file("moose.txt", false); + EXPECT_TRUE(sub_file != nullptr); + if (sub_file) { + EXPECT_TRUE( + utils::file::file_exists_in_path(test_dir.get_path(), "moose.txt")); + + EXPECT_FALSE(utils::file::directory_exists_in_path(test_dir.get_path(), + "moose.txt")); + + EXPECT_TRUE(utils::file::file_exists_in_path( + utils::string::from_utf8(test_dir.get_path()), L"moose.txt")); + + EXPECT_FALSE(utils::file::directory_exists_in_path( + utils::string::from_utf8(test_dir.get_path()), L"moose.txt")); + } +} } // namespace repertory