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 (XmlRpcConnectTest, connect_failure)
 
 TEST_F (XmlRpcConnectTest, connect_ipv4)
 
 TEST_F (XmlRpcConnectTest, connect_ipv6)
 
 TEST_F (XmlRpcConnectTest, connect_lookup_fail)
 
 TEST_F (XmlRpcConnectTest, connect_multiple_result)
 
 TEST_F (XmlRpcSocketTest, accept)
 
 TEST_F (XmlRpcSocketTest, bind)
 
 TEST_F (XmlRpcSocketTest, close)
 
 TEST_F (XmlRpcSocketTest, get_port)
 
 TEST_F (XmlRpcSocketTest, listen)
 
 TEST_F (XmlRpcSocketTest, nbRead)
 
 TEST_F (XmlRpcSocketTest, nbRead_EINTR)
 
 TEST_F (XmlRpcSocketTest, nbWrite)
 
 TEST_F (XmlRpcSocketTest, setNonBlocking)
 
 TEST_F (XmlRpcSocketTest, setReuseAddr)
 
 TEST_F (XmlRpcSocketTest, socket)
 
 TEST_F (XmlRpcSocketTest, TestMocks)
 
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 (FALSE, EACCES)
 
 TEST_READ (FALSE, EBADF)
 
 TEST_READ (FALSE, ECONNREFUSED)
 
 TEST_READ (FALSE, EFAULT)
 
 TEST_READ (FALSE, EINVAL)
 
 TEST_READ (FALSE, EIO)
 
 TEST_READ (FALSE, EISDIR)
 
 TEST_READ (FALSE, ENOMEM)
 
 TEST_READ (FALSE, ENOTCONN)
 
 TEST_READ (TRUE, EAGAIN)
 
 TEST_READ (TRUE, EWOULDBLOCK)
 
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 (FALSE, EACCES)
 
 TEST_WRITE (FALSE, EBADF)
 
 TEST_WRITE (FALSE, ECONNRESET)
 
 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, EISCONN)
 
 TEST_WRITE (FALSE, ENOBUFS)
 
 TEST_WRITE (FALSE, ENOMEM)
 
 TEST_WRITE (FALSE, ENOSPC)
 
 TEST_WRITE (FALSE, ENOTCONN)
 
 TEST_WRITE (FALSE, EPIPE)
 
 TEST_WRITE (TRUE, EAGAIN)
 
 TEST_WRITE (TRUE, EINTR)
 
 TEST_WRITE (TRUE, EWOULDBLOCK)
 

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

◆ FOR_ERRNO

#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.

◆ TEST_READ

#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(); \
}

Definition at line 376 of file test_socket.cpp.

◆ TEST_WRITE

#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(); \
}

Definition at line 546 of file test_socket.cpp.

Function Documentation

◆ EXPECT_SOCKADDR_EQ()

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

Definition at line 943 of file test_socket.cpp.

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1388 of file test_socket.cpp.

◆ mock_read()

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

Definition at line 313 of file test_socket.cpp.

◆ mock_write()

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

Definition at line 475 of file test_socket.cpp.

◆ operator==()

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

Definition at line 628 of file test_socket.cpp.

◆ test_accept()

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

Definition at line 824 of file test_socket.cpp.

◆ test_bind()

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

Definition at line 638 of file test_socket.cpp.

◆ test_close()

int test_close ( int  fd)

Definition at line 224 of file test_socket.cpp.

◆ test_connect()

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

Definition at line 981 of file test_socket.cpp.

◆ TEST_F() [1/17]

TEST_F ( XmlRpcConnectTest  ,
connect_failure   
)

Definition at line 1321 of file test_socket.cpp.

◆ TEST_F() [2/17]

TEST_F ( XmlRpcConnectTest  ,
connect_ipv4   
)

Definition at line 1166 of file test_socket.cpp.

◆ TEST_F() [3/17]

TEST_F ( XmlRpcConnectTest  ,
connect_ipv6   
)

Definition at line 1204 of file test_socket.cpp.

◆ TEST_F() [4/17]

TEST_F ( XmlRpcConnectTest  ,
connect_lookup_fail   
)

Definition at line 1234 of file test_socket.cpp.

◆ TEST_F() [5/17]

TEST_F ( XmlRpcConnectTest  ,
connect_multiple_result   
)

Definition at line 1318 of file test_socket.cpp.

◆ TEST_F() [6/17]

TEST_F ( XmlRpcSocketTest  ,
accept   
)

Definition at line 845 of file test_socket.cpp.

◆ TEST_F() [7/17]

TEST_F ( XmlRpcSocketTest  ,
bind   
)

Definition at line 665 of file test_socket.cpp.

◆ TEST_F() [8/17]

TEST_F ( XmlRpcSocketTest  ,
close   
)

Definition at line 232 of file test_socket.cpp.

◆ TEST_F() [9/17]

TEST_F ( XmlRpcSocketTest  ,
get_port   
)

Definition at line 736 of file test_socket.cpp.

◆ TEST_F() [10/17]

TEST_F ( XmlRpcSocketTest  ,
listen   
)

Definition at line 800 of file test_socket.cpp.

◆ TEST_F() [11/17]

TEST_F ( XmlRpcSocketTest  ,
nbRead   
)

Definition at line 355 of file test_socket.cpp.

◆ TEST_F() [12/17]

TEST_F ( XmlRpcSocketTest  ,
nbRead_EINTR   
)

Definition at line 401 of file test_socket.cpp.

◆ TEST_F() [13/17]

TEST_F ( XmlRpcSocketTest  ,
nbWrite   
)

Definition at line 505 of file test_socket.cpp.

◆ TEST_F() [14/17]

TEST_F ( XmlRpcSocketTest  ,
setNonBlocking   
)

Definition at line 270 of file test_socket.cpp.

◆ TEST_F() [15/17]

TEST_F ( XmlRpcSocketTest  ,
setReuseAddr   
)

Definition at line 600 of file test_socket.cpp.

◆ TEST_F() [16/17]

TEST_F ( XmlRpcSocketTest  ,
socket   
)

Definition at line 181 of file test_socket.cpp.

◆ TEST_F() [17/17]

TEST_F ( XmlRpcSocketTest  ,
TestMocks   
)

Definition at line 80 of file test_socket.cpp.

◆ test_fcntl()

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

Definition at line 260 of file test_socket.cpp.

◆ test_freeaddrinfo()

void test_freeaddrinfo ( struct addrinfo *  res)

Definition at line 934 of file test_socket.cpp.

◆ test_getaddrinfo()

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

Definition at line 909 of file test_socket.cpp.

◆ test_getsockname()

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

Definition at line 715 of file test_socket.cpp.

◆ test_listen()

int test_listen ( int  sockfd,
int  backlog 
)

Definition at line 792 of file test_socket.cpp.

◆ TEST_READ() [1/11]

TEST_READ ( FALSE  ,
EACCES   
)

◆ TEST_READ() [2/11]

TEST_READ ( FALSE  ,
EBADF   
)

◆ TEST_READ() [3/11]

TEST_READ ( FALSE  ,
ECONNREFUSED   
)

◆ TEST_READ() [4/11]

TEST_READ ( FALSE  ,
EFAULT   
)

◆ TEST_READ() [5/11]

TEST_READ ( FALSE  ,
EINVAL   
)

◆ TEST_READ() [6/11]

TEST_READ ( FALSE  ,
EIO   
)

◆ TEST_READ() [7/11]

TEST_READ ( FALSE  ,
EISDIR   
)

◆ TEST_READ() [8/11]

TEST_READ ( FALSE  ,
ENOMEM   
)

◆ TEST_READ() [9/11]

TEST_READ ( FALSE  ,
ENOTCONN   
)

◆ TEST_READ() [10/11]

TEST_READ ( TRUE  ,
EAGAIN   
)

◆ TEST_READ() [11/11]

TEST_READ ( TRUE  ,
EWOULDBLOCK   
)

◆ test_setsockopt()

int test_setsockopt ( int  sockfd,
int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)

Definition at line 583 of file test_socket.cpp.

◆ test_socket()

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

Definition at line 171 of file test_socket.cpp.

◆ TEST_WRITE() [1/18]

TEST_WRITE ( FALSE  ,
EACCES   
)

◆ TEST_WRITE() [2/18]

TEST_WRITE ( FALSE  ,
EBADF   
)

◆ TEST_WRITE() [3/18]

TEST_WRITE ( FALSE  ,
ECONNRESET   
)

◆ TEST_WRITE() [4/18]

TEST_WRITE ( FALSE  ,
EDESTADDRREQ   
)

◆ TEST_WRITE() [5/18]

TEST_WRITE ( FALSE  ,
EDQUOT   
)

◆ TEST_WRITE() [6/18]

TEST_WRITE ( FALSE  ,
EFAULT   
)

◆ TEST_WRITE() [7/18]

TEST_WRITE ( FALSE  ,
EFBIG   
)

◆ TEST_WRITE() [8/18]

TEST_WRITE ( FALSE  ,
EINVAL   
)

◆ TEST_WRITE() [9/18]

TEST_WRITE ( FALSE  ,
EIO   
)

◆ TEST_WRITE() [10/18]

TEST_WRITE ( FALSE  ,
EISCONN   
)

◆ TEST_WRITE() [11/18]

TEST_WRITE ( FALSE  ,
ENOBUFS   
)

◆ TEST_WRITE() [12/18]

TEST_WRITE ( FALSE  ,
ENOMEM   
)

◆ TEST_WRITE() [13/18]

TEST_WRITE ( FALSE  ,
ENOSPC   
)

◆ TEST_WRITE() [14/18]

TEST_WRITE ( FALSE  ,
ENOTCONN   
)

◆ TEST_WRITE() [15/18]

TEST_WRITE ( FALSE  ,
EPIPE   
)

◆ TEST_WRITE() [16/18]

TEST_WRITE ( TRUE  ,
EAGAIN   
)

◆ TEST_WRITE() [17/18]

TEST_WRITE ( TRUE  ,
EINTR   
)

◆ TEST_WRITE() [18/18]

TEST_WRITE ( TRUE  ,
EWOULDBLOCK   
)

Variable Documentation

◆ accept_addr

void* accept_addr = 0

Definition at line 822 of file test_socket.cpp.

◆ accept_addrlen

socklen_t accept_addrlen = 0

Definition at line 823 of file test_socket.cpp.

◆ accept_errno

int accept_errno = 0

Definition at line 820 of file test_socket.cpp.

◆ accept_ret

int accept_ret = 0

Definition at line 819 of file test_socket.cpp.

◆ accept_sockfd

int accept_sockfd = 0

Definition at line 821 of file test_socket.cpp.

◆ bind_errno

int bind_errno = 0

Definition at line 634 of file test_socket.cpp.

◆ bind_family

int bind_family = 0

Definition at line 636 of file test_socket.cpp.

◆ bind_port

int bind_port = 0

Definition at line 637 of file test_socket.cpp.

◆ bind_ret

int bind_ret = 0

Definition at line 633 of file test_socket.cpp.

◆ bind_sockfd

int bind_sockfd = 0

Definition at line 635 of file test_socket.cpp.

◆ close_errno

int close_errno = 0

Definition at line 222 of file test_socket.cpp.

◆ close_fd

int close_fd = 0

Definition at line 221 of file test_socket.cpp.

◆ close_ret

int close_ret = 0

Definition at line 223 of file test_socket.cpp.

◆ connect_addr

const struct sockaddr* connect_addr = 0

Definition at line 979 of file test_socket.cpp.

◆ connect_addrlen

socklen_t connect_addrlen = 0

Definition at line 980 of file test_socket.cpp.

◆ connect_errno

int connect_errno = 0

Definition at line 977 of file test_socket.cpp.

◆ connect_ret

int connect_ret = 0

Definition at line 976 of file test_socket.cpp.

◆ connect_sockfd

int connect_sockfd = 0

Definition at line 978 of file test_socket.cpp.

◆ expected_reads

std::deque<expected_read> expected_reads

Definition at line 311 of file test_socket.cpp.

◆ expected_writes

std::deque<expected_write> expected_writes

Definition at line 473 of file test_socket.cpp.

◆ fcntl_arg

unsigned long fcntl_arg = 0

Definition at line 257 of file test_socket.cpp.

◆ fcntl_cmd

int fcntl_cmd = 0

Definition at line 256 of file test_socket.cpp.

◆ fcntl_errno

int fcntl_errno = 0

Definition at line 258 of file test_socket.cpp.

◆ fcntl_fd

int fcntl_fd = 0

Definition at line 255 of file test_socket.cpp.

◆ fcntl_ret

int fcntl_ret = 0

Definition at line 259 of file test_socket.cpp.

◆ freeaddrinfo_res

struct addrinfo* freeaddrinfo_res = 0

Definition at line 933 of file test_socket.cpp.

◆ getaddrinfo_errno

int getaddrinfo_errno = 0

Definition at line 897 of file test_socket.cpp.

◆ getaddrinfo_hints

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 900 of file test_socket.cpp.

◆ getaddrinfo_node

const char* getaddrinfo_node = 0

Definition at line 898 of file test_socket.cpp.

◆ getaddrinfo_res

struct addrinfo* getaddrinfo_res = 0

Definition at line 908 of file test_socket.cpp.

◆ getaddrinfo_ret

int getaddrinfo_ret = 0

Definition at line 896 of file test_socket.cpp.

◆ getaddrinfo_service

const char* getaddrinfo_service = 0

Definition at line 899 of file test_socket.cpp.

◆ getsockname_addr

void* getsockname_addr = 0

Definition at line 713 of file test_socket.cpp.

◆ getsockname_errno

int getsockname_errno = 0

Definition at line 711 of file test_socket.cpp.

◆ getsockname_len

socklen_t getsockname_len = 0

Definition at line 714 of file test_socket.cpp.

◆ getsockname_ret

int getsockname_ret = 0

Definition at line 710 of file test_socket.cpp.

◆ getsockname_sockfd

int getsockname_sockfd = 0

Definition at line 712 of file test_socket.cpp.

◆ listen_backlog

int listen_backlog = 0

Definition at line 791 of file test_socket.cpp.

◆ listen_errno

int listen_errno = 0

Definition at line 789 of file test_socket.cpp.

◆ listen_ret

int listen_ret = 0

Definition at line 788 of file test_socket.cpp.

◆ listen_sockfd

int listen_sockfd = 0

Definition at line 790 of file test_socket.cpp.

◆ setsockopt_errno

int setsockopt_errno = 0

Definition at line 581 of file test_socket.cpp.

◆ setsockopt_ret

int setsockopt_ret = 0

Definition at line 580 of file test_socket.cpp.

◆ setsockopt_sockfd

int setsockopt_sockfd = 0

Definition at line 582 of file test_socket.cpp.

◆ socket_domain

int socket_domain = 0

Definition at line 168 of file test_socket.cpp.

◆ socket_errno

int socket_errno = 0

Definition at line 167 of file test_socket.cpp.

◆ socket_protocol

int socket_protocol = 0

Definition at line 170 of file test_socket.cpp.

◆ socket_ret

int socket_ret = 0

Definition at line 166 of file test_socket.cpp.

◆ socket_type

int socket_type = 0

Definition at line 169 of file test_socket.cpp.

TEST_F
TEST_F(XmlRpcSocketTest, TestMocks)
Definition: test_socket.cpp:80
expected_reads
std::deque< expected_read > expected_reads
Definition: test_socket.cpp:311
mock_read
ssize_t mock_read(int fd, void *buf, size_t count)
Definition: test_socket.cpp:313
XmlRpcSocketTest
Definition: test_socket.cpp:48
expected_read
Definition: test_socket.cpp:296
expected_write
Definition: test_socket.cpp:453
expected_writes
std::deque< expected_write > expected_writes
Definition: test_socket.cpp:473
mock_write
ssize_t mock_write(int fd, const void *buf, size_t count)
Definition: test_socket.cpp:475


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:32