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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 typedef ::testing::Types<ChromiumEnvStdio, ChromiumEnvWin> ChromiumEnvMultiPlatf
ormTestsTypes; | 106 typedef ::testing::Types<ChromiumEnvStdio, ChromiumEnvWin> ChromiumEnvMultiPlatf
ormTestsTypes; |
107 #else | 107 #else |
108 typedef ::testing::Types<ChromiumEnvStdio> ChromiumEnvMultiPlatformTestsTypes; | 108 typedef ::testing::Types<ChromiumEnvStdio> ChromiumEnvMultiPlatformTestsTypes; |
109 #endif | 109 #endif |
110 TYPED_TEST_CASE(ChromiumEnvMultiPlatformTests, ChromiumEnvMultiPlatformTestsType
s); | 110 TYPED_TEST_CASE(ChromiumEnvMultiPlatformTests, ChromiumEnvMultiPlatformTestsType
s); |
111 | 111 |
112 TYPED_TEST(ChromiumEnvMultiPlatformTests, DirectorySyncing) { | 112 TYPED_TEST(ChromiumEnvMultiPlatformTests, DirectorySyncing) { |
113 MyEnv<TypeParam> env; | 113 MyEnv<TypeParam> env; |
114 | 114 |
115 base::ScopedTempDir dir; | 115 base::ScopedTempDir dir; |
116 dir.CreateUniqueTempDir(); | 116 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
117 base::FilePath dir_path = dir.path(); | 117 base::FilePath dir_path = dir.path(); |
118 std::string some_data = "some data"; | 118 std::string some_data = "some data"; |
119 Slice data = some_data; | 119 Slice data = some_data; |
120 | 120 |
121 std::string manifest_file_name = | 121 std::string manifest_file_name = |
122 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("MANIFEST-001"))); | 122 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("MANIFEST-001"))); |
123 WritableFile* manifest_file_ptr; | 123 WritableFile* manifest_file_ptr; |
124 Status s = env.NewWritableFile(manifest_file_name, &manifest_file_ptr); | 124 Status s = env.NewWritableFile(manifest_file_name, &manifest_file_ptr); |
125 EXPECT_TRUE(s.ok()); | 125 EXPECT_TRUE(s.ok()); |
126 scoped_ptr<WritableFile> manifest_file(manifest_file_ptr); | 126 scoped_ptr<WritableFile> manifest_file(manifest_file_ptr); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 169 } |
170 return false; | 170 return false; |
171 } | 171 } |
172 | 172 |
173 TEST(ChromiumEnv, BackupTables) { | 173 TEST(ChromiumEnv, BackupTables) { |
174 Options options; | 174 Options options; |
175 options.create_if_missing = true; | 175 options.create_if_missing = true; |
176 options.env = IDBEnv(); | 176 options.env = IDBEnv(); |
177 | 177 |
178 base::ScopedTempDir scoped_temp_dir; | 178 base::ScopedTempDir scoped_temp_dir; |
179 scoped_temp_dir.CreateUniqueTempDir(); | 179 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
180 base::FilePath dir = scoped_temp_dir.path(); | 180 base::FilePath dir = scoped_temp_dir.path(); |
181 | 181 |
182 DB* db; | 182 DB* db; |
183 Status status = DB::Open(options, dir.AsUTF8Unsafe(), &db); | 183 Status status = DB::Open(options, dir.AsUTF8Unsafe(), &db); |
184 EXPECT_TRUE(status.ok()) << status.ToString(); | 184 EXPECT_TRUE(status.ok()) << status.ToString(); |
185 status = db->Put(WriteOptions(), "key", "value"); | 185 status = db->Put(WriteOptions(), "key", "value"); |
186 EXPECT_TRUE(status.ok()) << status.ToString(); | 186 EXPECT_TRUE(status.ok()) << status.ToString(); |
187 Slice a = "a"; | 187 Slice a = "a"; |
188 Slice z = "z"; | 188 Slice z = "z"; |
189 db->CompactRange(&a, &z); | 189 db->CompactRange(&a, &z); |
(...skipping 24 matching lines...) Expand all Loading... |
214 EXPECT_TRUE(GetFirstLDBFile(dir, &ldb_file)); | 214 EXPECT_TRUE(GetFirstLDBFile(dir, &ldb_file)); |
215 options.env->DeleteFile(ldb_file.AsUTF8Unsafe()); | 215 options.env->DeleteFile(ldb_file.AsUTF8Unsafe()); |
216 ldb_files = CountFilesWithExtension(dir, FPL(".ldb")); | 216 ldb_files = CountFilesWithExtension(dir, FPL(".ldb")); |
217 bak_files = CountFilesWithExtension(dir, FPL(".bak")); | 217 bak_files = CountFilesWithExtension(dir, FPL(".bak")); |
218 EXPECT_EQ(orig_ldb_files - 1, ldb_files); | 218 EXPECT_EQ(orig_ldb_files - 1, ldb_files); |
219 EXPECT_EQ(bak_files, ldb_files); | 219 EXPECT_EQ(bak_files, ldb_files); |
220 } | 220 } |
221 | 221 |
222 TEST(ChromiumEnv, GetChildrenEmptyDir) { | 222 TEST(ChromiumEnv, GetChildrenEmptyDir) { |
223 base::ScopedTempDir scoped_temp_dir; | 223 base::ScopedTempDir scoped_temp_dir; |
224 scoped_temp_dir.CreateUniqueTempDir(); | 224 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
225 base::FilePath dir = scoped_temp_dir.path(); | 225 base::FilePath dir = scoped_temp_dir.path(); |
226 | 226 |
227 Env* env = IDBEnv(); | 227 Env* env = IDBEnv(); |
228 std::vector<std::string> result; | 228 std::vector<std::string> result; |
229 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 229 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
230 EXPECT_TRUE(status.ok()); | 230 EXPECT_TRUE(status.ok()); |
231 EXPECT_EQ(0, result.size()); | 231 EXPECT_EQ(0, result.size()); |
232 } | 232 } |
233 | 233 |
234 TEST(ChromiumEnv, GetChildrenPriorResults) { | 234 TEST(ChromiumEnv, GetChildrenPriorResults) { |
235 base::ScopedTempDir scoped_temp_dir; | 235 base::ScopedTempDir scoped_temp_dir; |
236 scoped_temp_dir.CreateUniqueTempDir(); | 236 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
237 base::FilePath dir = scoped_temp_dir.path(); | 237 base::FilePath dir = scoped_temp_dir.path(); |
238 | 238 |
239 base::FilePath new_file_dir = dir.Append(FPL("tmp_file")); | 239 base::FilePath new_file_dir = dir.Append(FPL("tmp_file")); |
240 FILE* f = fopen(new_file_dir.AsUTF8Unsafe().c_str(), "w"); | 240 FILE* f = fopen(new_file_dir.AsUTF8Unsafe().c_str(), "w"); |
241 if (f) { | 241 if (f) { |
242 fputs("Temp file contents", f); | 242 fputs("Temp file contents", f); |
243 fclose(f); | 243 fclose(f); |
244 } | 244 } |
245 | 245 |
246 Env* env = IDBEnv(); | 246 Env* env = IDBEnv(); |
247 std::vector<std::string> result; | 247 std::vector<std::string> result; |
248 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 248 leveldb::Status status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
249 EXPECT_TRUE(status.ok()); | 249 EXPECT_TRUE(status.ok()); |
250 EXPECT_EQ(1, result.size()); | 250 EXPECT_EQ(1, result.size()); |
251 | 251 |
252 // And a second time should also return one result | 252 // And a second time should also return one result |
253 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 253 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
254 EXPECT_TRUE(status.ok()); | 254 EXPECT_TRUE(status.ok()); |
255 EXPECT_EQ(1, result.size()); | 255 EXPECT_EQ(1, result.size()); |
256 } | 256 } |
257 | 257 |
258 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } | 258 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } |
OLD | NEW |