diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..282d7993a057737a2c194f80366d6d4d961c597f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libdap-test"] + path = libdap-test + url = https://github.com/kelvinblockchain/libdap-test diff --git a/core/dap_common.h b/core/dap_common.h index 264b48fbba8e6201d5fedf3eea63f8e1fbb317d3..60cb956e5a11b4283c68a0b7507427d672a2e02d 100644 --- a/core/dap_common.h +++ b/core/dap_common.h @@ -37,29 +37,26 @@ #define DAP_PROTOCOL_VERSION 21 - - #if defined(__GNUC__) ||defined (__clang__) #define DAP_ALIGN_PACKED __attribute__((aligned(1),packed)) #endif enum log_level{L_CRITICAL=5,L_ERROR=4, L_WARNING=3,L_NOTICE=2,L_INFO=1,L_DEBUG=0}; -//extern enum log_level log_level; #ifdef __cplusplus extern "C" { #endif int dap_common_init( const char * a_log_file ); -void dap_common_deinit(); +void dap_common_deinit(void); void _log_it(const char * log_tag, enum log_level, const char * format,...); void _vlog_it(const char * log_tag, enum log_level, const char * format, va_list ap ); #define log_it(_log_level,...) _log_it(LOG_TAG,_log_level,##__VA_ARGS__) #define vlog_it(a_log_level,a_format,a_ap) _vlog_it(LOG_TAG,a_log_level,a_format,a_ap) -const char * log_error(); +const char * log_error(void); void set_log_level(enum log_level ll); #ifdef __GNUC__ @@ -71,8 +68,8 @@ char *strndup(const char *s, size_t n); #endif int time_to_rfc822(char * out, size_t out_size_max, time_t t); -int get_select_breaker(); -int send_select_break(); +int get_select_breaker(void); +int send_select_break(void); char * exec_with_ret(const char * a_cmd); char * exec_with_ret_multistring(const char * a_cmd); char * random_string_create(size_t a_length); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6f2f3eedc285f033820da35e3eaf536a9e3b139c..ed2b77cb538d36b7742a5a0d462b78bfce235d97 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(libdap-test) - +project(test) +add_subdirectory(libdap-test) add_subdirectory(core) diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index e81ee045ded490ab2639e39a18309fd2217c2e1d..a5153d538cffe7d50f8173e39ed0ca2640c2d534 100755 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -1,14 +1,15 @@ cmake_minimum_required(VERSION 3.0) -project(core-test) +project(core_test) -file(GLOB SRC *.h *.c) +file(GLOB SRCS *.c) +file(GLOB HRDS *.c) -add_executable(${PROJECT_NAME} ${SRC}) +add_executable(${PROJECT_NAME} ${SRCS} ${HRDS}) -target_link_libraries(${PROJECT_NAME} dap_core) +target_link_libraries(core_test dap_test dap_core) add_test( NAME core-test - COMMAND core-test + COMMAND core_test ) diff --git a/test/core/dap_common_test.c b/test/core/dap_common_test.c index cfc733974fafc1f54351c7a92337ffdf44bc9820..dff06eb30a159cb3ca774f4faedb33e770e9b029 100644 --- a/test/core/dap_common_test.c +++ b/test/core/dap_common_test.c @@ -4,10 +4,11 @@ void test_put_int() { const int INT_VAL = 10; const char * EXPECTED_RESULT = "10"; char * result_arr = itoa(INT_VAL); - assert(strcmp(result_arr, EXPECTED_RESULT) == 0 && "test_put_int failed"); + dap_assert(strcmp(result_arr, EXPECTED_RESULT) == 0, + "Check string result from itoa"); } void dap_common_test_run() { - printf("Start running dap_common_test\n"); + dap_print_module_name("dap_common"); test_put_int(); } diff --git a/test/core/dap_common_test.h b/test/core/dap_common_test.h index 00959ed03798809630a519497a974fb1bac50331..3934603b16c0648e11bd40865e28cf960cdd5cb6 100644 --- a/test/core/dap_common_test.h +++ b/test/core/dap_common_test.h @@ -1,9 +1,5 @@ #pragma once +#include "dap_test.h" #include "dap_common.h" -#include "assert.h" -#include "stdbool.h" -#include "stdlib.h" -#include "stdio.h" -#include "string.h" extern void dap_common_test_run(void); diff --git a/test/core/dap_config_test.c b/test/core/dap_config_test.c index b831ee9b46d262a4f08a4cc6cc71ca9af36dd257..22c788df151c85802f736f1a48ca69f8563f5750 100644 --- a/test/core/dap_config_test.c +++ b/test/core/dap_config_test.c @@ -27,8 +27,7 @@ static dap_config_t * config; void create_test_config_file() { config_file = fopen(testconfigName, "w+"); - assert(config_file != NULL && - "Can't create config file"); + dap_assert(config_file != NULL, "Create config file"); fwrite(config_data, sizeof(char), strlen(config_data), config_file); @@ -46,43 +45,43 @@ void init_test_case() { } void cleanup_test_case() { - assert(remove("test_dap_config.cfg") == 0 && - "Error remove config file"); + dap_assert(remove("test_dap_config.cfg") == 0, + "Remove config file"); dap_config_close(config); } void test_config_open_fail() { - assert(dap_config_open("RandomNeverExistName") == NULL - && "configOpenFail failed"); + dap_assert(dap_config_open("RandomNeverExistName") == NULL, + "Try open not exists config file"); } void test_get_int() { int32_t resultTTL = dap_config_get_item_int32(config, "server_options", "TTL_session_key"); - assert(resultTTL == 600 && "get_int failed"); + dap_assert(resultTTL == 600, "Get int from config"); } void test_get_double() { double timeout = dap_config_get_item_double(config, "server_options", "timeout"); - assert(timeout == 1.0 && "test_get_double failed"); + dap_assert(timeout == 1.0, "Get double from config"); } void test_get_bool() { bool rBool = dap_config_get_item_bool(config, "server_options", "vpn_enable"); - assert(rBool == true && "test_get_bool failed"); + dap_assert(rBool == true, "Get bool from config"); rBool = dap_config_get_item_bool(config, "server_options", "proxy_enable"); - assert(rBool == false && "test_get_bool failed"); + dap_assert(rBool == false, "Get bool from config"); } void test_array_str() { uint16_t arraySize; char ** result_arr = dap_config_get_array_str(config, "server_options", "str_arr", &arraySize); - assert(result_arr != NULL && "test_array_str failed, result_arr is NULL"); - assert(arraySize == STR_ARR_LEN); + dap_assert(result_arr != NULL, "Get array str from config"); + dap_assert(arraySize == STR_ARR_LEN, "Check array length"); for(uint i = 0; i < arraySize; i++) { assert(strcmp(result_arr[i], str_add_test_case[i]) == 0 && "test_array_str failed"); @@ -93,19 +92,20 @@ void test_array_int() { uint16_t arraySize; char ** result_arr = dap_config_get_array_str(config, "server_options", "int_arr", &arraySize); - assert(result_arr != NULL && "test_array_str failed, result_arr is NULL"); - assert(arraySize == INT_ARR_LEN && "test_array_str failed, arraySize is not equal INT_ARR_LEN"); + dap_assert(result_arr != NULL, "Get array int"); + dap_assert(arraySize == INT_ARR_LEN, "Check array int length"); + dap_test_msg("Testing array int values."); for(uint i = 0; i < arraySize; i++) { - assert(atoi(result_arr[i]) == int_arr_test_cases[i] && "test_array_int failed"); + dap_assert_PIF(atoi(result_arr[i]) == int_arr_test_cases[i], "Check array int"); } } void dap_config_tests_run() { - printf("Start running dap_config_tests\n"); - init_test_case(); + dap_print_module_name("dap_config"); + init_test_case(); test_config_open_fail(); test_get_int(); test_get_bool(); diff --git a/test/core/dap_config_test.h b/test/core/dap_config_test.h index 1381b6667522056d50834dacc2dd08226a3b31ce..0fd0c131b4e93d1900cb21c403c7b843686719fa 100755 --- a/test/core/dap_config_test.h +++ b/test/core/dap_config_test.h @@ -1,9 +1,5 @@ #pragma once +#include "dap_test.h" #include "dap_config.h" -#include "assert.h" -#include "stdbool.h" -#include "stdlib.h" -#include "stdio.h" -#include "string.h" extern void dap_config_tests_run(void);