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_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
9 #include "base/test/test_suite.h" | 10 #include "base/test/test_suite.h" |
10 #include "env_chromium_stdio.h" | 11 #include "env_chromium_stdio.h" |
11 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
12 #include "env_chromium_win.h" | 13 #include "env_chromium_win.h" |
13 #endif | 14 #endif |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/leveldatabase/env_idb.h" | 16 #include "third_party/leveldatabase/env_idb.h" |
16 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 17 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
17 | 18 |
18 using namespace leveldb_env; | 19 using namespace leveldb_env; |
19 using namespace leveldb; | 20 using namespace leveldb; |
20 | 21 |
21 #define FPL FILE_PATH_LITERAL | 22 #define FPL FILE_PATH_LITERAL |
22 | 23 |
23 TEST(ErrorEncoding, OnlyAMethod) { | 24 TEST(ErrorEncoding, OnlyAMethod) { |
24 const MethodID in_method = kSequentialFileRead; | 25 const MethodID in_method = kSequentialFileRead; |
25 const Status s = MakeIOError("Somefile.txt", "message", in_method); | 26 const Status s = MakeIOError("Somefile.txt", "message", in_method); |
26 MethodID method; | 27 MethodID method; |
27 int error = -75; | 28 int error = -75; |
28 EXPECT_EQ(METHOD_ONLY, | 29 EXPECT_EQ(METHOD_ONLY, |
29 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 30 ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
30 EXPECT_EQ(in_method, method); | 31 EXPECT_EQ(in_method, method); |
31 EXPECT_EQ(-75, error); | 32 EXPECT_EQ(-75, error); |
32 } | 33 } |
33 | 34 |
34 TEST(ErrorEncoding, PlatformFileError) { | 35 TEST(ErrorEncoding, FileError) { |
35 const MethodID in_method = kWritableFileClose; | 36 const MethodID in_method = kWritableFileClose; |
36 const base::PlatformFileError pfe = | 37 const base::File::Error fe = base::File::FILE_ERROR_INVALID_OPERATION; |
37 base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 38 const Status s = MakeIOError("Somefile.txt", "message", in_method, fe); |
38 const Status s = MakeIOError("Somefile.txt", "message", in_method, pfe); | |
39 MethodID method; | 39 MethodID method; |
40 int error; | 40 int error; |
41 EXPECT_EQ(METHOD_AND_PFE, | 41 EXPECT_EQ(METHOD_AND_PFE, |
42 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 42 ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
43 EXPECT_EQ(in_method, method); | 43 EXPECT_EQ(in_method, method); |
44 EXPECT_EQ(pfe, error); | 44 EXPECT_EQ(fe, error); |
45 } | 45 } |
46 | 46 |
47 TEST(ErrorEncoding, Errno) { | 47 TEST(ErrorEncoding, Errno) { |
48 const MethodID in_method = kWritableFileFlush; | 48 const MethodID in_method = kWritableFileFlush; |
49 const int some_errno = ENOENT; | 49 const int some_errno = ENOENT; |
50 const Status s = | 50 const Status s = |
51 MakeIOError("Somefile.txt", "message", in_method, some_errno); | 51 MakeIOError("Somefile.txt", "message", in_method, some_errno); |
52 MethodID method; | 52 MethodID method; |
53 int error; | 53 int error; |
54 EXPECT_EQ(METHOD_AND_ERRNO, | 54 EXPECT_EQ(METHOD_AND_ERRNO, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |