1 //===-- UUIDTest.cpp ------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
11 #include "lldb/Utility/UUID.h"
13 using namespace lldb_private
;
15 TEST(UUIDTest
, RelationalOperators
) {
17 UUID a16
= UUID("1234567890123456", 16);
18 UUID b16
= UUID("1234567890123457", 16);
19 UUID a20
= UUID("12345678901234567890", 20);
20 UUID b20
= UUID("12345678900987654321", 20);
22 EXPECT_EQ(empty
, empty
);
29 EXPECT_NE(empty
, a16
);
31 EXPECT_LT(empty
, a16
);
37 TEST(UUIDTest
, Validity
) {
39 std::vector
<uint8_t> zeroes(20, 0);
40 UUID a16
= UUID(zeroes
.data(), 16);
41 UUID a20
= UUID(zeroes
.data(), 20);
43 from_str
.SetFromStringRef("00000000-0000-0000-0000-000000000000");
48 EXPECT_FALSE(from_str
);
51 TEST(UUIDTest
, SetFromStringRef
) {
53 EXPECT_TRUE(u
.SetFromStringRef("404142434445464748494a4b4c4d4e4f"));
54 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u
);
56 EXPECT_TRUE(u
.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
57 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u
);
60 u
.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f-50515253"));
61 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u
);
63 EXPECT_TRUE(u
.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
65 EXPECT_FALSE(u
.SetFromStringRef("40xxxxx"));
66 EXPECT_FALSE(u
.SetFromStringRef(""));
67 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u
)
68 << "uuid was changed by failed parse calls";
70 EXPECT_TRUE(u
.SetFromStringRef("404142434445464748494a4b4c4d4e4f-50515253"));
71 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u
);
73 EXPECT_TRUE(u
.SetFromStringRef("40414243"));
74 EXPECT_EQ(UUID("@ABCD", 4), u
);
76 EXPECT_FALSE(u
.SetFromStringRef("4"));
79 TEST(UUIDTest
, StringConverion
) {
80 EXPECT_EQ("40414243", UUID("@ABC", 4).GetAsString());
81 EXPECT_EQ("40414243-4445-4647", UUID("@ABCDEFG", 8).GetAsString());
82 EXPECT_EQ("40414243-4445-4647-4849-4A4B",
83 UUID("@ABCDEFGHIJK", 12).GetAsString());
84 EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F",
85 UUID("@ABCDEFGHIJKLMNO", 16).GetAsString());
86 EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F-50515253",
87 UUID("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString());