aboutsummaryrefslogtreecommitdiffstats
path: root/test/mock
diff options
context:
space:
mode:
Diffstat (limited to 'test/mock')
-rw-r--r--test/mock/memory_mock.hpp53
-rw-r--r--test/mock/syscall_io_mock.hpp14
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);