llvm-project
88 строк · 2.7 Кб
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) {
16UUID empty;
17UUID a16 = UUID("1234567890123456", 16);
18UUID b16 = UUID("1234567890123457", 16);
19UUID a20 = UUID("12345678901234567890", 20);
20UUID b20 = UUID("12345678900987654321", 20);
21
22EXPECT_EQ(empty, empty);
23EXPECT_EQ(a16, a16);
24EXPECT_EQ(a20, a20);
25
26EXPECT_NE(a16, b16);
27EXPECT_NE(a20, b20);
28EXPECT_NE(a16, a20);
29EXPECT_NE(empty, a16);
30
31EXPECT_LT(empty, a16);
32EXPECT_LT(a16, a20);
33EXPECT_LT(a16, b16);
34EXPECT_GT(a20, b20);
35}
36
37TEST(UUIDTest, Validity) {
38UUID empty;
39std::vector<uint8_t> zeroes(20, 0);
40UUID a16 = UUID(zeroes.data(), 16);
41UUID a20 = UUID(zeroes.data(), 20);
42UUID from_str;
43from_str.SetFromStringRef("00000000-0000-0000-0000-000000000000");
44
45EXPECT_FALSE(empty);
46EXPECT_FALSE(a16);
47EXPECT_FALSE(a20);
48EXPECT_FALSE(from_str);
49}
50
51TEST(UUIDTest, SetFromStringRef) {
52UUID u;
53EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f"));
54EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u);
55
56EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
57EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u);
58
59EXPECT_TRUE(
60u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f-50515253"));
61EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u);
62
63EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
64
65EXPECT_FALSE(u.SetFromStringRef("40xxxxx"));
66EXPECT_FALSE(u.SetFromStringRef(""));
67EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u)
68<< "uuid was changed by failed parse calls";
69
70EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f-50515253"));
71EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u);
72
73EXPECT_TRUE(u.SetFromStringRef("40414243"));
74EXPECT_EQ(UUID("@ABCD", 4), u);
75
76EXPECT_FALSE(u.SetFromStringRef("4"));
77}
78
79TEST(UUIDTest, StringConverion) {
80EXPECT_EQ("40414243", UUID("@ABC", 4).GetAsString());
81EXPECT_EQ("40414243-4445-4647", UUID("@ABCDEFG", 8).GetAsString());
82EXPECT_EQ("40414243-4445-4647-4849-4A4B",
83UUID("@ABCDEFGHIJK", 12).GetAsString());
84EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F",
85UUID("@ABCDEFGHIJKLMNO", 16).GetAsString());
86EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F-50515253",
87UUID("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString());
88}
89