move to new build system

This commit is contained in:
2024-06-06 14:17:47 -05:00
parent 88d8bf63f5
commit aee68520b3
563 changed files with 4283 additions and 361439 deletions

View File

@ -0,0 +1,158 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
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 TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
#define TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
#ifndef _WIN32
#include "test_common.hpp"
#include "drives/fuse/i_fuse_drive.hpp"
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
class mock_fuse_drive final : public virtual i_fuse_drive {
public:
explicit mock_fuse_drive(std::string mount_location)
: mount_location_(std::move(mount_location)) {}
private:
std::string mount_location_;
std::unordered_map<std::string, api_meta_map> meta_;
public:
auto check_owner(const std::string &) const -> api_error override {
return api_error::success;
}
auto check_parent_access(const std::string &, int) const
-> api_error override {
return api_error::success;
}
auto get_directory_item_count(const std::string &) const
-> std::uint64_t override {
return 1;
}
auto get_directory_items(const std::string &) const
-> directory_item_list override {
directory_item_list list{};
directory_item dir_item{};
dir_item.api_path = ".";
dir_item.directory = true;
dir_item.size = 0;
dir_item.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(dir_item);
dir_item.api_path = "..";
list.emplace_back(dir_item);
return list;
}
auto get_file_size(const std::string &) const -> std::uint64_t override {
return 0U;
}
auto get_item_meta(const std::string &api_path, api_meta_map &meta) const
-> api_error override {
meta = const_cast<mock_fuse_drive *>(this)->meta_[api_path];
return api_error::success;
}
auto get_item_meta(const std::string &api_path, const std::string &name,
std::string &value) const -> api_error override {
value = const_cast<mock_fuse_drive *>(this)->meta_[api_path][name];
if (value.empty()) {
value = "0";
}
return api_error::success;
}
auto get_total_drive_space() const -> std::uint64_t override {
return 100ULL * 1024ULL * 1024ULL;
}
auto get_total_item_count() const -> std::uint64_t override { return 0U; }
auto get_used_drive_space() const -> std::uint64_t override { return 0U; }
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const override {
free_size = 100u;
total_size = 200u;
volume_label = "TestVolumeLabel";
}
auto rename_directory(const std::string &from_api_path,
const std::string &to_api_path) -> int override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
utils::path::combine(mount_location_, {to_api_path});
return rename(from_file_path.c_str(), to_file_path.c_str());
}
auto rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite)
-> int override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
utils::path::combine(mount_location_, {to_api_path});
if (overwrite) {
if (not utils::file::retry_delete_file(to_file_path)) {
return -1;
}
} else if (utils::file::is_directory(to_file_path) ||
utils::file::is_file(to_file_path)) {
errno = EEXIST;
return -1;
}
return rename(from_file_path.c_str(), to_file_path.c_str());
}
auto is_processing(const std::string &) const -> bool override {
return false;
}
void set_item_meta(const std::string &api_path, const std::string &key,
const std::string &value) override {
meta_[api_path][key] = value;
}
};
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_

View File

@ -0,0 +1,98 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
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 TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
#define TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
#include "test_common.hpp"
#include "file_manager/i_open_file.hpp"
namespace repertory {
class mock_open_file : public virtual i_closeable_open_file {
public:
MOCK_METHOD(std::string, get_api_path, (), (const, override));
MOCK_METHOD(std::size_t, get_chunk_size, (), (const, override));
MOCK_METHOD(std::uint64_t, get_file_size, (), (const, override));
MOCK_METHOD(filesystem_item, get_filesystem_item, (), (const, override));
MOCK_METHOD(open_file_data, get_open_data, (std::uint64_t handle),
(const, override));
MOCK_METHOD(std::size_t, get_open_file_count, (), (const, override));
MOCK_METHOD(boost::dynamic_bitset<>, get_read_state, (), (const, override));
MOCK_METHOD(bool, get_read_state, (std::size_t chunk), (const, override));
MOCK_METHOD(std::string, get_source_path, (), (const, override));
MOCK_METHOD(bool, has_handle, (std::uint64_t handle), (const, override));
MOCK_METHOD(bool, is_directory, (), (const, override));
MOCK_METHOD(api_error, native_operation, (native_operation_callback callback),
(override));
MOCK_METHOD(api_error, native_operation,
(std::uint64_t new_file_size, native_operation_callback callback),
(override));
MOCK_METHOD(api_error, read,
(std::size_t read_size, std::uint64_t read_offset,
data_buffer &data),
(override));
MOCK_METHOD(api_error, resize, (std::uint64_t new_file_size), (override));
MOCK_METHOD(void, set_api_path, (const std::string &api_path), (override));
MOCK_METHOD(api_error, write,
(std::uint64_t write_offset, const data_buffer &data,
std::size_t &bytes_written),
(override));
MOCK_METHOD(void, add, (std::uint64_t handle, open_file_data ofd),
(override));
MOCK_METHOD(bool, can_close, (), (const, override));
MOCK_METHOD(bool, close, (), (override));
MOCK_METHOD(std::vector<std::uint64_t>, get_handles, (), (const, override));
MOCK_METHOD((std::map<std::uint64_t, open_file_data>), get_open_data, (),
(const, override));
MOCK_METHOD(bool, is_complete, (), (const, override));
MOCK_METHOD(bool, is_modified, (), (const, override));
MOCK_METHOD(bool, is_write_supported, (), (const, override));
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_OPEN_FILE_HPP_

View File

@ -0,0 +1,162 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
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 TESTS_MOCKS_MOCK_PROVIDER_HPP_
#define TESTS_MOCKS_MOCK_PROVIDER_HPP_
#include "test_common.hpp"
#include "providers/i_provider.hpp"
#include "types/repertory.hpp"
namespace repertory {
class mock_provider : public virtual i_provider {
public:
mock_provider(bool allow_rename = true) : allow_rename_(allow_rename) {}
private:
const bool allow_rename_;
public:
MOCK_METHOD(api_error, create_directory,
(const std::string &api_path, api_meta_map &meta), (override));
MOCK_METHOD(api_error, create_directory_clone_source_meta,
(const std::string &source_api_path, const std::string &api_path),
(override));
MOCK_METHOD(api_error, create_file,
(const std::string &api_path, api_meta_map &meta), (override));
MOCK_METHOD(api_error, get_api_path_from_source,
(const std::string &source_path, std::string &api_path),
(const, override));
MOCK_METHOD(std::uint64_t, get_directory_item_count,
(const std::string &api_path), (const, override));
MOCK_METHOD(api_error, get_directory_items,
(const std::string &api_path, directory_item_list &list),
(const, override));
MOCK_METHOD(api_error, get_file,
(const std::string &api_path, api_file &file), (const, override));
MOCK_METHOD(api_error, get_file_list, (api_file_list & list),
(const, override));
MOCK_METHOD(api_error, get_file_size,
(const std::string &api_path, std::uint64_t &file_size),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item,
(const std::string &api_path, bool directory,
filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item_and_file,
(const std::string &api_path, api_file &file,
filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item_from_source_path,
(const std::string &source_path, filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_item_meta,
(const std::string &api_path, api_meta_map &meta),
(const, override));
MOCK_METHOD(api_error, get_item_meta,
(const std::string &api_path, const std::string &key,
std::string &value),
(const, override));
MOCK_METHOD((std::vector<std::string>), get_pinned_files, (),
(const, override));
MOCK_METHOD(provider_type, get_provider_type, (), (const, override));
MOCK_METHOD(std::uint64_t, get_total_drive_space, (), (const, override));
MOCK_METHOD(std::uint64_t, get_total_item_count, (), (const, override));
MOCK_METHOD(std::uint64_t, get_used_drive_space, (), (const, override));
MOCK_METHOD(bool, is_direct_only, (), (const, override));
MOCK_METHOD(api_error, is_directory,
(const std::string &api_path, bool &exists), (const, override));
MOCK_METHOD(api_error, is_file, (const std::string &api_path, bool &exists),
(const, override));
bool is_file_writeable(const std::string & /* api_path */) const override {
return true;
}
MOCK_METHOD(bool, is_online, (), (const, override));
bool is_rename_supported() const override { return allow_rename_; }
MOCK_METHOD(api_error, read_file_bytes,
(const std::string &path, std::size_t size, std::uint64_t offset,
data_buffer &data, stop_type &stop_requested),
(override));
MOCK_METHOD(api_error, remove_directory, (const std::string &api_path),
(override));
MOCK_METHOD(api_error, remove_file, (const std::string &api_path),
(override));
MOCK_METHOD(api_error, remove_item_meta,
(const std::string &api_path, const std::string &key),
(override));
MOCK_METHOD(api_error, rename_file,
(const std::string &from_api_path,
const std::string &to_api_path),
(override));
MOCK_METHOD(api_error, set_item_meta,
(const std::string &api_path, const std::string &key,
const std::string &value),
(override));
MOCK_METHOD(api_error, set_item_meta,
(const std::string &api_path, const api_meta_map &meta),
(override));
MOCK_METHOD(bool, start,
(api_item_added_callback api_item_added, i_file_manager *fm),
(override));
MOCK_METHOD(void, stop, (), (override));
MOCK_METHOD(api_error, upload_file,
(const std::string &api_path, const std::string &source_path,
stop_type &stop_requested),
(override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_PROVIDER_HPP_

View File

@ -0,0 +1,44 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
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 TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#define TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#include "test_common.hpp"
#include "file_manager/i_upload_manager.hpp"
namespace repertory {
class mock_upload_manager : public i_upload_manager {
public:
MOCK_METHOD(void, queue_upload, (const i_open_file &o), (override));
MOCK_METHOD(void, remove_resume,
(const std::string &api_path, const std::string &source_path),
(override));
MOCK_METHOD(void, remove_upload, (const std::string &api_path), (override));
MOCK_METHOD(void, store_resume, (const i_open_file &o), (override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_

View File

@ -0,0 +1,168 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
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 TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#define TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#ifdef _WIN32
#include "test_common.hpp"
#include "drives/winfsp/i_winfsp_drive.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
class mock_winfsp_drive final : public virtual i_winfsp_drive {
public:
explicit mock_winfsp_drive(std::string mount_location)
: mount_location_(std::move(mount_location)) {}
private:
const std::string mount_location_;
public:
[[nodiscard]] auto
get_directory_item_count(const std::string & /*api_path*/) const
-> std::uint64_t override {
return 1;
}
[[nodiscard]] auto get_directory_items(const std::string & /*api_path*/) const
-> directory_item_list override {
directory_item_list list{};
directory_item di{};
di.api_path = ".";
di.directory = true;
di.size = 0u;
di.meta = {{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(di);
di.api_path = "..";
list.emplace_back(di);
return list;
}
[[nodiscard]] auto get_file_size(const std::string & /*api_path*/) const
-> std::uint64_t override {
return 0;
}
auto get_item_meta(const std::string & /*api_path*/, api_meta_map &meta) const
-> api_error override {
return api_error::error;
}
auto get_item_meta(const std::string & /*api_path*/,
const std::string & /*name*/,
std::string & /*value*/) const -> api_error override {
return api_error::error;
}
auto get_security_by_name(PWSTR /*file_name*/, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
std::uint64_t *descriptor_size)
-> NTSTATUS override {
auto ret = STATUS_SUCCESS;
if (attributes) {
*attributes = FILE_ATTRIBUTE_NORMAL;
}
if (descriptor_size) {
ULONG sz = 0;
PSECURITY_DESCRIPTOR sd = nullptr;
if (::ConvertStringSecurityDescriptorToSecurityDescriptor(
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)",
SDDL_REVISION_1, &sd, &sz)) {
if (sz > *descriptor_size) {
ret = STATUS_BUFFER_TOO_SMALL;
} else {
::CopyMemory(descriptor, sd, sz);
}
*descriptor_size = sz;
::LocalFree(sd);
} else {
ret = FspNtStatusFromWin32(::GetLastError());
}
}
return ret;
}
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override {
return 100 * 1024 * 1024;
}
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override {
return 0;
}
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override {
return 0;
}
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const override {
free_size = 100;
total_size = 200;
volume_label = "TestVolumeLabel";
}
auto populate_file_info(const std::string &api_path,
remote::file_info &file_info) -> api_error override {
const auto file_path = utils::path::combine(mount_location_, {api_path});
const auto directory = utils::file::is_directory(file_path);
const auto attributes =
FILE_FLAG_BACKUP_SEMANTICS |
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
const auto share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
auto handle = ::CreateFileA(&file_path[0], GENERIC_READ, share_mode,
nullptr, OPEN_EXISTING, attributes, nullptr);
FILE_BASIC_INFO fi{};
::GetFileInformationByHandleEx(handle, FileBasicInfo, &fi, sizeof(fi));
if (not directory) {
utils::file::get_file_size(file_path, file_info.FileSize);
}
file_info.AllocationSize =
directory ? 0
: utils::divide_with_ceiling(file_info.FileSize,
WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;
file_info.FileAttributes = fi.FileAttributes;
file_info.ChangeTime = fi.ChangeTime.QuadPart;
file_info.CreationTime = fi.CreationTime.QuadPart;
file_info.LastAccessTime = fi.LastAccessTime.QuadPart;
file_info.LastWriteTime = fi.LastWriteTime.QuadPart;
::CloseHandle(handle);
return api_error::success;
}
};
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_