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

Side by Side Diff: net/disk_cache/simple/simple_util_unittest.cc

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h>
6
5 #include "base/logging.h" 7 #include "base/logging.h"
6 #include "base/port.h"
7 #include "net/disk_cache/simple/simple_util.h" 8 #include "net/disk_cache/simple/simple_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 using disk_cache::simple_util::ConvertEntryHashKeyToHexString; 11 using disk_cache::simple_util::ConvertEntryHashKeyToHexString;
11 using disk_cache::simple_util::GetEntryHashKeyAsHexString; 12 using disk_cache::simple_util::GetEntryHashKeyAsHexString;
12 using disk_cache::simple_util::GetEntryHashKeyFromHexString; 13 using disk_cache::simple_util::GetEntryHashKeyFromHexString;
13 using disk_cache::simple_util::GetEntryHashKey; 14 using disk_cache::simple_util::GetEntryHashKey;
14 using disk_cache::simple_util::GetFileSizeFromKeyAndDataSize; 15 using disk_cache::simple_util::GetFileSizeFromKeyAndDataSize;
15 using disk_cache::simple_util::GetDataSizeFromKeyAndFileSize; 16 using disk_cache::simple_util::GetDataSizeFromKeyAndFileSize;
16 17
17 class SimpleUtilTest : public testing::Test {}; 18 class SimpleUtilTest : public testing::Test {};
18 19
19 TEST_F(SimpleUtilTest, ConvertEntryHashKeyToHexString) { 20 TEST_F(SimpleUtilTest, ConvertEntryHashKeyToHexString) {
20 EXPECT_EQ("0000000005f5e0ff", 21 EXPECT_EQ("0000000005f5e0ff",
21 ConvertEntryHashKeyToHexString(GG_UINT64_C(99999999))); 22 ConvertEntryHashKeyToHexString(UINT64_C(99999999)));
22 EXPECT_EQ("7fffffffffffffff", 23 EXPECT_EQ("7fffffffffffffff",
23 ConvertEntryHashKeyToHexString(GG_UINT64_C(9223372036854775807))); 24 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775807)));
24 EXPECT_EQ("8000000000000000", 25 EXPECT_EQ("8000000000000000",
25 ConvertEntryHashKeyToHexString(GG_UINT64_C(9223372036854775808))); 26 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775808)));
26 EXPECT_EQ("ffffffffffffffff", 27 EXPECT_EQ("ffffffffffffffff",
27 ConvertEntryHashKeyToHexString(GG_UINT64_C(18446744073709551615))); 28 ConvertEntryHashKeyToHexString(UINT64_C(18446744073709551615)));
28 } 29 }
29 30
30 TEST_F(SimpleUtilTest, GetEntryHashKey) { 31 TEST_F(SimpleUtilTest, GetEntryHashKey) {
31 EXPECT_EQ("7ac408c1dff9c84b", 32 EXPECT_EQ("7ac408c1dff9c84b",
32 GetEntryHashKeyAsHexString("http://www.amazon.com/")); 33 GetEntryHashKeyAsHexString("http://www.amazon.com/"));
33 EXPECT_EQ(GG_UINT64_C(0x7ac408c1dff9c84b), 34 EXPECT_EQ(UINT64_C(0x7ac408c1dff9c84b),
34 GetEntryHashKey("http://www.amazon.com/")); 35 GetEntryHashKey("http://www.amazon.com/"));
35 36
36 EXPECT_EQ("9fe947998c2ccf47", 37 EXPECT_EQ("9fe947998c2ccf47",
37 GetEntryHashKeyAsHexString("www.amazon.com")); 38 GetEntryHashKeyAsHexString("www.amazon.com"));
38 EXPECT_EQ(GG_UINT64_C(0x9fe947998c2ccf47), GetEntryHashKey("www.amazon.com")); 39 EXPECT_EQ(UINT64_C(0x9fe947998c2ccf47), GetEntryHashKey("www.amazon.com"));
39 40
40 EXPECT_EQ("0d4b6b5eeea339da", GetEntryHashKeyAsHexString("")); 41 EXPECT_EQ("0d4b6b5eeea339da", GetEntryHashKeyAsHexString(""));
41 EXPECT_EQ(GG_UINT64_C(0x0d4b6b5eeea339da), GetEntryHashKey("")); 42 EXPECT_EQ(UINT64_C(0x0d4b6b5eeea339da), GetEntryHashKey(""));
42 43
43 EXPECT_EQ("a68ac2ecc87dfd04", GetEntryHashKeyAsHexString("http://www.domain.co m/uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfTxlOVWY8vFwzhsRzoNYKhUIOTc5Tn UlT0vpdQflPyk2nh7vurXOj60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY01RK3ZcN l8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6EgMzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGTbx sPSJK5QRyNea9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm")); 44 EXPECT_EQ("a68ac2ecc87dfd04", GetEntryHashKeyAsHexString("http://www.domain.co m/uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfTxlOVWY8vFwzhsRzoNYKhUIOTc5Tn UlT0vpdQflPyk2nh7vurXOj60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY01RK3ZcN l8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6EgMzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGTbx sPSJK5QRyNea9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm"));
44 45
45 EXPECT_EQ(GG_UINT64_C(0xa68ac2ecc87dfd04), GetEntryHashKey("http://www.domain. com/uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfTxlOVWY8vFwzhsRzoNYKhUIOTc5 TnUlT0vpdQflPyk2nh7vurXOj60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY01RK3Z cNl8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6EgMzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGT bxsPSJK5QRyNea9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm")); 46 EXPECT_EQ(UINT64_C(0xa68ac2ecc87dfd04),
47 GetEntryHashKey("http://www.domain.com/"
48 "uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfT"
49 "xlOVWY8vFwzhsRzoNYKhUIOTc5TnUlT0vpdQflPyk2nh7vurXO"
50 "j60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY"
51 "01RK3ZcNl8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6Eg"
52 "MzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGTbxsPSJK5QRyNea"
53 "9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm"));
46 } 54 }
47 55
48 TEST_F(SimpleUtilTest, GetEntryHashKeyFromHexString) { 56 TEST_F(SimpleUtilTest, GetEntryHashKeyFromHexString) {
49 uint64 hash_key = 0; 57 uint64 hash_key = 0;
50 EXPECT_TRUE(GetEntryHashKeyFromHexString("0000000005f5e0ff", &hash_key)); 58 EXPECT_TRUE(GetEntryHashKeyFromHexString("0000000005f5e0ff", &hash_key));
51 EXPECT_EQ(GG_UINT64_C(99999999), hash_key); 59 EXPECT_EQ(UINT64_C(99999999), hash_key);
52 60
53 EXPECT_TRUE(GetEntryHashKeyFromHexString("7ffffffffffffffF", &hash_key)); 61 EXPECT_TRUE(GetEntryHashKeyFromHexString("7ffffffffffffffF", &hash_key));
54 EXPECT_EQ(GG_UINT64_C(9223372036854775807), hash_key); 62 EXPECT_EQ(UINT64_C(9223372036854775807), hash_key);
55 63
56 EXPECT_TRUE(GetEntryHashKeyFromHexString("8000000000000000", &hash_key)); 64 EXPECT_TRUE(GetEntryHashKeyFromHexString("8000000000000000", &hash_key));
57 EXPECT_EQ(GG_UINT64_C(9223372036854775808), hash_key); 65 EXPECT_EQ(UINT64_C(9223372036854775808), hash_key);
58 66
59 EXPECT_TRUE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFF", &hash_key)); 67 EXPECT_TRUE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFF", &hash_key));
60 EXPECT_EQ(GG_UINT64_C(18446744073709551615), hash_key); 68 EXPECT_EQ(UINT64_C(18446744073709551615), hash_key);
61 69
62 // Wrong hash string size. 70 // Wrong hash string size.
63 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFF", &hash_key)); 71 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFF", &hash_key));
64 72
65 // Wrong hash string size. 73 // Wrong hash string size.
66 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFFF", &hash_key)); 74 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFFF", &hash_key));
67 75
68 EXPECT_FALSE(GetEntryHashKeyFromHexString("iwr8wglhg8*(&1231((", &hash_key)); 76 EXPECT_FALSE(GetEntryHashKeyFromHexString("iwr8wglhg8*(&1231((", &hash_key));
69 } 77 }
70 78
71 TEST_F(SimpleUtilTest, SizesAndOffsets) { 79 TEST_F(SimpleUtilTest, SizesAndOffsets) {
72 const char key[] = "This is an example key"; 80 const char key[] = "This is an example key";
73 const int data_size = 1000; 81 const int data_size = 1000;
74 const int file_size = GetFileSizeFromKeyAndDataSize(key, data_size); 82 const int file_size = GetFileSizeFromKeyAndDataSize(key, data_size);
75 EXPECT_EQ(data_size, GetDataSizeFromKeyAndFileSize(key, file_size)); 83 EXPECT_EQ(data_size, GetDataSizeFromKeyAndFileSize(key, file_size));
76 } 84 }
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index_unittest.cc ('k') | net/disk_cache/simple/simple_version_upgrade_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698