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