protocol

protocol tests
Log | Files | Refs | Submodules | README | git clone https://git.ne02ptzero.me/git/protocol

commit affcdd48b41b9a8e22bcefbeae451964c615ee6f
parent 336d733842183a757879d70de0a0a82dfac09c23
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 20 Mar 2017 14:58:54 +0100

Add(Timeout): Add timeout on reads

Diffstat:
Minc/client_test.h | 2++
Msrc/client_test.c | 16+++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/inc/client_test.h b/inc/client_test.h @@ -5,6 +5,8 @@ # include <sys/types.h> # include <sys/socket.h> # include <netinet/in.h> +# include <sys/select.h> +# include <strings.h> # include <netdb.h> # include "package.h" diff --git a/src/client_test.c b/src/client_test.c @@ -36,11 +36,21 @@ TEST(pkg_auth_1_write) { TEST(pkg_auth_1_read) { void *ret, *expect; package_t *pkg; - size_t r_n = 0, size; + auth_t *auth; + fd_set set; + size_t r_n = 0, size, rv; + struct timeval timeout; TEST_ASSERT(sockfd, "Server is not responding"); expect = pkg_build_auth_ack(&size, 1, 0); ret = malloc(2048); + + FD_ZERO(&set); + FD_SET(sockfd, &set); + timeout.tv_sec = 1; + timeout.tv_usec = 0; + rv = select(sockfd + 1, &set, NULL, NULL, &timeout); + TEST_ASSERT(rv > 0, "Timeout on read"); r_n = read(sockfd, ret, 2048); TEST_ASSERT(r_n == size, "Package returned size is wrong"); @@ -48,6 +58,10 @@ TEST(pkg_auth_1_read) { pkg = read_pkg(ret); TEST_ASSERT(pkg, "Can't read package"); TEST_ASSERT(pkg->type == PKG_TYPE_AUTH_ACK, "Package type is wrong"); + + auth = pkg->payload->member; + TEST_ASSERT(auth->mpm_major_version == 1, "MPM major version is wrong"); + TEST_ASSERT(auth->mpm_minor_version == 0, "MPM minor version is wrong"); free(ret); return TEST_SUCCESS; }