aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/fs_win_ut.cpp
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2022-12-20 00:50:48 +0300
committeralexv-smirnov <alex@ydb.tech>2022-12-20 00:50:48 +0300
commit84f2cfa253cc618438ed6e9d68b33fa7c0d88cb9 (patch)
treef0cf2236e0aafb3e437199f1ac7b559e7fad554a /util/system/fs_win_ut.cpp
parentbde6febc1ad3b826e72746de21d7250803e8e0b5 (diff)
downloadydb-84f2cfa253cc618438ed6e9d68b33fa7c0d88cb9.tar.gz
add windows platform to ydb github export
Diffstat (limited to 'util/system/fs_win_ut.cpp')
-rw-r--r--util/system/fs_win_ut.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/util/system/fs_win_ut.cpp b/util/system/fs_win_ut.cpp
new file mode 100644
index 0000000000..46a8c5f2b0
--- /dev/null
+++ b/util/system/fs_win_ut.cpp
@@ -0,0 +1,71 @@
+#include "fs.h"
+#include "fs_win.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+#include "fileapi.h"
+
+#include "file.h"
+#include "fstat.h"
+#include "win_undef.h"
+#include <util/charset/wide.h>
+#include <util/folder/path.h>
+#include <util/generic/string.h>
+
+static void Touch(const TFsPath& path) {
+ TFile file(path, CreateAlways | WrOnly);
+ file.Write("1115", 4);
+}
+
+static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) {
+ wstr.resize(str.size());
+ size_t written = 0;
+ if (!UTF8ToWide(str.data(), str.size(), wstr.begin(), written))
+ return nullptr;
+ wstr.erase(written);
+ static_assert(sizeof(WCHAR) == sizeof(wchar16), "expect sizeof(WCHAR) == sizeof(wchar16)");
+ return (const WCHAR*)wstr.data();
+}
+
+Y_UNIT_TEST_SUITE(TFsWinTest) {
+ Y_UNIT_TEST(TestRemoveDirWithROFiles) {
+ TFsPath dir1 = "dir1";
+ NFsPrivate::WinRemove(dir1);
+ UNIT_ASSERT(!NFsPrivate::WinExists(dir1));
+ UNIT_ASSERT(NFsPrivate::WinMakeDirectory(dir1));
+
+ UNIT_ASSERT(TFileStat(dir1).IsDir());
+ TFsPath file1 = dir1 / "file.txt";
+ Touch(file1);
+ UNIT_ASSERT(NFsPrivate::WinExists(file1));
+ {
+ TUtf16String wstr;
+ LPCWSTR wname = UTF8ToWCHAR(static_cast<const TString&>(file1), wstr);
+ UNIT_ASSERT(wname);
+ WIN32_FILE_ATTRIBUTE_DATA fad;
+ fad.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
+ ::SetFileAttributesW(wname, fad.dwFileAttributes);
+ }
+ NFsPrivate::WinRemove(dir1);
+ UNIT_ASSERT(!NFsPrivate::WinExists(dir1));
+ }
+
+ Y_UNIT_TEST(TestRemoveReadOnlyDir) {
+ TFsPath dir1 = "dir1";
+ NFsPrivate::WinRemove(dir1);
+ UNIT_ASSERT(!NFsPrivate::WinExists(dir1));
+ UNIT_ASSERT(NFsPrivate::WinMakeDirectory(dir1));
+
+ UNIT_ASSERT(TFileStat(dir1).IsDir());
+ {
+ TUtf16String wstr;
+ LPCWSTR wname = UTF8ToWCHAR(static_cast<const TString&>(dir1), wstr);
+ UNIT_ASSERT(wname);
+ WIN32_FILE_ATTRIBUTE_DATA fad;
+ fad.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
+ ::SetFileAttributesW(wname, fad.dwFileAttributes);
+ }
+ NFsPrivate::WinRemove(dir1);
+ UNIT_ASSERT(!NFsPrivate::WinExists(dir1));
+ }
+}