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_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/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/test/test_suite.h" | 9 #include "base/test/test_suite.h" |
10 #include "env_chromium_stdio.h" | 10 #include "env_chromium.h" |
11 #if defined(OS_WIN) | |
12 #include "env_chromium_win.h" | |
13 #endif | |
14 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/leveldatabase/env_idb.h" | 12 #include "third_party/leveldatabase/env_idb.h" |
16 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 13 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
17 | 14 |
18 using namespace leveldb_env; | 15 using namespace leveldb_env; |
19 using namespace leveldb; | 16 using namespace leveldb; |
20 | 17 |
21 #define FPL FILE_PATH_LITERAL | 18 #define FPL FILE_PATH_LITERAL |
22 | 19 |
23 TEST(ErrorEncoding, OnlyAMethod) { | 20 TEST(ErrorEncoding, OnlyAMethod) { |
(...skipping 26 matching lines...) Expand all Loading... |
50 const Status s = | 47 const Status s = |
51 MakeIOError("Somefile.txt", "message", in_method, some_errno); | 48 MakeIOError("Somefile.txt", "message", in_method, some_errno); |
52 MethodID method; | 49 MethodID method; |
53 int error; | 50 int error; |
54 EXPECT_EQ(METHOD_AND_ERRNO, | 51 EXPECT_EQ(METHOD_AND_ERRNO, |
55 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 52 ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
56 EXPECT_EQ(in_method, method); | 53 EXPECT_EQ(in_method, method); |
57 EXPECT_EQ(some_errno, error); | 54 EXPECT_EQ(some_errno, error); |
58 } | 55 } |
59 | 56 |
60 #if defined(OS_WIN) | |
61 TEST(ErrorEncoding, ErrnoWin32) { | |
62 const MethodID in_method = kWritableFileFlush; | |
63 const DWORD some_errno = ERROR_FILE_NOT_FOUND; | |
64 const Status s = | |
65 MakeIOErrorWin("Somefile.txt", "message", in_method, some_errno); | |
66 MethodID method; | |
67 int error; | |
68 EXPECT_EQ(METHOD_AND_ERRNO, | |
69 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | |
70 EXPECT_EQ(in_method, method); | |
71 EXPECT_EQ(some_errno, error); | |
72 } | |
73 #endif | |
74 | |
75 TEST(ErrorEncoding, NoEncodedMessage) { | 57 TEST(ErrorEncoding, NoEncodedMessage) { |
76 Status s = Status::IOError("Some message", "from leveldb itself"); | 58 Status s = Status::IOError("Some message", "from leveldb itself"); |
77 MethodID method = kRandomAccessFileRead; | 59 MethodID method = kRandomAccessFileRead; |
78 int error = 4; | 60 int error = 4; |
79 EXPECT_EQ(NONE, ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 61 EXPECT_EQ(NONE, ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
80 EXPECT_EQ(kRandomAccessFileRead, method); | 62 EXPECT_EQ(kRandomAccessFileRead, method); |
81 EXPECT_EQ(4, error); | 63 EXPECT_EQ(4, error); |
82 } | 64 } |
83 | 65 |
84 template <typename T> | 66 class MyEnv : public ChromiumEnv { |
85 class MyEnv : public T { | |
86 public: | 67 public: |
87 MyEnv() : directory_syncs_(0) {} | 68 MyEnv() : directory_syncs_(0) {} |
88 int directory_syncs() { return directory_syncs_; } | 69 int directory_syncs() { return directory_syncs_; } |
89 | 70 |
90 protected: | 71 protected: |
91 virtual void DidSyncDir(const std::string& fname) { | 72 virtual void DidSyncDir(const std::string& fname) { |
92 ++directory_syncs_; | 73 ++directory_syncs_; |
93 ChromiumEnv::DidSyncDir(fname); | 74 ChromiumEnv::DidSyncDir(fname); |
94 } | 75 } |
95 | 76 |
96 private: | 77 private: |
97 int directory_syncs_; | 78 int directory_syncs_; |
98 }; | 79 }; |
99 | 80 |
100 template <typename T> | 81 TEST(ChromiumEnv, DirectorySyncing) { |
101 class ChromiumEnvMultiPlatformTests : public ::testing::Test { | 82 MyEnv env; |
102 public: | |
103 }; | |
104 | |
105 #if defined(OS_WIN) | |
106 typedef ::testing::Types<ChromiumEnvStdio, ChromiumEnvWin> ChromiumEnvMultiPlatf
ormTestsTypes; | |
107 #else | |
108 typedef ::testing::Types<ChromiumEnvStdio> ChromiumEnvMultiPlatformTestsTypes; | |
109 #endif | |
110 TYPED_TEST_CASE(ChromiumEnvMultiPlatformTests, ChromiumEnvMultiPlatformTestsType
s); | |
111 | |
112 TYPED_TEST(ChromiumEnvMultiPlatformTests, DirectorySyncing) { | |
113 MyEnv<TypeParam> env; | |
114 | |
115 base::ScopedTempDir dir; | 83 base::ScopedTempDir dir; |
116 dir.CreateUniqueTempDir(); | 84 dir.CreateUniqueTempDir(); |
117 base::FilePath dir_path = dir.path(); | 85 base::FilePath dir_path = dir.path(); |
118 std::string some_data = "some data"; | 86 std::string some_data = "some data"; |
119 Slice data = some_data; | 87 Slice data = some_data; |
120 | 88 |
121 std::string manifest_file_name = | 89 std::string manifest_file_name = |
122 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("MANIFEST-001"))); | 90 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("MANIFEST-001"))); |
123 WritableFile* manifest_file_ptr; | 91 WritableFile* manifest_file_ptr; |
124 Status s = env.NewWritableFile(manifest_file_name, &manifest_file_ptr); | 92 Status s = env.NewWritableFile(manifest_file_name, &manifest_file_ptr); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 EXPECT_TRUE(status.ok()); | 217 EXPECT_TRUE(status.ok()); |
250 EXPECT_EQ(1, result.size()); | 218 EXPECT_EQ(1, result.size()); |
251 | 219 |
252 // And a second time should also return one result | 220 // And a second time should also return one result |
253 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 221 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
254 EXPECT_TRUE(status.ok()); | 222 EXPECT_TRUE(status.ok()); |
255 EXPECT_EQ(1, result.size()); | 223 EXPECT_EQ(1, result.size()); |
256 } | 224 } |
257 | 225 |
258 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } | 226 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); } |
OLD | NEW |