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

Side by Side Diff: net/disk_cache/simple/simple_version_upgrade_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
« no previous file with comments | « net/disk_cache/simple/simple_version_upgrade.cc ('k') | net/dns/address_sorter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "net/disk_cache/simple/simple_version_upgrade.h" 5 #include "net/disk_cache/simple/simple_version_upgrade.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/basictypes.h"
10 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
13 #include "base/format_macros.h" 12 #include "base/format_macros.h"
14 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
15 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
16 #include "net/disk_cache/simple/simple_backend_version.h" 15 #include "net/disk_cache/simple/simple_backend_version.h"
17 #include "net/disk_cache/simple/simple_entry_format_history.h" 16 #include "net/disk_cache/simple/simple_entry_format_history.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 // The migration process relies on ability to rename newly created files, which 19 // The migration process relies on ability to rename newly created files, which
21 // could be problematic on Windows XP. 20 // could be problematic on Windows XP.
22 #if defined(OS_POSIX) 21 #if defined(OS_POSIX)
23 22
24 namespace { 23 namespace {
25 24
26 // Same as |disk_cache::kSimpleInitialMagicNumber|. 25 // Same as |disk_cache::kSimpleInitialMagicNumber|.
27 const uint64 kSimpleInitialMagicNumber = UINT64_C(0xfcfb6d1ba7725c30); 26 const uint64_t kSimpleInitialMagicNumber = UINT64_C(0xfcfb6d1ba7725c30);
28 27
29 // The "fake index" file that cache backends use to distinguish whether the 28 // The "fake index" file that cache backends use to distinguish whether the
30 // cache belongs to one backend or another. 29 // cache belongs to one backend or another.
31 const char kFakeIndexFileName[] = "index"; 30 const char kFakeIndexFileName[] = "index";
32 31
33 // Same as |SimpleIndexFile::kIndexFileName|. 32 // Same as |SimpleIndexFile::kIndexFileName|.
34 const char kIndexFileName[] = "the-real-index"; 33 const char kIndexFileName[] = "the-real-index";
35 34
36 bool WriteFakeIndexFileV5(const base::FilePath& cache_path) { 35 bool WriteFakeIndexFileV5(const base::FilePath& cache_path) {
37 disk_cache::FakeIndexData data; 36 disk_cache::FakeIndexData data;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 const base::FilePath cache_path = cache_dir.path(); 94 const base::FilePath cache_path = cache_dir.path();
96 95
97 WriteFakeIndexFileV5(cache_path); 96 WriteFakeIndexFileV5(cache_path);
98 const std::string file_contents("incorrectly serialized data"); 97 const std::string file_contents("incorrectly serialized data");
99 const base::FilePath index_file = cache_path.AppendASCII(kIndexFileName); 98 const base::FilePath index_file = cache_path.AppendASCII(kIndexFileName);
100 ASSERT_EQ( 99 ASSERT_EQ(
101 static_cast<int>(file_contents.size()), 100 static_cast<int>(file_contents.size()),
102 base::WriteFile(index_file, file_contents.data(), file_contents.size())); 101 base::WriteFile(index_file, file_contents.data(), file_contents.size()));
103 102
104 // Create a few entry-like files. 103 // Create a few entry-like files.
105 const uint64 kEntries = 5; 104 const uint64_t kEntries = 5;
106 for (uint64 entry_hash = 0; entry_hash < kEntries; ++entry_hash) { 105 for (uint64_t entry_hash = 0; entry_hash < kEntries; ++entry_hash) {
107 for (int index = 0; index < 3; ++index) { 106 for (int index = 0; index < 3; ++index) {
108 std::string file_name = 107 std::string file_name =
109 base::StringPrintf("%016" PRIx64 "_%1d", entry_hash, index); 108 base::StringPrintf("%016" PRIx64 "_%1d", entry_hash, index);
110 std::string entry_contents = 109 std::string entry_contents =
111 file_contents + 110 file_contents +
112 base::StringPrintf(" %" PRIx64, static_cast<uint64>(entry_hash)); 111 base::StringPrintf(" %" PRIx64, static_cast<uint64_t>(entry_hash));
113 ASSERT_EQ(static_cast<int>(entry_contents.size()), 112 ASSERT_EQ(static_cast<int>(entry_contents.size()),
114 base::WriteFile(cache_path.AppendASCII(file_name), 113 base::WriteFile(cache_path.AppendASCII(file_name),
115 entry_contents.data(), entry_contents.size())); 114 entry_contents.data(), entry_contents.size()));
116 } 115 }
117 } 116 }
118 117
119 // Upgrade. 118 // Upgrade.
120 ASSERT_TRUE(disk_cache::UpgradeIndexV5V6(cache_path)); 119 ASSERT_TRUE(disk_cache::UpgradeIndexV5V6(cache_path));
121 120
122 // Check that the old index disappeared but the files remain unchanged. 121 // Check that the old index disappeared but the files remain unchanged.
123 EXPECT_FALSE(base::PathExists(index_file)); 122 EXPECT_FALSE(base::PathExists(index_file));
124 for (uint64 entry_hash = 0; entry_hash < kEntries; ++entry_hash) { 123 for (uint64_t entry_hash = 0; entry_hash < kEntries; ++entry_hash) {
125 for (int index = 0; index < 3; ++index) { 124 for (int index = 0; index < 3; ++index) {
126 std::string file_name = 125 std::string file_name =
127 base::StringPrintf("%016" PRIx64 "_%1d", entry_hash, index); 126 base::StringPrintf("%016" PRIx64 "_%1d", entry_hash, index);
128 std::string expected_contents = 127 std::string expected_contents =
129 file_contents + 128 file_contents +
130 base::StringPrintf(" %" PRIx64, static_cast<uint64>(entry_hash)); 129 base::StringPrintf(" %" PRIx64, static_cast<uint64_t>(entry_hash));
131 std::string real_contents; 130 std::string real_contents;
132 EXPECT_TRUE(base::ReadFileToString(cache_path.AppendASCII(file_name), 131 EXPECT_TRUE(base::ReadFileToString(cache_path.AppendASCII(file_name),
133 &real_contents)); 132 &real_contents));
134 EXPECT_EQ(expected_contents, real_contents); 133 EXPECT_EQ(expected_contents, real_contents);
135 } 134 }
136 } 135 }
137 } 136 }
138 137
139 } // namespace 138 } // namespace
140 139
141 #endif // defined(OS_POSIX) 140 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_version_upgrade.cc ('k') | net/dns/address_sorter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698