winfsp unit tests and fixes
This commit is contained in:
parent
a231c2afaf
commit
73afdaedb9
@ -31,11 +31,14 @@ namespace repertory {
|
||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
||||
|
||||
TYPED_TEST(winfsp_test, cr8_nl_can_create_file_of_max_component_length) {
|
||||
if (this->current_provider != provider_type::s3) {
|
||||
if (this->current_provider == provider_type::s3) {
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD max_length{};
|
||||
EXPECT_TRUE(::GetVolumeInformationA(this->mount_location.c_str(), nullptr,
|
||||
0, nullptr, &max_length, nullptr,
|
||||
nullptr, 0));
|
||||
EXPECT_TRUE(::GetVolumeInformationA(this->mount_location.c_str(), nullptr, 0,
|
||||
nullptr, &max_length, nullptr, nullptr,
|
||||
0));
|
||||
EXPECT_EQ(255U, max_length);
|
||||
|
||||
auto file_path = utils::path::combine(this->mount_location,
|
||||
@ -43,22 +46,24 @@ TYPED_TEST(winfsp_test, cr8_nl_can_create_file_of_max_component_length) {
|
||||
std::string(max_length, 'a'),
|
||||
});
|
||||
|
||||
auto handle = ::CreateFileA(
|
||||
file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
auto handle =
|
||||
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_NEW,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, nullptr);
|
||||
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
EXPECT_TRUE(::CloseHandle(handle));
|
||||
}
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test,
|
||||
cr8_nl_can_not_create_file_greater_than_max_component_length) {
|
||||
if (this->current_provider != provider_type::s3) {
|
||||
if (this->current_provider == provider_type::s3) {
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD max_length{};
|
||||
EXPECT_TRUE(::GetVolumeInformationA(this->mount_location.c_str(), nullptr,
|
||||
0, nullptr, &max_length, nullptr,
|
||||
nullptr, 0));
|
||||
EXPECT_TRUE(::GetVolumeInformationA(this->mount_location.c_str(), nullptr, 0,
|
||||
nullptr, &max_length, nullptr, nullptr,
|
||||
0));
|
||||
EXPECT_EQ(255U, max_length);
|
||||
|
||||
auto file_path = utils::path::combine(this->mount_location,
|
||||
@ -66,14 +71,13 @@ TYPED_TEST(winfsp_test,
|
||||
std::string(max_length + 1U, 'a'),
|
||||
});
|
||||
|
||||
auto handle = ::CreateFileA(
|
||||
file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
auto handle =
|
||||
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_NEW,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, nullptr);
|
||||
ASSERT_EQ(INVALID_HANDLE_VALUE, handle);
|
||||
EXPECT_EQ(ERROR_INVALID_NAME, ::GetLastError());
|
||||
}
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // defined(_WIN32)
|
||||
|
133
repertory/repertory_test/src/winfsp_drive_rename_test.cpp
Normal file
133
repertory/repertory_test/src/winfsp_drive_rename_test.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
#if defined(_WIN32)
|
||||
|
||||
//
|
||||
// Implemented test cases based on WinFsp tests:
|
||||
// https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests
|
||||
//
|
||||
#include "fixtures/winfsp_fixture.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
||||
|
||||
TYPED_TEST(winfsp_test, rename_can_rename_file_if_dest_does_not_exist) {
|
||||
if (this->current_provider == provider_type::s3) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto dir_path{
|
||||
utils::path::combine(this->mount_location, {"test_dir_4"}),
|
||||
};
|
||||
auto file_path{
|
||||
utils::path::combine(dir_path, {"test_file_4"}),
|
||||
};
|
||||
auto file_path2{
|
||||
utils::path::combine(dir_path, {"test_file2_4"}),
|
||||
};
|
||||
|
||||
ASSERT_TRUE(::CreateDirectoryA(dir_path.c_str(), nullptr));
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
EXPECT_TRUE(::MoveFileExA(file_path.c_str(), file_path2.c_str(), 0));
|
||||
|
||||
EXPECT_TRUE(::DeleteFileA(file_path2.c_str()));
|
||||
EXPECT_TRUE(::RemoveDirectoryA(dir_path.c_str()));
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, rename_fails_if_dest_exists_and_replace_is_false) {
|
||||
if (this->current_provider == provider_type::s3) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto dir_path{
|
||||
utils::path::combine(this->mount_location, {"test_dir_4"}),
|
||||
};
|
||||
auto file_path{
|
||||
utils::path::combine(dir_path, {"test_file_4"}),
|
||||
};
|
||||
auto file_path2{
|
||||
utils::path::combine(dir_path, {"test_file2_4"}),
|
||||
};
|
||||
|
||||
ASSERT_TRUE(::CreateDirectoryA(dir_path.c_str(), nullptr));
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
EXPECT_TRUE(::MoveFileExA(file_path.c_str(), file_path2.c_str(), 0));
|
||||
|
||||
EXPECT_FALSE(::MoveFileExA(file_path.c_str(), file_path2.c_str(), 0));
|
||||
EXPECT_EQ(ERROR_ALREADY_EXISTS, ::GetLastError());
|
||||
|
||||
EXPECT_TRUE(::DeleteFileA(file_path2.c_str()));
|
||||
EXPECT_TRUE(::RemoveDirectoryA(dir_path.c_str()));
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, rename_succeeds_if_dest_exists_and_replace_is_true) {
|
||||
if (this->current_provider == provider_type::s3) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto dir_path{
|
||||
utils::path::combine(this->mount_location, {"test_dir_4"}),
|
||||
};
|
||||
auto file_path{
|
||||
utils::path::combine(dir_path, {"test_file_4"}),
|
||||
};
|
||||
auto file_path2{
|
||||
utils::path::combine(dir_path, {"test_file2_4"}),
|
||||
};
|
||||
|
||||
ASSERT_TRUE(::CreateDirectoryA(dir_path.c_str(), nullptr));
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
EXPECT_TRUE(::MoveFileExA(file_path.c_str(), file_path2.c_str(), 0));
|
||||
|
||||
handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
EXPECT_TRUE(::MoveFileExA(file_path.c_str(), file_path2.c_str(),
|
||||
MOVEFILE_REPLACE_EXISTING));
|
||||
|
||||
EXPECT_TRUE(::DeleteFileA(file_path2.c_str()));
|
||||
EXPECT_TRUE(::RemoveDirectoryA(dir_path.c_str()));
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // defined(_WIN32)
|
@ -30,6 +30,7 @@
|
||||
// TODO revisit create_share
|
||||
// TODO revisit delete_access_test
|
||||
// TODO revisit getfileattr_test
|
||||
// TODO revisit delete_ex_test
|
||||
|
||||
//
|
||||
// Implemented test cases based on WinFsp tests:
|
||||
|
Loading…
x
Reference in New Issue
Block a user