add debug and gtest hook like as option

This commit is contained in:
2023-10-18 00:29:32 +02:00
parent c61357bcd7
commit 736fc3232f
11 changed files with 173 additions and 271 deletions
+10 -10
View File
@@ -108,16 +108,16 @@ extern struct list_base_fmock *g_list_base_fmock;
PRINT_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>count call of %s: %ld\n",#namefunction,count_call_f);\
struct list_mock_return_ ## namefunction *tmp_mock = &list_mo_ ## namefunction;\
if( (tmp_mock->info_mock)->times_left == INITSTATE ){\
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," WARNING, %s, no EXPECT_MOCK_CALL or WILL_MOCK_CALL, but called %ld times.\n",#namefunction, count_call_f);\
PRINT_HK_C(colors_f[k_YELLOW],tab_hk_f[hk_TR]," WARNING, %s, no EXPECT_MOCK_CALL or WILL_MOCK_CALL, but called %ld times.\n",#namefunction, count_call_f);\
if(count_call_f==1){\
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," For instance:\n"\
PRINT_HK_C(colors_f[k_YELLOW],tab_hk_f[hk_TR]," For instance:\n"\
"%s EXPECT_MOCK_CALL(%s,%s,%s,true,1){\n"\
"%s\t %s ret;\n%s \t ...do something with %s;\n"\
"%s\t return ret;\n"\
"%s }\n"\
"%s if call once and accept all args, the same args with WILL_MOCK_CALL \n\n",\
HK_TR, #returntype, #namefunction,#args_prototype_with_parenthesis, HK_TR,#returntype, \
HK_TR, #args_call_with_parenthesis, HK_TR, HK_TR, HK_TR ); \
tab_hk_f[hk_TR], #returntype, #namefunction,#args_prototype_with_parenthesis, tab_hk_f[hk_TR],#returntype, \
tab_hk_f[hk_TR], #args_call_with_parenthesis, tab_hk_f[hk_TR], tab_hk_f[hk_TR], tab_hk_f[hk_TR] ); \
/*return (returntype)0;*/ \
INIT_MOCK_INFO_IF_NO_(tmp_mock,namefunction, PRE_ID);\
}/* to have log */\
@@ -129,15 +129,15 @@ extern struct list_base_fmock *g_list_base_fmock;
append_variable_current(&((tmp_mock->info_mock)->l_current_var), tmp_mock->str_print_current_variables args_call_with_parenthesis);\
}\
else if(count_call_f == 1){\
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," no printer variable function defined, to define it:\n"\
PRINT_HK_C(colors_f[k_YELLOW],tab_hk_f[hk_TR]," no printer variable function defined, to define it:\n"\
"%s STR_PRINT_CUR_VAR(%s,%s,%s){\n"\
"%s\t char* ret=malloc(256);/*for instance*/;\n"\
"%s\t ... sprintf(ret,...., %s);/*for instance*/ \n"\
"%s\t return ret;\n"\
"%s }\n"\
"%s same prototype as MOCK_FUNC whithout returntype which always char* i\n\n",\
HK_TR, #namefunction,#args_prototype_with_parenthesis, #args_call_with_parenthesis, \
HK_TR, HK_TR, #args_call_with_parenthesis, HK_TR, HK_TR, HK_TR ); \
tab_hk_f[hk_TR], #namefunction,#args_prototype_with_parenthesis, #args_call_with_parenthesis, \
tab_hk_f[hk_TR], tab_hk_f[hk_TR], #args_call_with_parenthesis, tab_hk_f[hk_TR], tab_hk_f[hk_TR], tab_hk_f[hk_TR] ); \
}\
/*LOG("condition_func:%d\n", tmp_mock->call_mock_condition args_call_with_parenthesis);*/ /*LOG("%s\n","failure condition");*/\
/*EXPECT_EQ_TYPE_INT(1, tmp_mock->call_mock_condition args_call_with_parenthesis);*/ /*LOG("%s\n","failure condition");*/\
@@ -145,13 +145,13 @@ extern struct list_base_fmock *g_list_base_fmock;
/*return (returntype)0;*//* default return */\
if( (tmp_mock->info_mock)->str_caller == NULL){ \
if(count_call_f == 1){\
PRINT_HK_C(colors_f[k_YELLOW],HK_TR," WARNING, no INIT_CALLER_MOCK; you can put it like this: \n"\
PRINT_HK_C(colors_f[k_YELLOW],tab_hk_f[hk_TR]," WARNING, no INIT_CALLER_MOCK; you can put it like this: \n"\
"%s TEST(nametest){\n"\
"%s\t INIT_CALLER_MOCK(%s); \n"\
"%s\t %s%s; \n"\
"%s }\n"\
"%s i.e before calling %s in this TEST, to have explicit logs\n",\
HK_TR, HK_TR, #namefunction, HK_TR,#namefunction,#args_call_with_parenthesis, HK_TR, HK_TR, #namefunction);} \
tab_hk_f[hk_TR], tab_hk_f[hk_TR], #namefunction, tab_hk_f[hk_TR],#namefunction,#args_call_with_parenthesis, tab_hk_f[hk_TR], tab_hk_f[hk_TR], #namefunction);} \
/*return (returntype)0;*/ \
}\
else if (((tmp_mock->info_mock)->times_left != 0) && ((tmp_mock->info_mock)->times_left != INITSTATE )) {\
@@ -164,7 +164,7 @@ extern struct list_base_fmock *g_list_base_fmock;
}\
/*if(0 == tmp_mock->call_mock_condition args_call_with_parenthesis){\
PRINT_LOC("Failure, arguments not expected\ncondition ( %s ) not verified\n\n", (tmp_mock->info_mock)->str_conditions);\
PRINT_HK_C(RED_K,HK_TR," 1 argument check failed from %s \n",__func__); \
PRINT_HK_C(RED_K,tab_hk_f[hk_TR]," 1 argument check failed from %s \n",__func__); \
}*/\
PRINT_DEBUG(" %*c VALUES: mock function:%s, conditions:%s t_left:%ld, init_left:%ld| args:%s\n",8,'^',(tmp_mock->info_mock)->str_namefunc, (tmp_mock->info_mock)->str_conditions, (tmp_mock->info_mock)->times_left,(tmp_mock->info_mock)->init_times_left, #args_call_with_parenthesis);\
if (((tmp_mock->info_mock)->times_left <= INFINITY) || ((tmp_mock->info_mock)->times_left > 0)){\
+5 -5
View File
@@ -163,7 +163,7 @@ char * strprint_caller_(char *input){
#define PRINT_VAR_CUR(mockinfo)\
do{\
PRINTF("\n%s list of variables when %s was called, with condition %s:\n\t\t",HK_EQ,mockinfo->str_namefunc,mockinfo->str_conditions);\
PRINTF("\n%s list of variables when %s was called, with condition %s:\n\t\t",tab_hk_f[hk_EQ],mockinfo->str_namefunc,mockinfo->str_conditions);\
size_t cal_cur=0;\
struct list_current_variable *tmp_cur_v = mockinfo->l_current_var;\
while(tmp_cur_v){\
@@ -187,7 +187,7 @@ __attribute__((destructor))
//k_GREEN=k_NOTHING; k_RED=k_NOTHING; k_YELLOW=k_NOTHING; k_BLUE=k_NOTHING;
//for(int i=0; i< Dk_NOTHING;++i) strcpy(colors_f[i]," ");
//}
if(only_usage) return; /* do nothing */
struct winsize w;
ioctl(1, TIOCGWINSZ, &w);
@@ -207,7 +207,7 @@ __attribute__((destructor))
PRINT_DEBUG("**** STAT mock function:%s, conditions:%s t_left:%ld, init_left:%ld, failed_call:%ld\n",tmock->str_namefunc, tmock->str_conditions, tmock->times_left,tmock->init_times_left, tmock->failed_call);
if(((tmock->expect_call) && (tmock->init_times_left == tmock->times_left)) || (tmock->failed_call)){
if(tmock->l_current_var){
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s\n",colors_f[k_RED],HK_FL,colors_f[k_YELLOW],tmock->str_namefunc,DEFAULT_K,
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s\n",colors_f[k_RED],tab_hk_f[hk_FL],colors_f[k_YELLOW],tmock->str_namefunc,DEFAULT_K,
number_call_translate(tmock->init_times_left),
tmock->call/*tmock->failed_call + (tmock->init_times_left - tmock->times_left)*/,
tmock->failed_call,
@@ -216,7 +216,7 @@ __attribute__((destructor))
PRINT_VAR_CUR(tmock);
}
else
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s \n",colors_f[k_RED],HK_FL,colors_f[k_YELLOW],tmock->str_namefunc,DEFAULT_K,
PRINTF("%s%s %s%s %s: expect %s, it was called %ld times and failed %ld times, with condition %s \n",colors_f[k_RED],tab_hk_f[hk_FL],colors_f[k_YELLOW],tmock->str_namefunc,DEFAULT_K,
number_call_translate(tmock->init_times_left),
tmock->call/*tmock->failed_call + (tmock->init_times_left - tmock->times_left)*/,
tmock->failed_call,
@@ -227,7 +227,7 @@ __attribute__((destructor))
//free(tfree);
}
PRINTF("\n%s%s STAT MOCK : there are %ld mock functions, %ld wished responses, %ld expected responses, which are:\n\n",colors_f[k_GREEN],HK_EQ,count_f_mock, count_f_mock_wished, count_expect_mock);
PRINTF("\n%s%s STAT MOCK : there are %ld mock functions, %ld wished responses, %ld expected responses, which are:\n\n",colors_f[k_GREEN],tab_hk_f[hk_EQ],count_f_mock, count_f_mock_wished, count_expect_mock);
struct list_base_fmock *tmp_list_fm = g_list_base_fmock;
struct func_mock_info_struct *tmp_inf_mock;
/* list each fmock an each calls */