OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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/metrics/metrics_service.h" |
| 6 |
| 7 #include <string> |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 #if defined(OS_POSIX) && defined(LINUX2) |
| 11 TEST(MetricsServiceTest, ClientIdGeneratesAllZeroes) { |
| 12 uint64 bytes[] = { 0, 0 }; |
| 13 std::string clientid = MetricsService::RandomBytesToGUIDString(bytes); |
| 14 EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid); |
| 15 } |
| 16 TEST(MetricsServiceTest, ClientIdGeneratesCorrectly) { |
| 17 uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL }; |
| 18 std::string clientid = MetricsService::RandomBytesToGUIDString(bytes); |
| 19 EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid); |
| 20 } |
| 21 |
| 22 TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { |
| 23 std::string clientid = MetricsService::GenerateClientID(); |
| 24 EXPECT_EQ(36U, clientid.length()); |
| 25 std::string hexchars = "0123456789ABCDEF"; |
| 26 for (uint32 i = 0; i < clientid.length(); i++) { |
| 27 char current = clientid.at(i); |
| 28 if (i == 8 || i == 13 || i == 18 || i == 23) { |
| 29 EXPECT_EQ('-', current); |
| 30 } else { |
| 31 EXPECT_TRUE(std::string::npos != hexchars.find(current)); |
| 32 } |
| 33 } |
| 34 } |
| 35 #endif |
OLD | NEW |