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

Side by Side Diff: net/disk_cache/simple/simple_index_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: to commit again, since the last dcommit failed 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "base/hash.h"
6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/pickle.h"
9 #include "base/sha1.h"
10 #include "base/stringprintf.h"
11 #include "base/time.h"
12 #include "net/disk_cache/simple/simple_index.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 const uint64 kTestHashKey = 4364515;
18 const int64 kTestLastUsedTimeInternal = 12345;
19 const base::Time kTestLastUsedTime =
20 base::Time::FromInternalValue(kTestLastUsedTimeInternal);
21 const uint64 kTestEntrySize = 789;
22
23 } // namespace
24
25 using disk_cache::EntryMetadata;
26
27 class EntryMetadataTest : public testing::Test {
28 public:
29 EntryMetadata NewEntryMetadataWithValues() {
30 return EntryMetadata(kTestHashKey,
31 kTestLastUsedTime,
32 kTestEntrySize);
33 }
34
35 void CheckEntryMetadataValues(const EntryMetadata& entry_metadata) {
36 EXPECT_EQ(kTestLastUsedTime, entry_metadata.GetLastUsedTime());
37 EXPECT_EQ(kTestEntrySize, entry_metadata.GetEntrySize());
38 }
39 };
40
41 TEST_F(EntryMetadataTest, Basics) {
42 EntryMetadata entry_metadata;
43 EXPECT_EQ(base::Time::FromInternalValue(0), entry_metadata.GetLastUsedTime());
44 EXPECT_EQ(size_t(0), entry_metadata.GetEntrySize());
45
46 entry_metadata = NewEntryMetadataWithValues();
47 CheckEntryMetadataValues(entry_metadata);
48 EXPECT_EQ(kTestHashKey, entry_metadata.GetHashKey());
49
50 const base::Time new_time = base::Time::FromInternalValue(5);
51 entry_metadata.SetLastUsedTime(new_time);
52 EXPECT_EQ(new_time, entry_metadata.GetLastUsedTime());
53 }
54
55 TEST_F(EntryMetadataTest, Serialize) {
56 EntryMetadata entry_metadata = NewEntryMetadataWithValues();
57
58 Pickle pickle;
59 entry_metadata.Serialize(&pickle);
60
61 PickleIterator it(pickle);
62 EntryMetadata new_entry_metadata;
63 new_entry_metadata.Deserialize(&it);
64 CheckEntryMetadataValues(new_entry_metadata);
65 EXPECT_EQ(kTestHashKey, new_entry_metadata.GetHashKey());
66 }
67
68 TEST_F(EntryMetadataTest, Merge) {
69 EntryMetadata entry_metadata_a = NewEntryMetadataWithValues();
70 // MergeWith assumes the hash_key of both entries is the same, so we
71 // initialize it to be that way.
72 base::Time dummy_time = base::Time::FromInternalValue(0);
73 EntryMetadata entry_metadata_b(entry_metadata_a.GetHashKey(), dummy_time, 0);
74 entry_metadata_b.MergeWith(entry_metadata_a);
75 CheckEntryMetadataValues(entry_metadata_b);
76
77 EntryMetadata entry_metadata_c(entry_metadata_a.GetHashKey(), dummy_time, 0);
78 entry_metadata_a.MergeWith(entry_metadata_c);
79 CheckEntryMetadataValues(entry_metadata_a);
80
81 EntryMetadata entry_metadata_d(entry_metadata_a.GetHashKey(), dummy_time, 0);
82 const base::Time new_time = base::Time::FromInternalValue(5);
83 entry_metadata_d.SetLastUsedTime(new_time);
84 entry_metadata_d.MergeWith(entry_metadata_a);
85 EXPECT_EQ(entry_metadata_a.GetEntrySize(), entry_metadata_d.GetEntrySize());
86 EXPECT_EQ(new_time, entry_metadata_d.GetLastUsedTime());
87
88 EntryMetadata entry_metadata_e(entry_metadata_a.GetHashKey(), dummy_time, 0);
89 const uint64 entry_size = 9999999;
90 entry_metadata_e.SetEntrySize(entry_size);
91 entry_metadata_e.MergeWith(entry_metadata_a);
92 EXPECT_EQ(entry_size, entry_metadata_e.GetEntrySize());
93 EXPECT_EQ(entry_metadata_a.GetLastUsedTime(),
94 entry_metadata_e.GetLastUsedTime());
95 }
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index_file_unittest.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698