Just remove --css-mixins: {...}; in presubmit checked contents
[chromium-blink-merge.git] / base / guid_unittest.cc
blob1485497155fab269e560bace55179239c5cc2d9a
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
3 // found in the LICENSE file.
5 #include "base/guid.h"
7 #include <limits>
9 #include "base/strings/string_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace base {
14 #if defined(OS_POSIX)
16 namespace {
18 bool IsGUIDv4(const std::string& guid) {
19 // The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
20 // where y is one of [8, 9, A, B].
21 return IsValidGUID(guid) && guid[14] == '4' &&
22 (guid[19] == '8' || guid[19] == '9' || guid[19] == 'A' ||
23 guid[19] == 'a' || guid[19] == 'B' || guid[19] == 'b');
26 } // namespace
28 TEST(GUIDTest, GUIDGeneratesAllZeroes) {
29 uint64 bytes[] = { 0, 0 };
30 std::string clientid = RandomDataToGUIDString(bytes);
31 EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid);
34 TEST(GUIDTest, GUIDGeneratesCorrectly) {
35 uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL };
36 std::string clientid = RandomDataToGUIDString(bytes);
37 EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid);
39 #endif
41 TEST(GUIDTest, GUIDCorrectlyFormatted) {
42 const int kIterations = 10;
43 for (int it = 0; it < kIterations; ++it) {
44 std::string guid = GenerateGUID();
45 EXPECT_TRUE(IsValidGUID(guid));
46 EXPECT_TRUE(IsValidGUID(StringToLowerASCII(guid)));
47 EXPECT_TRUE(IsValidGUID(StringToUpperASCII(guid)));
51 TEST(GUIDTest, GUIDBasicUniqueness) {
52 const int kIterations = 10;
53 for (int it = 0; it < kIterations; ++it) {
54 std::string guid1 = GenerateGUID();
55 std::string guid2 = GenerateGUID();
56 EXPECT_EQ(36U, guid1.length());
57 EXPECT_EQ(36U, guid2.length());
58 EXPECT_NE(guid1, guid2);
59 #if defined(OS_POSIX)
60 EXPECT_TRUE(IsGUIDv4(guid1));
61 EXPECT_TRUE(IsGUIDv4(guid2));
62 #endif
66 } // namespace base