continue refactor drive tests
This commit is contained in:
parent
0ad0ff508b
commit
982e5357a5
@ -137,22 +137,21 @@ protected:
|
|||||||
std::filesystem::current_path(current_directory);
|
std::filesystem::current_path(current_directory);
|
||||||
[[maybe_unused]] auto ret =
|
[[maybe_unused]] auto ret =
|
||||||
utils::file::directory(test_directory).remove_recursively();
|
utils::file::directory(test_directory).remove_recursively();
|
||||||
/* if (PROVIDER_INDEX != 0) {
|
|
||||||
drive.reset();
|
|
||||||
provider.reset();
|
|
||||||
comm.reset();
|
|
||||||
config.reset();
|
|
||||||
|
|
||||||
event_system::instance().stop();
|
|
||||||
EXPECT_TRUE(utils::file::directory(
|
|
||||||
utils::path::combine(
|
|
||||||
test::get_test_output_dir(),
|
|
||||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}))
|
|
||||||
.remove_recursively());
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
[[nodiscard]] static auto create_directory_and_test(std::string &dir_name)
|
||||||
|
-> std::string {
|
||||||
|
dir_name += std::to_string(++idx);
|
||||||
|
auto api_path = utils::path::create_api_path(dir_name);
|
||||||
|
auto dir_path = utils::path::combine(mount_location, {dir_name});
|
||||||
|
|
||||||
|
EXPECT_FALSE(::PathIsDirectoryA(dir_path.c_str()));
|
||||||
|
EXPECT_TRUE(::CreateDirectoryA(dir_path.c_str(), nullptr));
|
||||||
|
EXPECT_TRUE(::PathIsDirectoryA(dir_path.c_str()));
|
||||||
|
return dir_path;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] static auto create_file_and_test(std::string &file_name)
|
[[nodiscard]] static auto create_file_and_test(std::string &file_name)
|
||||||
-> std::string {
|
-> std::string {
|
||||||
file_name += std::to_string(++idx);
|
file_name += std::to_string(++idx);
|
||||||
@ -179,6 +178,12 @@ public:
|
|||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void delete_directory_and_test(const std::string &dir_path) {
|
||||||
|
EXPECT_TRUE(::PathIsDirectoryA(dir_path.c_str()));
|
||||||
|
EXPECT_TRUE(::RemoveDirectoryA(dir_path.c_str()));
|
||||||
|
EXPECT_FALSE(::PathIsDirectoryA(dir_path.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
static void delete_file_and_test(std::string_view file_path) {
|
static void delete_file_and_test(std::string_view file_path) {
|
||||||
EXPECT_TRUE(utils::file::file(file_path).remove());
|
EXPECT_TRUE(utils::file::file(file_path).remove());
|
||||||
EXPECT_FALSE(utils::file::file(file_path).exists());
|
EXPECT_FALSE(utils::file::file(file_path).exists());
|
||||||
@ -225,6 +230,9 @@ std::filesystem::path winfsp_test<provider_t>::current_directory;
|
|||||||
template <typename provider_t>
|
template <typename provider_t>
|
||||||
std::unique_ptr<curl_comm> winfsp_test<provider_t>::comm;
|
std::unique_ptr<curl_comm> winfsp_test<provider_t>::comm;
|
||||||
|
|
||||||
|
template <typename provider_t>
|
||||||
|
std::string winfsp_test<provider_t>::mount_location;
|
||||||
|
|
||||||
template <typename provider_t>
|
template <typename provider_t>
|
||||||
std::unique_ptr<i_provider> winfsp_test<provider_t>::provider;
|
std::unique_ptr<i_provider> winfsp_test<provider_t>::provider;
|
||||||
|
|
||||||
|
@ -24,72 +24,6 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
// static void create_directory_test(const std::string &directory) {
|
|
||||||
// TEST_HEADER(__FUNCTION__);
|
|
||||||
//
|
|
||||||
// EXPECT_FALSE(::PathIsDirectory(&directory[0]));
|
|
||||||
// EXPECT_TRUE(::CreateDirectoryA(&directory[0], nullptr));
|
|
||||||
// EXPECT_TRUE(::PathIsDirectory(&directory[0]));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static void remove_directory_test(const std::string &directory) {
|
|
||||||
// TEST_HEADER(__FUNCTION__);
|
|
||||||
//
|
|
||||||
// event_capture ec({"directory_removed"});
|
|
||||||
// EXPECT_TRUE(::PathIsDirectory(&directory[0]));
|
|
||||||
// EXPECT_TRUE(::RemoveDirectoryA(&directory[0]));
|
|
||||||
// EXPECT_FALSE(::PathIsDirectory(&directory[0]));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static void write_file_test(const std::string &mount_point) {
|
|
||||||
// TEST_HEADER(__FUNCTION__);
|
|
||||||
//
|
|
||||||
// const auto file = utils::path::combine(mount_point, {"test_write.txt"});
|
|
||||||
// auto handle =
|
|
||||||
// ::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
|
|
||||||
// nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
||||||
// EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
|
||||||
// const std::string data = "0123456789";
|
|
||||||
// DWORD bytes_written = 0;
|
|
||||||
// EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
|
|
||||||
// &bytes_written, nullptr));
|
|
||||||
// EXPECT_EQ(10, bytes_written);
|
|
||||||
// EXPECT_TRUE(::CloseHandle(handle));
|
|
||||||
//
|
|
||||||
// EXPECT_TRUE(utils::file::file(file).exists());
|
|
||||||
//
|
|
||||||
// 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) {
|
|
||||||
// TEST_HEADER(__FUNCTION__);
|
|
||||||
//
|
|
||||||
// const auto file = utils::path::combine(mount_point, {"test_read.txt"});
|
|
||||||
// auto handle =
|
|
||||||
// ::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
|
|
||||||
// nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
||||||
// EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
|
||||||
// const std::string data = "0123456789";
|
|
||||||
// DWORD bytes_written = 0;
|
|
||||||
// EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
|
|
||||||
// &bytes_written, nullptr));
|
|
||||||
// EXPECT_EQ(10, bytes_written);
|
|
||||||
//
|
|
||||||
// data_buffer data2;
|
|
||||||
// data2.resize(10);
|
|
||||||
// DWORD bytes_read = 0;
|
|
||||||
// EXPECT_EQ(0, ::SetFilePointer(handle, 0, nullptr, FILE_BEGIN));
|
|
||||||
// EXPECT_TRUE(::ReadFile(handle, &data2[0], static_cast<DWORD>(data2.size()),
|
|
||||||
// &bytes_read, nullptr));
|
|
||||||
// EXPECT_EQ(10, bytes_read);
|
|
||||||
// for (auto i = 0; i < data.size(); i++) {
|
|
||||||
// EXPECT_EQ(data[i], data2[i]);
|
|
||||||
// }
|
|
||||||
// EXPECT_TRUE(::CloseHandle(handle));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static void rename_file_test(winfsp_test *test,
|
// static void rename_file_test(winfsp_test *test,
|
||||||
// const std::string &mount_point) {
|
// const std::string &mount_point) {
|
||||||
// TEST_HEADER(__FUNCTION__);
|
// TEST_HEADER(__FUNCTION__);
|
||||||
@ -295,17 +229,69 @@ TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
|||||||
|
|
||||||
TYPED_TEST(winfsp_test, root_is_created) {
|
TYPED_TEST(winfsp_test, root_is_created) {
|
||||||
WIN32_FILE_ATTRIBUTE_DATA ad{};
|
WIN32_FILE_ATTRIBUTE_DATA ad{};
|
||||||
ASSERT_TRUE(::GetFileAttributesEx(mount_location.c_str(),
|
ASSERT_TRUE(::GetFileAttributesEx(this->mount_location.c_str(),
|
||||||
GetFileExInfoStandard, &ad));
|
GetFileExInfoStandard, &ad));
|
||||||
EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, ad.dwFileAttributes);
|
EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, ad.dwFileAttributes);
|
||||||
EXPECT_EQ(0, ad.nFileSizeHigh);
|
EXPECT_EQ(0, ad.nFileSizeHigh);
|
||||||
EXPECT_EQ(0, ad.nFileSizeLow);
|
EXPECT_EQ(0, ad.nFileSizeLow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(winfsp_test, can_create_and_delete_directory) {
|
||||||
|
std::string dir_name{"test_create_and_delete_dir"};
|
||||||
|
auto dir_path = this->create_directory_and_test(dir_name);
|
||||||
|
this->delete_directory_and_test(dir_path);
|
||||||
|
}
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, can_create_and_delete_file) {
|
TYPED_TEST(winfsp_test, can_create_and_delete_file) {
|
||||||
std::string file_name{"test_create_and_delete"};
|
std::string file_name{"test_create_and_delete_file"};
|
||||||
auto file_path = create_file_and_test(file_name);
|
auto file_path = this->create_file_and_test(file_name);
|
||||||
delete_file_and_test(file_path);
|
this->delete_file_and_test(file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(winfsp_test, can_write_to_and_read_from_file) {
|
||||||
|
std::string file_name{"test_write_file"};
|
||||||
|
auto file_path = this->create_file_and_test(file_name);
|
||||||
|
|
||||||
|
auto handle =
|
||||||
|
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
|
||||||
|
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||||
|
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||||
|
if (handle == INVALID_HANDLE_VALUE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string write_buffer{"0123456789"};
|
||||||
|
{
|
||||||
|
DWORD bytes_written{0};
|
||||||
|
EXPECT_TRUE(::WriteFile(handle, write_buffer.c_str(),
|
||||||
|
static_cast<DWORD>(write_buffer.size()),
|
||||||
|
&bytes_written, nullptr));
|
||||||
|
EXPECT_EQ(static_cast<DWORD>(write_buffer.size()), bytes_written);
|
||||||
|
|
||||||
|
auto opt_size = utils::file::file(file_path).size();
|
||||||
|
EXPECT_TRUE(opt_size.has_value());
|
||||||
|
EXPECT_EQ(write_buffer.size(), opt_size.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
data_buffer read_buffer;
|
||||||
|
read_buffer.resize(write_buffer.size());
|
||||||
|
|
||||||
|
DWORD bytes_read{0};
|
||||||
|
EXPECT_EQ(0, ::SetFilePointer(handle, 0, nullptr, FILE_BEGIN));
|
||||||
|
EXPECT_TRUE(::ReadFile(handle, read_buffer.data(),
|
||||||
|
static_cast<DWORD>(read_buffer.size()), &bytes_read,
|
||||||
|
nullptr));
|
||||||
|
EXPECT_EQ(static_cast<DWORD>(write_buffer.size()), bytes_read);
|
||||||
|
for (std::size_t idx = 0U; idx < read_buffer.size(); ++idx) {
|
||||||
|
EXPECT_EQ(write_buffer.at(idx), read_buffer.at(idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_TRUE(::CloseHandle(handle));
|
||||||
|
|
||||||
|
this->delete_file_and_test(file_path);
|
||||||
}
|
}
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user