| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 using leveldb::WritableFile; | 25 using leveldb::WritableFile; |
| 26 using leveldb::WriteOptions; | 26 using leveldb::WriteOptions; |
| 27 using leveldb_env::ChromiumEnv; | 27 using leveldb_env::ChromiumEnv; |
| 28 using leveldb_env::MethodID; | 28 using leveldb_env::MethodID; |
| 29 | 29 |
| 30 TEST(ErrorEncoding, OnlyAMethod) { | 30 TEST(ErrorEncoding, OnlyAMethod) { |
| 31 const MethodID in_method = leveldb_env::kSequentialFileRead; | 31 const MethodID in_method = leveldb_env::kSequentialFileRead; |
| 32 const Status s = MakeIOError("Somefile.txt", "message", in_method); | 32 const Status s = MakeIOError("Somefile.txt", "message", in_method); |
| 33 MethodID method; | 33 MethodID method; |
| 34 int error = -75; | 34 int error = -75; |
| 35 EXPECT_EQ(leveldb_env::METHOD_ONLY, | 35 EXPECT_EQ(leveldb_env::METHOD_ONLY, ParseMethodAndError(s, &method, &error)); |
| 36 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | |
| 37 EXPECT_EQ(in_method, method); | 36 EXPECT_EQ(in_method, method); |
| 38 EXPECT_EQ(-75, error); | 37 EXPECT_EQ(-75, error); |
| 39 } | 38 } |
| 40 | 39 |
| 41 TEST(ErrorEncoding, FileError) { | 40 TEST(ErrorEncoding, FileError) { |
| 42 const MethodID in_method = leveldb_env::kWritableFileClose; | 41 const MethodID in_method = leveldb_env::kWritableFileClose; |
| 43 const base::File::Error fe = base::File::FILE_ERROR_INVALID_OPERATION; | 42 const base::File::Error fe = base::File::FILE_ERROR_INVALID_OPERATION; |
| 44 const Status s = MakeIOError("Somefile.txt", "message", in_method, fe); | 43 const Status s = MakeIOError("Somefile.txt", "message", in_method, fe); |
| 45 MethodID method; | 44 MethodID method; |
| 46 int error; | 45 int error; |
| 47 EXPECT_EQ(leveldb_env::METHOD_AND_PFE, | 46 EXPECT_EQ(leveldb_env::METHOD_AND_PFE, |
| 48 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 47 ParseMethodAndError(s, &method, &error)); |
| 49 EXPECT_EQ(in_method, method); | 48 EXPECT_EQ(in_method, method); |
| 50 EXPECT_EQ(fe, error); | 49 EXPECT_EQ(fe, error); |
| 51 } | 50 } |
| 52 | 51 |
| 53 TEST(ErrorEncoding, NoEncodedMessage) { | 52 TEST(ErrorEncoding, NoEncodedMessage) { |
| 54 Status s = Status::IOError("Some message", "from leveldb itself"); | 53 Status s = Status::IOError("Some message", "from leveldb itself"); |
| 55 MethodID method = leveldb_env::kRandomAccessFileRead; | 54 MethodID method = leveldb_env::kRandomAccessFileRead; |
| 56 int error = 4; | 55 int error = 4; |
| 57 EXPECT_EQ(leveldb_env::NONE, | 56 EXPECT_EQ(leveldb_env::NONE, ParseMethodAndError(s, &method, &error)); |
| 58 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | |
| 59 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method); | 57 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method); |
| 60 EXPECT_EQ(4, error); | 58 EXPECT_EQ(4, error); |
| 61 } | 59 } |
| 62 | 60 |
| 63 template <typename T> | 61 template <typename T> |
| 64 class MyEnv : public T { | 62 class MyEnv : public T { |
| 65 public: | 63 public: |
| 66 MyEnv() : directory_syncs_(0) {} | 64 MyEnv() : directory_syncs_(0) {} |
| 67 int directory_syncs() { return directory_syncs_; } | 65 int directory_syncs() { return directory_syncs_; } |
| 68 | 66 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 EXPECT_TRUE(status.ok()); | 222 EXPECT_TRUE(status.ok()); |
| 225 EXPECT_EQ(1U, result.size()); | 223 EXPECT_EQ(1U, result.size()); |
| 226 | 224 |
| 227 // And a second time should also return one result | 225 // And a second time should also return one result |
| 228 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 226 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
| 229 EXPECT_TRUE(status.ok()); | 227 EXPECT_TRUE(status.ok()); |
| 230 EXPECT_EQ(1U, result.size()); | 228 EXPECT_EQ(1U, result.size()); |
| 231 } | 229 } |
| 232 | 230 |
| 233 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } | 231 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } |
| OLD | NEW |