blob: 76f645e6e6906dd708e29925a6dc6b2ad47e70c4 [file] [log] [blame]
Hector Dearmanf275f692019-07-31 12:56:59 +01001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "perfetto/ext/base/uuid.h"
18
Primiano Tucci919ca1e2019-08-21 20:26:58 +020019#include "test/gtest_and_gmock.h"
Hector Dearmanf275f692019-07-31 12:56:59 +010020
Hector Dearman70d455d2019-11-01 17:07:37 +000021#include "perfetto/ext/base/optional.h"
22
Hector Dearmanf275f692019-07-31 12:56:59 +010023namespace perfetto {
24namespace base {
25namespace {
26
Hector Dearman5e88eef2019-11-18 12:57:47 +000027TEST(Uuid, DefaultConstructorIsBlank) {
28 Uuid a;
29 Uuid b;
30 EXPECT_EQ(a, b);
31 EXPECT_EQ(a.msb(), 0);
32 EXPECT_EQ(a.lsb(), 0);
33}
34
Hector Dearmanf275f692019-07-31 12:56:59 +010035TEST(Uuid, TwoUuidsShouldBeDifferent) {
Hector Dearman2bdd2be2019-08-07 14:50:37 +010036 Uuid a = Uuidv4();
37 Uuid b = Uuidv4();
Hector Dearmanf275f692019-07-31 12:56:59 +010038 EXPECT_NE(a, b);
Hector Dearman5e88eef2019-11-18 12:57:47 +000039 EXPECT_EQ(a, a);
40 EXPECT_EQ(b, b);
Hector Dearmanf275f692019-07-31 12:56:59 +010041}
42
Hector Dearman2bdd2be2019-08-07 14:50:37 +010043TEST(Uuid, CanRoundTripUuid) {
44 Uuid uuid = Uuidv4();
Hector Dearman5e88eef2019-11-18 12:57:47 +000045 EXPECT_EQ(Uuid(uuid.ToString()), uuid);
Hector Dearman2bdd2be2019-08-07 14:50:37 +010046}
47
Hector Dearman9dded812019-11-15 11:59:46 +000048TEST(Uuid, SetGet) {
49 Uuid a = Uuidv4();
50 Uuid b;
Hector Dearman5e88eef2019-11-18 12:57:47 +000051 b.set_lsb_msb(a.lsb(), a.msb());
52 EXPECT_EQ(a, b);
Hector Dearman9dded812019-11-15 11:59:46 +000053}
54
Hector Dearman5e88eef2019-11-18 12:57:47 +000055TEST(Uuid, LsbMsbConstructor) {
56 Uuid uuid(-6605018796207623390, 1314564453825188563);
57 EXPECT_EQ(uuid.ToPrettyString(), "123e4567-e89b-12d3-a456-426655443322");
Hector Dearman70d455d2019-11-01 17:07:37 +000058}
59
60TEST(Uuid, UuidToPrettyString) {
Hector Dearman9dded812019-11-15 11:59:46 +000061 Uuid uuid;
Hector Dearman5e88eef2019-11-18 12:57:47 +000062 uuid.set_lsb_msb(-6605018796207623390, 1314564453825188563);
63 EXPECT_EQ(uuid.ToPrettyString(), "123e4567-e89b-12d3-a456-426655443322");
Hector Dearman70d455d2019-11-01 17:07:37 +000064}
65
Hector Dearmanf275f692019-07-31 12:56:59 +010066} // namespace
67} // namespace base
68} // namespace perfetto