Classes | Macros | Functions | Variables
test_socket.cpp File Reference
#include "xmlrpcpp/XmlRpcUtil.h"
#include "xmlrpcpp/XmlRpcSocket.h"
#include "test_system_mocks.h"
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <netdb.h>
#include <stdarg.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <deque>
#include <gtest/gtest.h>
Include dependency graph for test_socket.cpp:

Go to the source code of this file.

Classes

struct  expected_read
 
struct  expected_write
 
class  XmlRpcConnectTest
 
class  XmlRpcSocketTest
 

Macros

#define FOR_ERRNO(itr, var, ...)
 
#define TEST_READ(RES, ERR)
 
#define TEST_WRITE(RES, ERR)
 

Functions

void EXPECT_SOCKADDR_EQ (const sockaddr *addr1, const sockaddr *addr2)
 
int main (int argc, char **argv)
 
ssize_t mock_read (int fd, void *buf, size_t count)
 
ssize_t mock_write (int fd, const void *buf, size_t count)
 
bool operator== (const in6_addr a, const in6_addr b)
 
int test_accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 
int test_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 
int test_close (int fd)
 
int test_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 
 TEST_F (XmlRpcSocketTest, TestMocks)
 
 TEST_F (XmlRpcSocketTest, socket)
 
 TEST_F (XmlRpcSocketTest, close)
 
 TEST_F (XmlRpcSocketTest, setNonBlocking)
 
 TEST_F (XmlRpcSocketTest, nbRead)
 
 TEST_F (XmlRpcSocketTest, nbRead_EINTR)
 
 TEST_F (XmlRpcSocketTest, nbWrite)
 
 TEST_F (XmlRpcSocketTest, setReuseAddr)
 
 TEST_F (XmlRpcSocketTest, bind)
 
 TEST_F (XmlRpcSocketTest, get_port)
 
 TEST_F (XmlRpcSocketTest, listen)
 
 TEST_F (XmlRpcSocketTest, accept)
 
 TEST_F (XmlRpcConnectTest, connect_ipv4)
 
 TEST_F (XmlRpcConnectTest, connect_ipv6)
 
 TEST_F (XmlRpcConnectTest, connect_lookup_fail)
 
 TEST_F (XmlRpcConnectTest, connect_multiple_result)
 
 TEST_F (XmlRpcConnectTest, connect_failure)
 
int test_fcntl (int fd, int cmd, unsigned long arg)
 
void test_freeaddrinfo (struct addrinfo *res)
 
int test_getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
 
int test_getsockname (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 
int test_listen (int sockfd, int backlog)
 
 TEST_READ (TRUE, EAGAIN)
 
 TEST_READ (TRUE, EWOULDBLOCK)
 
 TEST_READ (FALSE, EBADF)
 
 TEST_READ (FALSE, EFAULT)
 
 TEST_READ (FALSE, EINVAL)
 
 TEST_READ (FALSE, EIO)
 
 TEST_READ (FALSE, EISDIR)
 
 TEST_READ (FALSE, EACCES)
 
 TEST_READ (FALSE, ECONNREFUSED)
 
 TEST_READ (FALSE, ENOMEM)
 
 TEST_READ (FALSE, ENOTCONN)
 
int test_setsockopt (int sockfd, int level, int optname, const void *optval, socklen_t optlen)
 
int test_socket (int domain, int type, int protocol)
 
 TEST_WRITE (TRUE, EAGAIN)
 
 TEST_WRITE (TRUE, EWOULDBLOCK)
 
 TEST_WRITE (TRUE, EINTR)
 
 TEST_WRITE (FALSE, EBADF)
 
 TEST_WRITE (FALSE, EDESTADDRREQ)
 
 TEST_WRITE (FALSE, EDQUOT)
 
 TEST_WRITE (FALSE, EFAULT)
 
 TEST_WRITE (FALSE, EFBIG)
 
 TEST_WRITE (FALSE, EINVAL)
 
 TEST_WRITE (FALSE, EIO)
 
 TEST_WRITE (FALSE, ENOSPC)
 
 TEST_WRITE (FALSE, EPIPE)
 
 TEST_WRITE (FALSE, EACCES)
 
 TEST_WRITE (FALSE, ECONNRESET)
 
 TEST_WRITE (FALSE, EISCONN)
 
 TEST_WRITE (FALSE, ENOBUFS)
 
 TEST_WRITE (FALSE, ENOMEM)
 
 TEST_WRITE (FALSE, ENOTCONN)
 

Variables

void * accept_addr = 0
 
socklen_t accept_addrlen = 0
 
int accept_errno = 0
 
int accept_ret = 0
 
int accept_sockfd = 0
 
int bind_errno = 0
 
int bind_family = 0
 
int bind_port = 0
 
int bind_ret = 0
 
int bind_sockfd = 0
 
int close_errno = 0
 
int close_fd = 0
 
int close_ret = 0
 
const struct sockaddr * connect_addr = 0
 
socklen_t connect_addrlen = 0
 
int connect_errno = 0
 
int connect_ret = 0
 
int connect_sockfd = 0
 
std::deque< expected_readexpected_reads
 
std::deque< expected_writeexpected_writes
 
unsigned long fcntl_arg = 0
 
int fcntl_cmd = 0
 
int fcntl_errno = 0
 
int fcntl_fd = 0
 
int fcntl_ret = 0
 
struct addrinfo * freeaddrinfo_res = 0
 
int getaddrinfo_errno = 0
 
struct addrinfo getaddrinfo_hints
 
const char * getaddrinfo_node = 0
 
struct addrinfo * getaddrinfo_res = 0
 
int getaddrinfo_ret = 0
 
const char * getaddrinfo_service = 0
 
void * getsockname_addr = 0
 
int getsockname_errno = 0
 
socklen_t getsockname_len = 0
 
int getsockname_ret = 0
 
int getsockname_sockfd = 0
 
int listen_backlog = 0
 
int listen_errno = 0
 
int listen_ret = 0
 
int listen_sockfd = 0
 
int setsockopt_errno = 0
 
int setsockopt_ret = 0
 
int setsockopt_sockfd = 0
 
int socket_domain = 0
 
int socket_errno = 0
 
int socket_protocol = 0
 
int socket_ret = 0
 
int socket_type = 0
 

Macro Definition Documentation

#define FOR_ERRNO (   itr,
  var,
  ... 
)
Value:
int var[] = {__VA_ARGS__}; \
for (size_t itr = 0; itr < sizeof(var) / sizeof(int); itr++)

Definition at line 42 of file test_socket.cpp.

#define TEST_READ (   RES,
  ERR 
)
Value:
TEST_F(XmlRpcSocketTest, nbRead_##ERR) { \
fake_read = mock_read; \
bool eof = false; \
std::string data_out; \
\
expected_reads.push_back(expected_read(7, ERR)); \
\
EXPECT_##RES(XmlRpcSocket::nbRead(7, data_out, &eof)); \
EXPECT_EQ("", data_out); \
EXPECT_FALSE(eof); \
EXPECT_EQ(1, read_calls); \
EXPECT_EQ(ERR, XmlRpcSocket::getError()); \
EXPECT_EQ(0u, expected_reads.size()); \
expected_reads.clear(); \
}
TEST_F(XmlRpcSocketTest, TestMocks)
Definition: test_socket.cpp:80
std::deque< expected_read > expected_reads
ssize_t mock_read(int fd, void *buf, size_t count)

Definition at line 376 of file test_socket.cpp.

#define TEST_WRITE (   RES,
  ERR 
)
Value:
TEST_F(XmlRpcSocketTest, nbWrite_##ERR) { \
fake_write = mock_write; \
int count = 0; \
std::string hello = "hello world"; \
errno = 0; \
expected_writes.push_back(expected_write(10, 11, -1, ERR)); \
EXPECT_##RES(XmlRpcSocket::nbWrite(10, hello, &count)); \
EXPECT_EQ(count, 0); \
EXPECT_EQ(ERR, XmlRpcSocket::getError()); \
EXPECT_EQ(0u, expected_writes.size()); \
EXPECT_EQ(1, write_calls); \
expected_writes.clear(); \
}
TEST_F(XmlRpcSocketTest, TestMocks)
Definition: test_socket.cpp:80
std::deque< expected_write > expected_writes
ssize_t mock_write(int fd, const void *buf, size_t count)

Definition at line 546 of file test_socket.cpp.

Function Documentation

void EXPECT_SOCKADDR_EQ ( const sockaddr *  addr1,
const sockaddr *  addr2 
)

Definition at line 942 of file test_socket.cpp.

int main ( int  argc,
char **  argv 
)

Definition at line 1387 of file test_socket.cpp.

ssize_t mock_read ( int  fd,
void *  buf,
size_t  count 
)

Definition at line 313 of file test_socket.cpp.

ssize_t mock_write ( int  fd,
const void *  buf,
size_t  count 
)

Definition at line 475 of file test_socket.cpp.

bool operator== ( const in6_addr  a,
const in6_addr  b 
)

Definition at line 628 of file test_socket.cpp.

int test_accept ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

Definition at line 823 of file test_socket.cpp.

int test_bind ( int  sockfd,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Definition at line 638 of file test_socket.cpp.

int test_close ( int  fd)

Definition at line 224 of file test_socket.cpp.

int test_connect ( int  sockfd,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Definition at line 980 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
TestMocks   
)

Definition at line 80 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
socket   
)

Definition at line 181 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
close   
)

Definition at line 232 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
setNonBlocking   
)

Definition at line 270 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
nbRead   
)

Definition at line 355 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
nbRead_EINTR   
)

Definition at line 401 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
nbWrite   
)

Definition at line 505 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
setReuseAddr   
)

Definition at line 600 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
bind   
)

Definition at line 665 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
get_port   
)

Definition at line 735 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
listen   
)

Definition at line 799 of file test_socket.cpp.

TEST_F ( XmlRpcSocketTest  ,
accept   
)

Definition at line 844 of file test_socket.cpp.

TEST_F ( XmlRpcConnectTest  ,
connect_ipv4   
)

Definition at line 1165 of file test_socket.cpp.

TEST_F ( XmlRpcConnectTest  ,
connect_ipv6   
)

Definition at line 1203 of file test_socket.cpp.

TEST_F ( XmlRpcConnectTest  ,
connect_lookup_fail   
)

Definition at line 1233 of file test_socket.cpp.

TEST_F ( XmlRpcConnectTest  ,
connect_multiple_result   
)

Definition at line 1317 of file test_socket.cpp.

TEST_F ( XmlRpcConnectTest  ,
connect_failure   
)

Definition at line 1320 of file test_socket.cpp.

int test_fcntl ( int  fd,
int  cmd,
unsigned long  arg 
)

Definition at line 260 of file test_socket.cpp.

void test_freeaddrinfo ( struct addrinfo *  res)

Definition at line 933 of file test_socket.cpp.

int test_getaddrinfo ( const char *  node,
const char *  service,
const struct addrinfo *  hints,
struct addrinfo **  res 
)

Definition at line 908 of file test_socket.cpp.

int test_getsockname ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

Definition at line 715 of file test_socket.cpp.

int test_listen ( int  sockfd,
int  backlog 
)

Definition at line 791 of file test_socket.cpp.

TEST_READ ( TRUE  ,
EAGAIN   
)
TEST_READ ( TRUE  ,
EWOULDBLOCK   
)
TEST_READ ( FALSE  ,
EBADF   
)
TEST_READ ( FALSE  ,
EFAULT   
)
TEST_READ ( FALSE  ,
EINVAL   
)
TEST_READ ( FALSE  ,
EIO   
)
TEST_READ ( FALSE  ,
EISDIR   
)
TEST_READ ( FALSE  ,
EACCES   
)
TEST_READ ( FALSE  ,
ECONNREFUSED   
)
TEST_READ ( FALSE  ,
ENOMEM   
)
TEST_READ ( FALSE  ,
ENOTCONN   
)
int test_setsockopt ( int  sockfd,
int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)

Definition at line 583 of file test_socket.cpp.

int test_socket ( int  domain,
int  type,
int  protocol 
)

Definition at line 171 of file test_socket.cpp.

TEST_WRITE ( TRUE  ,
EAGAIN   
)
TEST_WRITE ( TRUE  ,
EWOULDBLOCK   
)
TEST_WRITE ( TRUE  ,
EINTR   
)
TEST_WRITE ( FALSE  ,
EBADF   
)
TEST_WRITE ( FALSE  ,
EDESTADDRREQ   
)
TEST_WRITE ( FALSE  ,
EDQUOT   
)
TEST_WRITE ( FALSE  ,
EFAULT   
)
TEST_WRITE ( FALSE  ,
EFBIG   
)
TEST_WRITE ( FALSE  ,
EINVAL   
)
TEST_WRITE ( FALSE  ,
EIO   
)
TEST_WRITE ( FALSE  ,
ENOSPC   
)
TEST_WRITE ( FALSE  ,
EPIPE   
)
TEST_WRITE ( FALSE  ,
EACCES   
)
TEST_WRITE ( FALSE  ,
ECONNRESET   
)
TEST_WRITE ( FALSE  ,
EISCONN   
)
TEST_WRITE ( FALSE  ,
ENOBUFS   
)
TEST_WRITE ( FALSE  ,
ENOMEM   
)
TEST_WRITE ( FALSE  ,
ENOTCONN   
)

Variable Documentation

void* accept_addr = 0

Definition at line 821 of file test_socket.cpp.

socklen_t accept_addrlen = 0

Definition at line 822 of file test_socket.cpp.

int accept_errno = 0

Definition at line 819 of file test_socket.cpp.

int accept_ret = 0

Definition at line 818 of file test_socket.cpp.

int accept_sockfd = 0

Definition at line 820 of file test_socket.cpp.

int bind_errno = 0

Definition at line 634 of file test_socket.cpp.

int bind_family = 0

Definition at line 636 of file test_socket.cpp.

int bind_port = 0

Definition at line 637 of file test_socket.cpp.

int bind_ret = 0

Definition at line 633 of file test_socket.cpp.

int bind_sockfd = 0

Definition at line 635 of file test_socket.cpp.

int close_errno = 0

Definition at line 222 of file test_socket.cpp.

int close_fd = 0

Definition at line 221 of file test_socket.cpp.

int close_ret = 0

Definition at line 223 of file test_socket.cpp.

const struct sockaddr* connect_addr = 0

Definition at line 978 of file test_socket.cpp.

socklen_t connect_addrlen = 0

Definition at line 979 of file test_socket.cpp.

int connect_errno = 0

Definition at line 976 of file test_socket.cpp.

int connect_ret = 0

Definition at line 975 of file test_socket.cpp.

int connect_sockfd = 0

Definition at line 977 of file test_socket.cpp.

std::deque<expected_read> expected_reads

Definition at line 311 of file test_socket.cpp.

std::deque<expected_write> expected_writes

Definition at line 473 of file test_socket.cpp.

unsigned long fcntl_arg = 0

Definition at line 257 of file test_socket.cpp.

int fcntl_cmd = 0

Definition at line 256 of file test_socket.cpp.

int fcntl_errno = 0

Definition at line 258 of file test_socket.cpp.

int fcntl_fd = 0

Definition at line 255 of file test_socket.cpp.

int fcntl_ret = 0

Definition at line 259 of file test_socket.cpp.

struct addrinfo* freeaddrinfo_res = 0

Definition at line 932 of file test_socket.cpp.

int getaddrinfo_errno = 0

Definition at line 896 of file test_socket.cpp.

struct addrinfo getaddrinfo_hints
Initial value:
= {.ai_flags = 0,
.ai_family = 0,
.ai_socktype = 0,
.ai_protocol = 0,
.ai_addrlen = 0,
.ai_addr = 0,
.ai_canonname = 0,
.ai_next = 0}

Definition at line 899 of file test_socket.cpp.

const char* getaddrinfo_node = 0

Definition at line 897 of file test_socket.cpp.

struct addrinfo* getaddrinfo_res = 0

Definition at line 907 of file test_socket.cpp.

int getaddrinfo_ret = 0

Definition at line 895 of file test_socket.cpp.

const char* getaddrinfo_service = 0

Definition at line 898 of file test_socket.cpp.

void* getsockname_addr = 0

Definition at line 713 of file test_socket.cpp.

int getsockname_errno = 0

Definition at line 711 of file test_socket.cpp.

socklen_t getsockname_len = 0

Definition at line 714 of file test_socket.cpp.

int getsockname_ret = 0

Definition at line 710 of file test_socket.cpp.

int getsockname_sockfd = 0

Definition at line 712 of file test_socket.cpp.

int listen_backlog = 0

Definition at line 790 of file test_socket.cpp.

int listen_errno = 0

Definition at line 788 of file test_socket.cpp.

int listen_ret = 0

Definition at line 787 of file test_socket.cpp.

int listen_sockfd = 0

Definition at line 789 of file test_socket.cpp.

int setsockopt_errno = 0

Definition at line 581 of file test_socket.cpp.

int setsockopt_ret = 0

Definition at line 580 of file test_socket.cpp.

int setsockopt_sockfd = 0

Definition at line 582 of file test_socket.cpp.

int socket_domain = 0

Definition at line 168 of file test_socket.cpp.

int socket_errno = 0

Definition at line 167 of file test_socket.cpp.

int socket_protocol = 0

Definition at line 170 of file test_socket.cpp.

int socket_ret = 0

Definition at line 166 of file test_socket.cpp.

int socket_type = 0

Definition at line 169 of file test_socket.cpp.



xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix
autogenerated on Sun Feb 3 2019 03:29:51