summaryrefslogtreecommitdiffstats
path: root/base/guid_unittest.cc
diff options
context:
space:
mode:
authormarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 14:22:07 +0000
committermarja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 14:22:07 +0000
commit7e49ad360632304e1890082e1605b2239956afdb (patch)
tree1e3451b1a1af73cc5996c218a2888e35f1337709 /base/guid_unittest.cc
parentfacd6e7bd32c811fa8be9a065505f465396cd92e (diff)
downloadchromium_src-7e49ad360632304e1890082e1605b2239956afdb.zip
chromium_src-7e49ad360632304e1890082e1605b2239956afdb.tar.gz
chromium_src-7e49ad360632304e1890082e1605b2239956afdb.tar.bz2
Move guid generation from chrome/common/ to base/.
It will be needed in webkit/dom_storage/. BUG=NONE TEST=Existing tests. Review URL: https://chromiumcodereview.appspot.com/10540003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142142 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/guid_unittest.cc')
-rw-r--r--base/guid_unittest.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/base/guid_unittest.cc b/base/guid_unittest.cc
new file mode 100644
index 0000000..18c04a9
--- /dev/null
+++ b/base/guid_unittest.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2012 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 "base/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 = base::RandomDataToGUIDString(bytes);
+ EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid);
+}
+
+TEST(GUIDTest, GUIDGeneratesCorrectly) {
+ uint64 bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL };
+ std::string clientid = base::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 = base::GenerateGUID();
+ EXPECT_TRUE(base::IsValidGUID(guid));
+ }
+}
+
+TEST(GUIDTest, 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);
+ }
+}