aboutsummaryrefslogtreecommitdiffstats
path: root/test/mock/syscall_io_mock.hpp
diff options
context:
space:
mode:
authorNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2022-07-20 08:13:43 +0900
committerNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2022-08-02 01:01:32 +0900
commita34f8913fbe3fc82ed32754ec6976d1a6f7904e6 (patch)
tree6ab53895bc2d62f983dff89ad2ba189b52ffc5b5 /test/mock/syscall_io_mock.hpp
parent0ca708eae20ba675458c29124f771c8f29dd12a7 (diff)
Update test case for file operations
This patch add test case for file operations into source tree. Bug-AGL: SPEC-4500 Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> Change-Id: I37c3fb3f2c0260a844cb6d6ea984cc6c868cee1b
Diffstat (limited to 'test/mock/syscall_io_mock.hpp')
-rw-r--r--test/mock/syscall_io_mock.hpp54
1 files changed, 45 insertions, 9 deletions
diff --git a/test/mock/syscall_io_mock.hpp b/test/mock/syscall_io_mock.hpp
index 75efdb1..61e1840 100644
--- a/test/mock/syscall_io_mock.hpp
+++ b/test/mock/syscall_io_mock.hpp
@@ -7,6 +7,11 @@
#include <sys/stat.h>
/*
+int open(const char *pathname, int flags);
+int open(const char *pathname, int flags, mode_t mode);
+*/
+static std::function<int(const char *pathname, int flags)> _open;
+/*
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
int close(int fd);
@@ -16,6 +21,11 @@ static std::function<ssize_t(int fd, const void *buf, size_t count)> _write;
static std::function<int(int)> _close;
/*
+int fsync(int fd);
+*/
+static std::function<int(int)> _fsync;
+
+/*
int unlink(const char *pathname);
int stat(const char *pathname, struct stat *buf);
*/
@@ -39,6 +49,10 @@ static std::function<int(int sockfd, struct sockaddr *addr,
class SyscallIOMocker {
public:
SyscallIOMocker() {
+ _open = [this](const char *pathname, int flags) {
+ return open(pathname, flags);
+ };
+
_read = [this](int fd, void *buf, size_t count) {
return read(fd, buf, count);
};
@@ -49,6 +63,10 @@ public:
return close(fd);
};
+ _fsync = [this](int fd){
+ return fsync(fd);
+ };
+
_unlink = [this](const char *pathname){
return unlink(pathname);
};
@@ -72,10 +90,14 @@ public:
}
~SyscallIOMocker() {
+ _open = {};
+
_read = {};
_write = {};
_close = {};
+ _fsync = {};
+
_unlink = {};
_stat = {};
@@ -85,10 +107,14 @@ public:
_accept4 = {};
}
+ MOCK_CONST_METHOD2(open, int(const char *pathname, int flags));
+
MOCK_CONST_METHOD3(read, ssize_t(int fd, void *buf, size_t count));
MOCK_CONST_METHOD3(write, ssize_t(int fd, const void *buf, size_t count));
MOCK_CONST_METHOD1(close, int(int));
+ MOCK_CONST_METHOD1(fsync, int(int));
+
MOCK_CONST_METHOD1(unlink, int(const char *));
MOCK_CONST_METHOD2(stat, int(const char *pathname, struct stat *buf));
@@ -106,47 +132,57 @@ protected:
#ifdef __cplusplus
extern "C" {
#endif
-ssize_t read(int fd, void *buf, size_t count)
+static int open(const char *pathname, int flags, ...)
+{
+ return _open(pathname, flags);
+}
+
+static ssize_t read(int fd, void *buf, size_t count)
{
return _read(fd, buf, count);
}
-ssize_t write(int fd, const void *buf, size_t count)
+static ssize_t write(int fd, const void *buf, size_t count)
{
return _write(fd, buf, count);
}
-int close(int fd)
+static int close(int fd)
{
return _close(fd);
}
-int unlink(const char *pathname)
+static int fsync(int fd)
+{
+ return _fsync(fd);
+}
+
+static int unlink(const char *pathname)
{
return _unlink(pathname);
}
-int stat(const char *pathname, struct stat *buf)
+static int stat(const char *pathname, struct stat *buf)
{
return _stat(pathname, buf);
}
-int socket(int socket_family, int socket_type, int protocol)
+static int socket(int socket_family, int socket_type, int protocol)
{
return _socket(socket_family, socket_type, protocol);
}
-int bind(int sockfd, const struct sockaddr *addr,socklen_t addrlen)
+static int bind(int sockfd, const struct sockaddr *addr,socklen_t addrlen)
{
return _bind(sockfd, addr, addrlen);
}
-int listen(int sockfd, int backlog)
+static int listen(int sockfd, int backlog)
{
return _listen(sockfd, backlog);
}
-int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
+static int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
{
return _accept4(sockfd, addr, addrlen, flags);
}