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

Unified Diff: net/disk_cache/simple/simple_index_file_unittest.cc

Issue 14263005: Refactor our SimpleIndex file format and serialization to use Pickle instead of the previously bugg… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 7 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 side-by-side diff with in-line comments
Download patch
Index: net/disk_cache/simple/simple_index_file_unittest.cc
diff --git a/net/disk_cache/simple/simple_index_file_unittest.cc b/net/disk_cache/simple/simple_index_file_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35fe2ab7f21054574735ca2ccda3ae967976f79d
--- /dev/null
+++ b/net/disk_cache/simple/simple_index_file_unittest.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2013 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/logging.h"
+#include "net/disk_cache/simple/simple_index_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using disk_cache::ConvertEntryHashKeyToHexString;
+using disk_cache::GetEntryHashKeyAsHexString;
+using disk_cache::GetEntryHashKeyFromHexString;
+using disk_cache::GetEntryHashKey;
+
+class IndexUtilTest : public testing::Test {};
+
+TEST_F(IndexUtilTest, ConvertEntryHashKeyToHexString) {
+ EXPECT_EQ("0000000005f5e0ff",
+ ConvertEntryHashKeyToHexString(99999999));
+ EXPECT_EQ("7fffffffffffffff",
+ ConvertEntryHashKeyToHexString(9223372036854775807UL));
+ EXPECT_EQ("8000000000000000",
+ ConvertEntryHashKeyToHexString(9223372036854775808UL));
+ EXPECT_EQ("ffffffffffffffff",
+ ConvertEntryHashKeyToHexString(18446744073709551615UL));
+}
+
+TEST_F(IndexUtilTest, GetEntryHashKey) {
+ EXPECT_EQ("7ac408c1dff9c84b",
+ GetEntryHashKeyAsHexString("http://www.amazon.com/"));
+ EXPECT_EQ(0x7ac408c1dff9c84bUL, GetEntryHashKey("http://www.amazon.com/"));
+
+ EXPECT_EQ("9fe947998c2ccf47",
+ GetEntryHashKeyAsHexString("www.amazon.com"));
+ EXPECT_EQ(0x9fe947998c2ccf47UL, GetEntryHashKey("www.amazon.com"));
+
+ EXPECT_EQ("0d4b6b5eeea339da", GetEntryHashKeyAsHexString(""));
+ EXPECT_EQ(0x0d4b6b5eeea339daUL, GetEntryHashKey(""));
+
+ EXPECT_EQ("a68ac2ecc87dfd04", GetEntryHashKeyAsHexString("http://www.domain.com/uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfTxlOVWY8vFwzhsRzoNYKhUIOTc5TnUlT0vpdQflPyk2nh7vurXOj60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY01RK3ZcNl8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6EgMzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGTbxsPSJK5QRyNea9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm"));
+
+ EXPECT_EQ(0xa68ac2ecc87dfd04UL, GetEntryHashKey("http://www.domain.com/uoQ76Kb2QL5hzaVOSAKWeX0W9LfDLqphmRXpsfHN8tgF5lCsfTxlOVWY8vFwzhsRzoNYKhUIOTc5TnUlT0vpdQflPyk2nh7vurXOj60cDnkG3nsrXMhFCsPjhcZAic2jKpF9F9TYRYQwJo81IMi6gY01RK3ZcNl8WGfqcvoZ702UIdetvR7kiaqo1czwSJCMjRFdG6EgMzgXrwE8DYMz4fWqoa1F1c1qwTCBk3yOcmGTbxsPSJK5QRyNea9IFLrBTjfE7ZlN2vZiI7adcDYJef.htm"));
+}
+
+TEST_F(IndexUtilTest, GetEntryHashKeyFromHexString) {
+ uint64 hash_key = 0;
+ EXPECT_TRUE(GetEntryHashKeyFromHexString("0000000005f5e0ff", &hash_key));
+ EXPECT_EQ(99999999UL, hash_key);
+
+ EXPECT_TRUE(GetEntryHashKeyFromHexString("7ffffffffffffffF", &hash_key));
+ EXPECT_EQ(9223372036854775807UL, hash_key);
+
+ EXPECT_TRUE(GetEntryHashKeyFromHexString("8000000000000000", &hash_key));
+ EXPECT_EQ(9223372036854775808UL, hash_key);
+
+ EXPECT_TRUE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFF", &hash_key));
+ EXPECT_EQ(18446744073709551615UL, hash_key);
+
+ // Wrong hash string size.
+ EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFF", &hash_key));
+
+ // Wrong hash string size.
+ EXPECT_FALSE(GetEntryHashKeyFromHexString("FFFFFFFFFFFFFFFFF", &hash_key));
+
+ EXPECT_FALSE(GetEntryHashKeyFromHexString("iwr8wglhg8*(&1231((", &hash_key));
+}

Powered by Google App Engine
This is Rietveld 408576698