OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2008 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. |
| 4 |
| 5 #include "chrome/browser/guid.h" |
| 6 |
| 7 #include <limits> |
| 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 #if defined(OS_POSIX) |
| 12 TEST(GUIDTest, GUIDGeneratesAllZeroes) { |
| 13 uint64 bytes[] = { 0, 0 }; |
| 14 std::string clientid = guid::RandomDataToGUIDString(bytes); |
| 15 EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid); |
| 16 } |
| 17 |
| 18 TEST(GUIDTest, GUIDGeneratesCorrectly) { |
| 19 uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL }; |
| 20 std::string clientid = guid::RandomDataToGUIDString(bytes); |
| 21 EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid); |
| 22 } |
| 23 #endif |
| 24 |
| 25 TEST(GUIDTest, GUIDCorrectlyFormatted) { |
| 26 const int kIterations = 10; |
| 27 for (int it = 0; it < kIterations; ++it) { |
| 28 std::string guid = guid::GenerateGUID(); |
| 29 EXPECT_EQ(36U, guid.length()); |
| 30 std::string hexchars = "0123456789ABCDEF"; |
| 31 for (uint32 i = 0; i < guid.length(); ++i) { |
| 32 char current = guid.at(i); |
| 33 if (i == 8 || i == 13 || i == 18 || i == 23) { |
| 34 EXPECT_EQ('-', current); |
| 35 } else { |
| 36 EXPECT_TRUE(std::string::npos != hexchars.find(current)); |
| 37 } |
| 38 } |
| 39 } |
| 40 } |
| 41 |
| 42 TEST(GUIDTest, GUIDBasicUniqueness) { |
| 43 const int kIterations = 10; |
| 44 for (int it = 0; it < kIterations; ++it) { |
| 45 std::string guid1 = guid::GenerateGUID(); |
| 46 std::string guid2 = guid::GenerateGUID(); |
| 47 EXPECT_EQ(36U, guid1.length()); |
| 48 EXPECT_EQ(36U, guid2.length()); |
| 49 EXPECT_NE(guid1, guid2); |
| 50 } |
| 51 } |
OLD | NEW |