diff options
author | Terry Wang <tytytyww@google.com> | 2020-10-28 01:36:03 -0700 |
---|---|---|
committer | Terry Wang <tytytyww@google.com> | 2020-10-28 01:36:03 -0700 |
commit | 71b8eddc99c6337ff304a2f3cd0588c42239202f (patch) | |
tree | 7c54063a7f10e35a282cdfd4cafd369696672fbe /icing/legacy | |
parent | 5abfe5bcac00f4f188d3d8041fa97bf77206b577 (diff) | |
download | icing-71b8eddc99c6337ff304a2f3cd0588c42239202f.tar.gz |
Pull upstream changes.
Change-Id: I73ea5f80ccf16a02519f6f7ccfc993e9b0f39f86
Diffstat (limited to 'icing/legacy')
-rw-r--r-- | icing/legacy/index/icing-mock-filesystem.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/icing/legacy/index/icing-mock-filesystem.h b/icing/legacy/index/icing-mock-filesystem.h index 5a064ea..75ac62f 100644 --- a/icing/legacy/index/icing-mock-filesystem.h +++ b/icing/legacy/index/icing-mock-filesystem.h @@ -28,9 +28,143 @@ namespace icing { namespace lib { +using ::testing::_; +using ::testing::A; class IcingMockFilesystem : public IcingFilesystem { public: + IcingMockFilesystem() { + ON_CALL(*this, DeleteFile).WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.DeleteFile(file_name); + }); + + ON_CALL(*this, DeleteDirectory).WillByDefault([this](const char *dir_name) { + return real_icing_filesystem_.DeleteDirectory(dir_name); + }); + + ON_CALL(*this, DeleteDirectoryRecursively) + .WillByDefault([this](const char *dir_name) { + return real_icing_filesystem_.DeleteDirectoryRecursively(dir_name); + }); + + ON_CALL(*this, FileExists).WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.FileExists(file_name); + }); + + ON_CALL(*this, DirectoryExists).WillByDefault([this](const char *dir_name) { + return real_icing_filesystem_.DirectoryExists(dir_name); + }); + + ON_CALL(*this, GetBasenameIndex) + .WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.GetBasenameIndex(file_name); + }); + + ON_CALL(*this, GetBasename).WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.GetBasename(file_name); + }); + + ON_CALL(*this, GetDirname).WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.GetDirname(file_name); + }); + + ON_CALL(*this, ListDirectory) + .WillByDefault( + [this](const char *dir_name, std::vector<std::string> *entries) { + return real_icing_filesystem_.ListDirectory(dir_name, entries); + }); + + ON_CALL(*this, GetMatchingFiles) + .WillByDefault( + [this](const char *glob, std::vector<std::string> *matches) { + return real_icing_filesystem_.GetMatchingFiles(glob, matches); + }); + + ON_CALL(*this, OpenForWrite).WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.OpenForWrite(file_name); + }); + + ON_CALL(*this, OpenForAppend).WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.OpenForAppend(file_name); + }); + + ON_CALL(*this, OpenForRead).WillByDefault([this](const char *file_name) { + return real_icing_filesystem_.OpenForRead(file_name); + }); + + ON_CALL(*this, GetFileSize(A<int>())).WillByDefault([this](int fd) { + return real_icing_filesystem_.GetFileSize(fd); + }); + + ON_CALL(*this, GetFileSize(A<const char *>())) + .WillByDefault([this](const char *filename) { + return real_icing_filesystem_.GetFileSize(filename); + }); + + ON_CALL(*this, Truncate(A<int>(), _)) + .WillByDefault([this](int fd, uint64_t new_size) { + return real_icing_filesystem_.Truncate(fd, new_size); + }); + + ON_CALL(*this, Truncate(A<const char *>(), _)) + .WillByDefault([this](const char *filename, uint64_t new_size) { + return real_icing_filesystem_.Truncate(filename, new_size); + }); + + ON_CALL(*this, Grow).WillByDefault([this](int fd, uint64_t new_size) { + return real_icing_filesystem_.Grow(fd, new_size); + }); + + ON_CALL(*this, Write) + .WillByDefault([this](int fd, const void *data, size_t data_size) { + return real_icing_filesystem_.Write(fd, data, data_size); + }); + ON_CALL(*this, PWrite) + .WillByDefault( + [this](int fd, off_t offset, const void *data, size_t data_size) { + return real_icing_filesystem_.PWrite(fd, offset, data, data_size); + }); + + ON_CALL(*this, DataSync).WillByDefault([this](int fd) { + return real_icing_filesystem_.DataSync(fd); + }); + + ON_CALL(*this, RenameFile) + .WillByDefault([this](const char *old_name, const char *new_name) { + return real_icing_filesystem_.RenameFile(old_name, new_name); + }); + + ON_CALL(*this, SwapFiles) + .WillByDefault([this](const char *one, const char *two) { + return real_icing_filesystem_.SwapFiles(one, two); + }); + + ON_CALL(*this, CreateDirectory).WillByDefault([this](const char *dir_name) { + return real_icing_filesystem_.CreateDirectory(dir_name); + }); + + ON_CALL(*this, CreateDirectoryRecursively) + .WillByDefault([this](const char *dir_name) { + return real_icing_filesystem_.CreateDirectoryRecursively(dir_name); + }); + + ON_CALL(*this, CopyFile) + .WillByDefault([this](const char *src, const char *dst) { + return real_icing_filesystem_.CopyFile(src, dst); + }); + + ON_CALL(*this, ComputeChecksum) + .WillByDefault([this](int fd, uint32_t *checksum, uint64_t offset, + uint64_t length) { + return real_icing_filesystem_.ComputeChecksum(fd, checksum, offset, + length); + }); + + ON_CALL(*this, GetDiskUsage).WillByDefault([this](const char *path) { + return real_icing_filesystem_.GetDiskUsage(path); + }); + } + MOCK_METHOD(bool, DeleteFile, (const char *file_name), (const, override)); MOCK_METHOD(bool, DeleteDirectory, (const char *dir_name), (const, override)); @@ -103,6 +237,9 @@ class IcingMockFilesystem : public IcingFilesystem { (const, override)); MOCK_METHOD(uint64_t, GetDiskUsage, (const char *path), (const, override)); + + private: + IcingFilesystem real_icing_filesystem_; }; } // namespace lib |