From b0ed05f610e4bf70eae7929163e1ac8794bd15b0 Mon Sep 17 00:00:00 2001 From: Naoto Yamaguchi Date: Thu, 21 Jul 2022 07:14:31 +0900 Subject: Update test case Ths patch update tase case Bug-AGL: SPEC-4500 Signed-off-by: Naoto Yamaguchi Change-Id: I27b4a537d522198f5f180ce22fb7f0af95b3ddb8 --- test/mock/memory_mock.hpp | 53 +++++++++++++++++++++++++++++++++++++++++++ test/mock/syscall_io_mock.hpp | 14 +++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/mock/memory_mock.hpp (limited to 'test/mock') diff --git a/test/mock/memory_mock.hpp b/test/mock/memory_mock.hpp new file mode 100644 index 0000000..e140840 --- /dev/null +++ b/test/mock/memory_mock.hpp @@ -0,0 +1,53 @@ +#include +#include + +#include + +/* +void *malloc(size_t size); +void free(void *ptr); +*/ +static std::function _malloc; +static std::function _free; + +class MemoryMocker { +public: + MemoryMocker() { + _malloc = [this](size_t size) { + return malloc(size); + }; + _free = [this](void *ptr) { + return free(ptr); + }; + } + + ~MemoryMocker() { + _malloc = {}; + _free = {}; + } + + MOCK_CONST_METHOD1(malloc, void*(size_t)); + MOCK_CONST_METHOD1(free, void(void *)); +}; + +class MemoryMockBase { +protected: + MemoryMocker memorym; +}; + +#ifdef __cplusplus +extern "C" { +#endif +static void* unittest_malloc(size_t size) +{ + return _malloc(size); +} +/* +static void free(void *ptr) +{ + _free(ptr); +} +*/ +#ifdef __cplusplus +} +#endif diff --git a/test/mock/syscall_io_mock.hpp b/test/mock/syscall_io_mock.hpp index 61e1840..6eb021a 100644 --- a/test/mock/syscall_io_mock.hpp +++ b/test/mock/syscall_io_mock.hpp @@ -5,6 +5,7 @@ #include #include #include +#include /* int open(const char *pathname, int flags); @@ -28,10 +29,11 @@ static std::function _fsync; /* int unlink(const char *pathname); int stat(const char *pathname, struct stat *buf); +int rename(const char *oldpath, const char *newpath); */ static std::function _unlink; static std::function _stat; - +static std::function _rename; /* int socket(int socket_family, int socket_type, int protocol); @@ -73,6 +75,9 @@ public: _stat = [this](const char *pathname, struct stat *buf) { return stat(pathname, buf); }; + _rename = [this](const char *oldpath, const char *newpath){ + return rename(oldpath, newpath); + }; _socket = [this](int socket_family, int socket_type, int protocol){ return socket(socket_family, socket_type, protocol); @@ -100,6 +105,7 @@ public: _unlink = {}; _stat = {}; + _rename = {}; _socket = {}; _bind = {}; @@ -117,6 +123,7 @@ public: MOCK_CONST_METHOD1(unlink, int(const char *)); MOCK_CONST_METHOD2(stat, int(const char *pathname, struct stat *buf)); + MOCK_CONST_METHOD2(rename, int(const char *oldpath, const char *newpath)); MOCK_CONST_METHOD3(socket, int(int socket_family, int socket_type, int protocol)); MOCK_CONST_METHOD3(bind, int(int sockfd, const struct sockaddr *addr,socklen_t addrlen)); @@ -167,6 +174,11 @@ static int stat(const char *pathname, struct stat *buf) return _stat(pathname, buf); } +static int rename(const char *oldpath, const char *newpath) +{ + return _rename(oldpath, newpath); +} + static int socket(int socket_family, int socket_type, int protocol) { return _socket(socket_family, socket_type, protocol); -- cgit