Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: util/misc/uuid_test.cc

Issue 430003003: Add UUID, strlcpy, and their tests to util (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "util/misc/uuid.h"
16
17 #include <stdint.h>
18
19 #include <string>
20
21 #include "base/basictypes.h"
22 #include "gtest/gtest.h"
23
24 namespace {
25
26 using namespace crashpad;
27
28 TEST(UUID, UUID) {
29 UUID uuid_zero;
30 for (size_t index = 0; index < 16; ++index) {
31 EXPECT_EQ(0u, uuid_zero.data[index]);
32 }
33 EXPECT_EQ("00000000-0000-0000-0000-000000000000", uuid_zero.ToString());
34
35 const uint8_t kBytes[16] = {0x00,
36 0x01,
37 0x02,
38 0x03,
39 0x04,
40 0x05,
41 0x06,
42 0x07,
43 0x08,
44 0x09,
45 0x0a,
46 0x0b,
47 0x0c,
48 0x0d,
49 0x0e,
50 0x0f};
51 UUID uuid(kBytes);
52 for (size_t index = 0; index < arraysize(kBytes); ++index) {
53 EXPECT_EQ(kBytes[index], uuid.data[index]);
54 }
55 EXPECT_EQ("00010203-0405-0607-0809-0a0b0c0d0e0f", uuid.ToString());
56
57 // UUID is a standard-layout structure. It is valid to memcpy to it.
58 const uint8_t kMoreBytes[16] = {0xff,
59 0xee,
60 0xdd,
61 0xcc,
62 0xbb,
63 0xaa,
64 0x99,
65 0x88,
66 0x77,
67 0x66,
68 0x55,
69 0x44,
70 0x33,
71 0x22,
72 0x11,
73 0x00};
74 memcpy(&uuid, kMoreBytes, sizeof(kMoreBytes));
75 EXPECT_EQ("ffeeddcc-bbaa-9988-7766-554433221100", uuid.ToString());
76 }
77
78 } // namespace
OLDNEW
« util/misc/uuid.cc ('K') | « util/misc/uuid.cc ('k') | util/stdlib/cxx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698