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

Side by Side Diff: third_party/leveldatabase/env_chromium_unittest.cc

Issue 710373002: LevelDB: Using base::File for all file I/O (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iterator -> range based for loop + GetDirectoryEntries cleanup Created 6 years, 1 month 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) 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/test/test_suite.h" 10 #include "base/test/test_suite.h"
11 #include "third_party/leveldatabase/env_chromium_stdio.h" 11 #include "third_party/leveldatabase/env_chromium.h"
12 #if defined(OS_WIN)
13 #include "third_party/leveldatabase/env_chromium_win.h"
14 #endif
15 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/leveldatabase/env_idb.h" 13 #include "third_party/leveldatabase/env_idb.h"
17 #include "third_party/leveldatabase/src/include/leveldb/db.h" 14 #include "third_party/leveldatabase/src/include/leveldb/db.h"
18 15
19 #define FPL FILE_PATH_LITERAL 16 #define FPL FILE_PATH_LITERAL
20 17
21 using leveldb::DB; 18 using leveldb::DB;
22 using leveldb::Env; 19 using leveldb::Env;
23 using leveldb::IDBEnv; 20 using leveldb::IDBEnv;
24 using leveldb::Options; 21 using leveldb::Options;
25 using leveldb::ReadOptions; 22 using leveldb::ReadOptions;
26 using leveldb::Slice; 23 using leveldb::Slice;
27 using leveldb::Status; 24 using leveldb::Status;
28 using leveldb::WritableFile; 25 using leveldb::WritableFile;
29 using leveldb::WriteOptions; 26 using leveldb::WriteOptions;
30 using leveldb_env::ChromiumEnvStdio; 27 using leveldb_env::ChromiumEnv;
31 #if defined(OS_WIN)
32 using leveldb_env::ChromiumEnvWin;
33 #endif
34 using leveldb_env::MethodID; 28 using leveldb_env::MethodID;
35 29
36 TEST(ErrorEncoding, OnlyAMethod) { 30 TEST(ErrorEncoding, OnlyAMethod) {
37 const MethodID in_method = leveldb_env::kSequentialFileRead; 31 const MethodID in_method = leveldb_env::kSequentialFileRead;
38 const Status s = MakeIOError("Somefile.txt", "message", in_method); 32 const Status s = MakeIOError("Somefile.txt", "message", in_method);
39 MethodID method; 33 MethodID method;
40 int error = -75; 34 int error = -75;
41 EXPECT_EQ(leveldb_env::METHOD_ONLY, 35 EXPECT_EQ(leveldb_env::METHOD_ONLY,
42 ParseMethodAndError(s.ToString().c_str(), &method, &error)); 36 ParseMethodAndError(s.ToString().c_str(), &method, &error));
43 EXPECT_EQ(in_method, method); 37 EXPECT_EQ(in_method, method);
44 EXPECT_EQ(-75, error); 38 EXPECT_EQ(-75, error);
45 } 39 }
46 40
47 TEST(ErrorEncoding, FileError) { 41 TEST(ErrorEncoding, FileError) {
48 const MethodID in_method = leveldb_env::kWritableFileClose; 42 const MethodID in_method = leveldb_env::kWritableFileClose;
49 const base::File::Error fe = base::File::FILE_ERROR_INVALID_OPERATION; 43 const base::File::Error fe = base::File::FILE_ERROR_INVALID_OPERATION;
50 const Status s = MakeIOError("Somefile.txt", "message", in_method, fe); 44 const Status s = MakeIOError("Somefile.txt", "message", in_method, fe);
51 MethodID method; 45 MethodID method;
52 int error; 46 int error;
53 EXPECT_EQ(leveldb_env::METHOD_AND_PFE, 47 EXPECT_EQ(leveldb_env::METHOD_AND_PFE,
54 ParseMethodAndError(s.ToString().c_str(), &method, &error)); 48 ParseMethodAndError(s.ToString().c_str(), &method, &error));
55 EXPECT_EQ(in_method, method); 49 EXPECT_EQ(in_method, method);
56 EXPECT_EQ(fe, error); 50 EXPECT_EQ(fe, error);
57 } 51 }
58 52
59 TEST(ErrorEncoding, Errno) {
60 const MethodID in_method = leveldb_env::kWritableFileFlush;
61 const int some_errno = ENOENT;
62 const Status s =
63 MakeIOError("Somefile.txt", "message", in_method, some_errno);
64 MethodID method;
65 int error;
66 EXPECT_EQ(leveldb_env::METHOD_AND_ERRNO,
67 ParseMethodAndError(s.ToString().c_str(), &method, &error));
68 EXPECT_EQ(in_method, method);
69 EXPECT_EQ(some_errno, error);
70 }
71
72 #if defined(OS_WIN)
73 TEST(ErrorEncoding, ErrnoWin32) {
74 const MethodID in_method = leveldb_env::kWritableFileFlush;
75 const DWORD some_errno = ERROR_FILE_NOT_FOUND;
76 const Status s =
77 MakeIOErrorWin("Somefile.txt", "message", in_method, some_errno);
78 MethodID method;
79 int error;
80 EXPECT_EQ(leveldb_env::METHOD_AND_ERRNO,
81 ParseMethodAndError(s.ToString().c_str(), &method, &error));
82 EXPECT_EQ(in_method, method);
83 EXPECT_EQ(some_errno, error);
84 }
85 #endif
86
87 TEST(ErrorEncoding, NoEncodedMessage) { 53 TEST(ErrorEncoding, NoEncodedMessage) {
88 Status s = Status::IOError("Some message", "from leveldb itself"); 54 Status s = Status::IOError("Some message", "from leveldb itself");
89 MethodID method = leveldb_env::kRandomAccessFileRead; 55 MethodID method = leveldb_env::kRandomAccessFileRead;
90 int error = 4; 56 int error = 4;
91 EXPECT_EQ(leveldb_env::NONE, 57 EXPECT_EQ(leveldb_env::NONE,
92 ParseMethodAndError(s.ToString().c_str(), &method, &error)); 58 ParseMethodAndError(s.ToString().c_str(), &method, &error));
93 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method); 59 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method);
94 EXPECT_EQ(4, error); 60 EXPECT_EQ(4, error);
95 } 61 }
96 62
(...skipping 11 matching lines...) Expand all
108 74
109 private: 75 private:
110 int directory_syncs_; 76 int directory_syncs_;
111 }; 77 };
112 78
113 template <typename T> 79 template <typename T>
114 class ChromiumEnvMultiPlatformTests : public ::testing::Test { 80 class ChromiumEnvMultiPlatformTests : public ::testing::Test {
115 public: 81 public:
116 }; 82 };
117 83
118 #if defined(OS_WIN) 84 typedef ::testing::Types<ChromiumEnv> ChromiumEnvMultiPlatformTestsTypes;
119 typedef ::testing::Types<ChromiumEnvStdio, ChromiumEnvWin>
120 ChromiumEnvMultiPlatformTestsTypes;
121 #else
122 typedef ::testing::Types<ChromiumEnvStdio> ChromiumEnvMultiPlatformTestsTypes;
123 #endif
124 TYPED_TEST_CASE(ChromiumEnvMultiPlatformTests, 85 TYPED_TEST_CASE(ChromiumEnvMultiPlatformTests,
125 ChromiumEnvMultiPlatformTestsTypes); 86 ChromiumEnvMultiPlatformTestsTypes);
126 87
127 TYPED_TEST(ChromiumEnvMultiPlatformTests, DirectorySyncing) { 88 TYPED_TEST(ChromiumEnvMultiPlatformTests, DirectorySyncing) {
128 MyEnv<TypeParam> env; 89 MyEnv<TypeParam> env;
129 90
130 base::ScopedTempDir dir; 91 base::ScopedTempDir dir;
131 ASSERT_TRUE(dir.CreateUniqueTempDir()); 92 ASSERT_TRUE(dir.CreateUniqueTempDir());
132 base::FilePath dir_path = dir.path(); 93 base::FilePath dir_path = dir.path();
133 std::string some_data = "some data"; 94 std::string some_data = "some data";
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 EXPECT_TRUE(status.ok()); 224 EXPECT_TRUE(status.ok());
264 EXPECT_EQ(1U, result.size()); 225 EXPECT_EQ(1U, result.size());
265 226
266 // And a second time should also return one result 227 // And a second time should also return one result
267 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); 228 status = env->GetChildren(dir.AsUTF8Unsafe(), &result);
268 EXPECT_TRUE(status.ok()); 229 EXPECT_TRUE(status.ok());
269 EXPECT_EQ(1U, result.size()); 230 EXPECT_EQ(1U, result.size());
270 } 231 }
271 232
272 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } 233 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698