• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2012 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_NET_MOCK_SOCKETS_H_
18 #define SHILL_NET_MOCK_SOCKETS_H_
19 
20 #include <string>
21 
22 #include "shill/net/sockets.h"
23 
24 #include <base/macros.h>
25 #include <gmock/gmock.h>
26 
27 namespace shill {
28 
29 class MockSockets : public Sockets {
30  public:
MockSockets()31   MockSockets() {}
~MockSockets()32   ~MockSockets() override {}
33 
34   MOCK_CONST_METHOD3(Accept, int(int sockfd, struct sockaddr* addr,
35                                  socklen_t* addrlen));
36   MOCK_CONST_METHOD2(AttachFilter, int(int sockfd, struct sock_fprog* pf));
37   MOCK_CONST_METHOD3(Bind, int(int sockfd, const struct sockaddr* addr,
38                                socklen_t addrlen));
39   MOCK_CONST_METHOD2(BindToDevice, int(int sockfd, const std::string& device));
40   MOCK_CONST_METHOD1(ReuseAddress, int(int sockfd));
41   MOCK_CONST_METHOD2(AddMulticastMembership, int(int sockfd, in_addr_t addr));
42   MOCK_CONST_METHOD1(Close, int(int fd));
43   MOCK_CONST_METHOD3(Connect, int(int sockfd, const struct sockaddr* addr,
44                                   socklen_t addrlen));
45   MOCK_CONST_METHOD0(Error, int());
46   MOCK_CONST_METHOD3(GetSockName, int(int sockfd, struct sockaddr* addr,
47                                       socklen_t* addrlen));
48   MOCK_CONST_METHOD1(GetSocketError, int(int fd));
49   MOCK_CONST_METHOD3(Ioctl, int(int d, int request, void* argp));
50   MOCK_CONST_METHOD2(Listen, int(int d, int backlog));
51   MOCK_CONST_METHOD6(RecvFrom, ssize_t(int sockfd,
52                                        void* buf,
53                                        size_t len,
54                                        int flags,
55                                        struct sockaddr* src_addr,
56                                        socklen_t* addrlen));
57   MOCK_CONST_METHOD5(Select, int(int nfds,
58                                  fd_set* readfds,
59                                  fd_set* writefds,
60                                  fd_set* exceptfds,
61                                  struct timeval* timeout));
62   MOCK_CONST_METHOD4(Send, ssize_t(int sockfd, const void* buf, size_t len,
63                                    int flags));
64   MOCK_CONST_METHOD6(SendTo, ssize_t(int sockfd,
65                                      const void* buf,
66                                      size_t len,
67                                      int flags,
68                                      const struct sockaddr* dest_addr,
69                                      socklen_t addrlen));
70   MOCK_CONST_METHOD1(SetNonBlocking, int(int sockfd));
71   MOCK_CONST_METHOD2(SetReceiveBuffer, int(int sockfd, int size));
72   MOCK_CONST_METHOD2(ShutDown, int(int sockfd, int how));
73   MOCK_CONST_METHOD3(Socket, int(int domain, int type, int protocol));
74 
75  private:
76   DISALLOW_COPY_AND_ASSIGN(MockSockets);
77 };
78 
79 }  // namespace shill
80 
81 #endif  // SHILL_NET_MOCK_SOCKETS_H_
82