new_build_system (#18)
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

Reviewed-on: #18
This commit is contained in:
2024-09-06 15:05:48 +00:00
parent 9d3e4b8767
commit a7239558bd
191 changed files with 10683 additions and 10598 deletions

View File

@@ -0,0 +1,235 @@
/*
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_TEST_INCLUDE_FIXTURES_FUSE_FIXTURE_HPP
#define REPERTORY_TEST_INCLUDE_FIXTURES_FUSE_FIXTURE_HPP
#if !defined(_WIN32)
#include "test_common.hpp"
#include "app_config.hpp"
#include "comm/curl/curl_comm.hpp"
#include "drives/fuse/fuse_drive.hpp"
#include "platform/platform.hpp"
#include "providers/encrypt/encrypt_provider.hpp"
#include "providers/s3/s3_provider.hpp"
#include "providers/sia/sia_provider.hpp"
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
#if !defined(ACCESSPERMS)
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
#endif
namespace repertory {
inline constexpr const auto SLEEP_SECONDS{1.5s};
template <typename provider_t> class fuse_test : public ::testing::Test {
public:
static std::string cfg_directory;
static std::unique_ptr<curl_comm> comm;
static std::unique_ptr<app_config> config;
static std::filesystem::path current_directory;
static std::unique_ptr<fuse_drive> drive;
static lock_data lock_data_;
static std::string mount_location;
static std::unique_ptr<i_provider> provider;
static std::string test_directory;
protected:
static void SetUpTestCase() {
current_directory = std::filesystem::current_path();
test_directory = utils::path::combine(
test::get_test_output_dir(),
{
"fuse_test",
std::to_string(static_cast<std::uint8_t>(provider_t::type)),
});
ASSERT_TRUE(utils::file::directory(test_directory).remove_recursively());
mount_location = utils::path::combine(test_directory, {"mount"});
ASSERT_TRUE(utils::file::directory(mount_location).create_directory());
cfg_directory = utils::path::combine(test_directory, {"cfg"});
ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory());
config = std::make_unique<app_config>(provider_t::type, cfg_directory);
std::vector<std::string> drive_args{};
switch (provider_t::type) {
case provider_type::s3: {
{
app_config src_cfg{
provider_type::s3,
utils::path::combine(test::get_test_input_dir(), {"storj"}),
};
config->set_enable_drive_events(true);
config->set_event_level(event_level::trace);
config->set_s3_config(src_cfg.get_s3_config());
}
comm = std::make_unique<curl_comm>(config->get_s3_config());
drive_args = std::vector<std::string>({
"-s3",
"-na",
"storj",
});
} break;
case provider_type::sia: {
{
app_config src_cfg{
provider_type::sia,
utils::path::combine(test::get_test_input_dir(), {"sia"}),
};
config->set_enable_drive_events(true);
config->set_event_level(event_level::debug);
config->set_host_config(src_cfg.get_host_config());
}
comm = std::make_unique<curl_comm>(config->get_host_config());
} break;
// case 0U: {
// config =
// std::make_unique<app_config>(provider_type::encrypt,
// cfg_directory);
// {
// app_config src_cfg(
// provider_type::s3,
// utils::path::combine(test::get_test_input_dir(), {"encrypt"}));
// config->set_enable_drive_events(true);
// config->set_event_level(event_level::trace);
// config->set_s3_config(src_cfg.get_s3_config());
// }
//
// comm = std::make_unique<curl_comm>(config->get_s3_config());
// provider = std::make_unique<s3_provider>(*config, *comm);
// drive_args = std::vector<std::string>({"-en"});
// } break;
default:
throw std::runtime_error("provider type is not implemented");
return;
}
provider = std::make_unique<provider_t>(*config, *comm);
drive_args.push_back(mount_location);
execute_mount(drive_args);
}
static void TearDownTestCase() {
execute_unmount();
std::filesystem::current_path(current_directory);
[[maybe_unused]] auto ret =
utils::file::directory(test_directory).remove_recursively();
}
public:
static auto create_file_and_test(std::string name) -> std::string {
auto file_path = utils::path::combine(mount_location, {name});
auto fd =
open(file_path.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP);
EXPECT_LE(1, fd);
EXPECT_TRUE(utils::file::file(file_path).exists());
EXPECT_FALSE(utils::file::directory(file_path).exists());
auto opt_size = utils::file::file{file_path}.size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(0U, opt_size.value());
EXPECT_EQ(0, close(fd));
std::this_thread::sleep_for(SLEEP_SECONDS);
return file_path;
}
static void execute_mount(auto &&drive_args) {
auto mount_cmd = "./repertory -dd \"" + config->get_data_directory() +
"\"" + " " + utils::string::join(drive_args, ' ');
std::cout << "mount command: " << mount_cmd << std::endl;
ASSERT_EQ(0, system(mount_cmd.c_str()));
std::this_thread::sleep_for(5s);
EXPECT_EQ(0, system(("mount|grep \"" + mount_location + "\"").c_str()));
}
static void execute_unmount() {
auto unmounted{false};
for (int i = 0; not unmounted && (i < 50); i++) {
unmounted = (fuse_base::unmount(mount_location) == 0);
if (not unmounted) {
std::this_thread::sleep_for(100ms);
}
}
EXPECT_TRUE(unmounted);
}
static void unlink_file_and_test(const std::string &file_path) {
int ret = 0;
for (auto i = 0; ((ret = unlink(file_path.c_str())) != 0) && (i < 20);
i++) {
std::this_thread::sleep_for(100ms);
}
EXPECT_EQ(0, ret);
std::this_thread::sleep_for(SLEEP_SECONDS);
EXPECT_FALSE(utils::file::directory(file_path).exists());
EXPECT_FALSE(utils::file::file(file_path).exists());
}
};
template <typename provider_t>
std::string fuse_test<provider_t>::cfg_directory{};
template <typename provider_t>
std::unique_ptr<curl_comm> fuse_test<provider_t>::comm{};
template <typename provider_t>
std::unique_ptr<app_config> fuse_test<provider_t>::config{};
template <typename provider_t>
std::filesystem::path fuse_test<provider_t>::current_directory{};
template <typename provider_t>
std::unique_ptr<fuse_drive> fuse_test<provider_t>::drive{};
template <typename provider_t> lock_data fuse_test<provider_t>::lock_data_{};
template <typename provider_t>
std::string fuse_test<provider_t>::mount_location{};
template <typename provider_t>
std::unique_ptr<i_provider> fuse_test<provider_t>::provider{};
template <typename provider_t>
std::string fuse_test<provider_t>::test_directory;
typedef ::testing::Types<s3_provider, sia_provider> fuse_provider_types;
} // namespace repertory
#endif // !defined(_WIN32)
#endif // REPERTORY_TEST_INCLUDE_FIXTURES_FUSE_FIXTURE_HPP

View File

@@ -19,8 +19,8 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef REPERTORY_WINFSP_FIXTURE_HPP
#define REPERTORY_WINFSP_FIXTURE_HPP
#ifndef REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP
#define REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP
#if defined(_WIN32)
#include "test_common.hpp"
@@ -31,6 +31,8 @@
#include "platform/platform.hpp"
#include "providers/s3/s3_provider.hpp"
#include "providers/sia/sia_provider.hpp"
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
extern std::size_t PROVIDER_INDEX;
@@ -47,14 +49,20 @@ protected:
void SetUp() override {
if (PROVIDER_INDEX != 0) {
if (PROVIDER_INDEX == 1) {
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX)));
EXPECT_TRUE(utils::file::directory(
utils::path::combine(
test::get_test_output_dir(),
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}))
.remove_recursively());
app_config src_cfg(provider_type::s3,
utils::path::combine(get_test_dir(), {"storj"}));
app_config src_cfg(
provider_type::s3,
utils::path::combine(test::get_test_input_dir(), {"storj"}));
config = std::make_unique<app_config>(
provider_type::s3,
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX));
utils::path::combine(
test::get_test_output_dir(),
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}));
EXPECT_FALSE(config
->set_value_by_name("S3Config.AccessKey",
src_cfg.get_s3_config().access_key)
@@ -89,14 +97,20 @@ protected:
}
if (PROVIDER_INDEX == 2) {
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX)));
EXPECT_TRUE(utils::file::directory(
utils::path::combine(
test::get_test_output_dir(),
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}))
.remove_recursively());
app_config src_cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
app_config src_cfg(
provider_type::sia,
utils::path::combine(test::get_test_input_dir(), {"sia"}));
config = std::make_unique<app_config>(
provider_type::sia,
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX));
utils::path::combine(
test::get_test_output_dir(),
{"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(
@@ -135,12 +149,15 @@ protected:
config.reset();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX)));
EXPECT_TRUE(utils::file::directory(
utils::path::combine(
test::get_test_output_dir(),
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}))
.remove_recursively());
}
}
};
} // namespace repertory
#endif
#endif // REPERTORY_WINFSP_FIXTURE_HPP
#endif // REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP

View File

@@ -19,8 +19,8 @@
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 REPERTORY_TEST_INCLUDE_FIXTURES_MOCKS_MOCK_FUSE_DRIVE_HPP_
#define REPERTORY_TEST_INCLUDE_FIXTURES_MOCKS_MOCK_FUSE_DRIVE_HPP_
#if !defined(_WIN32)
#include "test_common.hpp"
@@ -68,10 +68,10 @@ public:
dir_item.size = 0;
dir_item.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
{META_MODIFIED, std::to_string(utils::time::get_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_time_now())},
{META_CREATION, std::to_string(utils::time::get_time_now())}};
list.emplace_back(dir_item);
dir_item.api_path = "..";
@@ -132,11 +132,11 @@ public:
utils::path::combine(mount_location_, {to_api_path});
if (overwrite) {
if (not utils::file::retry_delete_file(to_file_path)) {
if (not utils::file::file(to_file_path).remove()) {
return -1;
}
} else if (utils::file::is_directory(to_file_path) ||
utils::file::is_file(to_file_path)) {
} else if (utils::file::directory(to_file_path).exists() ||
utils::file::file(to_file_path).exists()) {
errno = EEXIST;
return -1;
}
@@ -155,5 +155,5 @@ public:
};
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
#endif // !defined(_WIN32)
#endif // REPERTORY_TEST_INCLUDE_FIXTURES_MOCKS_MOCK_FUSE_DRIVE_HPP_

View File

@@ -19,8 +19,8 @@
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_
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_OPEN_FILE_HPP_
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_OPEN_FILE_HPP_
#include "test_common.hpp"
@@ -95,4 +95,4 @@ public:
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_OPEN_FILE_HPP_

View File

@@ -19,8 +19,8 @@
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_
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_PROVIDER_HPP_
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_PROVIDER_HPP_
#include "test_common.hpp"
@@ -159,4 +159,4 @@ public:
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_PROVIDER_HPP_
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_PROVIDER_HPP_

View File

@@ -19,8 +19,8 @@
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_
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#include "test_common.hpp"
@@ -41,4 +41,4 @@ public:
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_UPLOAD_MANAGER_HPP_

View File

@@ -19,8 +19,8 @@
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_
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#if defined(_WIN32)
#include "test_common.hpp"
@@ -57,10 +57,10 @@ public:
di.size = 0u;
di.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
{META_MODIFIED, std::to_string(utils::time::get_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_time_now())},
{META_CREATION, std::to_string(utils::time::get_time_now())}};
list.emplace_back(di);
di.api_path = "..";
@@ -138,7 +138,7 @@ public:
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 directory = utils::file::directory(file_path).exists();
const auto attributes =
FILE_FLAG_BACKUP_SEMANTICS |
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
@@ -148,8 +148,14 @@ public:
FILE_BASIC_INFO fi{};
::GetFileInformationByHandleEx(handle, FileBasicInfo, &fi, sizeof(fi));
if (not directory) {
utils::file::get_file_size(file_path, file_info.FileSize);
auto opt_size = utils::file::file{file_path}.size();
if (not opt_size.has_value()) {
return api_error::os_error;
}
file_info.FileSize = opt_size.value();
}
file_info.AllocationSize =
directory ? 0
: utils::divide_with_ceiling(file_info.FileSize,
@@ -167,4 +173,4 @@ public:
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_WINFSP_DRIVE_HPP_

View File

@@ -19,47 +19,15 @@
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_
#if defined(U)
#undef U
#endif
#ifndef REPERTORY_TEST_INCLUDE_TEST_COMMON_HPP_
#define REPERTORY_TEST_INCLUDE_TEST_COMMON_HPP_
REPERTORY_IGNORE_WARNINGS_ENABLE()
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "test.hpp"
REPERTORY_IGNORE_WARNINGS_DISABLE()
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "utils/encrypt.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_
#endif // REPERTORY_TEST_INCLUDE_TEST_COMMON_HPP_

View File

@@ -19,8 +19,8 @@
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_
#ifndef REPERTORY_TEST_INCLUDE_UTILS_EVENT_CAPTURE_HPP_
#define REPERTORY_TEST_INCLUDE_UTILS_EVENT_CAPTURE_HPP_
#include "test_common.hpp"
@@ -106,4 +106,4 @@ public:
};
} // namespace repertory
#endif // TESTS_UTILS_EVENT_CAPTURE_HPP_
#endif // REPERTORY_TEST_INCLUDE_UTILS_EVENT_CAPTURE_HPP_

View File

@@ -63,8 +63,6 @@ auto main(int argc, char **argv) -> int {
::testing::InitGoogleTest(&argc, argv);
auto ret = RUN_ALL_TESTS();
delete_generated_files();
repertory::project_cleanup();
return ret;

View File

@@ -33,20 +33,24 @@ public:
static console_consumer cs;
std::string s3_directory{
utils::path::combine("./test_config", {"config_test", "s3"})};
utils::path::combine(test::get_test_output_dir(), {"config_test", "s3"})};
std::string sia_directory{
utils::path::combine("./test_config", {"config_test", "sia"})};
std::string sia_directory{utils::path::combine(test::get_test_output_dir(),
{"config_test", "sia"})};
void SetUp() override {
event_system::instance().start();
ASSERT_TRUE(utils::file::delete_directory_recursively(
utils::path::combine("./test_config", {"config_test"})));
ASSERT_TRUE(
utils::file::directory(
utils::path::combine(test::get_test_output_dir(), {"config_test"}))
.remove_recursively());
}
void TearDown() override {
ASSERT_TRUE(utils::file::delete_directory_recursively(
utils::path::combine("./test_config", {"config_test"})));
ASSERT_TRUE(
utils::file::directory(
utils::path::combine(test::get_test_output_dir(), {"config_test"}))
.remove_recursively());
event_system::instance().stop();
}
};
@@ -163,10 +167,12 @@ TEST_F(config_test, sia_default_settings) {
json data;
EXPECT_TRUE(utils::file::read_json_file(config_file, data));
EXPECT_STREQ(DEFAULT_SIA_CONFIG.c_str(), data.dump(2).c_str());
EXPECT_TRUE(utils::file::is_directory(
utils::path::combine(sia_directory, {"cache"})));
EXPECT_TRUE(utils::file::is_directory(
utils::path::combine(sia_directory, {"logs"})));
EXPECT_TRUE(
utils::file::directory(utils::path::combine(sia_directory, {"cache"}))
.exists());
EXPECT_TRUE(
utils::file::directory(utils::path::combine(sia_directory, {"logs"}))
.exists());
}
}
@@ -180,10 +186,12 @@ TEST_F(config_test, s3_default_settings) {
json data;
EXPECT_TRUE(utils::file::read_json_file(config_file, data));
EXPECT_STREQ(DEFAULT_S3_CONFIG.c_str(), data.dump(2).c_str());
EXPECT_TRUE(utils::file::is_directory(
utils::path::combine(s3_directory, {"cache"})));
EXPECT_TRUE(utils::file::is_directory(
utils::path::combine(s3_directory, {"logs"})));
EXPECT_TRUE(
utils::file::directory(utils::path::combine(s3_directory, {"cache"}))
.exists());
EXPECT_TRUE(
utils::file::directory(utils::path::combine(s3_directory, {"logs"}))
.exists());
}
}

View File

@@ -35,8 +35,9 @@ TEST(database, db_insert) {
{
sqlite3 *db3_ptr{nullptr};
auto res = sqlite3_open_v2(
utils::path::combine(get_test_dir(), {"test.db3"}).c_str(), &db3_ptr,
SQLITE_OPEN_READWRITE, nullptr);
utils::path::combine(test::get_test_input_dir(), {"test.db3"})
.c_str(),
&db3_ptr, SQLITE_OPEN_READWRITE, nullptr);
ASSERT_EQ(SQLITE_OK, res);
ASSERT_TRUE(db3_ptr != nullptr);
@@ -78,8 +79,9 @@ TEST(database, db_select) {
{
sqlite3 *db3_ptr{nullptr};
auto res = sqlite3_open_v2(
utils::path::combine(get_test_dir(), {"test.db3"}).c_str(), &db3_ptr,
SQLITE_OPEN_READWRITE, nullptr);
utils::path::combine(test::get_test_input_dir(), {"test.db3"})
.c_str(),
&db3_ptr, SQLITE_OPEN_READWRITE, nullptr);
ASSERT_EQ(SQLITE_OK, res);
ASSERT_TRUE(db3_ptr != nullptr);

View File

@@ -1,283 +0,0 @@
/*
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.
*/
#include "test_common.hpp"
#include "types/repertory.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
static auto get_source_file_name() -> std::string {
return generate_test_file_name("./test_data", "encrypting_reader");
}
TEST(encrypting_reader, get_encrypted_file_name) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(source_file_name, 1024UL);
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader(
"test.dat", source_file_name, stop_requested, token, std::nullopt);
auto file_name = reader.get_encrypted_file_name();
EXPECT_EQ(api_error::success,
utils::encryption::decrypt_file_name(token, file_name));
EXPECT_STREQ("test.dat", file_name.c_str());
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data) {
const auto source_file_name = get_source_file_name();
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0U; i < 8U; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_EQ(
buffer.size() / 2U,
utils::encryption::encrypting_reader::reader_function(
reinterpret_cast<char *>(&buffer[(buffer.size() / 2U) * j]),
buffer.size() / 2U, 1U, &reader));
}
data_buffer decrypted_data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, buffer, decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_in_multiple_chunks) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2U);
EXPECT_EQ(buffer.size(),
utils::encryption::encrypting_reader::reader_function(
reinterpret_cast<char *>(buffer.data()), buffer.size(), 1U,
&reader));
for (std::uint8_t j = 0U; j < 2U; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2U));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
std::next(buffer.begin(), static_cast<std::int64_t>(
offset + (buffer.size() / 2U)))),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_as_stream) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
auto io_stream = reader.create_iostream();
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
EXPECT_TRUE(io_stream->good());
EXPECT_EQ(reader.get_total_size(),
static_cast<std::uint64_t>(io_stream->tellg()));
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0U; i < 8U; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
EXPECT_FALSE(
io_stream->seekg(static_cast<std::streamoff>(i * buffer.size()))
.fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_FALSE(
io_stream
->read(
reinterpret_cast<char *>(&buffer[(buffer.size() / 2U) * j]),
static_cast<std::streamsize>(buffer.size()) / 2U)
.fail());
EXPECT_TRUE(io_stream->good());
}
data_buffer decrypted_data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, buffer, decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_in_multiple_chunks_as_stream) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
auto io_stream = reader.create_iostream();
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
EXPECT_TRUE(io_stream->good());
EXPECT_EQ(reader.get_total_size(),
static_cast<std::uint64_t>(io_stream->tellg()));
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2U);
EXPECT_FALSE(io_stream
->read(reinterpret_cast<char *>(buffer.data()),
static_cast<std::streamsize>(buffer.size()))
.fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0U; j < 2U; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2U));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
std::next(buffer.begin(), static_cast<std::int64_t>(
offset + (buffer.size() / 2U)))),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
} // namespace repertory

View File

@@ -55,7 +55,7 @@ static void validate_write(file_manager::open_file &o, std::size_t offset,
TEST(open_file, properly_initializes_state_for_0_byte_file) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@@ -76,7 +76,7 @@ TEST(open_file, properly_initializes_state_for_0_byte_file) {
TEST(open_file, properly_initializes_state_based_on_chunk_size) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@@ -109,7 +109,7 @@ TEST(open_file, properly_initializes_state_based_on_chunk_size) {
TEST(open_file, will_not_change_source_path_for_0_byte_file) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@@ -128,12 +128,12 @@ TEST(open_file, will_not_change_source_path_for_0_byte_file) {
o.close();
EXPECT_EQ(api_error::success, o.get_api_error());
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
}
TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@@ -166,14 +166,14 @@ TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
o.close();
EXPECT_EQ(api_error::download_stopped, o.get_api_error());
EXPECT_STRNE(source_path.c_str(), o.get_source_path().c_str());
EXPECT_FALSE(utils::file::is_file(source_path));
EXPECT_FALSE(utils::file::file(source_path).exists());
}
TEST(open_file,
will_not_change_source_path_if_file_size_matches_existing_source) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
create_random_file(source_path, test_chunk_size)->close();
auto &rf = test::create_random_file(test_chunk_size);
const auto source_path = rf.get_path();
rf.close();
mock_provider mp;
mock_upload_manager um;
@@ -192,15 +192,12 @@ TEST(open_file,
o.close();
EXPECT_EQ(api_error::success, o.get_api_error());
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
EXPECT_TRUE(utils::file::is_file(source_path));
EXPECT_TRUE(utils::file::file(source_path).exists());
}
TEST(open_file, write_with_incomplete_download) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
auto nf = create_random_file(
generate_test_file_name("./test_config", "file_manager_open_file_test"),
test_chunk_size * 2u);
const auto source_path = test::generate_test_file_name("test");
auto &nf = test::create_random_file(test_chunk_size * 2u);
mock_provider mp;
mock_upload_manager um;
@@ -236,9 +233,8 @@ TEST(open_file, write_with_incomplete_download) {
if (offset == 0u) {
std::size_t bytes_read{};
data.resize(size);
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
? api_error::success
: api_error::os_error;
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
: api_error::os_error;
EXPECT_EQ(bytes_read, data.size());
return ret;
}
@@ -278,18 +274,18 @@ TEST(open_file, write_with_incomplete_download) {
test_state();
o.close();
nf->close();
nf.close();
test_state();
EXPECT_EQ(api_error::download_incomplete, o.get_api_error());
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
}
TEST(open_file, write_new_file) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@@ -357,12 +353,12 @@ TEST(open_file, write_new_file) {
EXPECT_EQ(api_error::success, o.get_api_error());
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
}
TEST(open_file, write_new_file_multiple_chunks) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@@ -449,13 +445,13 @@ TEST(open_file, write_new_file_multiple_chunks) {
EXPECT_EQ(api_error::success, o.get_api_error());
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
}
TEST(open_file, resize_file_to_0_bytes) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
create_random_file(source_path, test_chunk_size * 4u)->close();
auto &rf = test::create_random_file(test_chunk_size * 4u);
const auto source_path = rf.get_path();
rf.close();
mock_provider mp;
mock_upload_manager um;
@@ -503,9 +499,9 @@ TEST(open_file, resize_file_to_0_bytes) {
}
TEST(open_file, resize_file_by_full_chunk) {
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
create_random_file(source_path, test_chunk_size * 4u)->close();
auto &rf = test::create_random_file(test_chunk_size * 4u);
const auto source_path = rf.get_path();
rf.close();
mock_provider mp;
mock_upload_manager um;
@@ -556,7 +552,7 @@ TEST(open_file, can_add_handle) {
event_system::instance().start();
console_consumer c;
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;
@@ -618,7 +614,7 @@ TEST(open_file, can_remove_handle) {
console_consumer c;
const auto source_path =
generate_test_file_name("./test_config", "file_manager_open_file_test");
test::generate_test_file_name("file_manager_open_file_test");
mock_provider mp;
mock_upload_manager um;

View File

@@ -31,11 +31,11 @@
namespace repertory {
static constexpr const std::size_t test_chunk_size = 1024u;
static std::string ring_buffer_dir = utils::path::combine(
"./test_config", {"file_manager_ring_buffer_open_file_test"});
test::get_test_output_dir(), {"file_manager_ring_buffer_open_file_test"});
TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -61,13 +61,13 @@ TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file,
can_forward_to_last_chunk_if_count_is_greater_than_remaining) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -93,12 +93,12 @@ TEST(ring_buffer_open_file,
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -125,12 +125,12 @@ TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -153,12 +153,12 @@ TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
EXPECT_EQ(std::size_t(28u), rb.get_last_chunk());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -184,13 +184,13 @@ TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file,
can_reverse_to_first_chunk_if_count_is_greater_than_remaining) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -216,12 +216,12 @@ TEST(ring_buffer_open_file,
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -248,12 +248,12 @@ TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -284,12 +284,12 @@ TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, can_reverse_full_ring) {
const auto source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -316,16 +316,14 @@ TEST(ring_buffer_open_file, can_reverse_full_ring) {
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, read_full_file) {
const auto download_source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
auto &nf = test::create_random_file(test_chunk_size * 32u);
const auto download_source_path = nf.get_path();
const auto dest_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -335,8 +333,7 @@ TEST(ring_buffer_open_file, read_full_file) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,
@@ -346,9 +343,8 @@ TEST(ring_buffer_open_file, read_full_file) {
EXPECT_FALSE(stop_requested);
std::size_t bytes_read{};
data.resize(size);
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
? api_error::success
: api_error::os_error;
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
: api_error::os_error;
EXPECT_EQ(bytes_read, data.size());
return ret;
});
@@ -356,8 +352,9 @@ TEST(ring_buffer_open_file, read_full_file) {
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
30U, fsi, mp, 8u);
native_file_ptr nf2;
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
auto ptr = utils::file::file::open_or_create_file(dest_path);
auto &nf2 = *ptr;
EXPECT_TRUE(nf2);
auto to_read = fsi.size;
std::size_t chunk = 0u;
@@ -367,28 +364,31 @@ TEST(ring_buffer_open_file, read_full_file) {
rb.read(test_chunk_size, chunk * test_chunk_size, data));
std::size_t bytes_written{};
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(),
chunk * test_chunk_size, bytes_written));
EXPECT_TRUE(nf2.write(data, chunk * test_chunk_size, &bytes_written));
chunk++;
to_read -= data.size();
}
nf2->close();
nf->close();
nf2.close();
nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
utils::file::generate_sha256(dest_path).c_str());
auto hash1 = utils::file::file(download_source_path).sha256();
auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, read_full_file_in_reverse) {
const auto download_source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
auto &nf = test::create_random_file(test_chunk_size * 32u);
const auto download_source_path = nf.get_path();
const auto dest_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -398,8 +398,7 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,
@@ -409,9 +408,8 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
EXPECT_FALSE(stop_requested);
std::size_t bytes_read{};
data.resize(size);
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
? api_error::success
: api_error::os_error;
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
: api_error::os_error;
EXPECT_EQ(bytes_read, data.size());
return ret;
});
@@ -419,8 +417,9 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
30U, fsi, mp, 8u);
native_file_ptr nf2;
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
auto ptr = utils::file::file::open_or_create_file(dest_path);
auto &nf2 = *ptr;
EXPECT_TRUE(nf2);
auto to_read = fsi.size;
std::size_t chunk = rb.get_total_chunks() - 1u;
@@ -430,28 +429,31 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
rb.read(test_chunk_size, chunk * test_chunk_size, data));
std::size_t bytes_written{};
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(),
chunk * test_chunk_size, bytes_written));
EXPECT_TRUE(nf2.write(data, chunk * test_chunk_size, &bytes_written));
chunk--;
to_read -= data.size();
}
nf2->close();
nf->close();
nf2.close();
nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
utils::file::generate_sha256(dest_path).c_str());
auto hash1 = utils::file::file(download_source_path).sha256();
auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
const auto download_source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
auto &nf = test::create_random_file(test_chunk_size * 32u);
const auto download_source_path = nf.get_path();
const auto dest_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
const auto dest_path = test::generate_test_file_name("test");
mock_provider mp;
@@ -461,8 +463,7 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
fsi.source_path = test::generate_test_file_name("test");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,
@@ -472,9 +473,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
EXPECT_FALSE(stop_requested);
std::size_t bytes_read{};
data.resize(size);
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
? api_error::success
: api_error::os_error;
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
: api_error::os_error;
EXPECT_EQ(bytes_read, data.size());
return ret;
});
@@ -482,8 +482,11 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
30U, fsi, mp, 8u);
native_file_ptr nf2;
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
auto ptr = utils::file::file::open_or_create_file(dest_path);
auto &nf2 = *ptr;
EXPECT_TRUE(nf2);
// EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path,
// nf2));
auto total_read = std::uint64_t(0u);
@@ -492,27 +495,31 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
EXPECT_EQ(api_error::success, rb.read(3u, total_read, data));
std::size_t bytes_written{};
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(), total_read,
bytes_written));
EXPECT_TRUE(
nf2.write(data.data(), data.size(), total_read, &bytes_written));
total_read += data.size();
}
nf2->close();
nf->close();
nf2.close();
nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
utils::file::generate_sha256(dest_path).c_str());
auto hash1 = utils::file::file(download_source_path).sha256();
auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
const auto download_source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
auto &nf = test::create_random_file(test_chunk_size * 32u);
const auto download_source_path = nf.get_path();
const auto dest_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
mock_provider mp;
@@ -522,8 +529,7 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
fsi.directory = false;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 32u;
fsi.source_path =
generate_test_file_name("./test_config", "ring_buffer_open_file");
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([&nf](const std::string & /* api_path */,
@@ -533,9 +539,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
EXPECT_FALSE(stop_requested);
std::size_t bytes_read{};
data.resize(size);
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
? api_error::success
: api_error::os_error;
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
: api_error::os_error;
EXPECT_EQ(bytes_read, data.size());
return ret;
});
@@ -543,11 +548,12 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
30U, fsi, mp, 8u);
native_file_ptr nf2;
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
auto ptr = utils::file::file::open_or_create_file(dest_path);
auto &nf2 = *ptr;
EXPECT_TRUE(nf2);
auto total_read = std::uint64_t(0u);
const auto read_size = 3u;
std::uint64_t total_read{0U};
const auto read_size{3U};
while (total_read < fsi.size) {
const auto offset = fsi.size - total_read - read_size;
@@ -560,18 +566,23 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
(remain >= read_size) ? offset : 0u, data));
std::size_t bytes_written{};
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(),
(remain >= read_size) ? offset : 0u,
bytes_written));
EXPECT_TRUE(
nf2.write(data, (remain >= read_size) ? offset : 0u, &bytes_written));
total_read += data.size();
}
nf2->close();
nf->close();
nf2.close();
nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
utils::file::generate_sha256(dest_path).c_str());
auto hash1 = utils::file::file(download_source_path).sha256();
auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
}
EXPECT_TRUE(utils::file::delete_directory_recursively(ring_buffer_dir));
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
}
} // namespace repertory

View File

@@ -34,7 +34,6 @@
#include "utils/encrypting_reader.hpp"
#include "utils/event_capture.hpp"
#include "utils/file_utils.hpp"
#include "utils/native_file.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/string.hpp"
@@ -43,7 +42,7 @@
namespace repertory {
static std::string file_manager_dir =
utils::path::combine("./test_config", {"file_manager_test"});
utils::path::combine(test::get_test_output_dir(), {"file_manager_test"});
auto file_manager::open(std::shared_ptr<i_closeable_open_file> of,
const open_file_data &ofd, std::uint64_t &handle,
@@ -85,7 +84,7 @@ TEST(file_manager, can_start_and_stop) {
}
event_system::instance().stop();
// EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
// EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
}
TEST(file_manager, can_create_and_close_file) {
@@ -118,7 +117,7 @@ TEST(file_manager, can_create_and_close_file) {
{
std::shared_ptr<i_open_file> f;
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@@ -202,7 +201,7 @@ TEST(file_manager, can_create_and_close_file) {
polling::instance().stop();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, can_open_and_close_file) {
@@ -233,7 +232,7 @@ TEST(file_manager, can_open_and_close_file) {
std::uint64_t handle{};
{
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@@ -318,7 +317,7 @@ TEST(file_manager, can_open_and_close_file) {
polling::instance().stop();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
@@ -340,7 +339,7 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@@ -391,7 +390,7 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
polling::instance().stop();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
@@ -420,15 +419,14 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
event_capture ec({"download_stored"},
{"file_upload_completed", "file_upload_queued"});
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
source_path, 10, now + 4u);
auto nf = create_random_file(
generate_test_file_name("./test_config", "file_manage_test"),
utils::string::to_uint64(meta[META_SIZE]));
auto &nf =
test::create_random_file(utils::string::to_uint64(meta[META_SIZE]));
EXPECT_CALL(mp, get_filesystem_item)
.WillRepeatedly([&meta](const std::string &api_path, bool directory,
@@ -465,9 +463,8 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
if (offset == 0u) {
std::size_t bytes_read{};
data.resize(size);
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
? api_error::success
: api_error::os_error;
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
: api_error::os_error;
EXPECT_EQ(bytes_read, data.size());
return ret;
}
@@ -542,11 +539,11 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
EXPECT_EQ(std::size_t(0u), fm.get_open_file_count());
EXPECT_EQ(std::size_t(0u), fm.get_open_handle_count());
nf->close();
nf.close();
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
@@ -583,15 +580,14 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
});
event_capture ec({"download_end"});
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
source_path, 10, now + 4u);
auto nf = create_random_file(
generate_test_file_name("./test_config", "file_manage_test"),
utils::string::to_uint64(meta[META_SIZE]));
auto &nf =
test::create_random_file(utils::string::to_uint64(meta[META_SIZE]));
EXPECT_CALL(mp, get_filesystem_item)
.WillRepeatedly([&meta](const std::string &api_path, bool directory,
@@ -623,9 +619,8 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
stop_type & /* stop_requested */) -> api_error {
std::size_t bytes_read{};
data.resize(size);
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
? api_error::success
: api_error::os_error;
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
: api_error::os_error;
EXPECT_EQ(bytes_read, data.size());
return ret;
});
@@ -660,16 +655,16 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
fm.stop();
nf->close();
nf.close();
}
polling::instance().stop();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, can_evict_file) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
console_consumer c;
event_system::instance().start();
@@ -694,7 +689,7 @@ TEST(file_manager, can_evict_file) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
@@ -735,15 +730,15 @@ TEST(file_manager, can_evict_file) {
std::size_t bytes_written{};
EXPECT_EQ(api_error::success, f->write(0U, data, bytes_written));
std::uint64_t file_size{};
EXPECT_TRUE(utils::file::get_file_size(source_path, file_size));
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), file_size);
auto opt_size = utils::file::file{source_path}.size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), opt_size.value());
}
fm.close(handle);
capture.wait_for_empty();
EXPECT_TRUE(utils::retryable_action(
EXPECT_TRUE(utils::retry_action(
[&fm]() -> bool { return not fm.is_processing("/test_evict.txt"); }));
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
@@ -764,17 +759,17 @@ TEST(file_manager, can_evict_file) {
return api_error::success;
});
EXPECT_TRUE(fm.evict_file("/test_evict.txt"));
EXPECT_FALSE(utils::file::is_file(source_path));
EXPECT_FALSE(utils::file::file(source_path).exists());
fm.stop();
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_file_is_pinned) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
cfg.set_enable_chunk_downloader_timeout(false);
@@ -796,11 +791,11 @@ TEST(file_manager, evict_file_fails_if_file_is_pinned) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_provider_is_direct_only) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -812,11 +807,11 @@ TEST(file_manager, evict_file_fails_if_provider_is_direct_only) {
EXPECT_FALSE(fm.evict_file("/test.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_file_is_open) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -862,12 +857,12 @@ TEST(file_manager, evict_file_fails_if_file_is_open) {
fm.close(handle);
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager,
evict_file_fails_if_unable_to_get_source_path_from_item_meta) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -897,11 +892,11 @@ TEST(file_manager,
EXPECT_FALSE(fm.evict_file("/test_open.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_source_path_is_empty) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -931,11 +926,11 @@ TEST(file_manager, evict_file_fails_if_source_path_is_empty) {
EXPECT_FALSE(fm.evict_file("/test_open.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_file_is_uploading) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
console_consumer c;
event_system::instance().start();
@@ -960,7 +955,7 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
@@ -1008,29 +1003,30 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
std::size_t bytes_written{};
EXPECT_EQ(api_error::success, f->write(0U, data, bytes_written));
std::uint64_t file_size{};
EXPECT_TRUE(utils::file::get_file_size(source_path, file_size));
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), file_size);
auto opt_size = utils::file::file{source_path}.size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), opt_size.value());
fm.close(handle);
EXPECT_TRUE(utils::retryable_action(
EXPECT_TRUE(utils::retry_action(
[&fm]() -> bool { return fm.is_processing("/test_evict.txt"); }));
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
}
capture.wait_for_empty();
EXPECT_TRUE(utils::file::is_file(source_path));
EXPECT_TRUE(utils::file::file(source_path).exists());
fm.stop();
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_file_is_in_upload_queue) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1051,11 +1047,11 @@ TEST(file_manager, evict_file_fails_if_file_is_in_upload_queue) {
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_file_is_modified) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1097,11 +1093,11 @@ TEST(file_manager, evict_file_fails_if_file_is_modified) {
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, evict_file_fails_if_file_is_not_complete) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1145,11 +1141,11 @@ TEST(file_manager, evict_file_fails_if_file_is_not_complete) {
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, can_get_directory_items) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1179,11 +1175,11 @@ TEST(file_manager, can_get_directory_items) {
EXPECT_EQ(std::size_t(2U), list.size());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1192,7 +1188,7 @@ TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "", 2, now + 3u, 3u, 4u, 0u, "/test_create.src", 10,
@@ -1215,11 +1211,11 @@ TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, create_fails_if_provider_create_is_unsuccessful) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1246,12 +1242,12 @@ TEST(file_manager, create_fails_if_provider_create_is_unsuccessful) {
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, get_open_file_fails_if_file_is_not_open) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1270,12 +1266,12 @@ TEST(file_manager, get_open_file_fails_if_file_is_not_open) {
EXPECT_FALSE(f);
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager,
get_open_file_promotes_non_writeable_file_if_writeable_is_specified) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1355,11 +1351,11 @@ TEST(file_manager,
EXPECT_EQ(std::size_t(1U), fm.get_open_file_count());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, open_file_fails_if_file_is_not_found) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1380,11 +1376,11 @@ TEST(file_manager, open_file_fails_if_file_is_not_found) {
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, open_file_fails_if_provider_get_filesystem_item_fails) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1424,11 +1420,11 @@ TEST(file_manager, open_file_fails_if_provider_get_filesystem_item_fails) {
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, open_file_fails_if_provider_set_item_meta_fails) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1475,11 +1471,11 @@ TEST(file_manager, open_file_fails_if_provider_set_item_meta_fails) {
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, open_file_creates_source_path_if_empty) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1538,11 +1534,11 @@ TEST(file_manager, open_file_creates_source_path_if_empty) {
EXPECT_EQ(std::size_t(1U), fm.get_open_file_count());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, open_file_first_file_handle_is_not_zero) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1586,11 +1582,11 @@ TEST(file_manager, open_file_first_file_handle_is_not_zero) {
EXPECT_GT(handle, std::uint64_t(0U));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, can_remove_file) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1601,11 +1597,11 @@ TEST(file_manager, can_remove_file) {
file_manager fm(cfg, mp);
native_file::native_file_ptr f{};
EXPECT_EQ(api_error::success,
native_file::create_or_open("./test_remove.txt", f));
f->close();
EXPECT_TRUE(utils::file::is_file("./test_remove.txt"));
{
auto file = utils::file::file::open_or_create_file("./test_remove.txt");
EXPECT_TRUE(*file);
}
EXPECT_TRUE(utils::file::file("./test_remove.txt").exists());
EXPECT_CALL(mp, get_filesystem_item)
.WillOnce([](const std::string &api_path, bool directory,
@@ -1624,14 +1620,14 @@ TEST(file_manager, can_remove_file) {
EXPECT_EQ(api_error::success, fm.remove_file("/test_remove.txt"));
EXPECT_FALSE(utils::file::is_file("./test_remove.txt"));
EXPECT_FALSE(utils::file::file("./test_remove.txt").exists());
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, can_queue_and_remove_upload) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
console_consumer c;
event_system::instance().start();
@@ -1662,11 +1658,11 @@ TEST(file_manager, can_queue_and_remove_upload) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, remove_file_fails_if_open_file_is_modified) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1716,7 +1712,7 @@ TEST(file_manager, remove_file_fails_if_open_file_is_modified) {
EXPECT_EQ(api_error::file_in_use, fm.remove_file("/test_remove.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, file_is_closed_after_download_timeout) {
@@ -1744,7 +1740,7 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
ee.get_api_path().get<std::string>().c_str());
});
const auto now = utils::time::get_file_time_now();
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
@@ -1814,11 +1810,11 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, remove_file_fails_if_file_does_not_exist) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
cfg.set_enable_chunk_downloader_timeout(false);
@@ -1839,11 +1835,11 @@ TEST(file_manager, remove_file_fails_if_file_does_not_exist) {
EXPECT_EQ(api_error::item_not_found, fm.remove_file("/test_remove.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
TEST(file_manager, remove_file_fails_if_provider_remove_file_fails) {
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
{
app_config cfg(provider_type::sia, file_manager_dir);
@@ -1871,6 +1867,6 @@ TEST(file_manager, remove_file_fails_if_provider_remove_file_fails) {
EXPECT_EQ(api_error::item_not_found, fm.remove_file("/test_remove.txt"));
}
EXPECT_TRUE(utils::file::delete_directory_recursively(file_manager_dir));
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
}
} // namespace repertory

View File

@@ -35,8 +35,7 @@ TEST(upload, can_upload_a_valid_file) {
event_system::instance().start();
const auto source_path =
generate_test_file_name("./test_config", "upload_test");
const auto source_path = test::generate_test_file_name("upload_test");
mock_provider mp;
@@ -79,8 +78,7 @@ TEST(upload, can_cancel_upload) {
event_system::instance().start();
const auto source_path =
generate_test_file_name("./test_config", "upload_test");
const auto source_path = test::generate_test_file_name("upload_test");
mock_provider mp;
@@ -145,8 +143,7 @@ TEST(upload, can_stop_upload) {
event_system::instance().start();
const auto source_path =
generate_test_file_name("./test_config", "upload_test");
const auto source_path = test::generate_test_file_name("upload_test");
mock_provider mp;

File diff suppressed because it is too large Load Diff

View File

@@ -57,7 +57,7 @@ const auto check_forced_dirs = [](const repertory::directory_item_list &list) {
const auto create_directory = [](repertory::i_provider &provider,
const std::string &api_path) {
auto date = repertory::utils::time::get_file_time_now();
auto date = repertory::utils::time::get_time_now();
auto meta = repertory::create_meta_attributes(
date, 1U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 2U,
3U, 0U, api_path + "_src", getuid(), date + 4U);
@@ -107,10 +107,9 @@ const auto create_directory = [](repertory::i_provider &provider,
const auto create_file = [](repertory::i_provider &provider,
const std::string &api_path) {
auto source_path =
repertory::generate_test_file_name("./test_config", "providers_test");
auto source_path = repertory::test::generate_test_file_name("providers_test");
auto date = repertory::utils::time::get_file_time_now();
auto date = repertory::utils::time::get_time_now();
auto meta = repertory::create_meta_attributes(
date, 1U, date + 1U, date + 2U, false, getgid(), "", 0700, date + 3U, 2U,
3U, 0U, source_path, getuid(), date + 4U);
@@ -121,7 +120,7 @@ const auto create_file = [](repertory::i_provider &provider,
EXPECT_EQ(repertory::api_error::success, provider.is_file(api_path, exists));
EXPECT_TRUE(exists);
EXPECT_TRUE(repertory::utils::file::delete_file(source_path));
EXPECT_TRUE(repertory::utils::file::file{source_path}.remove());
repertory::api_meta_map meta2{};
EXPECT_EQ(repertory::api_error::success,
@@ -167,9 +166,8 @@ const auto decrypt_parts = [](const repertory::app_config &cfg,
continue;
}
EXPECT_EQ(repertory::api_error::success,
repertory::utils::encryption::decrypt_file_name(
cfg.get_encrypt_config().encryption_token, part));
EXPECT_EQ(true, repertory::utils::encryption::decrypt_file_name(
cfg.get_encrypt_config().encryption_token, part));
}
path = repertory::utils::string::join(parts, '/');
}
@@ -398,7 +396,7 @@ static void get_directory_item_count(const app_config &cfg,
EXPECT_EQ(std::size_t(0U), provider.get_directory_item_count("/not_found"));
const auto source_path =
utils::path::combine("./test_data/encrypt", {"sub10"});
utils::path::combine(test::get_test_input_dir(), {"encrypt", "sub10"});
std::string api_path{};
EXPECT_EQ(api_error::success,
@@ -630,8 +628,8 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
TEST(providers, encrypt_provider) {
const auto config_path =
utils::path::combine("./test_config", {"encrypt_provider"});
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"});
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
console_consumer consumer{};
event_system::instance().start();
@@ -639,7 +637,7 @@ TEST(providers, encrypt_provider) {
app_config cfg(provider_type::encrypt, config_path);
const auto encrypt_path =
utils::path::combine("./test_data/encrypt", {"encrypt"});
utils::path::combine(test::get_test_input_dir(), {"encrypt"});
EXPECT_STREQ(
encrypt_path.c_str(),
@@ -673,16 +671,17 @@ TEST(providers, encrypt_provider) {
TEST(providers, s3_provider) {
const auto config_path =
utils::path::combine("./test_config", {"s3_provider"});
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
utils::path::combine(test::get_test_output_dir(), {"s3_provider"});
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
console_consumer consumer{};
event_system::instance().start();
{
app_config cfg(provider_type::s3, config_path);
{
app_config src_cfg(provider_type::s3,
utils::path::combine(get_test_dir(), {"storj"}));
app_config src_cfg(
provider_type::s3,
utils::path::combine(test::get_test_input_dir(), {"storj"}));
cfg.set_s3_config(src_cfg.get_s3_config());
}
@@ -711,16 +710,17 @@ TEST(providers, s3_provider) {
TEST(providers, sia_provider) {
const auto config_path =
utils::path::combine("./test_config", {"sia_provider"});
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
utils::path::combine(test::get_test_output_dir(), {"sia_provider"});
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
console_consumer consumer{};
event_system::instance().start();
{
app_config cfg(provider_type::sia, config_path);
{
app_config src_cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
app_config src_cfg(
provider_type::sia,
utils::path::combine(test::get_test_input_dir(), {"sia"}));
cfg.set_host_config(src_cfg.get_host_config());
}

View File

@@ -47,12 +47,12 @@ using namespace repertory::remote_fuse;
namespace fuse_test {
static std::string mount_location_;
static std::string fuse_remote_dir =
utils::path::combine("./test_config", {"fuse_remote_test"});
utils::path::combine(test::get_test_output_dir(), {"fuse_remote_test"});
static void access_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"access.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -64,13 +64,13 @@ static void access_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_access(api_path.c_str(), 0));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void chflags_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"chflags.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -86,13 +86,13 @@ static void chflags_test(repertory::remote_fuse::remote_client &client) {
#endif
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void chmod_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"chmod.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -108,13 +108,13 @@ static void chmod_test(repertory::remote_fuse::remote_client &client) {
#endif
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void chown_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"chown.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -134,7 +134,7 @@ static void chown_test(repertory::remote_fuse::remote_client &client) {
#endif
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void
@@ -143,7 +143,7 @@ create_and_release_test(repertory::remote_fuse::remote_client &client,
const auto test_file =
utils::path::combine(fuse_remote_dir, {"create_and_release.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -156,7 +156,7 @@ create_and_release_test(repertory::remote_fuse::remote_client &client,
EXPECT_EQ(0u, server.get_open_file_count(test_file));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void destroy_test(repertory::remote_fuse::remote_client &client) {
@@ -167,7 +167,7 @@ static void destroy_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir,
{"fallocate.txt"}); const auto api_path =
test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -181,14 +181,14 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
EXPECT_EQ(100, file_size);
}
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
}*/
static void fgetattr_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"fgetattr.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -219,23 +219,23 @@ static void fgetattr_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(st1.st_nlink, st.st_nlink);
EXPECT_EQ(st1.st_mode, st.st_mode);
EXPECT_LE(static_cast<remote::file_time>(st1.st_atime),
st.st_atimespec / NANOS_PER_SECOND);
st.st_atimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime),
st.st_mtimespec / NANOS_PER_SECOND);
st.st_mtimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_ctimespec / NANOS_PER_SECOND);
st.st_ctimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_birthtimespec / NANOS_PER_SECOND);
st.st_birthtimespec / utils::time::NANOS_PER_SECOND);
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void fsetattr_x_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"fsetattr_x.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -253,13 +253,13 @@ static void fsetattr_x_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void fsync_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"fsync.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -271,14 +271,14 @@ static void fsync_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void ftruncate_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"ftruncate.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -289,18 +289,18 @@ static void ftruncate_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_ftruncate(api_path.c_str(), 100, handle));
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(test_file, file_size));
EXPECT_EQ(100u, file_size);
auto opt_size = utils::file::file{test_file}.size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(100U, opt_size.value());
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void getattr_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"getattr.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -330,23 +330,23 @@ static void getattr_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(st1.st_nlink, st.st_nlink);
EXPECT_EQ(st1.st_mode, st.st_mode);
EXPECT_LE(static_cast<remote::file_time>(st1.st_atime),
st.st_atimespec / NANOS_PER_SECOND);
st.st_atimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime),
st.st_mtimespec / NANOS_PER_SECOND);
st.st_mtimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_ctimespec / NANOS_PER_SECOND);
st.st_ctimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_birthtimespec / NANOS_PER_SECOND);
st.st_birthtimespec / utils::time::NANOS_PER_SECOND);
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
/*static void getxattr_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir,
{"getxattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -359,14 +359,14 @@ nullptr, 0)); #else EXPECT_EQ(-EACCES, client.fuse_getxattr(api_path.c_str(),
"test", nullptr, 0)); #endif
}
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
}
static void getxattr_osx_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir,
{"getxattr_osx.txt"}); const auto api_path =
test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -377,14 +377,14 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
client.fuse_getxattrOSX(api_path.c_str(), "test", nullptr, 0, 0));
}
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
}*/
static void getxtimes_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"getxtimes.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -403,7 +403,7 @@ static void getxtimes_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void init_test(repertory::remote_fuse::remote_client &client) {
@@ -414,7 +414,7 @@ static void init_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir,
{"listxattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -427,29 +427,29 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
#endif
}
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
}*/
static void mkdir_test(repertory::remote_fuse::remote_client &client) {
const auto test_directory =
utils::path::combine(fuse_remote_dir, {"mkdir_test"});
const auto api_path = test_directory.substr(mount_location_.size());
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
#if defined(_WIN32)
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
#else
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
#endif
EXPECT_TRUE(utils::file::is_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).exists());
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
}
static void open_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"open.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
#if defined(_WIN32)
@@ -471,7 +471,7 @@ static void open_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle2));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void
@@ -479,27 +479,27 @@ opendir_and_releasedir_test(repertory::remote_fuse::remote_client &client) {
const auto test_directory =
utils::path::combine(fuse_remote_dir, {"opendir_and_release_dir"});
const auto api_path = test_directory.substr(mount_location_.size());
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
#if defined(_WIN32)
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
#else
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
#endif
EXPECT_TRUE(utils::file::is_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).exists());
remote::file_handle handle = 0;
EXPECT_EQ(0, client.fuse_opendir(api_path.c_str(), handle));
EXPECT_EQ(0, client.fuse_releasedir(api_path.c_str(), handle));
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
}
static void read_and_write_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"read_and_write.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -517,7 +517,7 @@ static void read_and_write_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void
@@ -525,7 +525,7 @@ read_and_write_base64_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"read_and_write_base64.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -534,7 +534,7 @@ read_and_write_base64_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, ret);
if (ret == 0) {
const auto data = macaron::Base64::Encode("1234567890");
EXPECT_EQ(10, client.fuse_write_base64(api_path.c_str(), &data[0],
EXPECT_EQ(10, client.fuse_write_base64(api_path.c_str(), data.data(),
data.size(), 0, handle));
data_buffer buffer(10);
EXPECT_EQ(10, client.fuse_read(api_path.c_str(),
@@ -544,21 +544,21 @@ read_and_write_base64_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void readdir_test(repertory::remote_fuse::remote_client &client) {
const auto test_directory =
utils::path::combine(fuse_remote_dir, {"readdir_test"});
const auto api_path = test_directory.substr(mount_location_.size());
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
#if defined(_WIN32)
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
#else
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
#endif
EXPECT_TRUE(utils::file::is_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).exists());
remote::file_handle handle = 0;
EXPECT_EQ(0, client.fuse_opendir(api_path.c_str(), handle));
@@ -572,14 +572,14 @@ static void readdir_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_releasedir(api_path.c_str(), handle));
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
}
/*static void removexattr_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir,
{"removexattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -592,7 +592,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
"test")); #endif
}
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
}*/
static void rename_test(repertory::remote_fuse::remote_client &client) {
@@ -602,8 +602,8 @@ static void rename_test(repertory::remote_fuse::remote_client &client) {
const auto api_path = test_file.substr(mount_location_.size());
const auto renamed_api_path =
renamed_test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::retry_delete_file(renamed_test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::file(renamed_test_file).remove());
remote::file_handle handle;
#if defined(_WIN32)
@@ -621,38 +621,38 @@ static void rename_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
EXPECT_EQ(0,
client.fuse_rename(api_path.c_str(), renamed_api_path.c_str()));
EXPECT_FALSE(utils::file::is_file(test_file));
EXPECT_TRUE(utils::file::is_file(renamed_test_file));
EXPECT_FALSE(utils::file::file(test_file).exists());
EXPECT_TRUE(utils::file::file(renamed_test_file).exists());
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::retry_delete_file(renamed_test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::file(renamed_test_file).remove());
}
static void rmdir_test(repertory::remote_fuse::remote_client &client) {
const auto test_directory =
utils::path::combine(fuse_remote_dir, {"rmdir_test"});
const auto api_path = test_directory.substr(mount_location_.size());
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
#if defined(_WIN32)
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
#else
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
#endif
EXPECT_TRUE(utils::file::is_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).exists());
EXPECT_EQ(0, client.fuse_rmdir(api_path.c_str()));
EXPECT_FALSE(utils::file::is_directory(test_directory));
EXPECT_FALSE(utils::file::directory(test_directory).exists());
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
}
static void setattr_x_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"setattr_x.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -670,14 +670,14 @@ static void setattr_x_test(repertory::remote_fuse::remote_client &client) {
#endif
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"setbkuptime.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -687,7 +687,7 @@ static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::time::get_file_time_now();
remote::file_time ts = utils::time::get_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setbkuptime(api_path.c_str(), ts));
#else
@@ -695,14 +695,14 @@ static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
#endif
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"setchgtime.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -712,7 +712,7 @@ static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::time::get_file_time_now();
remote::file_time ts = utils::time::get_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setchgtime(api_path.c_str(), ts));
#else
@@ -720,14 +720,14 @@ static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
#endif
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"setcrtime.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -737,7 +737,7 @@ static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::time::get_file_time_now();
remote::file_time ts = utils::time::get_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setcrtime(api_path.c_str(), ts));
#else
@@ -745,7 +745,7 @@ static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
#endif
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void setvolname_test(repertory::remote_fuse::remote_client &client) {
@@ -756,7 +756,7 @@ static void setvolname_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir,
{"setxattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -771,14 +771,14 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
5, 0)); #endif
}
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
}
static void setxattr_osx_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir,
{"setxattr_osx.txt"}); const auto api_path =
test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -791,7 +791,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
0));
}
utils::file::retry_delete_file(test_file);
utils::file::file(test_file).remove();
}*/
#if defined(_WIN32)
@@ -832,7 +832,7 @@ static void statfs_x_test(repertory::remote_fuse::remote_client &client,
remote::statfs_x st{};
EXPECT_EQ(0, client.fuse_statfs_x(api_path.c_str(), 4096, st));
EXPECT_STREQ(&st.f_mntfromname[0],
EXPECT_STREQ(st.f_mntfromname.data(),
utils::create_volume_label(provider_type::remote).c_str());
const auto total_bytes = drive.get_total_drive_space();
@@ -853,7 +853,7 @@ static void truncate_test(repertory::remote_fuse::remote_client &client) {
const auto test_file =
utils::path::combine(fuse_remote_dir, {"truncate.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
#if defined(_WIN32)
@@ -871,18 +871,18 @@ static void truncate_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_truncate(api_path.c_str(), 100));
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(test_file, file_size));
EXPECT_EQ(100u, file_size);
auto opt_size = utils::file::file{test_file}.size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(100U, opt_size.value());
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void unlink_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"unlink.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -892,16 +892,16 @@ static void unlink_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
EXPECT_EQ(0, client.fuse_unlink(api_path.c_str()));
EXPECT_FALSE(utils::file::is_file(test_file));
EXPECT_FALSE(utils::file::file(test_file).exists());
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void utimens_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"utimens.txt"});
const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle;
const auto ret = client.fuse_create(
@@ -915,7 +915,7 @@ static void utimens_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_utimens(api_path.c_str(), tv, 0, 0));
}
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
TEST(remote_fuse, all_tests) {
@@ -934,11 +934,11 @@ TEST(remote_fuse, all_tests) {
event_system::instance().start();
#if defined(_WIN32)
mount_location_ = std::string("./test_config").substr(0, 2);
mount_location_ = fuse_remote_dir.substr(0, 2);
mock_winfsp_drive drive(mount_location_);
remote_server server(config, drive, mount_location_);
#else
mount_location_ = utils::path::absolute(".");
mount_location_ = fuse_remote_dir;
mock_fuse_drive drive(mount_location_);
remote_server server(config, drive, mount_location_);
#endif
@@ -990,6 +990,6 @@ TEST(remote_fuse, all_tests) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(fuse_remote_dir));
EXPECT_TRUE(utils::file::directory(fuse_remote_dir).remove_recursively());
}
} // namespace fuse_test

View File

@@ -33,6 +33,7 @@
#include "platform/platform.hpp"
#include "types/repertory.hpp"
#include "utils/common.hpp"
#include "utils/time.hpp"
using namespace repertory;
using namespace repertory::remote_winfsp;
@@ -40,32 +41,32 @@ using namespace repertory::remote_winfsp;
namespace winfsp_test {
static std::string mount_location_;
static std::string win_remote_dir =
utils::path::combine("./test_config", {"win_remote_test"});
utils::path::combine(test::get_test_output_dir(), {"win_remote_test"});
static void can_delete_test(remote_client &client) {
const auto test_file =
utils::path::combine(win_remote_dir, {"candelete.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
native_file::native_file_ptr nf;
EXPECT_EQ(api_error::success, native_file::create_or_open(test_file, nf));
auto ptr = utils::file::file::open_or_create_file(test_file);
auto &nf = *ptr;
EXPECT_TRUE(nf);
if (nf) {
EXPECT_EQ(STATUS_INVALID_HANDLE,
client.winfsp_can_delete(
reinterpret_cast<PVOID>(nf->get_handle()), &api_path[0]));
client.winfsp_can_delete(reinterpret_cast<PVOID>(nf.get_handle()),
api_path.data()));
nf->close();
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
nf.close();
EXPECT_TRUE(utils::file::file(test_file).remove());
}
}
template <typename t>
static void create_and_close_test(remote_client &client, t &server) {
const auto test_file = utils::path::combine(win_remote_dir, {"create.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -83,12 +84,12 @@ static void create_and_close_test(remote_client &client, t &server) {
EXPECT_EQ(0u, client.get_open_file_count(utils::string::to_utf8(api_path)));
EXPECT_EQ(0u, server.get_open_file_count(test_file));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void cleanup_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"cleanup.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -107,12 +108,12 @@ static void cleanup_test(remote_client &client) {
EXPECT_FALSE(was_closed);
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void flush_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"flush.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -129,13 +130,13 @@ static void flush_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void get_file_info_test(remote_client &client) {
const auto test_file =
utils::path::combine(win_remote_dir, {"get_file_info.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -152,13 +153,13 @@ static void get_file_info_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void get_security_by_name_test(remote_client &client) {
const auto test_file =
utils::path::combine(win_remote_dir, {"get_security_by_name.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -181,7 +182,7 @@ static void get_security_by_name_test(remote_client &client) {
EXPECT_EQ(static_cast<UINT32>(FILE_ATTRIBUTE_NORMAL), attributes);
EXPECT_FALSE(str_descriptor.empty());
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void get_volume_info_test(remote_client &client) {
@@ -202,7 +203,7 @@ static void mounted_test(remote_client &client) {
static void open_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"open.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -229,13 +230,13 @@ static void open_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc2));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void overwrite_test(remote_client &client) {
const auto test_file =
utils::path::combine(win_remote_dir, {"overwrite.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -259,13 +260,13 @@ static void overwrite_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void create_and_read_directory_test(remote_client &client) {
const auto test_directory =
utils::path::combine(win_remote_dir, {"read_directory"});
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
auto api_path =
utils::string::from_utf8(test_directory).substr(mount_location_.size());
@@ -278,7 +279,7 @@ static void create_and_read_directory_test(remote_client &client) {
FILE_ATTRIBUTE_DIRECTORY, 0, &file_desc, &fi, normalized_name, exists);
EXPECT_EQ(STATUS_SUCCESS, ret);
EXPECT_TRUE(utils::file::is_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).exists());
json list;
ret = client.winfsp_read_directory(file_desc, nullptr, nullptr, list);
@@ -287,13 +288,13 @@ static void create_and_read_directory_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
}
static void open_and_read_directory_test(remote_client &client) {
const auto test_directory =
utils::path::combine(win_remote_dir, {"open_and_read_directory"});
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
auto api_path =
utils::string::from_utf8(test_directory).substr(mount_location_.size());
@@ -308,7 +309,7 @@ static void open_and_read_directory_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::is_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).exists());
file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
ret = client.winfsp_open(&api_path[0], FILE_DIRECTORY_FILE,
@@ -323,13 +324,13 @@ static void open_and_read_directory_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::delete_directory(test_directory));
EXPECT_TRUE(utils::file::directory(test_directory).remove());
}
static void read_and_write_test(remote_client &client) {
const auto test_file =
utils::path::combine(win_remote_dir, {"read_and_write.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -365,14 +366,14 @@ static void read_and_write_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void rename_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"rename.txt"});
const auto test_file2 = utils::path::combine(win_remote_dir, {"rename2.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::retry_delete_file(test_file2));
EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::file(test_file2).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
auto api_path2 =
@@ -389,20 +390,20 @@ static void rename_test(remote_client &client) {
ret = client.winfsp_rename(file_desc, &api_path[0], &api_path2[0], 0);
EXPECT_EQ(STATUS_SUCCESS, ret);
EXPECT_TRUE(utils::file::is_file(test_file2));
EXPECT_FALSE(utils::file::is_file(test_file));
EXPECT_TRUE(utils::file::file(test_file2).exists());
EXPECT_FALSE(utils::file::file(test_file).exists());
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::retry_delete_file(test_file2));
EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::file(test_file2).remove());
}
static void set_basic_info_test(remote_client &client) {
const auto test_file =
utils::path::combine(win_remote_dir, {"set_basic_info.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -429,7 +430,7 @@ static void set_basic_info_test(remote_client &client) {
const auto change_time = last_write_time;
#else
const auto creation_time =
utils::unix_time_to_windows_time(utils::time::get_time_now());
utils::time::unix_time_to_windows_time(utils::time::get_time_now());
const auto last_access_time = creation_time + 1;
const auto last_write_time = creation_time + 2;
const auto change_time = last_write_time;
@@ -447,13 +448,13 @@ static void set_basic_info_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void set_file_size_test(remote_client &client) {
const auto test_file =
utils::path::combine(win_remote_dir, {"set_file_size.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size());
@@ -472,13 +473,13 @@ static void set_file_size_test(remote_client &client) {
client.winfsp_set_file_size(file_desc, new_file_size,
set_allocation_size, &fi));
std::uint64_t file_size = 0u;
EXPECT_TRUE(utils::file::get_file_size(test_file, file_size));
EXPECT_EQ(34u, file_size);
auto opt_size = utils::file::file{test_file}.size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(34U, opt_size.value());
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
EXPECT_TRUE(utils::file::file(test_file).remove());
}
static void unmounted_test(remote_client &client) {
@@ -492,7 +493,6 @@ TEST(remote_winfsp, all_tests) {
EXPECT_TRUE(found_port);
if (found_port) {
console_consumer c;
app_config config(provider_type::remote, win_remote_dir);
config.set_remote_host_name_or_ip("localhost");
config.set_remote_port(port);
@@ -502,11 +502,11 @@ TEST(remote_winfsp, all_tests) {
event_system::instance().start();
#if defined(_WIN32)
mount_location_ = std::string("./test_config").substr(0, 2);
mount_location_ = win_remote_dir.substr(0, 2);
mock_winfsp_drive drive(mount_location_);
remote_server server(config, drive, mount_location_);
#else
mount_location_ = utils::path::absolute(".");
mount_location_ = win_remote_dir;
mock_fuse_drive drive(mount_location_);
remote_fuse::remote_server server(config, drive, mount_location_);
#endif
@@ -536,6 +536,6 @@ TEST(remote_winfsp, all_tests) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(win_remote_dir));
EXPECT_TRUE(utils::file::directory(win_remote_dir).remove_recursively());
}
} // namespace winfsp_test

View File

@@ -1,73 +0,0 @@
/*
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.
*/
#include "test_common.hpp"
#include "types/repertory.hpp"
#include "utils/common.hpp"
#include "utils/path.hpp"
namespace repertory {
std::vector<std::string> generated_files;
void delete_generated_files() {
for (const auto &file : generated_files) {
EXPECT_TRUE(utils::file::retry_delete_file(file));
}
}
auto create_random_file(std::string path, std::size_t size) -> native_file_ptr {
native_file_ptr file;
if (native_file::create_or_open(path, file) == api_error::success) {
generated_files.emplace_back(utils::path::absolute(path));
EXPECT_TRUE(file->truncate(0U));
data_buffer buf(size);
randombytes_buf(buf.data(), buf.size());
std::size_t bytes_written{};
EXPECT_TRUE(file->write_bytes(buf.data(), buf.size(), 0U, bytes_written));
file->flush();
std::uint64_t current_size{};
EXPECT_TRUE(utils::file::get_file_size(path, current_size));
EXPECT_EQ(size, current_size);
}
return file;
}
auto generate_test_file_name(const std::string &directory,
const std::string &file_name_no_extension)
-> std::string {
static std::atomic<std::uint32_t> idx{0U};
auto path = utils::path::combine(
directory, {file_name_no_extension + std::to_string(idx++) + ".dat"});
generated_files.emplace_back(path);
return path;
}
auto get_test_dir() -> std::string {
auto dir = utils::get_environment_variable("PROJECT_TEST_DIR");
return utils::path::combine(dir.empty() ? "." : dir, {"test_config"});
}
} // namespace repertory

View File

@@ -21,17 +21,14 @@
*/
#include "test_common.hpp"
#include "platform/platform.hpp"
#include "utils/common.hpp"
#include "utils/file_utils.hpp"
#include "utils/string.hpp"
#include "utils/utils.hpp"
#include "providers/s3/s3_provider.hpp"
#include "utils/file.hpp"
namespace repertory {
#if defined(_WIN32)
TEST(utils, convert_api_date) {
LARGE_INTEGER li{};
li.QuadPart = utils::convert_api_date("2009-10-12T17:50:30.111Z");
li.QuadPart = s3_provider::convert_api_date("2009-10-12T17:50:30.111Z");
SYSTEMTIME st{};
FileTimeToSystemTime(reinterpret_cast<FILETIME *>(&li), &st);
@@ -48,10 +45,13 @@ TEST(utils, convert_api_date) {
EXPECT_EQ(20, lt.wSecond);
EXPECT_EQ(111, lt.wMilliseconds);
}
#endif
#endif // defined(_WIN32)
TEST(utils, generate_sha256) {
const auto res = utils::file::generate_sha256(__FILE__);
std::cout << res << std::endl;
auto res = utils::file::file{__FILE__}.sha256();
EXPECT_TRUE(res.has_value());
if (res.has_value()) {
std::cout << res.value() << std::endl;
}
}
} // namespace repertory

View File

@@ -69,19 +69,19 @@ static void execute_mount(winfsp_test *test,
static void unmount(winfsp_test *test, const std::string &mount_point) {
test->drive->shutdown();
auto mounted = utils::file::is_directory(mount_point);
auto mounted = utils::file::directory(mount_point).exists();
for (auto i = 0; mounted && (i < 50); i++) {
std::this_thread::sleep_for(100ms);
mounted = utils::file::is_directory(mount_point);
mounted = utils::file::directory(mount_point).exists();
}
EXPECT_FALSE(utils::file::is_directory(mount_point));
EXPECT_FALSE(utils::file::directory(mount_point).exists());
}
static void root_creation_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
WIN32_FILE_ATTRIBUTE_DATA ad{};
EXPECT_TRUE(
::GetFileAttributesEx(&mount_point[0], GetFileExInfoStandard, &ad));
::GetFileAttributesEx(mount_point.c_str(), GetFileExInfoStandard, &ad));
EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, ad.dwFileAttributes);
EXPECT_EQ(0, ad.nFileSizeHigh);
EXPECT_EQ(0, ad.nFileSizeLow);
@@ -96,11 +96,11 @@ static auto create_test(winfsp_test *test, const std::string &mount_point) {
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
EXPECT_TRUE(::CloseHandle(handle));
EXPECT_TRUE(utils::file::is_file(file));
EXPECT_TRUE(utils::file::file(file).exists());
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
EXPECT_EQ(0, file_size);
auto opt_size = utils::file::file(file).size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(0, opt_size.value());
std::string attr;
EXPECT_EQ(api_error::success, test->provider->get_item_meta(
@@ -113,8 +113,8 @@ static auto create_test(winfsp_test *test, const std::string &mount_point) {
static void delete_file_test(const std::string &file) {
TEST_HEADER(__FUNCTION__);
event_capture ec({"file_removed"});
EXPECT_TRUE(utils::file::retry_delete_file(file));
EXPECT_FALSE(utils::file::is_file(file));
EXPECT_TRUE(utils::file::file(file).remove());
EXPECT_FALSE(utils::file::file(file).exists());
}
static void create_directory_test(const std::string &directory) {
@@ -149,11 +149,11 @@ static void write_file_test(const std::string &mount_point) {
EXPECT_EQ(10, bytes_written);
EXPECT_TRUE(::CloseHandle(handle));
EXPECT_TRUE(utils::file::is_file(file));
EXPECT_TRUE(utils::file::file(file).exists());
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
EXPECT_EQ(10, file_size);
auto opt_size = utils::file::file(file).size();
EXPECT_TRUE(opt_size.has_value());
EXPECT_EQ(10U, opt_size.value());
}
static void read_file_test(const std::string &mount_point) {
@@ -199,8 +199,8 @@ static void rename_file_test(winfsp_test *test,
const auto file2 = utils::path::combine(mount_point, {"rename_file2.txt"});
EXPECT_TRUE(::MoveFile(&file[0], &file2[0]));
EXPECT_TRUE(utils::file::is_file(file2));
EXPECT_FALSE(utils::file::is_file(file));
EXPECT_TRUE(utils::file::file(file2).exists());
EXPECT_FALSE(utils::file::file(file).exists());
api_meta_map meta2{};
EXPECT_EQ(api_error::success,