diff options
author | Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> | 2022-07-21 07:14:31 +0900 |
---|---|---|
committer | Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> | 2022-08-05 00:35:12 +0900 |
commit | b0ed05f610e4bf70eae7929163e1ac8794bd15b0 (patch) | |
tree | fa0d21d6fec4e8b6c0393776afbabdb592e78c41 /test/mock | |
parent | eb7fddaec547c4c9d47cee77bd5419d34ab5f1df (diff) |
Update test case
Ths patch update tase case
Bug-AGL: SPEC-4500
Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Change-Id: I27b4a537d522198f5f180ce22fb7f0af95b3ddb8
Diffstat (limited to 'test/mock')
-rw-r--r-- | test/mock/memory_mock.hpp | 53 | ||||
-rw-r--r-- | test/mock/syscall_io_mock.hpp | 14 |
2 files changed, 66 insertions, 1 deletions
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 <gmock/gmock.h> +#include <functional> + +#include <stdlib.h> + +/* +void *malloc(size_t size); +void free(void *ptr); +*/ +static std::function<void*(size_t size)> _malloc; +static std::function<void(void *ptr)> _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 <sys/socket.h> #include <sys/types.h> #include <sys/stat.h> +#include <stdio.h> /* int open(const char *pathname, int flags); @@ -28,10 +29,11 @@ static std::function<int(int)> _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<int(const char *)> _unlink; static std::function<int(const char *pathname, struct stat *buf)> _stat; - +static std::function<int(const char *oldpath, const char *newpath)> _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); |