From cd8dab491d3f78124be800252186a32a90c884b8 Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Tue, 15 Jan 2019 19:57:38 -0800 Subject: stop installing manager header Stop installing the manager header as it is no longer meant to be exported, but rather used only internally within this repository. Change-Id: I2ab21a31fd745e1b3e36fc39ffea5e26d373ff51 Signed-off-by: Patrick Venture --- Makefile.am | 5 +- blobs-ipmid/manager.hpp | 275 ---------------------------------- blobs-ipmid/test/blob_mock.hpp | 29 ---- blobs-ipmid/test/manager_mock.hpp | 44 ------ example/example.cpp | 1 - ipmi.hpp | 3 +- main.cpp | 2 +- manager.cpp | 3 +- manager.hpp | 275 ++++++++++++++++++++++++++++++++++ process.hpp | 2 +- test/blob_mock.hpp | 29 ++++ test/ipmi_close_unittest.cpp | 2 +- test/ipmi_commit_unittest.cpp | 2 +- test/ipmi_delete_unittest.cpp | 2 +- test/ipmi_enumerate_unittest.cpp | 2 +- test/ipmi_getcount_unittest.cpp | 2 +- test/ipmi_open_unittest.cpp | 2 +- test/ipmi_read_unittest.cpp | 2 +- test/ipmi_sessionstat_unittest.cpp | 2 +- test/ipmi_stat_unittest.cpp | 2 +- test/ipmi_validate_unittest.cpp | 2 +- test/ipmi_write_unittest.cpp | 2 +- test/ipmi_writemeta_unittest.cpp | 2 +- test/manager_close_unittest.cpp | 4 +- test/manager_commit_unittest.cpp | 5 +- test/manager_delete_unittest.cpp | 4 +- test/manager_getsession_unittest.cpp | 2 +- test/manager_mock.hpp | 45 ++++++ test/manager_open_unittest.cpp | 5 +- test/manager_read_unittest.cpp | 5 +- test/manager_sessionstat_unittest.cpp | 4 +- test/manager_stat_unittest.cpp | 4 +- test/manager_unittest.cpp | 5 +- test/manager_write_unittest.cpp | 4 +- test/manager_writemeta_unittest.cpp | 4 +- test/process_unittest.cpp | 2 +- test/utils_unittest.cpp | 4 +- utils.cpp | 2 +- utils.hpp | 2 +- 39 files changed, 398 insertions(+), 395 deletions(-) delete mode 100644 blobs-ipmid/manager.hpp delete mode 100644 blobs-ipmid/test/blob_mock.hpp delete mode 100644 blobs-ipmid/test/manager_mock.hpp create mode 100644 manager.hpp create mode 100644 test/blob_mock.hpp create mode 100644 test/manager_mock.hpp diff --git a/Makefile.am b/Makefile.am index ddca382..1008449 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,10 +27,7 @@ libblobcmds_la_CXXFLAGS = \ -flto nobase_include_HEADERS = \ - blobs-ipmid/blobs.hpp \ - blobs-ipmid/manager.hpp \ - blobs-ipmid/test/blob_mock.hpp \ - blobs-ipmid/test/manager_mock.hpp + blobs-ipmid/blobs.hpp # Install the blob handlers in ipmid-providers so you can leverage # meta-phosphor/blob/master/classes/obmc-phosphor-ipmiprovider-symlink.bbclass diff --git a/blobs-ipmid/manager.hpp b/blobs-ipmid/manager.hpp deleted file mode 100644 index d7282e6..0000000 --- a/blobs-ipmid/manager.hpp +++ /dev/null @@ -1,275 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace blobs -{ - -struct SessionInfo -{ - SessionInfo() = default; - SessionInfo(const std::string& path, GenericBlobInterface* handler, - uint16_t flags) : - blobId(path), - handler(handler), flags(flags) - { - } - ~SessionInfo() = default; - - std::string blobId; - GenericBlobInterface* handler; - uint16_t flags; -}; - -class ManagerInterface -{ - public: - virtual ~ManagerInterface() = default; - - virtual bool - registerHandler(std::unique_ptr handler) = 0; - - virtual uint32_t buildBlobList() = 0; - - virtual std::string getBlobId(uint32_t index) = 0; - - virtual bool open(uint16_t flags, const std::string& path, - uint16_t* session) = 0; - - virtual bool stat(const std::string& path, struct BlobMeta* meta) = 0; - - virtual bool stat(uint16_t session, struct BlobMeta* meta) = 0; - - virtual bool commit(uint16_t session, const std::vector& data) = 0; - - virtual bool close(uint16_t session) = 0; - - virtual std::vector read(uint16_t session, uint32_t offset, - uint32_t requestedSize) = 0; - - virtual bool write(uint16_t session, uint32_t offset, - const std::vector& data) = 0; - - virtual bool deleteBlob(const std::string& path) = 0; - - virtual bool writeMeta(uint16_t session, uint32_t offset, - const std::vector& data) = 0; -}; - -/** - * Blob Manager used to store handlers and sessions. - */ -class BlobManager : public ManagerInterface -{ - public: - BlobManager() - { - next = static_cast(std::time(nullptr)); - }; - - ~BlobManager() = default; - /* delete copy constructor & assignment operator, only support move - * operations. - */ - BlobManager(const BlobManager&) = delete; - BlobManager& operator=(const BlobManager&) = delete; - BlobManager(BlobManager&&) = default; - BlobManager& operator=(BlobManager&&) = default; - - /** - * Register a handler. We own the pointer. - * - * @param[in] handler - a pointer to a blob handler. - * @return bool - true if registered. - */ - bool - registerHandler(std::unique_ptr handler) override; - - /** - * Builds the blobId list for enumeration. - * - * @return lowest value returned is 0, otherwise the number of - * blobIds. - */ - uint32_t buildBlobList() override; - - /** - * Grabs the blobId for the indexed blobId. - * - * @param[in] index - the index into the blobId cache. - * @return string - the blobId or empty string on failure. - */ - std::string getBlobId(uint32_t index) override; - - /** - * Attempts to open the file specified and associates with a session. - * - * @param[in] flags - the flags to pass to open. - * @param[in] path - the file path to open. - * @param[in,out] session - pointer to store the session on success. - * @return bool - true if able to open. - */ - bool open(uint16_t flags, const std::string& path, - uint16_t* session) override; - - /** - * Attempts to retrieve a BlobMeta for the specified path. - * - * @param[in] path - the file path for stat(). - * @param[in,out] meta - a pointer to store the metadata. - * @return bool - true if able to retrieve the information. - */ - bool stat(const std::string& path, struct BlobMeta* meta) override; - - /** - * Attempts to retrieve a BlobMeta for a given session. - * - * @param[in] session - the session for this command. - * @param[in,out] meta - a pointer to store the metadata. - * @return bool - true if able to retrieve the information. - */ - bool stat(uint16_t session, struct BlobMeta* meta) override; - - /** - * Attempt to commit a blob for a given session. - * - * @param[in] session - the session for this command. - * @param[in] data - an optional commit blob. - * @return bool - true if the commit succeeds. - */ - bool commit(uint16_t session, const std::vector& data) override; - - /** - * Attempt to close a session. If the handler returns a failure - * in closing, the session is kept open. - * - * @param[in] session - the session for this command. - * @return bool - true if the session was closed. - */ - bool close(uint16_t session) override; - - /** - * Attempt to read bytes from the blob. If there's a failure, such as - * an invalid offset it'll just return 0 bytes. - * - * @param[in] session - the session for this command. - * @param[in] offset - the offset from which to read. - * @param[in] requestedSize - the number of bytes to try and read. - * @return the bytes read. - */ - std::vector read(uint16_t session, uint32_t offset, - uint32_t requestedSize) override; - - /** - * Attempt to write to a blob. The manager does not track whether - * the session opened the file for writing. - * - * @param[in] session - the session for this command. - * @param[in] offset - the offset into the blob to write. - * @param[in] data - the bytes to write to the blob. - * @return bool - true if the write succeeded. - */ - bool write(uint16_t session, uint32_t offset, - const std::vector& data) override; - - /** - * Attempt to delete a blobId. This method will just call the - * handler, which will return failure if the blob doesn't support - * deletion. This command will also fail if there are any open - * sessions against the specific blob. - * - * In the case where they specify a folder, such as /blob/skm where - * the "real" blobIds are /blob/skm/1, or /blob/skm/2, the manager - * may see there are on open sessions to that specific path and will - * call the handler. In this case, the handler is responsible for - * handling any checks or logic. - * - * @param[in] path - the blobId path. - * @return bool - true if delete was successful. - */ - bool deleteBlob(const std::string& path) override; - - /** - * Attempt to write Metadata to a blob. - * - * @param[in] session - the session for this command. - * @param[in] offset - the offset into the blob to write. - * @param[in] data - the bytes to write to the blob. - * @return bool - true if the write succeeded. - */ - bool writeMeta(uint16_t session, uint32_t offset, - const std::vector& data) override; - - /** - * Attempts to return a valid unique session id. - * - * @param[in,out] - pointer to the session. - * @return bool - true if able to allocate. - */ - bool getSession(uint16_t* session); - - /** - * Given a file path will return first handler to answer that it owns - * it. - * - * @param[in] path - the file path. - * @return pointer to the handler or nullptr if not found. - */ - GenericBlobInterface* getHandler(const std::string& path); - - /** - * Given a session id will return associated handler. - * - * @param[in] session - the session. - * @return pointer to the handler or nullptr if not found. - */ - GenericBlobInterface* getHandler(uint16_t session); - - /** - * Given a session id will return associated metadata, including - * the handler and the flags passed into open. - * - * @param[in] session - the session. - * @return pointer to the information or nullptr if not found. - */ - SessionInfo* getSessionInfo(uint16_t session); - - /** - * Given a session id will return associated path. - * - * @param[in] session - the session. - * @return the path or "" on failure. - */ - std::string getPath(uint16_t session) const; - - private: - void incrementOpen(const std::string& path); - void decrementOpen(const std::string& path); - int getOpen(const std::string& path) const; - - /* The next session ID to use */ - uint16_t next; - /* Temporary list of blobIds used for enumeration. */ - std::vector ids; - /* List of Blob handler. */ - std::vector> handlers; - /* Mapping of session ids to blob handlers and the path used with open. - */ - std::unordered_map sessions; - /* Mapping of open blobIds */ - std::unordered_map openFiles; -}; - -/** - * @brief Gets a handle to the BlobManager. - * - * @return a pointer to the BlobManager instance. - */ -ManagerInterface* getBlobManager(); - -} // namespace blobs diff --git a/blobs-ipmid/test/blob_mock.hpp b/blobs-ipmid/test/blob_mock.hpp deleted file mode 100644 index b70d3d1..0000000 --- a/blobs-ipmid/test/blob_mock.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -#include - -namespace blobs -{ - -class BlobMock : public GenericBlobInterface -{ - public: - virtual ~BlobMock() = default; - - MOCK_METHOD1(canHandleBlob, bool(const std::string&)); - MOCK_METHOD0(getBlobIds, std::vector()); - MOCK_METHOD1(deleteBlob, bool(const std::string&)); - MOCK_METHOD2(stat, bool(const std::string&, struct BlobMeta*)); - MOCK_METHOD3(open, bool(uint16_t, uint16_t, const std::string&)); - MOCK_METHOD3(read, std::vector(uint16_t, uint32_t, uint32_t)); - MOCK_METHOD3(write, bool(uint16_t, uint32_t, const std::vector&)); - MOCK_METHOD3(writeMeta, - bool(uint16_t, uint32_t, const std::vector&)); - MOCK_METHOD2(commit, bool(uint16_t, const std::vector&)); - MOCK_METHOD1(close, bool(uint16_t)); - MOCK_METHOD2(stat, bool(uint16_t, struct BlobMeta*)); - MOCK_METHOD1(expire, bool(uint16_t)); -}; -} // namespace blobs diff --git a/blobs-ipmid/test/manager_mock.hpp b/blobs-ipmid/test/manager_mock.hpp deleted file mode 100644 index 00eeb6b..0000000 --- a/blobs-ipmid/test/manager_mock.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include - -namespace blobs -{ - -class ManagerMock : public ManagerInterface -{ - public: - virtual ~ManagerMock() = default; - - MOCK_METHOD1(registerHandler, bool(std::unique_ptr)); - MOCK_METHOD0(buildBlobList, uint32_t()); - MOCK_METHOD1(getBlobId, std::string(uint32_t)); - MOCK_METHOD3(open, bool(uint16_t, const std::string&, uint16_t*)); - MOCK_METHOD2(stat, bool(const std::string&, struct BlobMeta*)); - MOCK_METHOD2(stat, bool(uint16_t, struct BlobMeta*)); - MOCK_METHOD2(commit, bool(uint16_t, const std::vector&)); - MOCK_METHOD1(close, bool(uint16_t)); - MOCK_METHOD3(read, std::vector(uint16_t, uint32_t, uint32_t)); - MOCK_METHOD3(write, bool(uint16_t, uint32_t, const std::vector&)); - MOCK_METHOD1(deleteBlob, bool(const std::string&)); - MOCK_METHOD3(writeMeta, - bool(uint16_t, uint32_t, const std::vector&)); -}; - -/* - * Provide a one-off implementation for now. - * To test this, set managerReturned as you need. - */ -ManagerInterface* managerReturned; - -ManagerInterface* getBlobManager() -{ - return managerReturned; -} - -} // namespace blobs diff --git a/example/example.cpp b/example/example.cpp index cc36e88..dd7c486 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -1,7 +1,6 @@ #include "example/example.hpp" #include -#include #include #include #include diff --git a/ipmi.hpp b/ipmi.hpp index a09d347..93bc953 100644 --- a/ipmi.hpp +++ b/ipmi.hpp @@ -1,8 +1,9 @@ #pragma once +#include "manager.hpp" + #include -#include #include namespace blobs diff --git a/main.cpp b/main.cpp index bc93ddd..dd755e6 100644 --- a/main.cpp +++ b/main.cpp @@ -17,12 +17,12 @@ #include "config.h" #include "ipmi.hpp" +#include "manager.hpp" #include "process.hpp" #include "utils.hpp" #include -#include #include #include #include diff --git a/manager.cpp b/manager.cpp index bc96b34..712d7db 100644 --- a/manager.cpp +++ b/manager.cpp @@ -14,8 +14,9 @@ * limitations under the License. */ +#include "manager.hpp" + #include -#include #include #include #include diff --git a/manager.hpp b/manager.hpp new file mode 100644 index 0000000..d7282e6 --- /dev/null +++ b/manager.hpp @@ -0,0 +1,275 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace blobs +{ + +struct SessionInfo +{ + SessionInfo() = default; + SessionInfo(const std::string& path, GenericBlobInterface* handler, + uint16_t flags) : + blobId(path), + handler(handler), flags(flags) + { + } + ~SessionInfo() = default; + + std::string blobId; + GenericBlobInterface* handler; + uint16_t flags; +}; + +class ManagerInterface +{ + public: + virtual ~ManagerInterface() = default; + + virtual bool + registerHandler(std::unique_ptr handler) = 0; + + virtual uint32_t buildBlobList() = 0; + + virtual std::string getBlobId(uint32_t index) = 0; + + virtual bool open(uint16_t flags, const std::string& path, + uint16_t* session) = 0; + + virtual bool stat(const std::string& path, struct BlobMeta* meta) = 0; + + virtual bool stat(uint16_t session, struct BlobMeta* meta) = 0; + + virtual bool commit(uint16_t session, const std::vector& data) = 0; + + virtual bool close(uint16_t session) = 0; + + virtual std::vector read(uint16_t session, uint32_t offset, + uint32_t requestedSize) = 0; + + virtual bool write(uint16_t session, uint32_t offset, + const std::vector& data) = 0; + + virtual bool deleteBlob(const std::string& path) = 0; + + virtual bool writeMeta(uint16_t session, uint32_t offset, + const std::vector& data) = 0; +}; + +/** + * Blob Manager used to store handlers and sessions. + */ +class BlobManager : public ManagerInterface +{ + public: + BlobManager() + { + next = static_cast(std::time(nullptr)); + }; + + ~BlobManager() = default; + /* delete copy constructor & assignment operator, only support move + * operations. + */ + BlobManager(const BlobManager&) = delete; + BlobManager& operator=(const BlobManager&) = delete; + BlobManager(BlobManager&&) = default; + BlobManager& operator=(BlobManager&&) = default; + + /** + * Register a handler. We own the pointer. + * + * @param[in] handler - a pointer to a blob handler. + * @return bool - true if registered. + */ + bool + registerHandler(std::unique_ptr handler) override; + + /** + * Builds the blobId list for enumeration. + * + * @return lowest value returned is 0, otherwise the number of + * blobIds. + */ + uint32_t buildBlobList() override; + + /** + * Grabs the blobId for the indexed blobId. + * + * @param[in] index - the index into the blobId cache. + * @return string - the blobId or empty string on failure. + */ + std::string getBlobId(uint32_t index) override; + + /** + * Attempts to open the file specified and associates with a session. + * + * @param[in] flags - the flags to pass to open. + * @param[in] path - the file path to open. + * @param[in,out] session - pointer to store the session on success. + * @return bool - true if able to open. + */ + bool open(uint16_t flags, const std::string& path, + uint16_t* session) override; + + /** + * Attempts to retrieve a BlobMeta for the specified path. + * + * @param[in] path - the file path for stat(). + * @param[in,out] meta - a pointer to store the metadata. + * @return bool - true if able to retrieve the information. + */ + bool stat(const std::string& path, struct BlobMeta* meta) override; + + /** + * Attempts to retrieve a BlobMeta for a given session. + * + * @param[in] session - the session for this command. + * @param[in,out] meta - a pointer to store the metadata. + * @return bool - true if able to retrieve the information. + */ + bool stat(uint16_t session, struct BlobMeta* meta) override; + + /** + * Attempt to commit a blob for a given session. + * + * @param[in] session - the session for this command. + * @param[in] data - an optional commit blob. + * @return bool - true if the commit succeeds. + */ + bool commit(uint16_t session, const std::vector& data) override; + + /** + * Attempt to close a session. If the handler returns a failure + * in closing, the session is kept open. + * + * @param[in] session - the session for this command. + * @return bool - true if the session was closed. + */ + bool close(uint16_t session) override; + + /** + * Attempt to read bytes from the blob. If there's a failure, such as + * an invalid offset it'll just return 0 bytes. + * + * @param[in] session - the session for this command. + * @param[in] offset - the offset from which to read. + * @param[in] requestedSize - the number of bytes to try and read. + * @return the bytes read. + */ + std::vector read(uint16_t session, uint32_t offset, + uint32_t requestedSize) override; + + /** + * Attempt to write to a blob. The manager does not track whether + * the session opened the file for writing. + * + * @param[in] session - the session for this command. + * @param[in] offset - the offset into the blob to write. + * @param[in] data - the bytes to write to the blob. + * @return bool - true if the write succeeded. + */ + bool write(uint16_t session, uint32_t offset, + const std::vector& data) override; + + /** + * Attempt to delete a blobId. This method will just call the + * handler, which will return failure if the blob doesn't support + * deletion. This command will also fail if there are any open + * sessions against the specific blob. + * + * In the case where they specify a folder, such as /blob/skm where + * the "real" blobIds are /blob/skm/1, or /blob/skm/2, the manager + * may see there are on open sessions to that specific path and will + * call the handler. In this case, the handler is responsible for + * handling any checks or logic. + * + * @param[in] path - the blobId path. + * @return bool - true if delete was successful. + */ + bool deleteBlob(const std::string& path) override; + + /** + * Attempt to write Metadata to a blob. + * + * @param[in] session - the session for this command. + * @param[in] offset - the offset into the blob to write. + * @param[in] data - the bytes to write to the blob. + * @return bool - true if the write succeeded. + */ + bool writeMeta(uint16_t session, uint32_t offset, + const std::vector& data) override; + + /** + * Attempts to return a valid unique session id. + * + * @param[in,out] - pointer to the session. + * @return bool - true if able to allocate. + */ + bool getSession(uint16_t* session); + + /** + * Given a file path will return first handler to answer that it owns + * it. + * + * @param[in] path - the file path. + * @return pointer to the handler or nullptr if not found. + */ + GenericBlobInterface* getHandler(const std::string& path); + + /** + * Given a session id will return associated handler. + * + * @param[in] session - the session. + * @return pointer to the handler or nullptr if not found. + */ + GenericBlobInterface* getHandler(uint16_t session); + + /** + * Given a session id will return associated metadata, including + * the handler and the flags passed into open. + * + * @param[in] session - the session. + * @return pointer to the information or nullptr if not found. + */ + SessionInfo* getSessionInfo(uint16_t session); + + /** + * Given a session id will return associated path. + * + * @param[in] session - the session. + * @return the path or "" on failure. + */ + std::string getPath(uint16_t session) const; + + private: + void incrementOpen(const std::string& path); + void decrementOpen(const std::string& path); + int getOpen(const std::string& path) const; + + /* The next session ID to use */ + uint16_t next; + /* Temporary list of blobIds used for enumeration. */ + std::vector ids; + /* List of Blob handler. */ + std::vector> handlers; + /* Mapping of session ids to blob handlers and the path used with open. + */ + std::unordered_map sessions; + /* Mapping of open blobIds */ + std::unordered_map openFiles; +}; + +/** + * @brief Gets a handle to the BlobManager. + * + * @return a pointer to the BlobManager instance. + */ +ManagerInterface* getBlobManager(); + +} // namespace blobs diff --git a/process.hpp b/process.hpp index 0e377bc..af19b22 100644 --- a/process.hpp +++ b/process.hpp @@ -1,10 +1,10 @@ #pragma once #include "crc.hpp" +#include "manager.hpp" #include -#include #include namespace blobs diff --git a/test/blob_mock.hpp b/test/blob_mock.hpp new file mode 100644 index 0000000..b70d3d1 --- /dev/null +++ b/test/blob_mock.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include + +namespace blobs +{ + +class BlobMock : public GenericBlobInterface +{ + public: + virtual ~BlobMock() = default; + + MOCK_METHOD1(canHandleBlob, bool(const std::string&)); + MOCK_METHOD0(getBlobIds, std::vector()); + MOCK_METHOD1(deleteBlob, bool(const std::string&)); + MOCK_METHOD2(stat, bool(const std::string&, struct BlobMeta*)); + MOCK_METHOD3(open, bool(uint16_t, uint16_t, const std::string&)); + MOCK_METHOD3(read, std::vector(uint16_t, uint32_t, uint32_t)); + MOCK_METHOD3(write, bool(uint16_t, uint32_t, const std::vector&)); + MOCK_METHOD3(writeMeta, + bool(uint16_t, uint32_t, const std::vector&)); + MOCK_METHOD2(commit, bool(uint16_t, const std::vector&)); + MOCK_METHOD1(close, bool(uint16_t)); + MOCK_METHOD2(stat, bool(uint16_t, struct BlobMeta*)); + MOCK_METHOD1(expire, bool(uint16_t)); +}; +} // namespace blobs diff --git a/test/ipmi_close_unittest.cpp b/test/ipmi_close_unittest.cpp index edfddca..2fa22b2 100644 --- a/test/ipmi_close_unittest.cpp +++ b/test/ipmi_close_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_commit_unittest.cpp b/test/ipmi_commit_unittest.cpp index 30f78bf..85bd8f3 100644 --- a/test/ipmi_commit_unittest.cpp +++ b/test/ipmi_commit_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_delete_unittest.cpp b/test/ipmi_delete_unittest.cpp index 6985eb1..9145fe3 100644 --- a/test/ipmi_delete_unittest.cpp +++ b/test/ipmi_delete_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_enumerate_unittest.cpp b/test/ipmi_enumerate_unittest.cpp index 184c686..3be56ba 100644 --- a/test/ipmi_enumerate_unittest.cpp +++ b/test/ipmi_enumerate_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_getcount_unittest.cpp b/test/ipmi_getcount_unittest.cpp index 267ae43..c6d74e6 100644 --- a/test/ipmi_getcount_unittest.cpp +++ b/test/ipmi_getcount_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_open_unittest.cpp b/test/ipmi_open_unittest.cpp index 704c144..9079df0 100644 --- a/test/ipmi_open_unittest.cpp +++ b/test/ipmi_open_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_read_unittest.cpp b/test/ipmi_read_unittest.cpp index ef36646..b6dab55 100644 --- a/test/ipmi_read_unittest.cpp +++ b/test/ipmi_read_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_sessionstat_unittest.cpp b/test/ipmi_sessionstat_unittest.cpp index a71252c..1e4005e 100644 --- a/test/ipmi_sessionstat_unittest.cpp +++ b/test/ipmi_sessionstat_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_stat_unittest.cpp b/test/ipmi_stat_unittest.cpp index e7ff277..cbff23d 100644 --- a/test/ipmi_stat_unittest.cpp +++ b/test/ipmi_stat_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_validate_unittest.cpp b/test/ipmi_validate_unittest.cpp index 5a1cbfe..6bf4200 100644 --- a/test/ipmi_validate_unittest.cpp +++ b/test/ipmi_validate_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_write_unittest.cpp b/test/ipmi_write_unittest.cpp index 99615af..a42e266 100644 --- a/test/ipmi_write_unittest.cpp +++ b/test/ipmi_write_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/ipmi_writemeta_unittest.cpp b/test/ipmi_writemeta_unittest.cpp index 2d63452..3542b23 100644 --- a/test/ipmi_writemeta_unittest.cpp +++ b/test/ipmi_writemeta_unittest.cpp @@ -1,6 +1,6 @@ #include "ipmi.hpp" +#include "manager_mock.hpp" -#include #include #include diff --git a/test/manager_close_unittest.cpp b/test/manager_close_unittest.cpp index 02b5dfe..47c9264 100644 --- a/test/manager_close_unittest.cpp +++ b/test/manager_close_unittest.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" #include diff --git a/test/manager_commit_unittest.cpp b/test/manager_commit_unittest.cpp index 48e6b67..b1b3c8c 100644 --- a/test/manager_commit_unittest.cpp +++ b/test/manager_commit_unittest.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" + #include #include diff --git a/test/manager_delete_unittest.cpp b/test/manager_delete_unittest.cpp index e35355d..9ad3afd 100644 --- a/test/manager_delete_unittest.cpp +++ b/test/manager_delete_unittest.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" #include diff --git a/test/manager_getsession_unittest.cpp b/test/manager_getsession_unittest.cpp index 2022146..e66729a 100644 --- a/test/manager_getsession_unittest.cpp +++ b/test/manager_getsession_unittest.cpp @@ -1,4 +1,4 @@ -#include +#include "manager.hpp" #include diff --git a/test/manager_mock.hpp b/test/manager_mock.hpp new file mode 100644 index 0000000..73d4d07 --- /dev/null +++ b/test/manager_mock.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "manager.hpp" + +#include +#include +#include + +#include + +namespace blobs +{ + +class ManagerMock : public ManagerInterface +{ + public: + virtual ~ManagerMock() = default; + + MOCK_METHOD1(registerHandler, bool(std::unique_ptr)); + MOCK_METHOD0(buildBlobList, uint32_t()); + MOCK_METHOD1(getBlobId, std::string(uint32_t)); + MOCK_METHOD3(open, bool(uint16_t, const std::string&, uint16_t*)); + MOCK_METHOD2(stat, bool(const std::string&, struct BlobMeta*)); + MOCK_METHOD2(stat, bool(uint16_t, struct BlobMeta*)); + MOCK_METHOD2(commit, bool(uint16_t, const std::vector&)); + MOCK_METHOD1(close, bool(uint16_t)); + MOCK_METHOD3(read, std::vector(uint16_t, uint32_t, uint32_t)); + MOCK_METHOD3(write, bool(uint16_t, uint32_t, const std::vector&)); + MOCK_METHOD1(deleteBlob, bool(const std::string&)); + MOCK_METHOD3(writeMeta, + bool(uint16_t, uint32_t, const std::vector&)); +}; + +/* + * Provide a one-off implementation for now. + * To test this, set managerReturned as you need. + */ +ManagerInterface* managerReturned; + +ManagerInterface* getBlobManager() +{ + return managerReturned; +} + +} // namespace blobs diff --git a/test/manager_open_unittest.cpp b/test/manager_open_unittest.cpp index 72aff85..309d3f6 100644 --- a/test/manager_open_unittest.cpp +++ b/test/manager_open_unittest.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" + #include #include diff --git a/test/manager_read_unittest.cpp b/test/manager_read_unittest.cpp index 23df9d4..1d40f5d 100644 --- a/test/manager_read_unittest.cpp +++ b/test/manager_read_unittest.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" + #include #include diff --git a/test/manager_sessionstat_unittest.cpp b/test/manager_sessionstat_unittest.cpp index 019d95b..6ae27d3 100644 --- a/test/manager_sessionstat_unittest.cpp +++ b/test/manager_sessionstat_unittest.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" #include diff --git a/test/manager_stat_unittest.cpp b/test/manager_stat_unittest.cpp index 0ae7822..a13a66d 100644 --- a/test/manager_stat_unittest.cpp +++ b/test/manager_stat_unittest.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" #include diff --git a/test/manager_unittest.cpp b/test/manager_unittest.cpp index a4c7a8c..7d4d49e 100644 --- a/test/manager_unittest.cpp +++ b/test/manager_unittest.cpp @@ -1,6 +1,7 @@ +#include "blob_mock.hpp" +#include "manager.hpp" + #include -#include -#include #include #include diff --git a/test/manager_write_unittest.cpp b/test/manager_write_unittest.cpp index 84b3400..33c6d5a 100644 --- a/test/manager_write_unittest.cpp +++ b/test/manager_write_unittest.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" #include diff --git a/test/manager_writemeta_unittest.cpp b/test/manager_writemeta_unittest.cpp index e83c904..919d259 100644 --- a/test/manager_writemeta_unittest.cpp +++ b/test/manager_writemeta_unittest.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "blob_mock.hpp" +#include "manager.hpp" #include diff --git a/test/process_unittest.cpp b/test/process_unittest.cpp index 0f683e5..bd1f886 100644 --- a/test/process_unittest.cpp +++ b/test/process_unittest.cpp @@ -1,9 +1,9 @@ #include "crc.hpp" #include "crc_mock.hpp" #include "ipmi.hpp" +#include "manager_mock.hpp" #include "process.hpp" -#include #include #include diff --git a/test/utils_unittest.cpp b/test/utils_unittest.cpp index 8a0cdca..b986bd8 100644 --- a/test/utils_unittest.cpp +++ b/test/utils_unittest.cpp @@ -1,9 +1,9 @@ +#include "blob_mock.hpp" #include "dlsys_mock.hpp" #include "fs.hpp" +#include "manager_mock.hpp" #include "utils.hpp" -#include -#include #include #include #include diff --git a/utils.cpp b/utils.cpp index 24166ca..e03ec90 100644 --- a/utils.cpp +++ b/utils.cpp @@ -17,10 +17,10 @@ #include "utils.hpp" #include "fs.hpp" +#include "manager.hpp" #include -#include #include #include #include diff --git a/utils.hpp b/utils.hpp index 50d320e..67380cd 100644 --- a/utils.hpp +++ b/utils.hpp @@ -1,8 +1,8 @@ #pragma once #include "internal/sys.hpp" +#include "manager.hpp" -#include #include #include -- cgit v1.2.3