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

Side by Side Diff: base/guid_unittest.cc

Issue 1538743002: Switch to standard integer types in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DEPS roll too Created 4 years, 12 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
« no previous file with comments | « base/guid_posix.cc ('k') | base/guid_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/guid.h" 5 #include "base/guid.h"
6 6
7 #include <stdint.h>
8
7 #include <limits> 9 #include <limits>
8 10
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 14
12 namespace base { 15 namespace base {
13 16
14 #if defined(OS_POSIX) 17 #if defined(OS_POSIX)
15 18
16 namespace { 19 namespace {
17 20
18 bool IsGUIDv4(const std::string& guid) { 21 bool IsGUIDv4(const std::string& guid) {
19 // The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, 22 // The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
20 // where y is one of [8, 9, A, B]. 23 // where y is one of [8, 9, A, B].
21 return IsValidGUID(guid) && guid[14] == '4' && 24 return IsValidGUID(guid) && guid[14] == '4' &&
22 (guid[19] == '8' || guid[19] == '9' || guid[19] == 'A' || 25 (guid[19] == '8' || guid[19] == '9' || guid[19] == 'A' ||
23 guid[19] == 'a' || guid[19] == 'B' || guid[19] == 'b'); 26 guid[19] == 'a' || guid[19] == 'B' || guid[19] == 'b');
24 } 27 }
25 28
26 } // namespace 29 } // namespace
27 30
28 TEST(GUIDTest, GUIDGeneratesAllZeroes) { 31 TEST(GUIDTest, GUIDGeneratesAllZeroes) {
29 uint64 bytes[] = { 0, 0 }; 32 uint64_t bytes[] = {0, 0};
30 std::string clientid = RandomDataToGUIDString(bytes); 33 std::string clientid = RandomDataToGUIDString(bytes);
31 EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid); 34 EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid);
32 } 35 }
33 36
34 TEST(GUIDTest, GUIDGeneratesCorrectly) { 37 TEST(GUIDTest, GUIDGeneratesCorrectly) {
35 uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL }; 38 uint64_t bytes[] = {0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL};
36 std::string clientid = RandomDataToGUIDString(bytes); 39 std::string clientid = RandomDataToGUIDString(bytes);
37 EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid); 40 EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid);
38 } 41 }
39 #endif 42 #endif
40 43
41 TEST(GUIDTest, GUIDCorrectlyFormatted) { 44 TEST(GUIDTest, GUIDCorrectlyFormatted) {
42 const int kIterations = 10; 45 const int kIterations = 10;
43 for (int it = 0; it < kIterations; ++it) { 46 for (int it = 0; it < kIterations; ++it) {
44 std::string guid = GenerateGUID(); 47 std::string guid = GenerateGUID();
45 EXPECT_TRUE(IsValidGUID(guid)); 48 EXPECT_TRUE(IsValidGUID(guid));
(...skipping 11 matching lines...) Expand all
57 EXPECT_EQ(36U, guid2.length()); 60 EXPECT_EQ(36U, guid2.length());
58 EXPECT_NE(guid1, guid2); 61 EXPECT_NE(guid1, guid2);
59 #if defined(OS_POSIX) 62 #if defined(OS_POSIX)
60 EXPECT_TRUE(IsGUIDv4(guid1)); 63 EXPECT_TRUE(IsGUIDv4(guid1));
61 EXPECT_TRUE(IsGUIDv4(guid2)); 64 EXPECT_TRUE(IsGUIDv4(guid2));
62 #endif 65 #endif
63 } 66 }
64 } 67 }
65 68
66 } // namespace base 69 } // namespace base
OLDNEW
« no previous file with comments | « base/guid_posix.cc ('k') | base/guid_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698