| 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 "base/files/file.h" | 5 #include "base/files/file.h" |
| 6 #include "base/files/file_enumerator.h" | 6 #include "base/files/file_enumerator.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return false; | 92 return false; |
| 93 } | 93 } |
| 94 | 94 |
| 95 TEST(ChromiumEnv, DeleteBackupTables) { | 95 TEST(ChromiumEnv, DeleteBackupTables) { |
| 96 Options options; | 96 Options options; |
| 97 options.create_if_missing = true; | 97 options.create_if_missing = true; |
| 98 options.env = Env::Default(); | 98 options.env = Env::Default(); |
| 99 | 99 |
| 100 base::ScopedTempDir scoped_temp_dir; | 100 base::ScopedTempDir scoped_temp_dir; |
| 101 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 101 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 102 base::FilePath dir = scoped_temp_dir.path(); | 102 base::FilePath dir = scoped_temp_dir.GetPath(); |
| 103 | 103 |
| 104 DB* db; | 104 DB* db; |
| 105 Status status = DB::Open(options, dir.AsUTF8Unsafe(), &db); | 105 Status status = DB::Open(options, dir.AsUTF8Unsafe(), &db); |
| 106 EXPECT_TRUE(status.ok()) << status.ToString(); | 106 EXPECT_TRUE(status.ok()) << status.ToString(); |
| 107 status = db->Put(WriteOptions(), "key", "value"); | 107 status = db->Put(WriteOptions(), "key", "value"); |
| 108 EXPECT_TRUE(status.ok()) << status.ToString(); | 108 EXPECT_TRUE(status.ok()) << status.ToString(); |
| 109 Slice a = "a"; | 109 Slice a = "a"; |
| 110 Slice z = "z"; | 110 Slice z = "z"; |
| 111 db->CompactRange(&a, &z); // Ensure manifest written out to table. | 111 db->CompactRange(&a, &z); // Ensure manifest written out to table. |
| 112 delete db; | 112 delete db; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 129 EXPECT_TRUE(status.ok()) << status.ToString(); | 129 EXPECT_TRUE(status.ok()) << status.ToString(); |
| 130 EXPECT_EQ(0, CountFilesWithExtension(dir, FPL(".bak"))); | 130 EXPECT_EQ(0, CountFilesWithExtension(dir, FPL(".bak"))); |
| 131 delete db; | 131 delete db; |
| 132 EXPECT_EQ(1, CountFilesWithExtension(dir, FPL(".ldb"))); | 132 EXPECT_EQ(1, CountFilesWithExtension(dir, FPL(".ldb"))); |
| 133 EXPECT_EQ(0, CountFilesWithExtension(dir, FPL(".bak"))); | 133 EXPECT_EQ(0, CountFilesWithExtension(dir, FPL(".bak"))); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST(ChromiumEnv, GetChildrenEmptyDir) { | 136 TEST(ChromiumEnv, GetChildrenEmptyDir) { |
| 137 base::ScopedTempDir scoped_temp_dir; | 137 base::ScopedTempDir scoped_temp_dir; |
| 138 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 138 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 139 base::FilePath dir = scoped_temp_dir.path(); | 139 base::FilePath dir = scoped_temp_dir.GetPath(); |
| 140 | 140 |
| 141 Env* env = Env::Default(); | 141 Env* env = Env::Default(); |
| 142 std::vector<std::string> result; | 142 std::vector<std::string> result; |
| 143 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 143 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
| 144 EXPECT_TRUE(status.ok()); | 144 EXPECT_TRUE(status.ok()); |
| 145 EXPECT_EQ(0U, result.size()); | 145 EXPECT_EQ(0U, result.size()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 TEST(ChromiumEnv, GetChildrenPriorResults) { | 148 TEST(ChromiumEnv, GetChildrenPriorResults) { |
| 149 base::ScopedTempDir scoped_temp_dir; | 149 base::ScopedTempDir scoped_temp_dir; |
| 150 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 150 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 151 base::FilePath dir = scoped_temp_dir.path(); | 151 base::FilePath dir = scoped_temp_dir.GetPath(); |
| 152 | 152 |
| 153 base::FilePath new_file_dir = dir.Append(FPL("tmp_file")); | 153 base::FilePath new_file_dir = dir.Append(FPL("tmp_file")); |
| 154 FILE* f = fopen(new_file_dir.AsUTF8Unsafe().c_str(), "w"); | 154 FILE* f = fopen(new_file_dir.AsUTF8Unsafe().c_str(), "w"); |
| 155 if (f) { | 155 if (f) { |
| 156 fputs("Temp file contents", f); | 156 fputs("Temp file contents", f); |
| 157 fclose(f); | 157 fclose(f); |
| 158 } | 158 } |
| 159 | 159 |
| 160 Env* env = Env::Default(); | 160 Env* env = Env::Default(); |
| 161 std::vector<std::string> result; | 161 std::vector<std::string> result; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 184 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(40 * MB)); | 184 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(40 * MB)); |
| 185 | 185 |
| 186 // Make sure sizes larger than 40MB are clamped to max buffer size. | 186 // Make sure sizes larger than 40MB are clamped to max buffer size. |
| 187 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(80 * MB)); | 187 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(80 * MB)); |
| 188 | 188 |
| 189 // Check for very large disk size (catch overflow). | 189 // Check for very large disk size (catch overflow). |
| 190 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(100 * MB * MB)); | 190 EXPECT_EQ(size_t(4 * MB), leveldb_env::WriteBufferSize(100 * MB * MB)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } | 193 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } |
| OLD | NEW |