forked from frc971/971-Robot-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuuid_test.cc
56 lines (41 loc) · 1.61 KB
/
uuid_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "aos/uuid.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
namespace aos {
namespace testing {
// Tests that random UUIDs are actually random, and we can convert them to a
// string. Not very exhaustive, but it is a good smoke test.
TEST(UUIDTest, GetOne) {
LOG(INFO) << UUID::Random();
UUID r = UUID::Random();
std::stringstream ss;
ss << r;
UUID r2 = UUID::FromString(ss.str());
EXPECT_EQ(r2, r);
EXPECT_NE(UUID::Random(), UUID::Random());
EXPECT_NE(UUID::Random(), UUID::Zero());
EXPECT_EQ(UUID::Zero(), UUID::Zero());
}
// Tests that converting to and from various formats produces the same UUID.
TEST(UUIDTest, FromStringOrSpan) {
std::string_view str = "4b88ab00-556a-455b-a395-17d1a0c6f906";
std::array<uint8_t, UUID::kDataSize> data = {
0x4b, 0x88, 0xab, 0x00, 0x55, 0x6a, 0x45, 0x5b,
0xa3, 0x95, 0x17, 0xd1, 0xa0, 0xc6, 0xf9, 0x06};
const UUID u_str = UUID::FromString(str);
const UUID u_span = UUID::FromSpan({data.data(), data.size()});
EXPECT_EQ(u_str.span(), absl::Span<uint8_t>(data.data(), data.size()));
EXPECT_EQ(u_span.span(), absl::Span<uint8_t>(data.data(), data.size()));
EXPECT_EQ(u_str.ToString(), str);
EXPECT_EQ(u_span.ToString(), str);
flatbuffers::FlatBufferBuilder fbb;
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> data_offset =
fbb.CreateVector(data.data(), data.size());
const flatbuffers::Vector<uint8_t> *data_vector =
flatbuffers::GetTemporaryPointer(fbb, data_offset);
const UUID u2 = UUID::FromVector(data_vector);
EXPECT_EQ(u_str, u2);
EXPECT_EQ(u_span, u2);
}
} // namespace testing
} // namespace aos