1731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// Use of this source code is governed by a BSD-style license that can be
3731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick// found in the LICENSE file.
4731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#include "chrome/common/guid.h"
6731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
7731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include <limits>
8731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
9731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "testing/gtest/include/gtest/gtest.h"
10731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
11731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#if defined(OS_POSIX)
12731df977c0511bca2206b5f333555b1205ff1f43Iain MerrickTEST(GUIDTest, GUIDGeneratesAllZeroes) {
13731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  uint64 bytes[] = { 0, 0 };
14731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string clientid = guid::RandomDataToGUIDString(bytes);
15731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid);
16731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick}
17731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
18731df977c0511bca2206b5f333555b1205ff1f43Iain MerrickTEST(GUIDTest, GUIDGeneratesCorrectly) {
19731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL };
20731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  std::string clientid = guid::RandomDataToGUIDString(bytes);
21731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid);
22731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick}
23731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#endif
24731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
25731df977c0511bca2206b5f333555b1205ff1f43Iain MerrickTEST(GUIDTest, GUIDCorrectlyFormatted) {
26731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  const int kIterations = 10;
27731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  for (int it = 0; it < kIterations; ++it) {
28731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    std::string guid = guid::GenerateGUID();
29731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    EXPECT_TRUE(guid::IsValidGUID(guid));
30731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  }
31731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick}
32731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
33731df977c0511bca2206b5f333555b1205ff1f43Iain MerrickTEST(GUIDTest, GUIDBasicUniqueness) {
34731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  const int kIterations = 10;
35731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  for (int it = 0; it < kIterations; ++it) {
36731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    std::string guid1 = guid::GenerateGUID();
37731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    std::string guid2 = guid::GenerateGUID();
38731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    EXPECT_EQ(36U, guid1.length());
39731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    EXPECT_EQ(36U, guid2.length());
40731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    EXPECT_NE(guid1, guid2);
41731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  }
42731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick}
43