remove tests
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
This commit is contained in:
parent
bb4e3c26f4
commit
acdc165102
@ -1,994 +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"
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#define NOT_IMPLEMENTED STATUS_NOT_IMPLEMENTED
|
|
||||||
#include "drives/winfsp/i_winfsp_drive.hpp"
|
|
||||||
#include "drives/winfsp/remotewinfsp/remote_server.hpp"
|
|
||||||
#include "mocks/mock_winfsp_drive.hpp"
|
|
||||||
#else
|
|
||||||
#define NOT_IMPLEMENTED -ENOTSUP
|
|
||||||
#include "drives/fuse/i_fuse_drive.hpp"
|
|
||||||
#include "drives/fuse/remotefuse/remote_server.hpp"
|
|
||||||
#include "mocks/mock_fuse_drive.hpp"
|
|
||||||
#endif
|
|
||||||
#include "drives/fuse/remotefuse/remote_client.hpp"
|
|
||||||
#include "types/repertory.hpp"
|
|
||||||
#include "utils/common.hpp"
|
|
||||||
#include "utils/time.hpp"
|
|
||||||
#include "utils/utils.hpp"
|
|
||||||
|
|
||||||
using namespace repertory;
|
|
||||||
#if defined(_WIN32)
|
|
||||||
using namespace repertory::remote_winfsp;
|
|
||||||
#else
|
|
||||||
using namespace repertory::remote_fuse;
|
|
||||||
#endif
|
|
||||||
namespace fuse_test {
|
|
||||||
static std::string mount_location_;
|
|
||||||
static std::string fuse_remote_dir =
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
EXPECT_EQ(0, client.fuse_access(api_path.c_str(), 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
#if defined(_WIN32)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_chflags(api_path.c_str(), 0));
|
|
||||||
#else
|
|
||||||
EXPECT_EQ(0, client.fuse_chflags(api_path.c_str(), 0));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
#if defined(_WIN32)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_chmod(api_path.c_str(), 0));
|
|
||||||
#else
|
|
||||||
EXPECT_EQ(0, client.fuse_chmod(api_path.c_str(), S_IRUSR | S_IWUSR));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
#if defined(_WIN32)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_chown(api_path.c_str(), 0, 0));
|
|
||||||
#else
|
|
||||||
if (getuid() == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_chown(api_path.c_str(), 0, 0));
|
|
||||||
} else {
|
|
||||||
EXPECT_EQ(-EPERM, client.fuse_chown(api_path.c_str(), 0, 0));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
create_and_release_test(repertory::remote_fuse::remote_client &client,
|
|
||||||
remote_server &server) {
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(1u, server.get_open_file_count(test_file));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
EXPECT_EQ(0u, server.get_open_file_count(test_file));
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void destroy_test(repertory::remote_fuse::remote_client &client) {
|
|
||||||
EXPECT_EQ(0, client.fuse_destroy());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*static void fallocate_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::file(test_file).remove();
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0, remote::open_flags::Create |
|
|
||||||
remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_fallocate(api_path.c_str(), 0, 0, 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(100, file_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_ftruncate(api_path.c_str(), 100, handle));
|
|
||||||
client.set_fuse_uid_gid(10, 11);
|
|
||||||
|
|
||||||
bool directory;
|
|
||||||
remote::stat st{};
|
|
||||||
EXPECT_EQ(0, client.fuse_fgetattr(api_path.c_str(), st, directory, handle));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
EXPECT_FALSE(directory);
|
|
||||||
#if defined(_WIN32)
|
|
||||||
struct _stat64 st1{};
|
|
||||||
_stat64(&test_file[0], &st1);
|
|
||||||
#else
|
|
||||||
struct stat st1{};
|
|
||||||
stat(&test_file[0], &st1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXPECT_EQ(11u, st.st_gid);
|
|
||||||
EXPECT_EQ(10u, st.st_uid);
|
|
||||||
EXPECT_EQ(static_cast<std::uint64_t>(st1.st_size), st.st_size);
|
|
||||||
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 / utils::time::NANOS_PER_SECOND);
|
|
||||||
EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime),
|
|
||||||
st.st_mtimespec / utils::time::NANOS_PER_SECOND);
|
|
||||||
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
|
|
||||||
st.st_ctimespec / utils::time::NANOS_PER_SECOND);
|
|
||||||
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
|
|
||||||
st.st_birthtimespec / utils::time::NANOS_PER_SECOND);
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
remote::setattr_x attr{};
|
|
||||||
#if defined(_WIN32)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED,
|
|
||||||
client.fuse_fsetattr_x(api_path.c_str(), attr, handle));
|
|
||||||
#else
|
|
||||||
EXPECT_EQ(0, client.fuse_fsetattr_x(api_path.c_str(), attr, handle));
|
|
||||||
#endif
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_fsync(api_path.c_str(), 0, handle));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_ftruncate(api_path.c_str(), 100, handle));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
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::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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_ftruncate(api_path.c_str(), 100, handle));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
client.set_fuse_uid_gid(10, 11);
|
|
||||||
|
|
||||||
bool directory;
|
|
||||||
remote::stat st{};
|
|
||||||
EXPECT_EQ(0, client.fuse_getattr(api_path.c_str(), st, directory));
|
|
||||||
EXPECT_FALSE(directory);
|
|
||||||
#if defined(_WIN32)
|
|
||||||
struct _stat64 st1{};
|
|
||||||
_stat64(&test_file[0], &st1);
|
|
||||||
#else
|
|
||||||
struct stat st1{};
|
|
||||||
stat(&test_file[0], &st1);
|
|
||||||
#endif
|
|
||||||
EXPECT_EQ(11u, st.st_gid);
|
|
||||||
EXPECT_EQ(10u, st.st_uid);
|
|
||||||
EXPECT_EQ(static_cast<remote::file_size>(st1.st_size), st.st_size);
|
|
||||||
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 / utils::time::NANOS_PER_SECOND);
|
|
||||||
EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime),
|
|
||||||
st.st_mtimespec / utils::time::NANOS_PER_SECOND);
|
|
||||||
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
|
|
||||||
st.st_ctimespec / utils::time::NANOS_PER_SECOND);
|
|
||||||
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
|
|
||||||
st.st_birthtimespec / utils::time::NANOS_PER_SECOND);
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove();
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0, remote::open_flags::Create |
|
|
||||||
remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
#if defined(_WIN32) || !defined(HAS_SETXATTR) || defined(__APPLE__)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_getxattr(api_path.c_str(), "test",
|
|
||||||
nullptr, 0)); #else EXPECT_EQ(-EACCES, client.fuse_getxattr(api_path.c_str(),
|
|
||||||
"test", nullptr, 0)); #endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove();
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0, remote::open_flags::Create |
|
|
||||||
remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED,
|
|
||||||
client.fuse_getxattrOSX(api_path.c_str(), "test", nullptr, 0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
remote::file_time bkuptime = 0;
|
|
||||||
remote::file_time crtime = 0;
|
|
||||||
#if defined(_WIN32)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED,
|
|
||||||
client.fuse_getxtimes(api_path.c_str(), bkuptime, crtime));
|
|
||||||
#else
|
|
||||||
EXPECT_EQ(0, client.fuse_getxtimes(api_path.c_str(), bkuptime, crtime));
|
|
||||||
#endif
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_test(repertory::remote_fuse::remote_client &client) {
|
|
||||||
EXPECT_EQ(0, client.fuse_init());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*static void listxattr_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::file(test_file).remove();
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0, remote::open_flags::Create |
|
|
||||||
remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
#if defined(_WIN32) || !defined(HAS_SETXATTR)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_listxattr(api_path.c_str(), nullptr,
|
|
||||||
0)); #else EXPECT_EQ(-EIO, client.fuse_listxattr(api_path.c_str(), nullptr, 0));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::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::directory(test_directory).exists());
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
#if defined(_WIN32)
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
#else
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), S_IRWXU,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
#endif
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
remote::file_handle handle2;
|
|
||||||
EXPECT_EQ(0, client.fuse_open(api_path.c_str(),
|
|
||||||
remote::open_flags::read_write, handle2));
|
|
||||||
EXPECT_NE(handle, handle2);
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle2));
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
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::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::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::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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(10,
|
|
||||||
client.fuse_write(api_path.c_str(), "1234567890", 10, 0, handle));
|
|
||||||
data_buffer buffer(10);
|
|
||||||
EXPECT_EQ(10, client.fuse_read(api_path.c_str(),
|
|
||||||
reinterpret_cast<char *>(buffer.data()), 10,
|
|
||||||
0, handle));
|
|
||||||
EXPECT_EQ(0, std::memcmp("1234567890", buffer.data(), 10));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
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.data(),
|
|
||||||
data.size(), 0, handle));
|
|
||||||
data_buffer buffer(10);
|
|
||||||
EXPECT_EQ(10, client.fuse_read(api_path.c_str(),
|
|
||||||
reinterpret_cast<char *>(buffer.data()), 10,
|
|
||||||
0, handle));
|
|
||||||
EXPECT_EQ(0, std::memcmp("1234567890", buffer.data(), 10));
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
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::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::directory(test_directory).exists());
|
|
||||||
|
|
||||||
remote::file_handle handle = 0;
|
|
||||||
EXPECT_EQ(0, client.fuse_opendir(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
std::string item_path;
|
|
||||||
EXPECT_EQ(0, client.fuse_readdir(api_path.c_str(), 0, handle, item_path));
|
|
||||||
EXPECT_STREQ(".", item_path.c_str());
|
|
||||||
|
|
||||||
EXPECT_EQ(0, client.fuse_readdir(api_path.c_str(), 1, handle, item_path));
|
|
||||||
EXPECT_STREQ("..", item_path.c_str());
|
|
||||||
|
|
||||||
EXPECT_EQ(0, client.fuse_releasedir(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
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::file(test_file).remove();
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0, remote::open_flags::Create |
|
|
||||||
remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
#if defined(_WIN32) || !defined(HAS_SETXATTR)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_removexattr(api_path.c_str(),
|
|
||||||
"test")); #else EXPECT_EQ(-EACCES, client.fuse_removexattr(api_path.c_str(),
|
|
||||||
"test")); #endif
|
|
||||||
}
|
|
||||||
|
|
||||||
utils::file::file(test_file).remove();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
static void rename_test(repertory::remote_fuse::remote_client &client) {
|
|
||||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"rename.txt"});
|
|
||||||
const auto renamed_test_file =
|
|
||||||
utils::path::combine(fuse_remote_dir, {"rename,.txt"});
|
|
||||||
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::file(test_file).remove());
|
|
||||||
EXPECT_TRUE(utils::file::file(renamed_test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
#if defined(_WIN32)
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
#else
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), S_IRWXU,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
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::file(test_file).exists());
|
|
||||||
EXPECT_TRUE(utils::file::file(renamed_test_file).exists());
|
|
||||||
}
|
|
||||||
|
|
||||||
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::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::directory(test_directory).exists());
|
|
||||||
|
|
||||||
EXPECT_EQ(0, client.fuse_rmdir(api_path.c_str()));
|
|
||||||
EXPECT_FALSE(utils::file::directory(test_directory).exists());
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
remote::setattr_x attr{};
|
|
||||||
#if defined(_WIN32)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setattr_x(api_path.c_str(), attr));
|
|
||||||
#else
|
|
||||||
EXPECT_EQ(0, client.fuse_setattr_x(api_path.c_str(), attr));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
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
|
|
||||||
EXPECT_EQ(0, client.fuse_setbkuptime(api_path.c_str(), ts));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
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
|
|
||||||
EXPECT_EQ(0, client.fuse_setchgtime(api_path.c_str(), ts));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
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
|
|
||||||
EXPECT_EQ(0, client.fuse_setcrtime(api_path.c_str(), ts));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setvolname_test(repertory::remote_fuse::remote_client &client) {
|
|
||||||
EXPECT_EQ(0, client.fuse_setvolname("moose"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*static void setxattr_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::file(test_file).remove();
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0, remote::open_flags::Create |
|
|
||||||
remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
#if defined(_WIN32) || !defined(HAS_SETXATTR)
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED,
|
|
||||||
client.fuse_setxattr(api_path.c_str(), "test", "moose", 5, 0));
|
|
||||||
#else
|
|
||||||
EXPECT_EQ(-EACCES, client.fuse_setxattr(api_path.c_str(), "test", "moose",
|
|
||||||
5, 0)); #endif
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove();
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0, remote::open_flags::Create |
|
|
||||||
remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
|
||||||
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
EXPECT_EQ(NOT_IMPLEMENTED,
|
|
||||||
client.fuse_setxattr_osx(api_path.c_str(), "test", "moose", 5, 0,
|
|
||||||
0));
|
|
||||||
}
|
|
||||||
|
|
||||||
utils::file::file(test_file).remove();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
static void test_statfs(repertory::remote_fuse::remote_client &client,
|
|
||||||
const i_winfsp_drive &drive) {
|
|
||||||
#else
|
|
||||||
static void test_statfs(repertory::remote_fuse::remote_client &client,
|
|
||||||
const i_fuse_drive &drive) {
|
|
||||||
#endif
|
|
||||||
const auto api_path = fuse_remote_dir.substr(mount_location_.size());
|
|
||||||
|
|
||||||
remote::statfs st{};
|
|
||||||
EXPECT_EQ(0, client.fuse_statfs(api_path.c_str(), 4096, st));
|
|
||||||
|
|
||||||
const auto total_bytes = drive.get_total_drive_space();
|
|
||||||
const auto total_used = drive.get_used_drive_space();
|
|
||||||
const auto used_blocks =
|
|
||||||
utils::divide_with_ceiling(total_used, static_cast<std::uint64_t>(4096));
|
|
||||||
EXPECT_EQ(
|
|
||||||
utils::divide_with_ceiling(total_bytes, static_cast<std::uint64_t>(4096)),
|
|
||||||
st.f_blocks);
|
|
||||||
EXPECT_EQ(st.f_blocks ? (st.f_blocks - used_blocks) : 0, st.f_bavail);
|
|
||||||
EXPECT_EQ(st.f_bavail, st.f_bfree);
|
|
||||||
EXPECT_EQ(4294967295U, st.f_files);
|
|
||||||
EXPECT_EQ(4294967295U - drive.get_total_item_count(), st.f_favail);
|
|
||||||
EXPECT_EQ(st.f_favail, st.f_ffree);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
static void statfs_x_test(repertory::remote_fuse::remote_client &client,
|
|
||||||
const i_winfsp_drive &drive) {
|
|
||||||
#else
|
|
||||||
|
|
||||||
static void statfs_x_test(repertory::remote_fuse::remote_client &client,
|
|
||||||
const i_fuse_drive &drive) {
|
|
||||||
#endif
|
|
||||||
const auto api_path = fuse_remote_dir.substr(mount_location_.size());
|
|
||||||
|
|
||||||
remote::statfs_x st{};
|
|
||||||
EXPECT_EQ(0, client.fuse_statfs_x(api_path.c_str(), 4096, st));
|
|
||||||
EXPECT_STREQ(st.f_mntfromname.data(),
|
|
||||||
utils::create_volume_label(provider_type::remote).c_str());
|
|
||||||
|
|
||||||
const auto total_bytes = drive.get_total_drive_space();
|
|
||||||
const auto total_used = drive.get_used_drive_space();
|
|
||||||
const auto used_blocks =
|
|
||||||
utils::divide_with_ceiling(total_used, static_cast<std::uint64_t>(4096));
|
|
||||||
EXPECT_EQ(
|
|
||||||
utils::divide_with_ceiling(total_bytes, static_cast<std::uint64_t>(4096)),
|
|
||||||
st.f_blocks);
|
|
||||||
EXPECT_EQ(st.f_blocks ? (st.f_blocks - used_blocks) : 0, st.f_bavail);
|
|
||||||
EXPECT_EQ(st.f_bavail, st.f_bfree);
|
|
||||||
EXPECT_EQ(4294967295U, st.f_files);
|
|
||||||
EXPECT_EQ(4294967295U - drive.get_total_item_count(), st.f_favail);
|
|
||||||
EXPECT_EQ(st.f_favail, st.f_ffree);
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
#if defined(_WIN32)
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
#else
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), S_IRWXU,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
#endif
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
EXPECT_EQ(0, client.fuse_truncate(api_path.c_str(), 100));
|
|
||||||
|
|
||||||
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::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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
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::file(test_file).exists());
|
|
||||||
}
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
|
|
||||||
remote::file_handle handle;
|
|
||||||
const auto ret = client.fuse_create(
|
|
||||||
api_path.c_str(), 0,
|
|
||||||
remote::open_flags::create | remote::open_flags::read_write, handle);
|
|
||||||
EXPECT_EQ(0, ret);
|
|
||||||
if (ret == 0) {
|
|
||||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
|
||||||
|
|
||||||
remote::file_time tv[2] = {0};
|
|
||||||
EXPECT_EQ(0, client.fuse_utimens(api_path.c_str(), tv, 0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(remote_fuse, all_tests) {
|
|
||||||
std::uint16_t port = 0u;
|
|
||||||
const auto found_port = utils::get_next_available_port(20000u, port);
|
|
||||||
EXPECT_TRUE(found_port);
|
|
||||||
if (found_port) {
|
|
||||||
console_consumer c;
|
|
||||||
|
|
||||||
app_config config(provider_type::remote, fuse_remote_dir);
|
|
||||||
config.set_remote_host_name_or_ip("localhost");
|
|
||||||
config.set_remote_port(port);
|
|
||||||
config.set_remote_token("testtoken");
|
|
||||||
config.set_enable_drive_events(true);
|
|
||||||
config.set_event_level(event_level::trace);
|
|
||||||
|
|
||||||
event_system::instance().start();
|
|
||||||
#if defined(_WIN32)
|
|
||||||
mount_location_ = fuse_remote_dir.substr(0, 2);
|
|
||||||
mock_winfsp_drive drive(mount_location_);
|
|
||||||
remote_server server(config, drive, mount_location_);
|
|
||||||
#else
|
|
||||||
mount_location_ = fuse_remote_dir;
|
|
||||||
mock_fuse_drive drive(mount_location_);
|
|
||||||
remote_server server(config, drive, mount_location_);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(2s);
|
|
||||||
|
|
||||||
std::thread([&]() {
|
|
||||||
repertory::remote_fuse::remote_client client(config);
|
|
||||||
|
|
||||||
create_and_release_test(client, server);
|
|
||||||
access_test(client);
|
|
||||||
chflags_test(client);
|
|
||||||
chmod_test(client);
|
|
||||||
chown_test(client);
|
|
||||||
destroy_test(client);
|
|
||||||
fgetattr_test(client);
|
|
||||||
fsetattr_x_test(client);
|
|
||||||
fsync_test(client);
|
|
||||||
ftruncate_test(client);
|
|
||||||
getattr_test(client);
|
|
||||||
getxtimes_test(client);
|
|
||||||
init_test(client);
|
|
||||||
mkdir_test(client);
|
|
||||||
open_test(client);
|
|
||||||
opendir_and_releasedir_test(client);
|
|
||||||
read_and_write_base64_test(client);
|
|
||||||
read_and_write_test(client);
|
|
||||||
readdir_test(client);
|
|
||||||
rename_test(client);
|
|
||||||
rmdir_test(client);
|
|
||||||
setattr_x_test(client);
|
|
||||||
setbkuptime_test(client);
|
|
||||||
setchgtime_test(client);
|
|
||||||
setcrtime_test(client);
|
|
||||||
setvolname_test(client);
|
|
||||||
statfs_x_test(client, drive);
|
|
||||||
test_statfs(client, drive);
|
|
||||||
truncate_test(client);
|
|
||||||
unlink_test(client);
|
|
||||||
utimens_test(client);
|
|
||||||
// fallocate_test(client);
|
|
||||||
// getxattr_osx_test(client);
|
|
||||||
// getxattr_test(client);
|
|
||||||
// listxattr_test(client);
|
|
||||||
// removexattr_test(client);
|
|
||||||
// setxattr_osx_test(client);
|
|
||||||
// setxattr_test(client);
|
|
||||||
}).join();
|
|
||||||
}
|
|
||||||
|
|
||||||
event_system::instance().stop();
|
|
||||||
}
|
|
||||||
} // namespace fuse_test
|
|
@ -1,542 +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 "drives/winfsp/remotewinfsp/remote_client.hpp"
|
|
||||||
#include "events/consumers/console_consumer.hpp"
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#include "drives/winfsp/remotewinfsp/remote_server.hpp"
|
|
||||||
#include "mocks/mock_winfsp_drive.hpp"
|
|
||||||
#else
|
|
||||||
#include "drives/fuse/remotefuse/remote_server.hpp"
|
|
||||||
#include "mocks/mock_fuse_drive.hpp"
|
|
||||||
#endif
|
|
||||||
#include "platform/platform.hpp"
|
|
||||||
#include "types/repertory.hpp"
|
|
||||||
#include "utils/common.hpp"
|
|
||||||
#include "utils/time.hpp"
|
|
||||||
|
|
||||||
using namespace repertory;
|
|
||||||
using namespace repertory::remote_winfsp;
|
|
||||||
|
|
||||||
namespace winfsp_test {
|
|
||||||
static std::string mount_location_;
|
|
||||||
static std::string win_remote_dir =
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
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.data()));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
const auto ret = client.winfsp_create(
|
|
||||||
&api_path[0], 0, GENERIC_READ | GENERIC_WRITE, FILE_ATTRIBUTE_NORMAL, 0,
|
|
||||||
&file_desc, &fi, normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(1u, client.get_open_file_count(utils::string::to_utf8(api_path)));
|
|
||||||
EXPECT_EQ(1u, server.get_open_file_count(test_file));
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
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::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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
BOOLEAN was_deleted{0U};
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS,
|
|
||||||
client.winfsp_cleanup(file_desc, &api_path[0], 0, was_deleted));
|
|
||||||
EXPECT_FALSE(was_deleted);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_flush(file_desc, &fi));
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_get_file_info(file_desc, &fi));
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
UINT32 attributes = 0u;
|
|
||||||
std::uint64_t security_descriptor_size = 1024;
|
|
||||||
std::wstring str_descriptor;
|
|
||||||
ret = client.winfsp_get_security_by_name(
|
|
||||||
&api_path[0], &attributes, &security_descriptor_size, str_descriptor);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(static_cast<UINT32>(FILE_ATTRIBUTE_ARCHIVE), attributes);
|
|
||||||
EXPECT_FALSE(str_descriptor.empty());
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_volume_info_test(remote_client &client) {
|
|
||||||
UINT64 total_size = 0u;
|
|
||||||
UINT64 free_size = 0u;
|
|
||||||
std::string volume_label;
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS,
|
|
||||||
client.winfsp_get_volume_info(total_size, free_size, volume_label));
|
|
||||||
EXPECT_EQ(100u, free_size);
|
|
||||||
EXPECT_EQ(200u, total_size);
|
|
||||||
EXPECT_STREQ(volume_label.c_str(), "TestVolumeLabel");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mounted_test(remote_client &client) {
|
|
||||||
const auto location = utils::string::from_utf8(mount_location_);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_mounted(location));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void open_test(remote_client &client) {
|
|
||||||
const auto test_file = utils::path::combine(win_remote_dir, {"open.txt"});
|
|
||||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
PVOID file_desc2 = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
{
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(
|
|
||||||
&api_path[0], 0, GENERIC_READ | GENERIC_WRITE, FILE_ATTRIBUTE_NORMAL, 0,
|
|
||||||
&file_desc, &fi, normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
const auto ret =
|
|
||||||
client.winfsp_open(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
&file_desc2, &fi, normalized_name);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc2));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
const UINT32 attributes = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE;
|
|
||||||
const BOOLEAN replace_attributes = 0u;
|
|
||||||
const UINT64 allocation_size = 0u;
|
|
||||||
ret = client.winfsp_overwrite(file_desc, attributes, replace_attributes,
|
|
||||||
allocation_size, &fi);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(0u, fi.FileSize);
|
|
||||||
EXPECT_EQ(attributes, fi.FileAttributes);
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::directory(test_directory).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_directory).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(
|
|
||||||
&api_path[0], FILE_DIRECTORY_FILE, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_DIRECTORY, 0, &file_desc, &fi, normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::directory(test_directory).exists());
|
|
||||||
|
|
||||||
json list;
|
|
||||||
ret = client.winfsp_read_directory(file_desc, nullptr, nullptr, list);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(2u, list.size());
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::directory(test_directory).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_directory).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(
|
|
||||||
&api_path[0], FILE_DIRECTORY_FILE, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_DIRECTORY, 0, &file_desc, &fi, normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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,
|
|
||||||
GENERIC_READ | GENERIC_WRITE, &file_desc, &fi,
|
|
||||||
normalized_name);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
json item_list;
|
|
||||||
ret = client.winfsp_read_directory(file_desc, nullptr, nullptr, item_list);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(2u, item_list.size());
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
data_buffer buffer;
|
|
||||||
buffer.emplace_back('T');
|
|
||||||
buffer.emplace_back('e');
|
|
||||||
buffer.emplace_back('s');
|
|
||||||
buffer.emplace_back('t');
|
|
||||||
UINT32 bytes_transferred = 0u;
|
|
||||||
ret = client.winfsp_write(file_desc, &buffer[0], 0,
|
|
||||||
static_cast<UINT32>(buffer.size()), 0, 0,
|
|
||||||
&bytes_transferred, &fi);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(buffer.size(), bytes_transferred);
|
|
||||||
|
|
||||||
data_buffer buffer2(buffer.size());
|
|
||||||
UINT32 bytes_transferred2 = 0u;
|
|
||||||
ret = client.winfsp_read(file_desc, &buffer2[0], 0,
|
|
||||||
static_cast<UINT32>(buffer2.size()),
|
|
||||||
&bytes_transferred2);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
EXPECT_EQ(bytes_transferred, bytes_transferred2);
|
|
||||||
EXPECT_EQ(0, memcmp(&buffer[0], &buffer2[0], buffer.size()));
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::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 =
|
|
||||||
utils::string::from_utf8(test_file2).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
ret = client.winfsp_rename(file_desc, &api_path[0], &api_path2[0], 0);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
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::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::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());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
const auto attributes = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE;
|
|
||||||
#if defined(_WIN32)
|
|
||||||
SYSTEMTIME st{};
|
|
||||||
::GetSystemTime(&st);
|
|
||||||
|
|
||||||
LARGE_INTEGER ft{};
|
|
||||||
::SystemTimeToFileTime(&st, reinterpret_cast<FILETIME *>(&ft));
|
|
||||||
|
|
||||||
const auto creation_time = ft.QuadPart;
|
|
||||||
const auto last_access_time = ft.QuadPart + 1;
|
|
||||||
const auto last_write_time = ft.QuadPart + 2;
|
|
||||||
const auto change_time = last_write_time;
|
|
||||||
#else
|
|
||||||
const auto creation_time =
|
|
||||||
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;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_set_basic_info(
|
|
||||||
file_desc, static_cast<UINT32>(attributes),
|
|
||||||
static_cast<UINT64>(creation_time),
|
|
||||||
static_cast<UINT64>(last_access_time),
|
|
||||||
static_cast<UINT64>(last_write_time),
|
|
||||||
static_cast<UINT64>(change_time), &fi));
|
|
||||||
EXPECT_EQ(static_cast<UINT32>(attributes), fi.FileAttributes);
|
|
||||||
EXPECT_EQ(static_cast<UINT64>(creation_time), fi.CreationTime);
|
|
||||||
EXPECT_EQ(static_cast<UINT64>(last_access_time), fi.LastAccessTime);
|
|
||||||
EXPECT_EQ(static_cast<UINT64>(last_write_time), fi.LastWriteTime);
|
|
||||||
EXPECT_EQ(static_cast<UINT64>(change_time), fi.ChangeTime);
|
|
||||||
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
auto api_path =
|
|
||||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
|
||||||
|
|
||||||
PVOID file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
|
||||||
remote::file_info fi{};
|
|
||||||
std::string normalized_name;
|
|
||||||
BOOLEAN exists = 0u;
|
|
||||||
auto ret = client.winfsp_create(&api_path[0], 0, GENERIC_READ | GENERIC_WRITE,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, 0, &file_desc, &fi,
|
|
||||||
normalized_name, exists);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
||||||
|
|
||||||
const UINT64 new_file_size = 34u;
|
|
||||||
const BOOLEAN set_allocation_size = 0u;
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS,
|
|
||||||
client.winfsp_set_file_size(file_desc, new_file_size,
|
|
||||||
set_allocation_size, &fi));
|
|
||||||
|
|
||||||
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::file(test_file).remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unmounted_test(remote_client &client) {
|
|
||||||
const auto location = utils::string::from_utf8(mount_location_);
|
|
||||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_unmounted(location));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(remote_winfsp, all_tests) {
|
|
||||||
std::uint16_t port = 0;
|
|
||||||
const auto found_port = utils::get_next_available_port(20020u, port);
|
|
||||||
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);
|
|
||||||
config.set_remote_token("testtoken");
|
|
||||||
config.set_enable_drive_events(true);
|
|
||||||
config.set_event_level(event_level::trace);
|
|
||||||
|
|
||||||
event_system::instance().start();
|
|
||||||
#if defined(_WIN32)
|
|
||||||
mount_location_ = win_remote_dir.substr(0, 2);
|
|
||||||
mock_winfsp_drive drive(mount_location_);
|
|
||||||
remote_server server(config, drive, mount_location_);
|
|
||||||
#else
|
|
||||||
mount_location_ = win_remote_dir;
|
|
||||||
mock_fuse_drive drive(mount_location_);
|
|
||||||
remote_fuse::remote_server server(config, drive, mount_location_);
|
|
||||||
#endif
|
|
||||||
std::this_thread::sleep_for(2s);
|
|
||||||
|
|
||||||
std::thread([&]() {
|
|
||||||
remote_client client(config);
|
|
||||||
|
|
||||||
can_delete_test(client);
|
|
||||||
cleanup_test(client);
|
|
||||||
create_and_close_test(client, server);
|
|
||||||
create_and_read_directory_test(client);
|
|
||||||
flush_test(client);
|
|
||||||
get_file_info_test(client);
|
|
||||||
get_security_by_name_test(client);
|
|
||||||
get_volume_info_test(client);
|
|
||||||
mounted_test(client);
|
|
||||||
open_and_read_directory_test(client);
|
|
||||||
open_test(client);
|
|
||||||
overwrite_test(client);
|
|
||||||
read_and_write_test(client);
|
|
||||||
rename_test(client);
|
|
||||||
set_basic_info_test(client);
|
|
||||||
set_file_size_test(client);
|
|
||||||
unmounted_test(client);
|
|
||||||
}).join();
|
|
||||||
}
|
|
||||||
|
|
||||||
event_system::instance().stop();
|
|
||||||
}
|
|
||||||
} // namespace winfsp_test
|
|
Loading…
x
Reference in New Issue
Block a user