1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_MOCK_SYSTEM_FUNC_H
17 #define OHOS_MOCK_SYSTEM_FUNC_H
18 
19 #include <gmock/gmock.h>
20 #include <dlfcn.h>
21 #include <sys/socket.h>
22 #include <sys/time.h>
23 #include <sys/types.h>
24 #include <unistd.h>
25 
26 using ::testing::_;
27 using ::testing::Return;
28 
29 namespace OHOS {
30 namespace DHCP {
31 class MockSystemFunc {
32 public:
33     MOCK_METHOD2(open, int(const char *__file, int __oflag));
34     MOCK_METHOD1(close, int(int));
35     MOCK_METHOD3(write, ssize_t(int fd, const void *buf, size_t count));
36     MOCK_METHOD3(read, ssize_t(int fd, void *buf, size_t count));
37     MOCK_METHOD3(socket, int(int __domain, int __type, int __protocol));
38     MOCK_METHOD5(setsockopt, int(int __fd, int __level, int __optname, const void *__optval, socklen_t __optlen));
39     MOCK_METHOD3(ioctl, int(int __fd, unsigned long __request, struct sockaddr *__ifreq));
40     MOCK_METHOD3(bind, int(int __fd, const struct sockaddr *__addr, socklen_t __len));
41     MOCK_METHOD2(listen, int(int __fd, int __n));
42     MOCK_METHOD3(connect, int(int __fd, const struct sockaddr *__addr, socklen_t __len));
43     MOCK_METHOD5(select, int(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout));
44     MOCK_METHOD6(sendto, ssize_t(int fd, const void *buf, size_t count, int flags, const struct sockaddr *addr,
45         socklen_t len));
46     MOCK_METHOD4(socketpair, int(int address, int type, int protocol, int *socket));
47 
48     static MockSystemFunc &GetInstance(void);
49     static void SetMockFlag(bool flag);
50     static bool GetMockFlag(void);
51 
52 private:
53     MockSystemFunc();
~MockSystemFunc()54     ~MockSystemFunc()
55     {}
56 };
57 }  // namespace DHCP
58 }  // namespace OHOS
59 #endif
60