protocol

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

commit 336d733842183a757879d70de0a0a82dfac09c23
parent 4fb9be0537b83226bfa581d4749e10da38298f1c
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 19 Mar 2017 16:11:19 +0100

Add(GET_PKG): Add the beginning of tests on get_pkg

Diffstat:
Msrc/client_test.c | 11+++++++++++
Msrc/package.c | 24+++++++++++++-----------
Msrc/write_package.c | 2+-
3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/src/client_test.c b/src/client_test.c @@ -52,6 +52,16 @@ TEST(pkg_auth_1_read) { return TEST_SUCCESS; } +TEST(pkg_req_get_pkg_1_write) { + void *ret; + size_t size; + + TEST_ASSERT(sockfd, "Server is not responding"); + ret = pkg_build_req_get_pkg(&size, 1, PKG_STABLE, "Test", "pkg", "v45.03"); + TEST_ASSERT(write(sockfd, ret, size), "Cannot send package to the server"); + return TEST_SUCCESS; +} + TEST(cleanup) { TEST_ASSERT(sockfd, "Server is not responding"); TEST_ASSERT(close(sockfd) != -1, "Cannot close socket"); @@ -62,6 +72,7 @@ void begin_client_test(void) { reg_test("connect", connect_1); reg_test("auth", pkg_auth_1_write); reg_test("auth", pkg_auth_1_read); + reg_test("get_pkg", pkg_req_get_pkg_1_write); reg_test("clean", cleanup); test_all(); test_free(); diff --git a/src/package.c b/src/package.c @@ -42,14 +42,14 @@ void *pkg_build_error(size_t *size, error_type_t type, const char *error) { pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_ERROR; pkg->payload = NULL; - list_add(pkg->payload, err, SIZEOF_ERR(err)); + list_add(pkg->payload, err, sizeof(*err)); return write_package(pkg, size); } void *pkg_build_req_get_pkg(size_t *size, u64_t id, u8_t state, const char *name, const char *category, const char *version) { req_get_pkg_t *req; - package_t *pkg; + package_t *pkg = NULL; req = malloc(sizeof(req_get_pkg_t)); req->id = id; @@ -64,7 +64,9 @@ void *pkg_build_req_get_pkg(size_t *size, u64_t id, u8_t state, const char *name pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_REQ_GET_PKG; pkg->payload = NULL; - list_add(pkg->payload, req, SIZEOF_REQ_GET_PKG(req)); + list_add(pkg->payload, req, sizeof(req_get_pkg_t)); + req = pkg->payload->member; + return write_package(pkg, size); } @@ -80,7 +82,7 @@ void *pkg_build_req_get_file(size_t *size, u64_t id, const char *path) { pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_REQ_GET_FILE; pkg->payload = NULL; - list_add(pkg->payload, file, SIZEOF_REQ_GET_FILE(file)); + list_add(pkg->payload, file, sizeof(*file)); return write_package(pkg, size); } @@ -98,7 +100,7 @@ void *pkg_build_req_get_news(size_t *size, time_t last_request, u16_t ids_size, pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_REQ_GET_NEWS; pkg->payload = NULL; - list_add(pkg->payload, news, SIZEOF_REQ_GET_NEWS(news)); + list_add(pkg->payload, news, sizeof(*news)); return write_package(pkg, size); } @@ -114,7 +116,7 @@ void *pkg_build_req_get_cat(size_t *size, u16_t len, u64_t *a_cat) { pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_REQ_CAT; pkg->payload = NULL; - list_add(pkg->payload, cat, SIZEOF_REQ_GET_CAT(cat)); + list_add(pkg->payload, cat, sizeof(*cat)); return write_package(pkg, size); } @@ -130,7 +132,7 @@ void *pkg_build_req_get_upd(size_t *size, u64_t len, u64_t *a_pkgs) { pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_REQ_UPD; pkg->payload = NULL; - list_add(pkg->payload, upd, SIZEOF_REQ_GET_UPD(upd)); + list_add(pkg->payload, upd, sizeof(*upd)); return write_package(pkg, size); } @@ -164,7 +166,7 @@ void *pkg_build_resp_pkg(size_t *size, u64_t id, float comp_time, ptr = malloc(sizeof(package_t)); ptr->type = PKG_TYPE_RESP_PKG; ptr->payload = NULL; - list_add(ptr->payload, pkg, SIZEOF_RESP_PKG(pkg)); + list_add(ptr->payload, pkg, sizeof(*pkg)); return write_package(ptr, size); } @@ -183,7 +185,7 @@ void *pkg_build_resp_file(size_t *size, u64_t id, u8_t type, u64_t parent_id, pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_RESP_FILE; pkg->payload = NULL; - list_add(pkg->payload, file, SIZEOF_RESP_FILE(file)); + list_add(pkg->payload, file, sizeof(*file)); return write_package(pkg, size); } @@ -206,7 +208,7 @@ void *pkg_build_resp_news(size_t *size, u64_t id, u64_t parent_id, const char *a pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_RESP_FILE; pkg->payload = NULL; - list_add(pkg->payload, news, SIZEOF_RESP_NEWS(news)); + list_add(pkg->payload, news, sizeof(*news)); return write_package(pkg, size); } @@ -223,6 +225,6 @@ void *pkg_build_resp_cat(size_t *size, u64_t id, u64_t parent_id, const char *na pkg = malloc(sizeof(package_t)); pkg->type = PKG_TYPE_RESP_CAT; pkg->payload = NULL; - list_add(pkg->payload, cat, SIZEOF_RESP_CAT(cat)); + list_add(pkg->payload, cat, sizeof(*cat)); return write_package(pkg, size); } diff --git a/src/write_package.c b/src/write_package.c @@ -66,7 +66,7 @@ static void *write_payload_req_get_pkg(void *pkg, size_t *count) { ret = malloc(sizeof(req->id) + sizeof(req->state) + sizeof(req->name_len) + sizeof(req->categ_len) + sizeof(req->version_len) + req->name_len + req->categ_len + req->version_len); - assert(req != NULL); + assert(ret != NULL); write_member(req->id, ret, *count); write_member(req->state, ret, *count);