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/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); |
(...skipping 18 matching lines...) Expand all Loading... |
62 const Status s = | 56 const Status s = |
63 MakeIOError("Somefile.txt", "message", in_method, some_errno); | 57 MakeIOError("Somefile.txt", "message", in_method, some_errno); |
64 MethodID method; | 58 MethodID method; |
65 int error; | 59 int error; |
66 EXPECT_EQ(leveldb_env::METHOD_AND_ERRNO, | 60 EXPECT_EQ(leveldb_env::METHOD_AND_ERRNO, |
67 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 61 ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
68 EXPECT_EQ(in_method, method); | 62 EXPECT_EQ(in_method, method); |
69 EXPECT_EQ(some_errno, error); | 63 EXPECT_EQ(some_errno, error); |
70 } | 64 } |
71 | 65 |
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) { | 66 TEST(ErrorEncoding, NoEncodedMessage) { |
88 Status s = Status::IOError("Some message", "from leveldb itself"); | 67 Status s = Status::IOError("Some message", "from leveldb itself"); |
89 MethodID method = leveldb_env::kRandomAccessFileRead; | 68 MethodID method = leveldb_env::kRandomAccessFileRead; |
90 int error = 4; | 69 int error = 4; |
91 EXPECT_EQ(leveldb_env::NONE, | 70 EXPECT_EQ(leveldb_env::NONE, |
92 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 71 ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
93 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method); | 72 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method); |
94 EXPECT_EQ(4, error); | 73 EXPECT_EQ(4, error); |
95 } | 74 } |
96 | 75 |
(...skipping 11 matching lines...) Expand all Loading... |
108 | 87 |
109 private: | 88 private: |
110 int directory_syncs_; | 89 int directory_syncs_; |
111 }; | 90 }; |
112 | 91 |
113 template <typename T> | 92 template <typename T> |
114 class ChromiumEnvMultiPlatformTests : public ::testing::Test { | 93 class ChromiumEnvMultiPlatformTests : public ::testing::Test { |
115 public: | 94 public: |
116 }; | 95 }; |
117 | 96 |
118 #if defined(OS_WIN) | 97 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, | 98 TYPED_TEST_CASE(ChromiumEnvMultiPlatformTests, |
125 ChromiumEnvMultiPlatformTestsTypes); | 99 ChromiumEnvMultiPlatformTestsTypes); |
126 | 100 |
127 TYPED_TEST(ChromiumEnvMultiPlatformTests, DirectorySyncing) { | 101 TYPED_TEST(ChromiumEnvMultiPlatformTests, DirectorySyncing) { |
128 MyEnv<TypeParam> env; | 102 MyEnv<TypeParam> env; |
129 | 103 |
130 base::ScopedTempDir dir; | 104 base::ScopedTempDir dir; |
131 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 105 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
132 base::FilePath dir_path = dir.path(); | 106 base::FilePath dir_path = dir.path(); |
133 std::string some_data = "some data"; | 107 std::string some_data = "some data"; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 EXPECT_TRUE(status.ok()); | 237 EXPECT_TRUE(status.ok()); |
264 EXPECT_EQ(1U, result.size()); | 238 EXPECT_EQ(1U, result.size()); |
265 | 239 |
266 // And a second time should also return one result | 240 // And a second time should also return one result |
267 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 241 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
268 EXPECT_TRUE(status.ok()); | 242 EXPECT_TRUE(status.ok()); |
269 EXPECT_EQ(1U, result.size()); | 243 EXPECT_EQ(1U, result.size()); |
270 } | 244 } |
271 | 245 |
272 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } | 246 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } |
OLD | NEW |