aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder/dirut_ut.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/folder/dirut_ut.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/folder/dirut_ut.cpp')
-rw-r--r--util/folder/dirut_ut.cpp224
1 files changed, 112 insertions, 112 deletions
diff --git a/util/folder/dirut_ut.cpp b/util/folder/dirut_ut.cpp
index 45ebfc842c..40f7879d7a 100644
--- a/util/folder/dirut_ut.cpp
+++ b/util/folder/dirut_ut.cpp
@@ -1,4 +1,4 @@
-#include "dirut.h"
+#include "dirut.h"
#include "tempdir.h"
#include <library/cpp/testing/unittest/registar.h>
@@ -6,128 +6,128 @@
#include <util/generic/string.h>
#include <util/memory/tempbuf.h>
#include <util/stream/file.h>
-#include <util/system/platform.h>
+#include <util/system/platform.h>
-Y_UNIT_TEST_SUITE(TDirutTest) {
- Y_UNIT_TEST(TestRealPath) {
+Y_UNIT_TEST_SUITE(TDirutTest) {
+ Y_UNIT_TEST(TestRealPath) {
UNIT_ASSERT(IsDir(RealPath(".")));
+ }
+
+ Y_UNIT_TEST(TestRealLocation) {
+ UNIT_ASSERT(IsDir(RealLocation(".")));
+
+ TTempDir tempDir;
+ TString base = RealPath(tempDir());
+ UNIT_ASSERT(!base.empty());
+
+ if (base.back() == GetDirectorySeparator()) {
+ base.pop_back();
+ }
+
+ TString path;
+ TString pathNotNorm;
+
+ path = base + GetDirectorySeparatorS() + "no_such_file";
+ UNIT_ASSERT(NFs::Exists(GetDirName(path)));
+ UNIT_ASSERT(!NFs::Exists(path));
+ path = RealLocation(path);
+ UNIT_ASSERT(NFs::Exists(GetDirName(path)));
+ UNIT_ASSERT(!NFs::Exists(path));
+ UNIT_ASSERT_EQUAL(GetDirName(path), base);
+
+ pathNotNorm = base + GetDirectorySeparatorS() + "some_dir" + GetDirectorySeparatorS() + ".." + GetDirectorySeparatorS() + "no_such_file";
+ MakeDirIfNotExist((base + GetDirectorySeparatorS() + "some_dir").data());
+ pathNotNorm = RealLocation(pathNotNorm);
+ UNIT_ASSERT(NFs::Exists(GetDirName(pathNotNorm)));
+ UNIT_ASSERT(!NFs::Exists(pathNotNorm));
+ UNIT_ASSERT_EQUAL(GetDirName(pathNotNorm), base);
+
+ UNIT_ASSERT_EQUAL(path, pathNotNorm);
+
+ path = base + GetDirectorySeparatorS() + "file";
+ {
+ TFixedBufferFileOutput file(path);
+ }
+ UNIT_ASSERT(NFs::Exists(GetDirName(path)));
+ UNIT_ASSERT(NFs::Exists(path));
+ UNIT_ASSERT(NFs::Exists(path));
+ path = RealLocation(path);
+ UNIT_ASSERT(NFs::Exists(GetDirName(path)));
+ UNIT_ASSERT(NFs::Exists(path));
+ UNIT_ASSERT_EQUAL(GetDirName(path), base);
}
- Y_UNIT_TEST(TestRealLocation) {
- UNIT_ASSERT(IsDir(RealLocation(".")));
-
- TTempDir tempDir;
- TString base = RealPath(tempDir());
- UNIT_ASSERT(!base.empty());
-
- if (base.back() == GetDirectorySeparator()) {
- base.pop_back();
- }
-
- TString path;
- TString pathNotNorm;
-
- path = base + GetDirectorySeparatorS() + "no_such_file";
- UNIT_ASSERT(NFs::Exists(GetDirName(path)));
- UNIT_ASSERT(!NFs::Exists(path));
- path = RealLocation(path);
- UNIT_ASSERT(NFs::Exists(GetDirName(path)));
- UNIT_ASSERT(!NFs::Exists(path));
- UNIT_ASSERT_EQUAL(GetDirName(path), base);
-
- pathNotNorm = base + GetDirectorySeparatorS() + "some_dir" + GetDirectorySeparatorS() + ".." + GetDirectorySeparatorS() + "no_such_file";
- MakeDirIfNotExist((base + GetDirectorySeparatorS() + "some_dir").data());
- pathNotNorm = RealLocation(pathNotNorm);
- UNIT_ASSERT(NFs::Exists(GetDirName(pathNotNorm)));
- UNIT_ASSERT(!NFs::Exists(pathNotNorm));
- UNIT_ASSERT_EQUAL(GetDirName(pathNotNorm), base);
-
- UNIT_ASSERT_EQUAL(path, pathNotNorm);
-
- path = base + GetDirectorySeparatorS() + "file";
- {
- TFixedBufferFileOutput file(path);
- }
- UNIT_ASSERT(NFs::Exists(GetDirName(path)));
- UNIT_ASSERT(NFs::Exists(path));
- UNIT_ASSERT(NFs::Exists(path));
- path = RealLocation(path);
- UNIT_ASSERT(NFs::Exists(GetDirName(path)));
- UNIT_ASSERT(NFs::Exists(path));
- UNIT_ASSERT_EQUAL(GetDirName(path), base);
- }
-
- void DoTest(const char* p, const char* base, const char* canon) {
- TString path(p);
- UNIT_ASSERT(resolvepath(path, base));
- UNIT_ASSERT(path == canon);
- }
+ void DoTest(const char* p, const char* base, const char* canon) {
+ TString path(p);
+ UNIT_ASSERT(resolvepath(path, base));
+ UNIT_ASSERT(path == canon);
+ }
- Y_UNIT_TEST(TestResolvePath) {
+ Y_UNIT_TEST(TestResolvePath) {
#ifdef _win_
- DoTest("bar", "c:\\foo\\baz", "c:\\foo\\baz\\bar");
- DoTest("c:\\foo\\bar", "c:\\bar\\baz", "c:\\foo\\bar");
+ DoTest("bar", "c:\\foo\\baz", "c:\\foo\\baz\\bar");
+ DoTest("c:\\foo\\bar", "c:\\bar\\baz", "c:\\foo\\bar");
#else
- DoTest("bar", "/foo/baz", "/foo/bar");
- DoTest("/foo/bar", "/bar/baz", "/foo/bar");
+ DoTest("bar", "/foo/baz", "/foo/bar");
+ DoTest("/foo/bar", "/bar/baz", "/foo/bar");
- #ifdef NDEBUG
- DoTest("bar", "./baz", "./bar");
- #if 0 // should we support, for consistency, single-label dirs
+ #ifdef NDEBUG
+ DoTest("bar", "./baz", "./bar");
+ #if 0 // should we support, for consistency, single-label dirs
DoTest("bar", "baz", "bar");
- #endif
- #endif
+ #endif
+ #endif
#endif
+ }
+
+ Y_UNIT_TEST(TestResolvePathRelative) {
+ TTempDir tempDir;
+ TTempBuf tempBuf;
+ TString base = RealPath(tempDir());
+ if (base.back() == GetDirectorySeparator()) {
+ base.pop_back();
+ }
+
+ // File
+ TString path = base + GetDirectorySeparatorS() + "file";
+ {
+ TFixedBufferFileOutput file(path);
+ }
+ ResolvePath("file", base.data(), tempBuf.Data(), false);
+ UNIT_ASSERT_EQUAL(tempBuf.Data(), path);
+
+ // Dir
+ path = base + GetDirectorySeparatorS() + "dir";
+ MakeDirIfNotExist(path.data());
+ ResolvePath("dir", base.data(), tempBuf.Data(), true);
+ UNIT_ASSERT_EQUAL(tempBuf.Data(), path + GetDirectorySeparatorS());
+
+ // Absent file in existent dir
+ path = base + GetDirectorySeparatorS() + "nofile";
+ ResolvePath("nofile", base.data(), tempBuf.Data(), false);
+ UNIT_ASSERT_EQUAL(tempBuf.Data(), path);
}
- Y_UNIT_TEST(TestResolvePathRelative) {
- TTempDir tempDir;
- TTempBuf tempBuf;
- TString base = RealPath(tempDir());
- if (base.back() == GetDirectorySeparator()) {
- base.pop_back();
- }
-
- // File
- TString path = base + GetDirectorySeparatorS() + "file";
- {
- TFixedBufferFileOutput file(path);
- }
- ResolvePath("file", base.data(), tempBuf.Data(), false);
- UNIT_ASSERT_EQUAL(tempBuf.Data(), path);
-
- // Dir
- path = base + GetDirectorySeparatorS() + "dir";
- MakeDirIfNotExist(path.data());
- ResolvePath("dir", base.data(), tempBuf.Data(), true);
- UNIT_ASSERT_EQUAL(tempBuf.Data(), path + GetDirectorySeparatorS());
-
- // Absent file in existent dir
- path = base + GetDirectorySeparatorS() + "nofile";
- ResolvePath("nofile", base.data(), tempBuf.Data(), false);
- UNIT_ASSERT_EQUAL(tempBuf.Data(), path);
- }
-
- Y_UNIT_TEST(TestGetDirName) {
- UNIT_ASSERT_VALUES_EQUAL(".", GetDirName("parambambam"));
+ Y_UNIT_TEST(TestGetDirName) {
+ UNIT_ASSERT_VALUES_EQUAL(".", GetDirName("parambambam"));
}
- Y_UNIT_TEST(TestStripFileComponent) {
- static const TString tmpDir = "tmp_dir_for_tests";
- static const TString tmpSubDir = tmpDir + GetDirectorySeparatorS() + "subdir";
- static const TString tmpFile = tmpDir + GetDirectorySeparatorS() + "file";
-
- // creating tmp dir and subdirs
- MakeDirIfNotExist(tmpDir.data());
- MakeDirIfNotExist(tmpSubDir.data());
- {
- TFixedBufferFileOutput file(tmpFile);
- }
-
- UNIT_ASSERT_EQUAL(StripFileComponent(tmpDir), tmpDir + GetDirectorySeparatorS());
- UNIT_ASSERT_EQUAL(StripFileComponent(tmpSubDir), tmpSubDir + GetDirectorySeparatorS());
- UNIT_ASSERT_EQUAL(StripFileComponent(tmpFile), tmpDir + GetDirectorySeparatorS());
-
- RemoveDirWithContents(tmpDir);
- }
-};
+ Y_UNIT_TEST(TestStripFileComponent) {
+ static const TString tmpDir = "tmp_dir_for_tests";
+ static const TString tmpSubDir = tmpDir + GetDirectorySeparatorS() + "subdir";
+ static const TString tmpFile = tmpDir + GetDirectorySeparatorS() + "file";
+
+ // creating tmp dir and subdirs
+ MakeDirIfNotExist(tmpDir.data());
+ MakeDirIfNotExist(tmpSubDir.data());
+ {
+ TFixedBufferFileOutput file(tmpFile);
+ }
+
+ UNIT_ASSERT_EQUAL(StripFileComponent(tmpDir), tmpDir + GetDirectorySeparatorS());
+ UNIT_ASSERT_EQUAL(StripFileComponent(tmpSubDir), tmpSubDir + GetDirectorySeparatorS());
+ UNIT_ASSERT_EQUAL(StripFileComponent(tmpFile), tmpDir + GetDirectorySeparatorS());
+
+ RemoveDirWithContents(tmpDir);
+ }
+};