OLD | NEW |
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> | 5 #include <stdint.h> |
| 6 #include <string> |
6 | 7 |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "net/disk_cache/simple/simple_util.h" | 9 #include "net/disk_cache/simple/simple_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 using disk_cache::simple_util::ConvertEntryHashKeyToHexString; | 12 using disk_cache::simple_util::ConvertEntryHashKeyToHexString; |
12 using disk_cache::simple_util::GetEntryHashKeyAsHexString; | 13 using disk_cache::simple_util::GetEntryHashKeyAsHexString; |
13 using disk_cache::simple_util::GetEntryHashKeyFromHexString; | 14 using disk_cache::simple_util::GetEntryHashKeyFromHexString; |
14 using disk_cache::simple_util::GetEntryHashKey; | 15 using disk_cache::simple_util::GetEntryHashKey; |
15 using disk_cache::simple_util::GetFileSizeFromKeyAndDataSize; | 16 using disk_cache::simple_util::GetFileSizeFromDataSize; |
16 using disk_cache::simple_util::GetDataSizeFromKeyAndFileSize; | 17 using disk_cache::simple_util::GetDataSizeFromFileSize; |
17 | 18 |
18 class SimpleUtilTest : public testing::Test {}; | 19 class SimpleUtilTest : public testing::Test {}; |
19 | 20 |
20 TEST_F(SimpleUtilTest, ConvertEntryHashKeyToHexString) { | 21 TEST_F(SimpleUtilTest, ConvertEntryHashKeyToHexString) { |
21 EXPECT_EQ("0000000005f5e0ff", | 22 EXPECT_EQ("0000000005f5e0ff", |
22 ConvertEntryHashKeyToHexString(UINT64_C(99999999))); | 23 ConvertEntryHashKeyToHexString(UINT64_C(99999999))); |
23 EXPECT_EQ("7fffffffffffffff", | 24 EXPECT_EQ("7fffffffffffffff", |
24 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775807))); | 25 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775807))); |
25 EXPECT_EQ("8000000000000000", | 26 EXPECT_EQ("8000000000000000", |
26 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775808))); | 27 ConvertEntryHashKeyToHexString(UINT64_C(9223372036854775808))); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Wrong hash string size. | 64 // Wrong hash string size. |
64 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFF", &hash_key)); | 65 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFF", &hash_key)); |
65 | 66 |
66 // Wrong hash string size. | 67 // Wrong hash string size. |
67 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFFF", &hash_key)); | 68 EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFFF", &hash_key)); |
68 | 69 |
69 EXPECT_FALSE(GetEntryHashKeyFromHexString("iwr8wglhg8*(&1231((", &hash_key)); | 70 EXPECT_FALSE(GetEntryHashKeyFromHexString("iwr8wglhg8*(&1231((", &hash_key)); |
70 } | 71 } |
71 | 72 |
72 TEST_F(SimpleUtilTest, SizesAndOffsets) { | 73 TEST_F(SimpleUtilTest, SizesAndOffsets) { |
73 const char key[] = "This is an example key"; | 74 const std::string key("This is an example key"); |
74 const int data_size = 1000; | 75 const int data_size = 1000; |
75 const int file_size = GetFileSizeFromKeyAndDataSize(key, data_size); | 76 const int file_size = GetFileSizeFromDataSize(key.size(), data_size); |
76 EXPECT_EQ(data_size, GetDataSizeFromKeyAndFileSize(key, file_size)); | 77 EXPECT_EQ(data_size, GetDataSizeFromFileSize(key.size(), file_size)); |
77 } | 78 } |
OLD | NEW |