Index: base/rand_util_unittest.cc |
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc |
index cbc338a3b4eec23299af3c4a7d97082ed60904d0..112099f09e17020baff62657f96b5f4a88b53bfb 100644 |
--- a/base/rand_util_unittest.cc |
+++ b/base/rand_util_unittest.cc |
@@ -35,3 +35,50 @@ TEST(RandUtilTest, RandGeneratorForRandomShuffle) { |
EXPECT_LE(std::numeric_limits<ptrdiff_t>::max(), |
std::numeric_limits<int64>::max()); |
} |
+ |
+#if defined(OS_POSIX) |
+// For unit testing purposes only. Do not use outside of tests. |
+namespace base { |
+extern std::string RandomBytesToGUIDString(const uint64 bytes[2]); |
+} // base |
+ |
+TEST(RandUtilTest, GUIDGeneratesAllZeroes) { |
+ uint64 bytes[] = { 0, 0 }; |
+ std::string clientid = base::RandomBytesToGUIDString(bytes); |
+ EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid); |
+} |
+ |
+TEST(RandUtilTest, GUIDGeneratesCorrectly) { |
+ uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL }; |
+ std::string clientid = base::RandomBytesToGUIDString(bytes); |
+ EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid); |
+} |
+#endif |
+ |
+TEST(RandUtilTest, GUIDCorrectlyFormatted) { |
+ const int kIterations = 10; |
+ for (int it = 0; it < kIterations; ++it) { |
+ std::string guid = base::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(RandUtilTest, GUIDBasicUniqueness) { |
+ const int kIterations = 10; |
+ for (int it = 0; it < kIterations; ++it) { |
+ std::string guid1 = base::GenerateGUID(); |
+ std::string guid2 = base::GenerateGUID(); |
+ EXPECT_EQ(36U, guid1.length()); |
+ EXPECT_EQ(36U, guid2.length()); |
+ EXPECT_NE(guid1, guid2); |
+ } |
+} |