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 13 matching lines...) Expand all Loading... | |
24 using leveldb::Status; | 24 using leveldb::Status; |
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 base::File::Error error = base::File::FILE_OK; |
jsbell
2015/02/19 19:56:51
I thought about using base::File::FILE_ERROR_MAX h
cmumford
2015/02/20 19:21:24
I guess the original intent of -75 was to verify t
jsbell
2015/02/20 20:03:40
Agreed. Given that we should never assign FILE_ERR
| |
35 EXPECT_EQ(leveldb_env::METHOD_ONLY, ParseMethodAndError(s, &method, &error)); | 35 EXPECT_EQ(leveldb_env::METHOD_ONLY, ParseMethodAndError(s, &method, &error)); |
36 EXPECT_EQ(in_method, method); | 36 EXPECT_EQ(in_method, method); |
37 EXPECT_EQ(-75, error); | 37 EXPECT_EQ(base::File::FILE_OK, error); |
38 } | 38 } |
39 | 39 |
40 TEST(ErrorEncoding, FileError) { | 40 TEST(ErrorEncoding, FileError) { |
41 const MethodID in_method = leveldb_env::kWritableFileClose; | 41 const MethodID in_method = leveldb_env::kWritableFileClose; |
42 const base::File::Error fe = base::File::FILE_ERROR_INVALID_OPERATION; | 42 const base::File::Error fe = base::File::FILE_ERROR_INVALID_OPERATION; |
43 const Status s = MakeIOError("Somefile.txt", "message", in_method, fe); | 43 const Status s = MakeIOError("Somefile.txt", "message", in_method, fe); |
44 MethodID method; | 44 MethodID method; |
45 int error; | 45 base::File::Error error; |
46 EXPECT_EQ(leveldb_env::METHOD_AND_PFE, | 46 EXPECT_EQ(leveldb_env::METHOD_AND_PFE, |
47 ParseMethodAndError(s, &method, &error)); | 47 ParseMethodAndError(s, &method, &error)); |
48 EXPECT_EQ(in_method, method); | 48 EXPECT_EQ(in_method, method); |
49 EXPECT_EQ(fe, error); | 49 EXPECT_EQ(fe, error); |
50 } | 50 } |
51 | 51 |
52 TEST(ErrorEncoding, NoEncodedMessage) { | 52 TEST(ErrorEncoding, NoEncodedMessage) { |
53 Status s = Status::IOError("Some message", "from leveldb itself"); | 53 Status s = Status::IOError("Some message", "from leveldb itself"); |
54 MethodID method = leveldb_env::kRandomAccessFileRead; | 54 MethodID method = leveldb_env::kRandomAccessFileRead; |
55 int error = 4; | 55 base::File::Error error = base::File::FILE_OK; |
56 EXPECT_EQ(leveldb_env::NONE, ParseMethodAndError(s, &method, &error)); | 56 EXPECT_EQ(leveldb_env::NONE, ParseMethodAndError(s, &method, &error)); |
57 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method); | 57 EXPECT_EQ(leveldb_env::kRandomAccessFileRead, method); |
58 EXPECT_EQ(4, error); | 58 EXPECT_EQ(base::File::FILE_OK, error); |
59 } | 59 } |
60 | 60 |
61 template <typename T> | 61 template <typename T> |
62 class MyEnv : public T { | 62 class MyEnv : public T { |
63 public: | 63 public: |
64 MyEnv() : directory_syncs_(0) {} | 64 MyEnv() : directory_syncs_(0) {} |
65 int directory_syncs() { return directory_syncs_; } | 65 int directory_syncs() { return directory_syncs_; } |
66 | 66 |
67 protected: | 67 protected: |
68 virtual void DidSyncDir(const std::string& fname) { | 68 virtual void DidSyncDir(const std::string& fname) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 EXPECT_TRUE(status.ok()); | 222 EXPECT_TRUE(status.ok()); |
223 EXPECT_EQ(1U, result.size()); | 223 EXPECT_EQ(1U, result.size()); |
224 | 224 |
225 // And a second time should also return one result | 225 // And a second time should also return one result |
226 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 226 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
227 EXPECT_TRUE(status.ok()); | 227 EXPECT_TRUE(status.ok()); |
228 EXPECT_EQ(1U, result.size()); | 228 EXPECT_EQ(1U, result.size()); |
229 } | 229 } |
230 | 230 |
231 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 |