1 /*
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
19 #include "test/gtest_and_gmock.h"
20
21 #include "perfetto/ext/base/optional.h"
22
23 namespace perfetto {
24 namespace base {
25 namespace {
26
TEST(Uuid,DefaultConstructorIsBlank)27 TEST(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
TEST(Uuid,TwoUuidsShouldBeDifferent)35 TEST(Uuid, TwoUuidsShouldBeDifferent) {
36 Uuid a = Uuidv4();
37 Uuid b = Uuidv4();
38 EXPECT_NE(a, b);
39 EXPECT_EQ(a, a);
40 EXPECT_EQ(b, b);
41 }
42
TEST(Uuid,CanRoundTripUuid)43 TEST(Uuid, CanRoundTripUuid) {
44 Uuid uuid = Uuidv4();
45 EXPECT_EQ(Uuid(uuid.ToString()), uuid);
46 }
47
TEST(Uuid,SetGet)48 TEST(Uuid, SetGet) {
49 Uuid a = Uuidv4();
50 Uuid b;
51 b.set_lsb_msb(a.lsb(), a.msb());
52 EXPECT_EQ(a, b);
53 }
54
TEST(Uuid,LsbMsbConstructor)55 TEST(Uuid, LsbMsbConstructor) {
56 Uuid uuid(-6605018796207623390, 1314564453825188563);
57 EXPECT_EQ(uuid.ToPrettyString(), "123e4567-e89b-12d3-a456-426655443322");
58 }
59
TEST(Uuid,UuidToPrettyString)60 TEST(Uuid, UuidToPrettyString) {
61 Uuid uuid;
62 uuid.set_lsb_msb(-6605018796207623390, 1314564453825188563);
63 EXPECT_EQ(uuid.ToPrettyString(), "123e4567-e89b-12d3-a456-426655443322");
64 }
65
66 } // namespace
67 } // namespace base
68 } // namespace perfetto
69