Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / net / disk_cache / simple / simple_util_unittest.cc
blobfbda55ca8a76e9720f1245ddc0631f73de6b4f83
1 // Copyright (c) 2013 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.
5 #include <stdint.h>
7 #include "base/logging.h"
8 #include "net/disk_cache/simple/simple_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 using disk_cache::simple_util::ConvertEntryHashKeyToHexString;
12 using disk_cache::simple_util::GetEntryHashKeyAsHexString;
13 using disk_cache::simple_util::GetEntryHashKeyFromHexString;
14 using disk_cache::simple_util::GetEntryHashKey;
15 using disk_cache::simple_util::GetFileSizeFromKeyAndDataSize;
16 using disk_cache::simple_util::GetDataSizeFromKeyAndFileSize;
18 class SimpleUtilTest : public testing::Test {};
20 TEST_F(SimpleUtilTest, ConvertEntryHashKeyToHexString) {
21 EXPECT_EQ("0000000005f5e0ff",
22 ConvertEntryHashKeyToHexString(UINT64_C(99999999)));
23 EXPECT_EQ("7fffffffffffffff",
24 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775807)));
25 EXPECT_EQ("8000000000000000",
26 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775808)));
27 EXPECT_EQ("ffffffffffffffff",
28 ConvertEntryHashKeyToHexString(UINT64_C(18446744073709551615)));
31 TEST_F(SimpleUtilTest, GetEntryHashKey) {
32 EXPECT_EQ("7ac408c1dff9c84b",
33 GetEntryHashKeyAsHexString("http://www.amazon.com/"));
34 EXPECT_EQ(UINT64_C(0x7ac408c1dff9c84b),
35 GetEntryHashKey("http://www.amazon.com/"));
37 EXPECT_EQ("9fe947998c2ccf47",
38 GetEntryHashKeyAsHexString("www.amazon.com"));
39 EXPECT_EQ(UINT64_C(0x9fe947998c2ccf47), GetEntryHashKey("www.amazon.com"));
41 EXPECT_EQ("0d4b6b5eeea339da", GetEntryHashKeyAsHexString(""));
42 EXPECT_EQ(UINT64_C(0x0d4b6b5eeea339da), GetEntryHashKey(""));
44 EXPECT_EQ("a68ac2ecc87dfd04", GetEntryHashKeyAsHexString("http://www.domain.com/uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfTxlOVWY8vFwzhsRzoNYKhUIOTc5TnUlT0vpdQflPyk2nh7vurXOj60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY01RK3ZcNl8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6EgMzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGTbxsPSJK5QRyNea9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm"));
46 EXPECT_EQ(UINT64_C(0xa68ac2ecc87dfd04), GetEntryHashKey("http://www.domain.com/uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfTxlOVWY8vFwzhsRzoNYKhUIOTc5TnUlT0vpdQflPyk2nh7vurXOj60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY01RK3ZcNl8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6EgMzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGTbxsPSJK5QRyNea9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm"));
49 TEST_F(SimpleUtilTest, GetEntryHashKeyFromHexString) {
50 uint64 hash_key = 0;
51 EXPECT_TRUE(GetEntryHashKeyFromHexString("0000000005f5e0ff", &hash_key));
52 EXPECT_EQ(UINT64_C(99999999), hash_key);
54 EXPECT_TRUE(GetEntryHashKeyFromHexString("7ffffffffffffffF", &hash_key));
55 EXPECT_EQ(UINT64_C(9223372036854775807), hash_key);
57 EXPECT_TRUE(GetEntryHashKeyFromHexString("8000000000000000", &hash_key));
58 EXPECT_EQ(UINT64_C(9223372036854775808), hash_key);
60 EXPECT_TRUE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFF", &hash_key));
61 EXPECT_EQ(UINT64_C(18446744073709551615), hash_key);
63 // Wrong hash string size.
64 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFF", &hash_key));
66 // Wrong hash string size.
67 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFFF", &hash_key));
69 EXPECT_FALSE(GetEntryHashKeyFromHexString("iwr8wglhg8*(&1231((", &hash_key));
72 TEST_F(SimpleUtilTest, SizesAndOffsets) {
73 const char key[] = "This is an example key";
74 const int data_size = 1000;
75 const int file_size = GetFileSizeFromKeyAndDataSize(key, data_size);
76 EXPECT_EQ(data_size, GetDataSizeFromKeyAndFileSize(key, file_size));