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.h" | 10 #include "env_chromium_stdio.h" |
11 #if defined(OS_WIN) | |
12 #include "env_chromium_win.h" | |
13 #endif | |
11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/leveldatabase/env_idb.h" | 15 #include "third_party/leveldatabase/env_idb.h" |
13 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 16 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
14 | 17 |
15 using namespace leveldb_env; | 18 using namespace leveldb_env; |
16 using namespace leveldb; | 19 using namespace leveldb; |
17 | 20 |
18 #define FPL FILE_PATH_LITERAL | 21 #define FPL FILE_PATH_LITERAL |
19 | 22 |
20 TEST(ErrorEncoding, OnlyAMethod) { | 23 TEST(ErrorEncoding, OnlyAMethod) { |
(...skipping 26 matching lines...) Expand all Loading... | |
47 const Status s = | 50 const Status s = |
48 MakeIOError("Somefile.txt", "message", in_method, some_errno); | 51 MakeIOError("Somefile.txt", "message", in_method, some_errno); |
49 MethodID method; | 52 MethodID method; |
50 int error; | 53 int error; |
51 EXPECT_EQ(METHOD_AND_ERRNO, | 54 EXPECT_EQ(METHOD_AND_ERRNO, |
52 ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 55 ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
53 EXPECT_EQ(in_method, method); | 56 EXPECT_EQ(in_method, method); |
54 EXPECT_EQ(some_errno, error); | 57 EXPECT_EQ(some_errno, error); |
55 } | 58 } |
56 | 59 |
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 | |
57 TEST(ErrorEncoding, NoEncodedMessage) { | 75 TEST(ErrorEncoding, NoEncodedMessage) { |
58 Status s = Status::IOError("Some message", "from leveldb itself"); | 76 Status s = Status::IOError("Some message", "from leveldb itself"); |
59 MethodID method = kRandomAccessFileRead; | 77 MethodID method = kRandomAccessFileRead; |
60 int error = 4; | 78 int error = 4; |
61 EXPECT_EQ(NONE, ParseMethodAndError(s.ToString().c_str(), &method, &error)); | 79 EXPECT_EQ(NONE, ParseMethodAndError(s.ToString().c_str(), &method, &error)); |
62 EXPECT_EQ(kRandomAccessFileRead, method); | 80 EXPECT_EQ(kRandomAccessFileRead, method); |
63 EXPECT_EQ(4, error); | 81 EXPECT_EQ(4, error); |
64 } | 82 } |
65 | 83 |
66 class MyEnv : public ChromiumEnv { | 84 template <typename T> |
85 class MyEnv : public T { | |
67 public: | 86 public: |
68 MyEnv() : directory_syncs_(0) {} | 87 MyEnv() : directory_syncs_(0) {} |
69 int directory_syncs() { return directory_syncs_; } | 88 int directory_syncs() { return directory_syncs_; } |
70 | 89 |
71 protected: | 90 protected: |
72 virtual void DidSyncDir(const std::string& fname) { | 91 virtual void DidSyncDir(const std::string& fname) { |
73 ++directory_syncs_; | 92 ++directory_syncs_; |
74 ChromiumEnv::DidSyncDir(fname); | 93 ChromiumEnv::DidSyncDir(fname); |
75 } | 94 } |
76 | 95 |
77 private: | 96 private: |
78 int directory_syncs_; | 97 int directory_syncs_; |
79 }; | 98 }; |
80 | 99 |
81 TEST(ChromiumEnv, DirectorySyncing) { | 100 template <typename T> |
82 MyEnv env; | 101 class ChromiumEnvMultiPlatformTests : public ::testing::Test { |
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) { | |
dgrogan
2014/01/07 01:38:41
Why not do the rest of the tests in this file as T
cmumford
2014/01/07 18:43:38
Not strictly necessary as this was the only explic
| |
113 MyEnv<TypeParam> env; | |
114 | |
83 base::ScopedTempDir dir; | 115 base::ScopedTempDir dir; |
84 dir.CreateUniqueTempDir(); | 116 dir.CreateUniqueTempDir(); |
85 base::FilePath dir_path = dir.path(); | 117 base::FilePath dir_path = dir.path(); |
86 std::string some_data = "some data"; | 118 std::string some_data = "some data"; |
87 Slice data = some_data; | 119 Slice data = some_data; |
88 | 120 |
89 std::string manifest_file_name = | 121 std::string manifest_file_name = |
90 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("MANIFEST-001"))); | 122 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("MANIFEST-001"))); |
91 WritableFile* manifest_file_ptr; | 123 WritableFile* manifest_file_ptr; |
92 Status s = env.NewWritableFile(manifest_file_name, &manifest_file_ptr); | 124 Status s = env.NewWritableFile(manifest_file_name, &manifest_file_ptr); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 EXPECT_TRUE(status.ok()); | 249 EXPECT_TRUE(status.ok()); |
218 EXPECT_EQ(1, result.size()); | 250 EXPECT_EQ(1, result.size()); |
219 | 251 |
220 // And a second time should also return one result | 252 // And a second time should also return one result |
221 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); | 253 status = env->GetChildren(dir.AsUTF8Unsafe(), &result); |
222 EXPECT_TRUE(status.ok()); | 254 EXPECT_TRUE(status.ok()); |
223 EXPECT_EQ(1, result.size()); | 255 EXPECT_EQ(1, result.size()); |
224 } | 256 } |
225 | 257 |
226 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 |