OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/misc/uuid.h" | 15 #include "util/misc/uuid.h" |
16 | 16 |
17 #include <stdint.h> | 17 #include <stdint.h> |
18 | 18 |
19 #include <string> | 19 #include <string> |
20 | 20 |
21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
22 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 using namespace crashpad; | 26 using namespace crashpad; |
27 | 27 |
28 TEST(UUID, UUID) { | 28 TEST(UUID, UUID) { |
29 UUID uuid_zero; | 29 UUID uuid_zero; |
30 for (size_t index = 0; index < 16; ++index) { | 30 EXPECT_EQ(0u, uuid_zero.data_1); |
31 EXPECT_EQ(0u, uuid_zero.data[index]); | 31 EXPECT_EQ(0u, uuid_zero.data_2); |
32 } | 32 EXPECT_EQ(0u, uuid_zero.data_3); |
| 33 EXPECT_EQ(0u, uuid_zero.data_4[0]); |
| 34 EXPECT_EQ(0u, uuid_zero.data_4[1]); |
| 35 EXPECT_EQ(0u, uuid_zero.data_5[0]); |
| 36 EXPECT_EQ(0u, uuid_zero.data_5[1]); |
| 37 EXPECT_EQ(0u, uuid_zero.data_5[2]); |
| 38 EXPECT_EQ(0u, uuid_zero.data_5[3]); |
| 39 EXPECT_EQ(0u, uuid_zero.data_5[4]); |
| 40 EXPECT_EQ(0u, uuid_zero.data_5[5]); |
33 EXPECT_EQ("00000000-0000-0000-0000-000000000000", uuid_zero.ToString()); | 41 EXPECT_EQ("00000000-0000-0000-0000-000000000000", uuid_zero.ToString()); |
34 | 42 |
35 const uint8_t kBytes[16] = {0x00, | 43 const uint8_t kBytes[16] = {0x00, |
36 0x01, | 44 0x01, |
37 0x02, | 45 0x02, |
38 0x03, | 46 0x03, |
39 0x04, | 47 0x04, |
40 0x05, | 48 0x05, |
41 0x06, | 49 0x06, |
42 0x07, | 50 0x07, |
43 0x08, | 51 0x08, |
44 0x09, | 52 0x09, |
45 0x0a, | 53 0x0a, |
46 0x0b, | 54 0x0b, |
47 0x0c, | 55 0x0c, |
48 0x0d, | 56 0x0d, |
49 0x0e, | 57 0x0e, |
50 0x0f}; | 58 0x0f}; |
51 UUID uuid(kBytes); | 59 UUID uuid(kBytes); |
52 for (size_t index = 0; index < arraysize(kBytes); ++index) { | 60 EXPECT_EQ(0x00010203u, uuid.data_1); |
53 EXPECT_EQ(kBytes[index], uuid.data[index]); | 61 EXPECT_EQ(0x0405u, uuid.data_2); |
54 } | 62 EXPECT_EQ(0x0607u, uuid.data_3); |
| 63 EXPECT_EQ(0x08u, uuid.data_4[0]); |
| 64 EXPECT_EQ(0x09u, uuid.data_4[1]); |
| 65 EXPECT_EQ(0x0au, uuid.data_5[0]); |
| 66 EXPECT_EQ(0x0bu, uuid.data_5[1]); |
| 67 EXPECT_EQ(0x0cu, uuid.data_5[2]); |
| 68 EXPECT_EQ(0x0du, uuid.data_5[3]); |
| 69 EXPECT_EQ(0x0eu, uuid.data_5[4]); |
| 70 EXPECT_EQ(0x0fu, uuid.data_5[5]); |
55 EXPECT_EQ("00010203-0405-0607-0809-0a0b0c0d0e0f", uuid.ToString()); | 71 EXPECT_EQ("00010203-0405-0607-0809-0a0b0c0d0e0f", uuid.ToString()); |
56 | 72 |
57 // UUID is a standard-layout structure. It is valid to memcpy to it. | |
58 const uint8_t kMoreBytes[16] = {0xff, | 73 const uint8_t kMoreBytes[16] = {0xff, |
59 0xee, | 74 0xee, |
60 0xdd, | 75 0xdd, |
61 0xcc, | 76 0xcc, |
62 0xbb, | 77 0xbb, |
63 0xaa, | 78 0xaa, |
64 0x99, | 79 0x99, |
65 0x88, | 80 0x88, |
66 0x77, | 81 0x77, |
67 0x66, | 82 0x66, |
68 0x55, | 83 0x55, |
69 0x44, | 84 0x44, |
70 0x33, | 85 0x33, |
71 0x22, | 86 0x22, |
72 0x11, | 87 0x11, |
73 0x00}; | 88 0x00}; |
74 memcpy(&uuid, kMoreBytes, sizeof(kMoreBytes)); | 89 uuid.InitializeFromBytes(kMoreBytes); |
| 90 EXPECT_EQ(0xffeeddccu, uuid.data_1); |
| 91 EXPECT_EQ(0xbbaau, uuid.data_2); |
| 92 EXPECT_EQ(0x9988u, uuid.data_3); |
| 93 EXPECT_EQ(0x77u, uuid.data_4[0]); |
| 94 EXPECT_EQ(0x66u, uuid.data_4[1]); |
| 95 EXPECT_EQ(0x55u, uuid.data_5[0]); |
| 96 EXPECT_EQ(0x44u, uuid.data_5[1]); |
| 97 EXPECT_EQ(0x33u, uuid.data_5[2]); |
| 98 EXPECT_EQ(0x22u, uuid.data_5[3]); |
| 99 EXPECT_EQ(0x11u, uuid.data_5[4]); |
| 100 EXPECT_EQ(0x00u, uuid.data_5[5]); |
75 EXPECT_EQ("ffeeddcc-bbaa-9988-7766-554433221100", uuid.ToString()); | 101 EXPECT_EQ("ffeeddcc-bbaa-9988-7766-554433221100", uuid.ToString()); |
76 } | 102 } |
77 | 103 |
78 } // namespace | 104 } // namespace |
OLD | NEW |