cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / third_party / leveldatabase / env_chromium_unittest.cc
blob0789b3c6337d37fd651840ba9d9e41550c604fad
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
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/files/scoped_temp_dir.h"
7 #include "base/test/test_suite.h"
8 #include "env_chromium.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 using namespace leveldb_env;
12 using namespace leveldb;
14 TEST(ErrorEncoding, OnlyAMethod) {
15 const MethodID in_method = kSequentialFileRead;
16 const Status s = MakeIOError("Somefile.txt", "message", in_method);
17 MethodID method;
18 int error = -75;
19 EXPECT_EQ(METHOD_ONLY,
20 ParseMethodAndError(s.ToString().c_str(), &method, &error));
21 EXPECT_EQ(in_method, method);
22 EXPECT_EQ(-75, error);
25 TEST(ErrorEncoding, PlatformFileError) {
26 const MethodID in_method = kWritableFileClose;
27 const base::PlatformFileError pfe =
28 base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
29 const Status s = MakeIOError("Somefile.txt", "message", in_method, pfe);
30 MethodID method;
31 int error;
32 EXPECT_EQ(METHOD_AND_PFE,
33 ParseMethodAndError(s.ToString().c_str(), &method, &error));
34 EXPECT_EQ(in_method, method);
35 EXPECT_EQ(pfe, error);
38 TEST(ErrorEncoding, Errno) {
39 const MethodID in_method = kWritableFileFlush;
40 const int some_errno = ENOENT;
41 const Status s =
42 MakeIOError("Somefile.txt", "message", in_method, some_errno);
43 MethodID method;
44 int error;
45 EXPECT_EQ(METHOD_AND_ERRNO,
46 ParseMethodAndError(s.ToString().c_str(), &method, &error));
47 EXPECT_EQ(in_method, method);
48 EXPECT_EQ(some_errno, error);
51 TEST(ErrorEncoding, NoEncodedMessage) {
52 Status s = Status::IOError("Some message", "from leveldb itself");
53 MethodID method = kRandomAccessFileRead;
54 int error = 4;
55 EXPECT_EQ(NONE, ParseMethodAndError(s.ToString().c_str(), &method, &error));
56 EXPECT_EQ(kRandomAccessFileRead, method);
57 EXPECT_EQ(4, error);
60 class MyEnv : public ChromiumEnv {
61 public:
62 MyEnv() : directory_syncs_(0) {}
63 int directory_syncs() { return directory_syncs_; }
65 protected:
66 virtual void DidSyncDir(const std::string& fname) {
67 ++directory_syncs_;
68 ChromiumEnv::DidSyncDir(fname);
71 private:
72 int directory_syncs_;
75 TEST(ChromiumEnv, DirectorySyncing) {
76 MyEnv env;
77 base::ScopedTempDir dir;
78 dir.CreateUniqueTempDir();
79 base::FilePath dir_path = dir.path();
80 std::string some_data = "some data";
81 Slice data = some_data;
83 std::string manifest_file_name =
84 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("MANIFEST-001")));
85 WritableFile* manifest_file;
86 Status s = env.NewWritableFile(manifest_file_name, &manifest_file);
87 EXPECT_TRUE(s.ok());
88 manifest_file->Append(data);
89 EXPECT_EQ(0, env.directory_syncs());
90 manifest_file->Append(data);
91 EXPECT_EQ(0, env.directory_syncs());
93 std::string sst_file_name =
94 FilePathToString(dir_path.Append(FILE_PATH_LITERAL("000003.sst")));
95 WritableFile* sst_file;
96 s = env.NewWritableFile(sst_file_name, &sst_file);
97 EXPECT_TRUE(s.ok());
98 sst_file->Append(data);
99 EXPECT_EQ(0, env.directory_syncs());
101 manifest_file->Append(data);
102 EXPECT_EQ(1, env.directory_syncs());
103 manifest_file->Append(data);
104 EXPECT_EQ(1, env.directory_syncs());
107 int main(int argc, char** argv) { return base::TestSuite(argc, argv).Run(); }