aboutsummaryrefslogtreecommitdiffstats
path: root/test/mock/libpthread_mock.hpp
diff options
context:
space:
mode:
authorNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2022-07-04 07:23:53 +0900
committerNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2022-07-30 23:42:18 +0900
commite8a05c6f1ac288a8cfa5b0837313fec8fb7aadaf (patch)
tree4f43e3521ea2384f7298a6f00406aab631f44cde /test/mock/libpthread_mock.hpp
parente5f52b7e2305019651fe4b6351d3466638af3488 (diff)
Add test case for librefop
The librefop aim to 100% code coverage testing. This patch add test case with mock to aim to that criteria. Bug-AGL: SPEC-4500 Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> Change-Id: I4bf14d343b9fca784fb7bc3ee6d3e53691a5ea4e
Diffstat (limited to 'test/mock/libpthread_mock.hpp')
-rw-r--r--test/mock/libpthread_mock.hpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/mock/libpthread_mock.hpp b/test/mock/libpthread_mock.hpp
new file mode 100644
index 0000000..61ce43c
--- /dev/null
+++ b/test/mock/libpthread_mock.hpp
@@ -0,0 +1,93 @@
+#include <gmock/gmock.h>
+#include <functional>
+
+#include <signal.h>
+
+/*
+int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset);
+*/
+static std::function<int(int how, const sigset_t *set, sigset_t *oldset)> _pthread_sigmask;
+
+/*
+int pthread_mutex_lock(pthread_mutex_t *mutex);
+int pthread_mutex_trylock(pthread_mutex_t *mutex);
+int pthread_mutex_unlock(pthread_mutex_t *mutex);
+
+static std::function<int(pthread_mutex_t *mutex)> _pthread_mutex_lock;
+static std::function<int(pthread_mutex_t *mutex)> _pthread_mutex_trylock;
+static std::function<int(pthread_mutex_t *mutex)> _pthread_mutex_unlock;
+*/
+
+class LibpthreadMocker {
+public:
+ LibpthreadMocker() {
+ _pthread_sigmask = [this](int how, const sigset_t *set, sigset_t *oldset)
+ {
+ return pthread_sigmask(how, set, oldset);
+ };
+
+/*
+ _pthread_mutex_lock = [this](pthread_mutex_t *mutex)
+ {
+ return pthread_mutex_lock(mutex);
+ };
+ _pthread_mutex_trylock = [this](pthread_mutex_t *mutex)
+ {
+ return pthread_mutex_trylock(mutex);
+ };
+ _pthread_mutex_unlock = [this](pthread_mutex_t *mutex)
+ {
+ return pthread_mutex_unlock(mutex);
+ };
+*/
+ }
+
+ ~LibpthreadMocker() {
+ _pthread_sigmask = {};
+
+/*
+ _pthread_mutex_lock = {};
+ _pthread_mutex_trylock = {};
+ _pthread_mutex_unlock = {};
+*/
+ }
+
+ MOCK_CONST_METHOD3(pthread_sigmask, int(int how, const sigset_t *set, sigset_t *oldset));
+/*
+ MOCK_CONST_METHOD1(pthread_mutex_lock, int(pthread_mutex_t *mutex));
+ MOCK_CONST_METHOD1(pthread_mutex_trylock, int(pthread_mutex_t *mutex));
+ MOCK_CONST_METHOD1(pthread_mutex_unlock, int(pthread_mutex_t *mutex));
+*/
+};
+
+class LibpthreadMockBase {
+protected:
+ LibpthreadMocker lpm;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset)
+{
+ return _pthread_sigmask(how, set, oldset);
+}
+
+/*
+static int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+ return _pthread_mutex_lock(mutex);
+}
+static int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+ return _pthread_mutex_trylock(mutex);
+}
+static int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+ return _pthread_mutex_unlock(mutex);
+}
+*/
+#ifdef __cplusplus
+}
+#endif