move to new build system
This commit is contained in:
148
repertory2/repertory2_test/include/fixtures/winfsp_fixture.hpp
Normal file
148
repertory2/repertory2_test/include/fixtures/winfsp_fixture.hpp
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
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 REPERTORY_WINFSP_FIXTURE_H
|
||||
#define REPERTORY_WINFSP_FIXTURE_H
|
||||
#if _WIN32
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
#include "drives/winfsp/winfsp_drive.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/s3/s3_provider.hpp"
|
||||
#include "providers/sia/sia_provider.hpp"
|
||||
|
||||
extern std::size_t PROVIDER_INDEX;
|
||||
|
||||
namespace repertory {
|
||||
class winfsp_test : public ::testing::Test {
|
||||
public:
|
||||
lock_data lock_data_;
|
||||
std::unique_ptr<app_config> config;
|
||||
std::unique_ptr<curl_comm> comm;
|
||||
std::unique_ptr<i_provider> provider;
|
||||
std::unique_ptr<winfsp_drive> drive;
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
if (PROVIDER_INDEX != 0) {
|
||||
if (PROVIDER_INDEX == 1) {
|
||||
#ifdef REPERTORY_ENABLE_S3
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(
|
||||
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
|
||||
|
||||
app_config src_cfg(provider_type::s3,
|
||||
utils::path::combine(get_test_dir(), {"storj"}));
|
||||
config = std::make_unique<app_config>(
|
||||
provider_type::s3,
|
||||
"./winfsp_test" + std::to_string(PROVIDER_INDEX));
|
||||
EXPECT_FALSE(config
|
||||
->set_value_by_name("S3Config.AccessKey",
|
||||
src_cfg.get_s3_config().access_key)
|
||||
.empty());
|
||||
EXPECT_FALSE(config
|
||||
->set_value_by_name("S3Config.SecretKey",
|
||||
src_cfg.get_s3_config().secret_key)
|
||||
.empty());
|
||||
EXPECT_FALSE(config
|
||||
->set_value_by_name("S3Config.Region",
|
||||
src_cfg.get_s3_config().region)
|
||||
.empty());
|
||||
EXPECT_FALSE(
|
||||
config
|
||||
->set_value_by_name("S3Config.EncryptionToken",
|
||||
src_cfg.get_s3_config().encryption_token)
|
||||
.empty());
|
||||
EXPECT_FALSE(
|
||||
config
|
||||
->set_value_by_name("S3Config.URL", src_cfg.get_s3_config().url)
|
||||
.empty());
|
||||
EXPECT_FALSE(
|
||||
config->set_value_by_name("S3Config.Bucket", "repertory").empty());
|
||||
config->set_event_level(event_level::verbose);
|
||||
config->set_enable_drive_events(true);
|
||||
event_system::instance().start();
|
||||
|
||||
comm = std::make_unique<curl_comm>(config->get_s3_config());
|
||||
provider = std::make_unique<s3_provider>(*config, *comm);
|
||||
drive = std::make_unique<winfsp_drive>(*config, lock_data_, *provider);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
if (PROVIDER_INDEX == 2) {
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(
|
||||
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
|
||||
|
||||
app_config src_cfg(provider_type::sia,
|
||||
utils::path::combine(get_test_dir(), {"sia"}));
|
||||
config = std::make_unique<app_config>(
|
||||
provider_type::sia,
|
||||
"./winfsp_test" + std::to_string(PROVIDER_INDEX));
|
||||
[[maybe_unused]] auto val = config->set_value_by_name(
|
||||
"HostConfig.AgentString", src_cfg.get_host_config().agent_string);
|
||||
EXPECT_FALSE(
|
||||
config
|
||||
->set_value_by_name("HostConfig.ApiPassword",
|
||||
src_cfg.get_host_config().api_password)
|
||||
.empty());
|
||||
EXPECT_FALSE(config
|
||||
->set_value_by_name(
|
||||
"HostConfig.ApiPort",
|
||||
std::to_string(src_cfg.get_host_config().api_port))
|
||||
.empty());
|
||||
EXPECT_FALSE(
|
||||
config
|
||||
->set_value_by_name("HostConfig.HostNameOrIp",
|
||||
src_cfg.get_host_config().host_name_or_ip)
|
||||
.empty());
|
||||
config->set_event_level(event_level::debug);
|
||||
config->set_enable_drive_events(true);
|
||||
event_system::instance().start();
|
||||
|
||||
comm = std::make_unique<curl_comm>(config->get_host_config());
|
||||
provider = std::make_unique<sia_provider>(*config, *comm);
|
||||
drive = std::make_unique<winfsp_drive>(*config, lock_data_, *provider);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
if (PROVIDER_INDEX != 0) {
|
||||
drive.reset();
|
||||
provider.reset();
|
||||
comm.reset();
|
||||
config.reset();
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(
|
||||
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif
|
||||
#endif // REPERTORY_WINFSP_FIXTURE_H
|
158
repertory2/repertory2_test/include/mocks/mock_fuse_drive.hpp
Normal file
158
repertory2/repertory2_test/include/mocks/mock_fuse_drive.hpp
Normal 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_
|
98
repertory2/repertory2_test/include/mocks/mock_open_file.hpp
Normal file
98
repertory2/repertory2_test/include/mocks/mock_open_file.hpp
Normal 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_
|
162
repertory2/repertory2_test/include/mocks/mock_provider.hpp
Normal file
162
repertory2/repertory2_test/include/mocks/mock_provider.hpp
Normal 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_
|
@@ -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_
|
168
repertory2/repertory2_test/include/mocks/mock_winfsp_drive.hpp
Normal file
168
repertory2/repertory2_test/include/mocks/mock_winfsp_drive.hpp
Normal 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_
|
66
repertory2/repertory2_test/include/test_common.hpp
Normal file
66
repertory2/repertory2_test/include/test_common.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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_TEST_COMMON_HPP_
|
||||
#define TESTS_TEST_COMMON_HPP_
|
||||
|
||||
#ifdef U
|
||||
#undef U
|
||||
#endif
|
||||
|
||||
REPERTORY_IGNORE_WARNINGS_ENABLE()
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
REPERTORY_IGNORE_WARNINGS_DISABLE()
|
||||
|
||||
#include "events/consumers/console_consumer.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "utils/encryption.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
|
||||
#define COMMA ,
|
||||
|
||||
using ::testing::_;
|
||||
using namespace ::testing;
|
||||
|
||||
namespace repertory {
|
||||
[[nodiscard]] auto create_random_file(std::string path, std::size_t size)
|
||||
-> native_file_ptr;
|
||||
|
||||
void delete_generated_files();
|
||||
|
||||
[[nodiscard]] auto
|
||||
generate_test_file_name(const std::string &directory,
|
||||
const std::string &file_name_no_extension)
|
||||
-> std::string;
|
||||
|
||||
template <typename T, typename T2>
|
||||
static void decrypt_and_verify(const T &buffer, const std::string &token,
|
||||
T2 &result) {
|
||||
EXPECT_TRUE(utils::encryption::decrypt_data(token, buffer, result));
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_test_dir() -> std::string;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_TEST_COMMON_HPP_
|
108
repertory2/repertory2_test/include/utils/event_capture.hpp
Normal file
108
repertory2/repertory2_test/include/utils/event_capture.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
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_UTILS_EVENT_CAPTURE_HPP_
|
||||
#define TESTS_UTILS_EVENT_CAPTURE_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class event_capture final {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
explicit event_capture(std::vector<std::string> event_names,
|
||||
std::vector<std::string> non_fired_event_names = {})
|
||||
: event_names_(std::move(event_names)),
|
||||
non_fired_event_names_(std::move(non_fired_event_names)) {
|
||||
E_SUBSCRIBE_ALL(process_event);
|
||||
}
|
||||
|
||||
~event_capture() {
|
||||
wait_for_empty();
|
||||
|
||||
E_CONSUMER_RELEASE();
|
||||
|
||||
EXPECT_TRUE(event_names_.empty());
|
||||
for (const auto &event_name : event_names_) {
|
||||
std::cerr << '\t' << event_name << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> event_names_;
|
||||
std::vector<std::string> fired_event_names_;
|
||||
std::vector<std::string> non_fired_event_names_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable notify_;
|
||||
|
||||
public:
|
||||
void process_event(const event &event) {
|
||||
unique_mutex_lock l(mutex_);
|
||||
utils::remove_element_from(event_names_, event.get_name());
|
||||
fired_event_names_.emplace_back(event.get_name());
|
||||
notify_.notify_all();
|
||||
l.unlock();
|
||||
|
||||
for (size_t i = 0; i < non_fired_event_names_.size(); i++) {
|
||||
const auto it = std::find(non_fired_event_names_.begin(),
|
||||
non_fired_event_names_.end(), event.get_name());
|
||||
EXPECT_EQ(non_fired_event_names_.end(), it);
|
||||
if (it != non_fired_event_names_.end()) {
|
||||
std::cerr << '\t' << *it << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wait_for_empty() {
|
||||
const auto start_time = std::chrono::system_clock::now();
|
||||
unique_mutex_lock l(mutex_);
|
||||
while (not event_names_.empty() &&
|
||||
(std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now() - start_time)
|
||||
.count() < 10)) {
|
||||
notify_.wait_for(l, 1s);
|
||||
}
|
||||
l.unlock();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto wait_for_event(const std::string &event_name) -> bool {
|
||||
auto missing = true;
|
||||
const auto start_time = std::chrono::system_clock::now();
|
||||
|
||||
unique_mutex_lock l(mutex_);
|
||||
while ((std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now() - start_time)
|
||||
.count() < 10) &&
|
||||
(missing =
|
||||
(std::find(fired_event_names_.begin(), fired_event_names_.end(),
|
||||
event_name) == fired_event_names_.end()))) {
|
||||
notify_.wait_for(l, 1s);
|
||||
}
|
||||
l.unlock();
|
||||
return not missing;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_UTILS_EVENT_CAPTURE_HPP_
|
Reference in New Issue
Block a user