winfsp unit tests and fixes
This commit is contained in:
parent
55762f9c92
commit
8247669d3b
182
repertory/repertory_test/src/winfsp_drive_create_attr_test.cpp
Normal file
182
repertory/repertory_test/src/winfsp_drive_create_attr_test.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
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 <fileapi.h>
|
||||
#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, cr8_attr_can_create_new_file_with_normal_attribute) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE, attr);
|
||||
|
||||
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_read_only_attribute) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
|
||||
FILE_ATTRIBUTE_READONLY, 0);
|
||||
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY, attr);
|
||||
|
||||
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
|
||||
|
||||
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
|
||||
}
|
||||
|
||||
// TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_system_attribute) {
|
||||
// auto file_path{
|
||||
// utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
// };
|
||||
//
|
||||
// auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ |
|
||||
// GENERIC_WRITE,
|
||||
// FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
// CREATE_NEW, FILE_ATTRIBUTE_SYSTEM, 0);
|
||||
// EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
// ::CloseHandle(handle);
|
||||
//
|
||||
// auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
// EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM, attr);
|
||||
//
|
||||
// EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(),
|
||||
// FILE_ATTRIBUTE_NORMAL));
|
||||
//
|
||||
// EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
|
||||
// }
|
||||
|
||||
TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_hidden_attribute) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
|
||||
FILE_ATTRIBUTE_HIDDEN, 0);
|
||||
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN, attr);
|
||||
|
||||
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
|
||||
|
||||
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, cr8_attr_can_create_always_file_with_normal_attribute) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE, attr);
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, cr8_attr_can_create_file_with_read_only_attribute) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_READONLY, 0);
|
||||
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY, attr);
|
||||
|
||||
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
|
||||
}
|
||||
|
||||
// TYPED_TEST(winfsp_test,
|
||||
// cr8_attr_can_create_always_file_with_system_attribute) {
|
||||
// auto file_path{
|
||||
// utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
// };
|
||||
//
|
||||
// auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ |
|
||||
// GENERIC_WRITE,
|
||||
// FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
// CREATE_ALWAYS, FILE_ATTRIBUTE_SYSTEM, 0);
|
||||
// EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
// ::CloseHandle(handle);
|
||||
//
|
||||
// auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
// EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM, attr);
|
||||
//
|
||||
// EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(),
|
||||
// FILE_ATTRIBUTE_NORMAL));
|
||||
// }
|
||||
|
||||
TYPED_TEST(winfsp_test, cr8_attr_can_create_always_file_with_hidden_attribute) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
|
||||
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0);
|
||||
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
::CloseHandle(handle);
|
||||
|
||||
auto attr = ::GetFileAttributesA(file_path.c_str());
|
||||
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN, attr);
|
||||
|
||||
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
|
||||
|
||||
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // defined(_WIN32)
|
@ -30,7 +30,7 @@
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
||||
|
||||
TYPED_TEST(winfsp_test, can_create_normal_file) {
|
||||
TYPED_TEST(winfsp_test, cr8_file_can_create_file) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
@ -41,7 +41,7 @@ TYPED_TEST(winfsp_test, can_create_normal_file) {
|
||||
::CloseHandle(handle);
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, create_new_fails_when_file_exists) {
|
||||
TYPED_TEST(winfsp_test, cr8_file_create_new_fails_when_file_exists) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
@ -52,7 +52,7 @@ TYPED_TEST(winfsp_test, create_new_fails_when_file_exists) {
|
||||
EXPECT_EQ(ERROR_FILE_EXISTS, ::GetLastError());
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, can_open_existing_file) {
|
||||
TYPED_TEST(winfsp_test, cr8_file_can_open_existing_file) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
@ -63,7 +63,7 @@ TYPED_TEST(winfsp_test, can_open_existing_file) {
|
||||
::CloseHandle(handle);
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, create_always_succeeds_when_file_exists) {
|
||||
TYPED_TEST(winfsp_test, cr8_file_create_always_succeeds_when_file_exists) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
@ -75,7 +75,7 @@ TYPED_TEST(winfsp_test, create_always_succeeds_when_file_exists) {
|
||||
::CloseHandle(handle);
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, can_delete_file_after_close) {
|
||||
TYPED_TEST(winfsp_test, cr8_file_can_delete_file_after_close) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location, {"test_file_0"}),
|
||||
};
|
||||
@ -94,7 +94,8 @@ TYPED_TEST(winfsp_test, can_delete_file_after_close) {
|
||||
// EXPECT file not found
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, cannot_create_files_with_invalid_characters_in_path) {
|
||||
TYPED_TEST(winfsp_test,
|
||||
cr8_file_cannot_create_files_with_invalid_characters_in_path) {
|
||||
for (auto &&invalid_char : std::array<std::string, 7U>{
|
||||
{"*", ":", "<", ">", "?", "|", "\""},
|
||||
}) {
|
||||
@ -111,7 +112,7 @@ TYPED_TEST(winfsp_test, cannot_create_files_with_invalid_characters_in_path) {
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test,
|
||||
cannot_create_stream_files_with_extra_component_in_path) {
|
||||
cr8_file_cannot_create_stream_files_with_extra_component_in_path) {
|
||||
auto file_path{
|
||||
utils::path::combine(this->mount_location,
|
||||
{
|
||||
@ -126,7 +127,7 @@ TYPED_TEST(winfsp_test,
|
||||
EXPECT_EQ(ERROR_INVALID_NAME, ::GetLastError());
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, can_create_directory) {
|
||||
TYPED_TEST(winfsp_test, cr8_file_can_create_directory) {
|
||||
auto dir_path{
|
||||
utils::path::combine(this->mount_location,
|
||||
{
|
||||
@ -137,7 +138,7 @@ TYPED_TEST(winfsp_test, can_create_directory) {
|
||||
EXPECT_FALSE(::CreateDirectoryA(dir_path.c_str(), nullptr));
|
||||
}
|
||||
|
||||
TYPED_TEST(winfsp_test, directory_delete_fails_if_not_empty) {
|
||||
TYPED_TEST(winfsp_test, cr8_file_directory_delete_fails_if_not_empty) {
|
||||
auto dir_path{
|
||||
utils::path::combine(this->mount_location,
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user