| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file.h" | 6 #include "base/files/file.h" |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/test/test_suite.h" | 10 #include "base/test/test_suite.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 status = leveldb::DB::Open(options, dir.AsUTF8Unsafe(), &db); | 201 status = leveldb::DB::Open(options, dir.AsUTF8Unsafe(), &db); |
| 202 EXPECT_TRUE(status.ok()) << status.ToString(); | 202 EXPECT_TRUE(status.ok()) << status.ToString(); |
| 203 std::string value; | 203 std::string value; |
| 204 status = db->Get(ReadOptions(), "key", &value); | 204 status = db->Get(ReadOptions(), "key", &value); |
| 205 EXPECT_TRUE(status.ok()) << status.ToString(); | 205 EXPECT_TRUE(status.ok()) << status.ToString(); |
| 206 EXPECT_EQ("value", value); | 206 EXPECT_EQ("value", value); |
| 207 delete db; | 207 delete db; |
| 208 | 208 |
| 209 // Ensure that deleting an ldb file also deletes its backup. | 209 // Ensure that deleting an ldb file also deletes its backup. |
| 210 int orig_ldb_files = CountFilesWithExtension(dir, FPL(".ldb")); | 210 int orig_ldb_files = CountFilesWithExtension(dir, FPL(".ldb")); |
| 211 int orig_bak_files = CountFilesWithExtension(dir, FPL(".bak")); | |
| 212 EXPECT_GT(ldb_files, 0); | 211 EXPECT_GT(ldb_files, 0); |
| 213 EXPECT_EQ(ldb_files, bak_files); | 212 EXPECT_EQ(ldb_files, bak_files); |
| 214 EXPECT_TRUE(GetFirstLDBFile(dir, &ldb_file)); | 213 EXPECT_TRUE(GetFirstLDBFile(dir, &ldb_file)); |
| 215 options.env->DeleteFile(ldb_file.AsUTF8Unsafe()); | 214 options.env->DeleteFile(ldb_file.AsUTF8Unsafe()); |
| 216 ldb_files = CountFilesWithExtension(dir, FPL(".ldb")); | 215 ldb_files = CountFilesWithExtension(dir, FPL(".ldb")); |
| 217 bak_files = CountFilesWithExtension(dir, FPL(".bak")); | 216 bak_files = CountFilesWithExtension(dir, FPL(".bak")); |
| 218 EXPECT_EQ(orig_ldb_files - 1, ldb_files); | 217 EXPECT_EQ(orig_ldb_files - 1, ldb_files); |
| 219 EXPECT_EQ(bak_files, ldb_files); | 218 EXPECT_EQ(bak_files, ldb_files); |
| 220 } | 219 } |
| 221 | 220 |
| 222 TEST(ChromiumEnv, GetChildrenEmptyDir) { | 221 TEST(ChromiumEnv, GetChildrenEmptyDir) { |
| 223 base::ScopedTempDir scoped_temp_dir; | 222 base::ScopedTempDir scoped_temp_dir; |
| 224 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 223 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 225 base::FilePath dir = scoped_temp_dir.path(); | 224 base::FilePath dir = scoped_temp_dir.path(); |
| 226 | 225 |
| 227 Env* env = IDBEnv(); | 226 Env* env = IDBEnv(); |
| 228 std::vector<std::string> result; | 227 std::vector<std::string> result; |
| 229 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 228 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
| 230 EXPECT_TRUE(status.ok()); | 229 EXPECT_TRUE(status.ok()); |
| 231 EXPECT_EQ(0, result.size()); | 230 EXPECT_EQ(0U, result.size()); |
| 232 } | 231 } |
| 233 | 232 |
| 234 TEST(ChromiumEnv, GetChildrenPriorResults) { | 233 TEST(ChromiumEnv, GetChildrenPriorResults) { |
| 235 base::ScopedTempDir scoped_temp_dir; | 234 base::ScopedTempDir scoped_temp_dir; |
| 236 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 235 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 237 base::FilePath dir = scoped_temp_dir.path(); | 236 base::FilePath dir = scoped_temp_dir.path(); |
| 238 | 237 |
| 239 base::FilePath new_file_dir = dir.Append(FPL("tmp_file")); | 238 base::FilePath new_file_dir = dir.Append(FPL("tmp_file")); |
| 240 FILE* f = fopen(new_file_dir.AsUTF8Unsafe().c_str(), "w"); | 239 FILE* f = fopen(new_file_dir.AsUTF8Unsafe().c_str(), "w"); |
| 241 if (f) { | 240 if (f) { |
| 242 fputs("Temp file contents", f); | 241 fputs("Temp file contents", f); |
| 243 fclose(f); | 242 fclose(f); |
| 244 } | 243 } |
| 245 | 244 |
| 246 Env* env = IDBEnv(); | 245 Env* env = IDBEnv(); |
| 247 std::vector<std::string> result; | 246 std::vector<std::string> result; |
| 248 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 247 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
| 249 EXPECT_TRUE(status.ok()); | 248 EXPECT_TRUE(status.ok()); |
| 250 EXPECT_EQ(1, result.size()); | 249 EXPECT_EQ(1, result.size()); |
| 251 | 250 |
| 252 // And a second time should also return one result | 251 // And a second time should also return one result |
| 253 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 252 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
| 254 EXPECT_TRUE(status.ok()); | 253 EXPECT_TRUE(status.ok()); |
| 255 EXPECT_EQ(1, result.size()); | 254 EXPECT_EQ(1, result.size()); |
| 256 } | 255 } |
| 257 | 256 |
| 258 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } | 257 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } |
| OLD | NEW |