aboutsummaryrefslogtreecommitdiffstats
path: root/test/mock/libpthread_mock.hpp
blob: 61ce43ce9392879db23d3a695417d9c887ddcd76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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