guid_unittest.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "butil/guid.h"
  5. #include <limits>
  6. #include <gtest/gtest.h>
  7. #if defined(OS_POSIX)
  8. TEST(GUIDTest, GUIDGeneratesAllZeroes) {
  9. uint64_t bytes[] = { 0, 0 };
  10. std::string clientid = butil::RandomDataToGUIDString(bytes);
  11. EXPECT_EQ("00000000-0000-0000-0000-000000000000", clientid);
  12. }
  13. TEST(GUIDTest, GUIDGeneratesCorrectly) {
  14. uint64_t bytes[] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL };
  15. std::string clientid = butil::RandomDataToGUIDString(bytes);
  16. EXPECT_EQ("01234567-89AB-CDEF-FEDC-BA9876543210", clientid);
  17. }
  18. #endif
  19. TEST(GUIDTest, GUIDCorrectlyFormatted) {
  20. const int kIterations = 10;
  21. for (int it = 0; it < kIterations; ++it) {
  22. std::string guid = butil::GenerateGUID();
  23. EXPECT_TRUE(butil::IsValidGUID(guid));
  24. }
  25. }
  26. TEST(GUIDTest, GUIDBasicUniqueness) {
  27. const int kIterations = 10;
  28. for (int it = 0; it < kIterations; ++it) {
  29. std::string guid1 = butil::GenerateGUID();
  30. std::string guid2 = butil::GenerateGUID();
  31. EXPECT_EQ(36U, guid1.length());
  32. EXPECT_EQ(36U, guid2.length());
  33. EXPECT_NE(guid1, guid2);
  34. }
  35. }