Hector Dearman | f275f69 | 2019-07-31 12:56:59 +0100 | [diff] [blame] | 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 | |
Primiano Tucci | 919ca1e | 2019-08-21 20:26:58 +0200 | [diff] [blame] | 19 | #include "test/gtest_and_gmock.h" |
Hector Dearman | f275f69 | 2019-07-31 12:56:59 +0100 | [diff] [blame] | 20 | |
Hector Dearman | 70d455d | 2019-11-01 17:07:37 +0000 | [diff] [blame] | 21 | #include "perfetto/ext/base/optional.h" |
| 22 | |
Hector Dearman | f275f69 | 2019-07-31 12:56:59 +0100 | [diff] [blame] | 23 | namespace perfetto { |
| 24 | namespace base { |
| 25 | namespace { |
| 26 | |
Hector Dearman | 5e88eef | 2019-11-18 12:57:47 +0000 | [diff] [blame] | 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 | |
Hector Dearman | f275f69 | 2019-07-31 12:56:59 +0100 | [diff] [blame] | 35 | TEST(Uuid, TwoUuidsShouldBeDifferent) { |
Hector Dearman | 2bdd2be | 2019-08-07 14:50:37 +0100 | [diff] [blame] | 36 | Uuid a = Uuidv4(); |
| 37 | Uuid b = Uuidv4(); |
Hector Dearman | f275f69 | 2019-07-31 12:56:59 +0100 | [diff] [blame] | 38 | EXPECT_NE(a, b); |
Hector Dearman | 5e88eef | 2019-11-18 12:57:47 +0000 | [diff] [blame] | 39 | EXPECT_EQ(a, a); |
| 40 | EXPECT_EQ(b, b); |
Hector Dearman | f275f69 | 2019-07-31 12:56:59 +0100 | [diff] [blame] | 41 | } |
| 42 | |
Hector Dearman | 2bdd2be | 2019-08-07 14:50:37 +0100 | [diff] [blame] | 43 | TEST(Uuid, CanRoundTripUuid) { |
| 44 | Uuid uuid = Uuidv4(); |
Hector Dearman | 5e88eef | 2019-11-18 12:57:47 +0000 | [diff] [blame] | 45 | EXPECT_EQ(Uuid(uuid.ToString()), uuid); |
Hector Dearman | 2bdd2be | 2019-08-07 14:50:37 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Hector Dearman | 9dded81 | 2019-11-15 11:59:46 +0000 | [diff] [blame] | 48 | TEST(Uuid, SetGet) { |
| 49 | Uuid a = Uuidv4(); |
| 50 | Uuid b; |
Hector Dearman | 5e88eef | 2019-11-18 12:57:47 +0000 | [diff] [blame] | 51 | b.set_lsb_msb(a.lsb(), a.msb()); |
| 52 | EXPECT_EQ(a, b); |
Hector Dearman | 9dded81 | 2019-11-15 11:59:46 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Hector Dearman | 5e88eef | 2019-11-18 12:57:47 +0000 | [diff] [blame] | 55 | TEST(Uuid, LsbMsbConstructor) { |
| 56 | Uuid uuid(-6605018796207623390, 1314564453825188563); |
| 57 | EXPECT_EQ(uuid.ToPrettyString(), "123e4567-e89b-12d3-a456-426655443322"); |
Hector Dearman | 70d455d | 2019-11-01 17:07:37 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TEST(Uuid, UuidToPrettyString) { |
Hector Dearman | 9dded81 | 2019-11-15 11:59:46 +0000 | [diff] [blame] | 61 | Uuid uuid; |
Hector Dearman | 5e88eef | 2019-11-18 12:57:47 +0000 | [diff] [blame] | 62 | uuid.set_lsb_msb(-6605018796207623390, 1314564453825188563); |
| 63 | EXPECT_EQ(uuid.ToPrettyString(), "123e4567-e89b-12d3-a456-426655443322"); |
Hector Dearman | 70d455d | 2019-11-01 17:07:37 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Hector Dearman | f275f69 | 2019-07-31 12:56:59 +0100 | [diff] [blame] | 66 | } // namespace |
| 67 | } // namespace base |
| 68 | } // namespace perfetto |