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

Unified Diff: chrome/browser/guid_unittest.cc

Issue 3800003: Moving GUID generation from base to chrome/browser/guid* (Closed)
Patch Set: Additional comment. Created 10 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/guid_posix.cc ('k') | chrome/browser/guid_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/guid_unittest.cc
diff --git a/chrome/browser/guid_unittest.cc b/chrome/browser/guid_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ebbce8f68f8cce84bcb091e40675a3c69b9b78eb
--- /dev/null
+++ b/chrome/browser/guid_unittest.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/guid.h"
+
+#include <limits>
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#if defined(OS_POSIX)
+TEST(GUIDTest, GUIDGeneratesAllZeroes) {
+ uint64 bytes[] = { 0, 0 };
+ std::string clientid = guid::RandomDataToGUIDString(bytes);
+ EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid);
+}
+
+TEST(GUIDTest, GUIDGeneratesCorrectly) {
+ uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL };
+ std::string clientid = guid::RandomDataToGUIDString(bytes);
+ EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid);
+}
+#endif
+
+TEST(GUIDTest, GUIDCorrectlyFormatted) {
+ const int kIterations = 10;
+ for (int it = 0; it < kIterations; ++it) {
+ std::string guid = guid::GenerateGUID();
+ EXPECT_EQ(36U, guid.length());
+ std::string hexchars = "0123456789ABCDEF";
+ for (uint32 i = 0; i < guid.length(); ++i) {
+ char current = guid.at(i);
+ if (i == 8 || i == 13 || i == 18 || i == 23) {
+ EXPECT_EQ('-', current);
+ } else {
+ EXPECT_TRUE(std::string::npos != hexchars.find(current));
+ }
+ }
+ }
+}
+
+TEST(GUIDTest, GUIDBasicUniqueness) {
+ const int kIterations = 10;
+ for (int it = 0; it < kIterations; ++it) {
+ std::string guid1 = guid::GenerateGUID();
+ std::string guid2 = guid::GenerateGUID();
+ EXPECT_EQ(36U, guid1.length());
+ EXPECT_EQ(36U, guid2.length());
+ EXPECT_NE(guid1, guid2);
+ }
+}
« no previous file with comments | « chrome/browser/guid_posix.cc ('k') | chrome/browser/guid_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698