From 6da534792b9b395ed493ed039a87118737ca54a6 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sun, 16 Nov 2014 01:55:06 +0100 Subject: [PATCH] Added gmock and written a simple test case for FuseOpenFileListTest --- src/test/fspp/impl/FuseOpenFileListTest.cpp | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/fspp/impl/FuseOpenFileListTest.cpp diff --git a/src/test/fspp/impl/FuseOpenFileListTest.cpp b/src/test/fspp/impl/FuseOpenFileListTest.cpp new file mode 100644 index 00000000..6e0a2e01 --- /dev/null +++ b/src/test/fspp/impl/FuseOpenFileListTest.cpp @@ -0,0 +1,49 @@ +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "fspp/impl/FuseOpenFileList.h" + +using std::unique_ptr; +using std::make_unique; + +using namespace fspp; + +class MyOpenFile: public OpenFile { +public: + MyOpenFile(int fileid_, int flags_) :fileid(fileid_), flags(flags_) {} + ~MyOpenFile() {} + int fileid; + int flags; + + void stat(struct ::stat *) const override {} + void truncate(off_t) const override {} + int read(void *, size_t, off_t) override {return 0;} + void write(const void *, size_t, off_t) override {} + void fsync() override {} + void fdatasync() override {} +}; + +class MyFile: public File { +public: + MyFile(int id_): id(id_) {} + int id; + + unique_ptr open(int flags) const override { + return make_unique(id, flags); + } + + void truncate(off_t) const override {} + void unlink() override {} + void stat(struct ::stat *) const override {} + void access(int) const override {} + void rename(const boost::filesystem::path &) override {} + void utimens(const timespec[2]) override {} +}; + +TEST(FuseOpenFileListTest, Open) { + MyFile file(3); + FuseOpenFileList list; + int id = list.open(file, 4); + EXPECT_EQ(3, dynamic_cast(list.get(id))->fileid); + EXPECT_EQ(4, dynamic_cast(list.get(id))->flags); +}