1//===-- UUIDTest.cpp ------------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "gtest/gtest.h"
10
11#include "lldb/Utility/UUID.h"
12
13using namespace lldb_private;
14
15TEST(UUIDTest, RelationalOperators) {
16 UUID empty;
17 UUID a16 = UUID("1234567890123456", 16);
18 UUID b16 = UUID("1234567890123457", 16);
19 UUID a20 = UUID("12345678901234567890", 20);
20 UUID b20 = UUID("12345678900987654321", 20);
21
22 EXPECT_EQ(empty, empty);
23 EXPECT_EQ(a16, a16);
24 EXPECT_EQ(a20, a20);
25
26 EXPECT_NE(a16, b16);
27 EXPECT_NE(a20, b20);
28 EXPECT_NE(a16, a20);
29 EXPECT_NE(empty, a16);
30
31 EXPECT_LT(empty, a16);
32 EXPECT_LT(a16, a20);
33 EXPECT_LT(a16, b16);
34 EXPECT_GT(a20, b20);
35}
36
37TEST(UUIDTest, Validity) {
38 UUID empty;
39 std::vector<uint8_t> zeroes(20, 0);
40 UUID a16 = UUID(zeroes.data(), 16);
41 UUID a20 = UUID(zeroes.data(), 20);
42 UUID from_str;
43 from_str.SetFromStringRef("00000000-0000-0000-0000-000000000000");
44
45 EXPECT_FALSE(empty);
46 EXPECT_FALSE(a16);
47 EXPECT_FALSE(a20);
48 EXPECT_FALSE(from_str);
49}
50
51TEST(UUIDTest, SetFromStringRef) {
52 UUID u;
53 EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f"));
54 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u);
55
56 EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
57 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u);
58
59 EXPECT_TRUE(
60 u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f-50515253"));
61 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u);
62
63 EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
64
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";
69
70 EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f-50515253"));
71 EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u);
72
73 EXPECT_TRUE(u.SetFromStringRef("40414243"));
74 EXPECT_EQ(UUID("@ABCD", 4), u);
75
76 EXPECT_FALSE(u.SetFromStringRef("4"));
77}
78
79TEST(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());
88}
89

source code of lldb/unittests/Utility/UUIDTest.cpp