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 17 #ifndef OHOS_DHCP_SYSTEM_FUNC_MOCK_H 18 #define OHOS_DHCP_SYSTEM_FUNC_MOCK_H 19 20 #include <gmock/gmock.h> 21 #include <cstdint> 22 #include <dlfcn.h> 23 #include <unistd.h> 24 25 using socklen_t = unsigned int; 26 using ::testing::_; 27 using ::testing::Return; 28 namespace OHOS { 29 namespace DHCP { 30 class SystemFuncMock { 31 public: 32 MOCK_METHOD2(open, int(const char *__file, int __oflag)); 33 MOCK_METHOD1(close, int(int)); 34 MOCK_METHOD3(write, ssize_t(int fd, const void *buf, size_t count)); 35 MOCK_METHOD3(read, ssize_t(int fd, void *buf, size_t count)); 36 MOCK_METHOD3(socket, int(int __domain, int __type, int __protocol)); 37 MOCK_METHOD5(setsockopt, int(int __fd, int __level, int __optname, const void *__optval, socklen_t __optlen)); 38 MOCK_METHOD3(ioctl, int(int __fd, unsigned long __request, struct sockaddr *__ifreq)); 39 MOCK_METHOD3(bind, int(int __fd, const struct sockaddr *__addr, socklen_t __len)); 40 MOCK_METHOD2(listen, int(int __fd, int __n)); 41 MOCK_METHOD3(connect, int(int __fd, const struct sockaddr *__addr, socklen_t __len)); 42 MOCK_METHOD5(select, int(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)); 43 MOCK_METHOD6(sendto, ssize_t(int __fd, const void *__buf, size_t __n, int __flags, struct sockaddr *__addr, 44 socklen_t __addr_len)); 45 MOCK_METHOD6(recvfrom, ssize_t(int __fd, void *__buf, size_t __n, int __flags, struct sockaddr *__addr, 46 socklen_t *__addr_len)); 47 MOCK_METHOD0(vfork, pid_t(void)); 48 MOCK_METHOD2(execv, int(const char *__path, char *const *__argv)); 49 MOCK_METHOD1(_exit, void(int status)); 50 MOCK_METHOD3(waitpid, pid_t(pid_t pid, int *status, int options)); 51 MOCK_METHOD2(kill, int(pid_t pid, int sig)); 52 53 static SystemFuncMock &GetInstance(void); 54 static void SetMockFlag(bool flag); 55 static bool GetMockFlag(void); 56 private: 57 SystemFuncMock(); 58 ~SystemFuncMock(); 59 }; 60 } // namespace DHCP 61 } // namespace OHOS 62 #endif 63