mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 10:20:04 +00:00
Unit test fixes
This commit is contained in:
11
src/config.c
11
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<<alg_rs256) | (1<<alg_rs384) | (1<<alg_rs512);
|
||||
@@ -94,10 +93,14 @@ void set_cloud_status(char *status)
|
||||
|
||||
char *get_cloud_status(void)
|
||||
{
|
||||
char *status = NULL;
|
||||
pthread_mutex_lock(&config_mut);
|
||||
parStrncpy(cloud_status, get_parodus_cfg()->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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include "../src/parodus_log.h"
|
||||
#include "../src/nopoll_helpers.h"
|
||||
#include "../src/config.h"
|
||||
#include <cjwt/cjwt.h>
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user