From 581d7fc966ced7486fa961fd3cb989051b88e97e Mon Sep 17 00:00:00 2001 From: Shilpa Seshadri Date: Thu, 17 Nov 2022 00:40:26 +0530 Subject: [PATCH] Unit test fixes --- src/config.c | 11 +++++++---- tests/CMakeLists.txt | 9 ++++++--- tests/test_nopoll_helpers.c | 26 +++++++------------------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/config.c b/src/config.c index 5e57318..00b2975 100644 --- a/src/config.c +++ b/src/config.c @@ -41,7 +41,6 @@ pthread_cond_t cloud_status_cond=PTHREAD_COND_INITIALIZER; char webpa_interface[64]={'\0'}; -char cloud_status[32]={'\0'}; static ParodusCfg parodusCfg; static unsigned int rsa_algorithms = (1<cloud_status, sizeof(cloud_status)); - pthread_mutex_unlock(&config_mut); - return cloud_status; + if(NULL != get_parodus_cfg()->cloud_status) + { + status = get_parodus_cfg()->cloud_status; + } + pthread_mutex_unlock(&config_mut); + return status; } const char *get_tok (const char *src, int delim, char *result, int resultsize) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a0ba8f7..4c8a2c4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,7 +61,10 @@ target_link_libraries (test_close_retry ${PARODUS_COMMON_LIBS} -lcmocka) #------------------------------------------------------------------------------- add_test(NAME test_mutex COMMAND ${MEMORY_CHECK} ./test_mutex) add_executable(test_mutex test_mutex.c ../src/mutex.c) -target_link_libraries (test_mutex ${PARODUS_COMMON_LIBS} -lcmocka) +target_link_libraries (test_mutex gcov -lcunit -lcimplog -lwrp-c + -luuid -lmsgpackc -lnopoll -lnanomsg -lpthread + -Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64 + -lssl -lcrypto -lrt -lm -lcmocka) #------------------------------------------------------------------------------- # test_networking @@ -74,8 +77,8 @@ target_link_libraries (test_networking ${PARODUS_COMMON_LIBS}) # test_nopoll_helpers #------------------------------------------------------------------------------- add_test(NAME test_nopoll_helpers COMMAND ${MEMORY_CHECK} ./test_nopoll_helpers) -add_executable(test_nopoll_helpers test_nopoll_helpers.c ../src/nopoll_helpers.c) -target_link_libraries (test_nopoll_helpers -Wl,--no-as-needed -lrt -lcmocka -lcimplog -lnopoll) +add_executable(test_nopoll_helpers test_nopoll_helpers.c ../src/nopoll_helpers.c ../src/string_helpers.c ../src/config.c) +target_link_libraries (test_nopoll_helpers -Wl,--no-as-needed -lrt -lcmocka -lcimplog -lnopoll ${PARODUS_COMMON_LIBS}) #------------------------------------------------------------------------------- # test_time diff --git a/tests/test_nopoll_helpers.c b/tests/test_nopoll_helpers.c index 13109e4..f8862d5 100644 --- a/tests/test_nopoll_helpers.c +++ b/tests/test_nopoll_helpers.c @@ -24,6 +24,9 @@ #include "../src/parodus_log.h" #include "../src/nopoll_helpers.h" #include "../src/config.h" +#include +#include "../src/connection.h" +#include "../src/ParodusInternal.h" /*----------------------------------------------------------------------------*/ /* Macros */ @@ -34,7 +37,6 @@ /* File Scoped Variables */ /*----------------------------------------------------------------------------*/ static noPollConn *conn = NULL; - static ParodusCfg cfg; /*----------------------------------------------------------------------------*/ /* Mocks */ @@ -57,12 +59,6 @@ nopoll_bool nopoll_conn_is_ready( noPollConn *conn ) return (nopoll_bool)mock(); } -ParodusCfg *get_parodus_cfg(void) -{ - function_called(); - return &cfg; -} - int __nopoll_conn_send_common (noPollConn * conn, const char * content, long length, nopoll_bool has_fin, long sleep_in_header, noPollOpCode frame_type) { UNUSED(has_fin); UNUSED(sleep_in_header); UNUSED(frame_type); UNUSED(content); @@ -131,10 +127,6 @@ bool get_interface_down_event() return false; } -char *get_cloud_status(void) -{ - return NULL; -} /*----------------------------------------------------------------------------*/ /* Tests */ @@ -226,8 +218,7 @@ void test_sendMessage() { int len = strlen("Hello Parodus!"); - cfg.cloud_status = CLOUD_STATUS_ONLINE; - expect_function_calls (get_parodus_cfg, 1); + get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE; expect_value(__nopoll_conn_send_common, (intptr_t)conn, (intptr_t)conn); expect_value(__nopoll_conn_send_common, length, len); @@ -241,8 +232,7 @@ void test_sendMessageOffline() { int len = strlen("Hello Parodus!"); - cfg.cloud_status = CLOUD_STATUS_OFFLINE; - expect_function_calls (get_parodus_cfg, 1); + get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE; sendMessage(conn, "Hello Parodus!", len); } @@ -251,8 +241,7 @@ void err_sendMessage() { int len = strlen("Hello Parodus!"); - cfg.cloud_status = CLOUD_STATUS_ONLINE; - expect_function_calls (get_parodus_cfg, 1); + get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE; expect_value(__nopoll_conn_send_common, (intptr_t)conn,(intptr_t) conn); expect_value(__nopoll_conn_send_common, length, len); @@ -271,8 +260,7 @@ void err_sendMessageConnNull() { int len = strlen("Hello Parodus!"); - cfg.cloud_status = CLOUD_STATUS_ONLINE; - expect_function_calls (get_parodus_cfg, 1); + get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE; expect_value(__nopoll_conn_send_common, (intptr_t)conn, NULL); expect_value(__nopoll_conn_send_common, length, len);