summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/string/unittests/guid_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/yt/string/unittests/guid_ut.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yt/string/unittests/guid_ut.cpp')
-rw-r--r--library/cpp/yt/string/unittests/guid_ut.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/library/cpp/yt/string/unittests/guid_ut.cpp b/library/cpp/yt/string/unittests/guid_ut.cpp
new file mode 100644
index 00000000000..4b5eebea16e
--- /dev/null
+++ b/library/cpp/yt/string/unittests/guid_ut.cpp
@@ -0,0 +1,58 @@
+#include <library/cpp/testing/gtest/gtest.h>
+
+#include <library/cpp/yt/string/guid.h>
+#include <library/cpp/yt/string/format.h>
+
+#include <util/string/hex.h>
+
+namespace NYT {
+namespace {
+
+////////////////////////////////////////////////////////////////////////////////
+
+static_assert(TFormatTraits<TGuid>::HasCustomFormatValue);
+
+TString CanonicalToString(TGuid value)
+{
+ return Sprintf("%x-%x-%x-%x",
+ value.Parts32[3],
+ value.Parts32[2],
+ value.Parts32[1],
+ value.Parts32[0]);
+}
+
+const ui32 TrickyValues[] = {
+ 0, 0x1, 0x12, 0x123, 0x1234, 0x12345, 0x123456, 0x1234567, 0x12345678
+};
+
+TEST(TGuidTest, FormatAllTricky)
+{
+ for (ui32 a : TrickyValues) {
+ for (ui32 b : TrickyValues) {
+ for (ui32 c : TrickyValues) {
+ for (ui32 d : TrickyValues) {
+ auto value = TGuid(a, b, c, d);
+ EXPECT_EQ(CanonicalToString(value), ToString(value));
+ }
+ }
+ }
+ }
+}
+
+TEST(TGuidTest, FormatAllSymbols)
+{
+ const auto Value = TGuid::FromString("12345678-abcdef01-12345678-abcdef01");
+ EXPECT_EQ(CanonicalToString(Value), ToString(Value));
+}
+
+TEST(TGuidTest, ByteOrder)
+{
+ auto guid = TGuid::FromStringHex32("12345678ABCDEF0112345678ABCDEF01");
+ TString bytes{reinterpret_cast<const char*>(&(guid.Parts32[0])), 16};
+ EXPECT_EQ(HexEncode(bytes), "01EFCDAB7856341201EFCDAB78563412");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace
+} // namespace NYT