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

Unified Diff: base/guid_unittest.cc

Issue 541633005: Make GUID generation on POSIX compliant with GUID v4 format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 | « base/guid_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/guid_unittest.cc
diff --git a/base/guid_unittest.cc b/base/guid_unittest.cc
index e57eb7e0bb48249ecbd61cba34cd5ac550cd3a0d..4eda7f68a374ce5ce60f1f891cd548293b76c01c 100644
--- a/base/guid_unittest.cc
+++ b/base/guid_unittest.cc
@@ -10,6 +10,20 @@
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_POSIX)
+
+namespace {
+
+bool IsGUIDv4(const std::string& guid) {
+ // The format of GUID version 4 must be xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
+ // where y is one of [8, 9, A, B].
+ return base::IsValidGUID(guid) && guid[14] == '4' &&
+ (guid[19] == '8' || guid[19] == '9' || guid[19] == 'A' ||
+ guid[19] == 'a' || guid[19] == 'B' || guid[19] == 'b');
+}
+
+} // namespace
+
+
TEST(GUIDTest, GUIDGeneratesAllZeroes) {
uint64 bytes[] = { 0, 0 };
std::string clientid = base::RandomDataToGUIDString(bytes);
@@ -41,5 +55,9 @@ TEST(GUIDTest, GUIDBasicUniqueness) {
EXPECT_EQ(36U, guid1.length());
EXPECT_EQ(36U, guid2.length());
EXPECT_NE(guid1, guid2);
+#if defined(OS_POSIX)
+ EXPECT_TRUE(IsGUIDv4(guid1));
+ EXPECT_TRUE(IsGUIDv4(guid2));
+#endif
}
}
« no previous file with comments | « base/guid_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698