protocol

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

commit 695f829d27167cd6bfaaa586a9daa43a1033cbf9
parent c7be10ff4d6ce64fbb779ba66e7eec3c99729ed4
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 20 Mar 2017 18:27:41 +0100

Add(Database): Add database file, Database argument, and test for database connections

Diffstat:
MMakefile | 10++++++++--
Minc/client_test.h | 2++
Amock.db | 0
Msrc/client_test.c | 22+++++++++++++++++++---
Msrc/main.c | 11+++++++++++
5 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,7 +1,13 @@ NAME = protocol_tests CC = gcc -CFLAGS = -Wall -Werror -Wextra -Wno-unused-result -I inc/ -I lib/inc/ -I lib/lib/libmorphux/inc/ -g -O3 -std=c99 -LFLAGS = -Llib/ -lmpm +CFLAGS = -Wall -Werror -Wextra -Wno-unused-result \ + -I inc/ \ + -I lib/inc/ \ + -I lib/lib/libmorphux/inc/ \ + -I lib/lib/sqlite/ \ + -I lib/lib/libconfuse/src/ \ + -g -O3 -std=c99 +LFLAGS = -Llib/ -lmpm -pthread -ldl SRCS = $(wildcard src/*.c) OBJS = $(SRCS:%.c=%.o) diff --git a/inc/client_test.h b/inc/client_test.h @@ -1,6 +1,7 @@ #ifndef CLIENT_TEST_H # define CLIENT_TEST_H # include <morphux.h> +# include <libmpm.h> # include <stdio.h> # include <sys/types.h> # include <sys/socket.h> @@ -26,5 +27,6 @@ void begin_client_test(void); int g_port; char *g_ip; +char *g_db_path; #endif /* CLIENT_TEST_H */ diff --git a/mock.db b/mock.db Binary files differ. diff --git a/src/client_test.c b/src/client_test.c @@ -1,6 +1,7 @@ #include "client_test.h" -static int sockfd; +static int sockfd; +static database_t *db; TEST(connect_1) { struct sockaddr_in serv_addr; @@ -22,6 +23,14 @@ TEST(connect_1) { return TEST_SUCCESS; } +TEST(connect_db) { + u8_t ret; + + db = mpm_database_open(&ret, g_db_path); + TEST_ASSERT(ret != 0, "Cannot open the database"); + return TEST_SUCCESS; +} + TEST(pkg_auth_1_write) { size_t size; void *ret; @@ -113,14 +122,20 @@ TEST(pkg_req_get_pkg_1_read) { return TEST_SUCCESS; } -TEST(cleanup) { +TEST(cleanup_co) { TEST_ASSERT(sockfd, "Server is not responding"); TEST_ASSERT(close(sockfd) != -1, "Cannot close socket"); return TEST_SUCCESS; } +TEST(cleanup_db) { + TEST_ASSERT(mpm_database_close(db) == 0, "Cannot close database"); + return TEST_SUCCESS; +} + void begin_client_test(void) { reg_test("connect", connect_1); + reg_test("connect", connect_db); reg_test("auth", pkg_auth_1_write); reg_test("auth", pkg_auth_1_read); reg_test("auth", pkg_auth_2_write); @@ -129,7 +144,8 @@ void begin_client_test(void) { reg_test("auth", pkg_auth_1_read); reg_test("get_pkg", pkg_req_get_pkg_1_write); reg_test("get_pkg", pkg_req_get_pkg_1_read); - reg_test("clean", cleanup); + reg_test("clean", cleanup_co); + reg_test("clean", cleanup_db); test_all(); test_free(); } diff --git a/src/main.c b/src/main.c @@ -12,9 +12,14 @@ static void callback_ip(const char *ip) { g_ip = strdup(ip); } +static void callback_db(const char *db) { + g_db_path = strdup(db); +} + static const mopts_t opts[] = { {'p', "port", "Port", true, &callback_port}, {'a', "ip", "IP Address", true, &callback_ip}, + {'d', "database", "Database Path", true, &callback_db}, ARGS_EOL }; @@ -26,7 +31,13 @@ int main(int ac, char **av) { mlist_t *list = NULL, *tmp; char *ptr; + g_port = 0; + g_ip = NULL; + g_db_path = NULL; read_opt(ac, av, opts, &list); + + if (g_port == 0 || g_ip == NULL || g_db_path == NULL) + m_panic("Missing arguments."); list_for_each(list, tmp, ptr) { if (strcmp(ptr, CLIENT_CMD) == 0) begin_client_test();