aboutsummaryrefslogtreecommitdiffstats
path: root/util/system
diff options
context:
space:
mode:
authorgleb-kov <gleb-kov@yandex-team.ru>2022-02-10 16:46:22 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:22 +0300
commit7b1cfa32681104c8468c5824c79fd80d9a88a579 (patch)
tree499e0a6e0f35aba718ac262605efb4342996bdca /util/system
parent89973d10cfeccd97d2f25449a523c93940565edf (diff)
downloadydb-7b1cfa32681104c8468c5824c79fd80d9a88a579.tar.gz
Restoring authorship annotation for <gleb-kov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system')
-rw-r--r--util/system/file_ut.cpp2
-rw-r--r--util/system/mktemp.cpp64
-rw-r--r--util/system/tempfile.cpp28
-rw-r--r--util/system/tempfile.h30
-rw-r--r--util/system/tempfile_ut.cpp262
-rw-r--r--util/system/type_name.cpp14
-rw-r--r--util/system/type_name.h48
-rw-r--r--util/system/type_name_ut.cpp320
-rw-r--r--util/system/ut/ya.make2
9 files changed, 385 insertions, 385 deletions
diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp
index 941e6a50f3..a8ef80b8c0 100644
--- a/util/system/file_ut.cpp
+++ b/util/system/file_ut.cpp
@@ -1,6 +1,6 @@
#include "file.h"
#include "fs.h"
-#include "tempfile.h"
+#include "tempfile.h"
#include <library/cpp/testing/unittest/registar.h>
diff --git a/util/system/mktemp.cpp b/util/system/mktemp.cpp
index 505b7b4a4b..c190bd4fe2 100644
--- a/util/system/mktemp.cpp
+++ b/util/system/mktemp.cpp
@@ -1,4 +1,4 @@
-#include "tempfile.h"
+#include "tempfile.h"
#include <util/folder/dirut.h>
#include <util/generic/yexception.h>
@@ -17,57 +17,57 @@
extern "C" int mkstemps(char* path, int slen);
-TString MakeTempName(const char* wrkDir, const char* prefix, const char* extension) {
+TString MakeTempName(const char* wrkDir, const char* prefix, const char* extension) {
#ifndef _win32_
- TString filePath;
+ TString filePath;
if (wrkDir && *wrkDir) {
- filePath += wrkDir;
+ filePath += wrkDir;
} else {
- filePath += GetSystemTempDir();
+ filePath += GetSystemTempDir();
}
- if (filePath.back() != '/') {
- filePath += '/';
+ if (filePath.back() != '/') {
+ filePath += '/';
}
- if (prefix) {
- filePath += prefix;
+ if (prefix) {
+ filePath += prefix;
}
- filePath += "XXXXXX"; // mkstemps requirement
+ filePath += "XXXXXX"; // mkstemps requirement
- size_t extensionPartLength = 0;
- if (extension && *extension) {
- if (extension[0] != '.') {
- filePath += '.';
- extensionPartLength += 1;
- }
- filePath += extension;
- extensionPartLength += strlen(extension);
+ size_t extensionPartLength = 0;
+ if (extension && *extension) {
+ if (extension[0] != '.') {
+ filePath += '.';
+ extensionPartLength += 1;
+ }
+ filePath += extension;
+ extensionPartLength += strlen(extension);
}
- int fd = mkstemps(const_cast<char*>(filePath.data()), extensionPartLength);
- if (fd >= 0) {
+ int fd = mkstemps(const_cast<char*>(filePath.data()), extensionPartLength);
+ if (fd >= 0) {
close(fd);
- return filePath;
+ return filePath;
}
#else
- char tmpDir[MAX_PATH + 1]; // +1 -- for terminating null character
- char filePath[MAX_PATH];
+ char tmpDir[MAX_PATH + 1]; // +1 -- for terminating null character
+ char filePath[MAX_PATH];
const char* pDir = 0;
- if (wrkDir && *wrkDir) {
+ if (wrkDir && *wrkDir) {
pDir = wrkDir;
- } else if (GetTempPath(MAX_PATH + 1, tmpDir)) {
- pDir = tmpDir;
- }
+ } else if (GetTempPath(MAX_PATH + 1, tmpDir)) {
+ pDir = tmpDir;
+ }
- // it always takes up to 3 characters, no more
- if (GetTempFileName(pDir, (prefix) ? (prefix) : "yan", 0, filePath)) {
- return filePath;
- }
+ // it always takes up to 3 characters, no more
+ if (GetTempFileName(pDir, (prefix) ? (prefix) : "yan", 0, filePath)) {
+ return filePath;
+ }
#endif
- ythrow TSystemError() << "can not create temp name(" << wrkDir << ", " << prefix << ", " << extension << ")";
+ ythrow TSystemError() << "can not create temp name(" << wrkDir << ", " << prefix << ", " << extension << ")";
}
diff --git a/util/system/tempfile.cpp b/util/system/tempfile.cpp
index a2e9f49eb1..534ccf9b26 100644
--- a/util/system/tempfile.cpp
+++ b/util/system/tempfile.cpp
@@ -1,9 +1,9 @@
#include "tempfile.h"
-TTempFileHandle::TTempFileHandle()
- : TTempFile(MakeTempName())
- , TFile(CreateFile())
-{
+TTempFileHandle::TTempFileHandle()
+ : TTempFile(MakeTempName())
+ , TFile(CreateFile())
+{
}
TTempFileHandle::TTempFileHandle(const TString& fname)
@@ -12,14 +12,14 @@ TTempFileHandle::TTempFileHandle(const TString& fname)
{
}
-TTempFileHandle TTempFileHandle::InCurrentDir(const TString& filePrefix, const TString& extension) {
- return TTempFileHandle(MakeTempName(".", filePrefix.c_str(), extension.c_str()));
-}
-
-TTempFileHandle TTempFileHandle::InDir(const TFsPath& dirPath, const TString& filePrefix, const TString& extension) {
- return TTempFileHandle(MakeTempName(dirPath.c_str(), filePrefix.c_str(), extension.c_str()));
-}
-
-TFile TTempFileHandle::CreateFile() const {
- return TFile(Name(), CreateAlways | RdWr);
+TTempFileHandle TTempFileHandle::InCurrentDir(const TString& filePrefix, const TString& extension) {
+ return TTempFileHandle(MakeTempName(".", filePrefix.c_str(), extension.c_str()));
}
+
+TTempFileHandle TTempFileHandle::InDir(const TFsPath& dirPath, const TString& filePrefix, const TString& extension) {
+ return TTempFileHandle(MakeTempName(dirPath.c_str(), filePrefix.c_str(), extension.c_str()));
+}
+
+TFile TTempFileHandle::CreateFile() const {
+ return TFile(Name(), CreateAlways | RdWr);
+}
diff --git a/util/system/tempfile.h b/util/system/tempfile.h
index de249c129d..fb8ec62ec6 100644
--- a/util/system/tempfile.h
+++ b/util/system/tempfile.h
@@ -3,7 +3,7 @@
#include "fs.h"
#include "file.h"
-#include <util/folder/path.h>
+#include <util/folder/path.h>
#include <util/generic/string.h>
class TTempFile {
@@ -30,21 +30,21 @@ public:
TTempFileHandle();
TTempFileHandle(const TString& fname);
- static TTempFileHandle InCurrentDir(const TString& filePrefix = "yandex", const TString& extension = "tmp");
- static TTempFileHandle InDir(const TFsPath& dirPath, const TString& filePrefix = "yandex", const TString& extension = "tmp");
-
+ static TTempFileHandle InCurrentDir(const TString& filePrefix = "yandex", const TString& extension = "tmp");
+ static TTempFileHandle InDir(const TFsPath& dirPath, const TString& filePrefix = "yandex", const TString& extension = "tmp");
+
private:
TFile CreateFile() const;
};
-
-/*
- * Creates a unique temporary filename in specified directory.
- * If specified directory is NULL or empty, then system temporary directory is used.
- *
- * Note, that the function is not race-free, the file is guaranteed to exist at the time the function returns, but not at the time the returned name is first used.
- * Throws TSystemError on error.
+
+/*
+ * Creates a unique temporary filename in specified directory.
+ * If specified directory is NULL or empty, then system temporary directory is used.
*
- * Returned filepath has such format: dir/prefixXXXXXX.extension or dir/prefixXXXXXX
- * But win32: dir/preXXXX.tmp (prefix is up to 3 characters, extension is always tmp).
- */
-TString MakeTempName(const char* wrkDir = nullptr, const char* prefix = "yandex", const char* extension = "tmp");
+ * Note, that the function is not race-free, the file is guaranteed to exist at the time the function returns, but not at the time the returned name is first used.
+ * Throws TSystemError on error.
+ *
+ * Returned filepath has such format: dir/prefixXXXXXX.extension or dir/prefixXXXXXX
+ * But win32: dir/preXXXX.tmp (prefix is up to 3 characters, extension is always tmp).
+ */
+TString MakeTempName(const char* wrkDir = nullptr, const char* prefix = "yandex", const char* extension = "tmp");
diff --git a/util/system/tempfile_ut.cpp b/util/system/tempfile_ut.cpp
index e4a0923d0b..3b9ad5fc50 100644
--- a/util/system/tempfile_ut.cpp
+++ b/util/system/tempfile_ut.cpp
@@ -3,11 +3,11 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/folder/dirut.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/stream/file.h>
-#include <algorithm>
-
+#include <algorithm>
+
Y_UNIT_TEST_SUITE(TTempFileHandle) {
Y_UNIT_TEST(Create) {
TString path;
@@ -20,132 +20,132 @@ Y_UNIT_TEST_SUITE(TTempFileHandle) {
}
UNIT_ASSERT(!NFs::Exists(path));
}
-
- Y_UNIT_TEST(InCurrentDir) {
-#ifndef _win32_
- static const TString TEST_PREFIX = "unique_prefix";
-#else
- static const TString TEST_PREFIX = "uni";
-#endif
-
- TString path;
- {
- TTempFileHandle tmp = TTempFileHandle::InCurrentDir(TEST_PREFIX);
- path = tmp.Name();
- UNIT_ASSERT(NFs::Exists(path));
-
- TVector<TString> names;
- TFsPath(".").ListNames(names);
- bool containsFileWithPrefix = std::any_of(names.begin(), names.end(), [&](const TString& name) {
- return name.Contains(TEST_PREFIX);
- });
- UNIT_ASSERT(containsFileWithPrefix);
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(UseExtensionWithoutDot) {
- TString path;
- {
- TTempFileHandle tmp = TTempFileHandle::InCurrentDir("hello", "world");
- path = tmp.Name();
- UNIT_ASSERT(NFs::Exists(path));
-
-#ifndef _win32_
- UNIT_ASSERT(path.Contains("hello"));
- UNIT_ASSERT(path.EndsWith(".world"));
- UNIT_ASSERT(!path.EndsWith("..world"));
-#else
- UNIT_ASSERT(path.Contains("hel"));
- UNIT_ASSERT(path.EndsWith(".tmp"));
-#endif
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(UseExtensionWithDot) {
- TString path;
- {
- TTempFileHandle tmp = TTempFileHandle::InCurrentDir("lorem", ".ipsum");
- path = tmp.Name();
- UNIT_ASSERT(NFs::Exists(path));
-
-#ifndef _win32_
- UNIT_ASSERT(path.Contains("lorem"));
- UNIT_ASSERT(path.EndsWith(".ipsum"));
- UNIT_ASSERT(!path.EndsWith("..ipsum"));
-#else
- UNIT_ASSERT(path.Contains("lor"));
- UNIT_ASSERT(path.EndsWith(".tmp"));
-#endif
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(SafeDestructor) {
- TString path;
- {
- path = MakeTempName();
- UNIT_ASSERT(NFs::Exists(path));
-
- TTempFileHandle tmp(path);
- Y_UNUSED(tmp);
- UNIT_ASSERT(NFs::Exists(path));
-
- TTempFileHandle anotherTmp(path);
- Y_UNUSED(anotherTmp);
- UNIT_ASSERT(NFs::Exists(path));
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(RemovesOpen) {
- TString path;
- {
- TTempFileHandle tmp;
- path = tmp.Name();
- tmp.Write("hello world\n", 12);
- tmp.FlushData();
- UNIT_ASSERT(NFs::Exists(path));
- UNIT_ASSERT(tmp.IsOpen());
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(NonExistingDirectory) {
- UNIT_ASSERT_EXCEPTION(TTempFileHandle::InDir("nonexsistingdirname"), TSystemError);
- }
-}
-
-Y_UNIT_TEST_SUITE(MakeTempName) {
- Y_UNIT_TEST(Default) {
- TString path;
- {
- TTempFile tmp(MakeTempName());
- path = tmp.Name();
-
- UNIT_ASSERT(!path.Contains('\0'));
- UNIT_ASSERT(NFs::Exists(path));
- UNIT_ASSERT(path.EndsWith(".tmp"));
-
-#ifndef _win32_
- UNIT_ASSERT(path.Contains("yandex"));
-#else
- UNIT_ASSERT(path.Contains("yan"));
-#endif
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(UseNullptr) {
- TString path;
- {
- TTempFile tmp(MakeTempName(nullptr, nullptr, nullptr));
- path = tmp.Name();
-
- UNIT_ASSERT(!path.Contains('\0'));
- UNIT_ASSERT(NFs::Exists(path));
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
+
+ Y_UNIT_TEST(InCurrentDir) {
+#ifndef _win32_
+ static const TString TEST_PREFIX = "unique_prefix";
+#else
+ static const TString TEST_PREFIX = "uni";
+#endif
+
+ TString path;
+ {
+ TTempFileHandle tmp = TTempFileHandle::InCurrentDir(TEST_PREFIX);
+ path = tmp.Name();
+ UNIT_ASSERT(NFs::Exists(path));
+
+ TVector<TString> names;
+ TFsPath(".").ListNames(names);
+ bool containsFileWithPrefix = std::any_of(names.begin(), names.end(), [&](const TString& name) {
+ return name.Contains(TEST_PREFIX);
+ });
+ UNIT_ASSERT(containsFileWithPrefix);
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(UseExtensionWithoutDot) {
+ TString path;
+ {
+ TTempFileHandle tmp = TTempFileHandle::InCurrentDir("hello", "world");
+ path = tmp.Name();
+ UNIT_ASSERT(NFs::Exists(path));
+
+#ifndef _win32_
+ UNIT_ASSERT(path.Contains("hello"));
+ UNIT_ASSERT(path.EndsWith(".world"));
+ UNIT_ASSERT(!path.EndsWith("..world"));
+#else
+ UNIT_ASSERT(path.Contains("hel"));
+ UNIT_ASSERT(path.EndsWith(".tmp"));
+#endif
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(UseExtensionWithDot) {
+ TString path;
+ {
+ TTempFileHandle tmp = TTempFileHandle::InCurrentDir("lorem", ".ipsum");
+ path = tmp.Name();
+ UNIT_ASSERT(NFs::Exists(path));
+
+#ifndef _win32_
+ UNIT_ASSERT(path.Contains("lorem"));
+ UNIT_ASSERT(path.EndsWith(".ipsum"));
+ UNIT_ASSERT(!path.EndsWith("..ipsum"));
+#else
+ UNIT_ASSERT(path.Contains("lor"));
+ UNIT_ASSERT(path.EndsWith(".tmp"));
+#endif
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(SafeDestructor) {
+ TString path;
+ {
+ path = MakeTempName();
+ UNIT_ASSERT(NFs::Exists(path));
+
+ TTempFileHandle tmp(path);
+ Y_UNUSED(tmp);
+ UNIT_ASSERT(NFs::Exists(path));
+
+ TTempFileHandle anotherTmp(path);
+ Y_UNUSED(anotherTmp);
+ UNIT_ASSERT(NFs::Exists(path));
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(RemovesOpen) {
+ TString path;
+ {
+ TTempFileHandle tmp;
+ path = tmp.Name();
+ tmp.Write("hello world\n", 12);
+ tmp.FlushData();
+ UNIT_ASSERT(NFs::Exists(path));
+ UNIT_ASSERT(tmp.IsOpen());
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(NonExistingDirectory) {
+ UNIT_ASSERT_EXCEPTION(TTempFileHandle::InDir("nonexsistingdirname"), TSystemError);
+ }
}
+
+Y_UNIT_TEST_SUITE(MakeTempName) {
+ Y_UNIT_TEST(Default) {
+ TString path;
+ {
+ TTempFile tmp(MakeTempName());
+ path = tmp.Name();
+
+ UNIT_ASSERT(!path.Contains('\0'));
+ UNIT_ASSERT(NFs::Exists(path));
+ UNIT_ASSERT(path.EndsWith(".tmp"));
+
+#ifndef _win32_
+ UNIT_ASSERT(path.Contains("yandex"));
+#else
+ UNIT_ASSERT(path.Contains("yan"));
+#endif
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(UseNullptr) {
+ TString path;
+ {
+ TTempFile tmp(MakeTempName(nullptr, nullptr, nullptr));
+ path = tmp.Name();
+
+ UNIT_ASSERT(!path.Contains('\0'));
+ UNIT_ASSERT(NFs::Exists(path));
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+}
diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp
index 0377da4212..fc578091b3 100644
--- a/util/system/type_name.cpp
+++ b/util/system/type_name.cpp
@@ -6,7 +6,7 @@
#include <cxxabi.h>
#endif
-#include "type_name.h"
+#include "type_name.h"
namespace {
@@ -42,19 +42,19 @@ const char* NPrivate::TCppDemangler::Demangle(const char* name) {
TString CppDemangle(const TString& name) {
return NPrivate::TCppDemangler().Demangle(name.data());
}
-
-TString TypeName(const std::type_info& typeInfo) {
+
+TString TypeName(const std::type_info& typeInfo) {
TString demangled = CppDemangle(typeInfo.name()); // NOLINT(arcadia-typeid-name-restriction)
#if defined(_linux_) || defined(_darwin_)
SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
#endif
return demangled;
-}
-
-TString TypeName(const std::type_index& typeIndex) {
+}
+
+TString TypeName(const std::type_index& typeIndex) {
TString demangled = CppDemangle(typeIndex.name());
#if defined(_linux_) || defined(_darwin_)
SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
#endif
return demangled;
-}
+}
diff --git a/util/system/type_name.h b/util/system/type_name.h
index b6619aba3f..72196542fe 100644
--- a/util/system/type_name.h
+++ b/util/system/type_name.h
@@ -3,28 +3,28 @@
#include <util/generic/string.h>
#include <util/string/subst.h>
-#include <typeindex>
-#include <typeinfo>
-
-// Consider using TypeName function family.
+#include <typeindex>
+#include <typeinfo>
+
+// Consider using TypeName function family.
TString CppDemangle(const TString& name);
-
-// TypeName function family return human readable type name.
-
-TString TypeName(const std::type_info& typeInfo);
-TString TypeName(const std::type_index& typeInfo);
-
-// Works for types known at compile-time
-// (thus, does not take any inheritance into account)
-template <class T>
-inline TString TypeName() {
- return TypeName(typeid(T));
-}
-
-// Works for dynamic type, including complex class hierarchies.
-// Also, distinguishes between T, T*, T const*, T volatile*, T const volatile*,
-// but not T and T const.
-template <class T>
-inline TString TypeName(const T& t) {
- return TypeName(typeid(t));
-}
+
+// TypeName function family return human readable type name.
+
+TString TypeName(const std::type_info& typeInfo);
+TString TypeName(const std::type_index& typeInfo);
+
+// Works for types known at compile-time
+// (thus, does not take any inheritance into account)
+template <class T>
+inline TString TypeName() {
+ return TypeName(typeid(T));
+}
+
+// Works for dynamic type, including complex class hierarchies.
+// Also, distinguishes between T, T*, T const*, T volatile*, T const volatile*,
+// but not T and T const.
+template <class T>
+inline TString TypeName(const T& t) {
+ return TypeName(typeid(t));
+}
diff --git a/util/system/type_name_ut.cpp b/util/system/type_name_ut.cpp
index 86597f4232..95b5a25428 100644
--- a/util/system/type_name_ut.cpp
+++ b/util/system/type_name_ut.cpp
@@ -1,13 +1,13 @@
-#include "type_name.h"
+#include "type_name.h"
#include <library/cpp/testing/unittest/registar.h>
-#include <util/generic/yexception.h>
-#include <util/generic/fwd.h>
-
-#include <stdexcept>
-#include <string>
-
+#include <util/generic/yexception.h>
+#include <util/generic/fwd.h>
+
+#include <stdexcept>
+#include <string>
+
Y_UNIT_TEST_SUITE(TDemangleTest) {
Y_UNIT_TEST(SimpleTest) {
// just check it does not crash or leak
@@ -16,169 +16,169 @@ Y_UNIT_TEST_SUITE(TDemangleTest) {
CppDemangle("Sfsdf$dfsdfTTSFSDF23234::SDFS:FSDFSDF#$%");
}
}
-
-namespace NUtil::NTypeNameTest {
-
- class TSonde {
- // intentionally left empty
- };
-
- class TRombicHead {
- public:
- virtual ~TRombicHead() = default;
- };
-
+
+namespace NUtil::NTypeNameTest {
+
+ class TSonde {
+ // intentionally left empty
+ };
+
+ class TRombicHead {
+ public:
+ virtual ~TRombicHead() = default;
+ };
+
class TRombicLeftArc: public virtual TRombicHead {
- public:
- int x;
- virtual ~TRombicLeftArc() = default;
- };
-
+ public:
+ int x;
+ virtual ~TRombicLeftArc() = default;
+ };
+
class TRombicRightArc: public virtual TRombicHead {
- public:
- int y;
- virtual ~TRombicRightArc() = default;
- };
-
+ public:
+ int y;
+ virtual ~TRombicRightArc() = default;
+ };
+
class TRombicTail: public virtual TRombicRightArc, TRombicLeftArc {
- public:
- virtual ~TRombicTail() = default;
- };
-
- class TFromThis {
- public:
- TString GetTypeName() const {
- return TypeName(*this);
- }
- };
-}
-
-using namespace NUtil::NTypeNameTest;
-
-Y_UNIT_TEST_SUITE(TypeName) {
- Y_UNIT_TEST(FromWellKnownTypes) {
- UNIT_ASSERT_VALUES_EQUAL(TypeName<void>(), "void");
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void * __ptr64");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void*");
-#endif
- UNIT_ASSERT_VALUES_EQUAL(TypeName<int>(), "int");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<double>(), "double");
-
-#ifdef _MSC_VER
+ public:
+ virtual ~TRombicTail() = default;
+ };
+
+ class TFromThis {
+ public:
+ TString GetTypeName() const {
+ return TypeName(*this);
+ }
+ };
+}
+
+using namespace NUtil::NTypeNameTest;
+
+Y_UNIT_TEST_SUITE(TypeName) {
+ Y_UNIT_TEST(FromWellKnownTypes) {
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<void>(), "void");
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void * __ptr64");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void*");
+#endif
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<int>(), "int");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<double>(), "double");
+
+#ifdef _MSC_VER
UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "class std::runtime_error");
-#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "class std::runtime_error");
+#else
UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "std::runtime_error");
-#endif
- }
-
- Y_UNIT_TEST(FromArcadiaTypes) {
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "class yexception");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "std::runtime_error");
+#endif
+ }
+
+ Y_UNIT_TEST(FromArcadiaTypes) {
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "class yexception");
UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "class TBasicString<char,struct std::char_traits<char> >");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "yexception");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "yexception");
UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "TBasicString<char, std::char_traits<char> >");
-#endif
- }
-
- Y_UNIT_TEST(FromUserTypes) {
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "class NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "class NUtil::NTypeNameTest::TRombicTail");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "NUtil::NTypeNameTest::TRombicTail");
-#endif
- }
-
- Y_UNIT_TEST(FromWellKnownValues) {
- void* value = (void*)"123";
- const void* constValue = (const void*)"456";
-
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void * __ptr64 * __ptr64");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const * __ptr64 * __ptr64");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void**");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const**");
-#endif
-
- int zero = 0;
- UNIT_ASSERT_VALUES_EQUAL(TypeName(zero), "int");
-
- double pi = M_PI;
- UNIT_ASSERT_VALUES_EQUAL(TypeName(pi), "double");
-
- std::string string;
- std::runtime_error err("This is awful");
-#ifdef _MSC_VER
+#endif
+ }
+
+ Y_UNIT_TEST(FromUserTypes) {
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "class NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "class NUtil::NTypeNameTest::TRombicTail");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "NUtil::NTypeNameTest::TRombicTail");
+#endif
+ }
+
+ Y_UNIT_TEST(FromWellKnownValues) {
+ void* value = (void*)"123";
+ const void* constValue = (const void*)"456";
+
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void * __ptr64 * __ptr64");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const * __ptr64 * __ptr64");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void**");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const**");
+#endif
+
+ int zero = 0;
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(zero), "int");
+
+ double pi = M_PI;
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(pi), "double");
+
+ std::string string;
+ std::runtime_error err("This is awful");
+#ifdef _MSC_VER
UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "class std::runtime_error");
-#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "class std::runtime_error");
+#else
UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "std::runtime_error");
-#endif
- }
-
- Y_UNIT_TEST(FromUserValues) {
- TSonde sonde;
- const TSonde constSonde;
-
- TRombicTail rombicTail;
- TRombicHead& castedTail = rombicTail;
-
- TFromThis obj;
-
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "class NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "class NUtil::NTypeNameTest::TSonde");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "class NUtil::NTypeNameTest::TRombicTail");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "class NUtil::NTypeNameTest::TRombicTail");
-
- UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "class NUtil::NTypeNameTest::TFromThis");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "NUtil::NTypeNameTest::TSonde");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "NUtil::NTypeNameTest::TRombicTail");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "NUtil::NTypeNameTest::TRombicTail");
-
- UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "NUtil::NTypeNameTest::TFromThis");
-#endif
- }
-
- Y_UNIT_TEST(FromTypeInfo) {
- UNIT_ASSERT_VALUES_EQUAL(TypeName(typeid(int)), "int");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(std::type_index(typeid(int))), "int");
- }
-
- Y_UNIT_TEST(DistinguishPointerQualifiers) {
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "std::runtime_error");
+#endif
+ }
+
+ Y_UNIT_TEST(FromUserValues) {
+ TSonde sonde;
+ const TSonde constSonde;
+
+ TRombicTail rombicTail;
+ TRombicHead& castedTail = rombicTail;
+
+ TFromThis obj;
+
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "class NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "class NUtil::NTypeNameTest::TSonde");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "class NUtil::NTypeNameTest::TRombicTail");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "class NUtil::NTypeNameTest::TRombicTail");
+
+ UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "class NUtil::NTypeNameTest::TFromThis");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "NUtil::NTypeNameTest::TSonde");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "NUtil::NTypeNameTest::TRombicTail");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "NUtil::NTypeNameTest::TRombicTail");
+
+ UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "NUtil::NTypeNameTest::TFromThis");
+#endif
+ }
+
+ Y_UNIT_TEST(FromTypeInfo) {
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(typeid(int)), "int");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(std::type_index(typeid(int))), "int");
+ }
+
+ Y_UNIT_TEST(DistinguishPointerQualifiers) {
char* simplePtr = nullptr;
const char* constPtr = nullptr;
volatile char* volatilePtr = nullptr;
const volatile char* cvPtr = nullptr;
-
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile * __ptr64");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile*");
-#endif
- }
-}
+
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile * __ptr64");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile*");
+#endif
+ }
+}
diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make
index 127e7c261e..04e9e24721 100644
--- a/util/system/ut/ya.make
+++ b/util/system/ut/ya.make
@@ -71,7 +71,7 @@ SRCS(
system/thread_ut.cpp
system/tls_ut.cpp
system/types_ut.cpp
- system/type_name_ut.cpp
+ system/type_name_ut.cpp
system/user_ut.cpp
system/unaligned_mem_ut.cpp
system/yassert_ut.cpp