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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/files/file.h" 5 #include "base/files/file.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 bool CompareTwoEntryMetadata(const EntryMetadata& a, const EntryMetadata& b) { 101 bool CompareTwoEntryMetadata(const EntryMetadata& a, const EntryMetadata& b) {
102 return 102 return
103 a.last_used_time_seconds_since_epoch_ == 103 a.last_used_time_seconds_since_epoch_ ==
104 b.last_used_time_seconds_since_epoch_ && 104 b.last_used_time_seconds_since_epoch_ &&
105 a.entry_size_ == b.entry_size_; 105 a.entry_size_ == b.entry_size_;
106 } 106 }
107 }; 107 };
108 108
109 TEST_F(SimpleIndexFileTest, Serialize) { 109 TEST_F(SimpleIndexFileTest, Serialize) {
110 SimpleIndex::EntrySet entries; 110 SimpleIndex::EntrySet entries;
111 static const uint64 kHashes[] = { 11, 22, 33 }; 111 static const uint64_t kHashes[] = {11, 22, 33};
112 static const size_t kNumHashes = arraysize(kHashes); 112 static const size_t kNumHashes = arraysize(kHashes);
113 EntryMetadata metadata_entries[kNumHashes]; 113 EntryMetadata metadata_entries[kNumHashes];
114 114
115 SimpleIndexFile::IndexMetadata index_metadata(static_cast<uint64>(kNumHashes), 115 SimpleIndexFile::IndexMetadata index_metadata(
116 456); 116 static_cast<uint64_t>(kNumHashes), 456);
117 for (size_t i = 0; i < kNumHashes; ++i) { 117 for (size_t i = 0; i < kNumHashes; ++i) {
118 uint64 hash = kHashes[i]; 118 uint64_t hash = kHashes[i];
119 metadata_entries[i] = EntryMetadata(Time(), hash); 119 metadata_entries[i] = EntryMetadata(Time(), hash);
120 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries); 120 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries);
121 } 121 }
122 122
123 scoped_ptr<base::Pickle> pickle = 123 scoped_ptr<base::Pickle> pickle =
124 WrappedSimpleIndexFile::Serialize(index_metadata, entries); 124 WrappedSimpleIndexFile::Serialize(index_metadata, entries);
125 EXPECT_TRUE(pickle.get() != NULL); 125 EXPECT_TRUE(pickle.get() != NULL);
126 base::Time now = base::Time::Now(); 126 base::Time now = base::Time::Now();
127 EXPECT_TRUE(WrappedSimpleIndexFile::SerializeFinalData(now, pickle.get())); 127 EXPECT_TRUE(WrappedSimpleIndexFile::SerializeFinalData(now, pickle.get()));
128 base::Time when_index_last_saw_cache; 128 base::Time when_index_last_saw_cache;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 EXPECT_TRUE(base::TouchFile(index_path, even_older, even_older)); 174 EXPECT_TRUE(base::TouchFile(index_path, even_older, even_older));
175 EXPECT_TRUE( 175 EXPECT_TRUE(
176 WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path)); 176 WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path));
177 } 177 }
178 178
179 TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) { 179 TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) {
180 base::ScopedTempDir cache_dir; 180 base::ScopedTempDir cache_dir;
181 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); 181 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
182 182
183 SimpleIndex::EntrySet entries; 183 SimpleIndex::EntrySet entries;
184 static const uint64 kHashes[] = { 11, 22, 33 }; 184 static const uint64_t kHashes[] = {11, 22, 33};
185 static const size_t kNumHashes = arraysize(kHashes); 185 static const size_t kNumHashes = arraysize(kHashes);
186 EntryMetadata metadata_entries[kNumHashes]; 186 EntryMetadata metadata_entries[kNumHashes];
187 for (size_t i = 0; i < kNumHashes; ++i) { 187 for (size_t i = 0; i < kNumHashes; ++i) {
188 uint64 hash = kHashes[i]; 188 uint64_t hash = kHashes[i];
189 metadata_entries[i] = EntryMetadata(Time(), hash); 189 metadata_entries[i] = EntryMetadata(Time(), hash);
190 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries); 190 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries);
191 } 191 }
192 192
193 const uint64 kCacheSize = 456U; 193 const uint64_t kCacheSize = 456U;
194 net::TestClosure closure; 194 net::TestClosure closure;
195 { 195 {
196 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); 196 WrappedSimpleIndexFile simple_index_file(cache_dir.path());
197 simple_index_file.WriteToDisk(entries, kCacheSize, base::TimeTicks(), 197 simple_index_file.WriteToDisk(entries, kCacheSize, base::TimeTicks(),
198 false, closure.closure()); 198 false, closure.closure());
199 closure.WaitForResult(); 199 closure.WaitForResult();
200 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); 200 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath()));
201 } 201 }
202 202
203 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); 203 WrappedSimpleIndexFile simple_index_file(cache_dir.path());
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 closure.WaitForResult(); 339 closure.WaitForResult();
340 340
341 // Check that the temporary file was deleted and the index file was created. 341 // Check that the temporary file was deleted and the index file was created.
342 EXPECT_FALSE(base::PathExists(simple_index_file.GetTempIndexFilePath())); 342 EXPECT_FALSE(base::PathExists(simple_index_file.GetTempIndexFilePath()));
343 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); 343 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath()));
344 } 344 }
345 345
346 #endif // defined(OS_POSIX) 346 #endif // defined(OS_POSIX)
347 347
348 } // namespace disk_cache 348 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index_file.cc ('k') | net/disk_cache/simple/simple_index_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698