debug mock, add list current call var if STR_PRINT_CUR_VAR is set for the mock function

This commit is contained in:
2023-10-01 00:22:40 +02:00
parent 0e662a73b9
commit f356445dec
6 changed files with 232 additions and 67 deletions
+1 -1
View File
@@ -5,4 +5,4 @@ log*
*/**.o
*/**/**.o
launch_*
eEcomp
+109 -21
View File
@@ -62,6 +62,28 @@ void append_list_base_fmock(struct list_base_fmock **l_fmock, struct func_mock_i
struct func_mock_info_struct *f_mock_glist;
pthread_mutex_t mut_f_mock_glist;
void append_variable_current(struct list_current_variable **lcurrent_var, char *current_var){
if(*lcurrent_var){
PRINT_DEBUG("----- l_current_var not NULL, content: %s have to add %s\n",(*lcurrent_var)->str_current_variables, current_var);
struct list_current_variable *tmp_lcv = *lcurrent_var;
while(tmp_lcv->next) tmp_lcv = tmp_lcv->next;
tmp_lcv->next = malloc(sizeof(struct list_current_variable));
//(tmp_lcv->next)->str_current_variables = malloc(strlen(current_var));
//strcpy((tmp_lcv->next)->str_current_variables,current_var);
(tmp_lcv->next)->str_current_variables = current_var;
(tmp_lcv->next)->next= NULL;
}
else{
PRINTF("-- lcurrent_var NULL\n");
*lcurrent_var = malloc(sizeof(struct list_current_variable));
//(*lcurrent_var)->str_current_variables = malloc(strlen(current_var));
//strcpy((*lcurrent_var)->str_current_variables,current_var);
(*lcurrent_var)->str_current_variables = current_var;
(*lcurrent_var)->next = NULL;
}
}
void append_fmock_to_listmock(struct func_mock_info_struct **f_mock_list, struct func_mock_info_struct *f_mock){
INCREMENT_(count_f_mock_wished);
if(f_mock->expect_call) {
@@ -80,11 +102,17 @@ void append_fmock_to_listmock(struct func_mock_info_struct **f_mock_list, struc
}
#define SSTRFY(x) STRFY(x)
char* extract_name_func_mock(char *input){
char * ret=malloc(strlen(input));
strcpy(ret,input);
for(size_t i=0; i<strlen(ret)-6; ++i){
if(strncmp(ret+i,"_line_",6) == 0){
char * pre_id_ = SSTRFY(PRE_ID);
size_t len_pre_id_ = strlen(pre_id_);
for(size_t i=0; i<strlen(ret)-len_pre_id_; ++i){
if(strncmp(ret+i,pre_id_,len_pre_id_) == 0){
ret[i]='\0';
break;
}
@@ -104,25 +132,43 @@ __attribute__((constructor))
extern bool is_parallel_nb;
char * number_call_translate(long nb){
char *ret=malloc(250);
if(nb>0) sprintf(ret,"%ld",nb);
else if(nb == 0 ) sprintf(ret,"zero");
else if(nb==INFINITY) sprintf(ret,"INFINITY");
else sprintf(ret,"negative");
if(nb>1) sprintf(ret," to be called %ld times",nb);
else if(nb == 1) sprintf(ret," to be called once");
else if(nb == 0 ) sprintf(ret," not to be executed");
else if(nb==INFINITY) sprintf(ret," to be called forever");
else sprintf(ret," nothing! it's negative:%ld", nb);
return ret;
}
#define PRINT_VAR_CUR(mockinfo)\
do{\
PRINTF("\n\tlist of variables when %s was called:\n\t\t",mockinfo->str_namefunc);\
size_t cal_cur=0;\
struct list_current_variable *tmp_cur_v = mockinfo->l_current_var;\
while(tmp_cur_v){\
PRINTF(" call : %ld : variables : %s \n\t\t",++cal_cur, tmp_cur_v->str_current_variables);\
tmp_cur_v = tmp_cur_v->next;\
}\
PRINTF("\n");\
}while(0);
__attribute__((destructor))
void
check_mock_excpected(){
//int kdefault=0, kgreen=1, kred=2, kyellow=3, kblue=4, knothing=5;
//int kdefault=0, kgreen=1, kred=2, kyellow=3, kblue=4, knothing;
if(unicolour) {
kgreen=5; kred=5; kyellow=5; kblue=5;
kgreen=knothing; kred=knothing; kyellow=knothing; kblue=knothing;
//for(int i=0; i< Dknothing;++i) strcpy(colors_f[i]," ");
}
struct winsize w;
@@ -143,50 +189,93 @@ __attribute__((destructor))
tfree=tmock;
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)){
PRINTF("%s%s %s %s expect to be called with condition %s, %s times, it was called %ld times and failed %ld times \n",colors_f[kred],HK_TR,tmock->str_namefunc,DEFAULT_K, tmock->str_conditions,
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[kred],HK_TR,colors_f[kyellow],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 );
tmock->failed_call,
tmock->str_conditions
);
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[kred],HK_TR,colors_f[kyellow],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,
tmock->str_conditions
);
}
tmock=tmock->next;
//free(tfree);
}
PRINTF("\n%s%s STAT MOCK : there are %ld mock functions, %ld wished response, %ld expected response, which are:\n\n",colors_f[kgreen],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[kgreen],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 */
while(tmp_list_fm){
tmp_inf_mock = tmp_list_fm->info_mock;
memset(reader,'=',w.ws_col-1);
char *caller = extract_func_edited_TEST_from_exec_func_name(tmp_inf_mock->str_caller);
size_t len_caller = strlen(caller);
char *nameff=extract_name_func_mock(tmp_inf_mock->str_namefunc);
size_t len_nameff=strlen(nameff);
size_t bg_rd=(w.ws_col - len_nameff)/2;
char *by_=" called by ";
size_t len_by_=strlen(by_);
size_t bg_rd=(w.ws_col - len_nameff - len_caller - len_by_)/2;
for(size_t i=0; i<len_nameff; ++i)
reader[bg_rd+i]=nameff[i];
for(size_t i=0;i<len_by_;++i)
reader[bg_rd+len_nameff+i]=by_[i];
for(size_t i=0;i<len_caller;++i)
reader[bg_rd+len_nameff+len_by_+i]=caller[i];
PRINTF("%s%s%s\n\n",colors_f[kblue],reader,DEFAULT_K );
while(tmp_inf_mock){
if(0==strncmp(tmp_inf_mock->str_namefunc,nameff, len_nameff)){
if(tmp_inf_mock->expect_call){
if(tmp_inf_mock->init_times_left == tmp_inf_mock->times_left || tmp_inf_mock->failed_call){
PRINTF("%s%s%s %s\t expect be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s \n" ,
colors_f[kred],HK_EQ,DEFAULT_K,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller);
int success = !((tmp_inf_mock->init_times_left == tmp_inf_mock->times_left) || (tmp_inf_mock->failed_call));
// if(tmp_inf_mock->init_times_left == tmp_inf_mock->times_left || tmp_inf_mock->failed_call){}
if(tmp_inf_mock->l_current_var){
PRINTF("%s%s%s %s\t expect %s,\t called %ld times and failed %ld times,\t called by: %s ,\t with condition: %s%s\n" ,
colors_f[!unicolour*(kred - success)],tab_hk_f[hk_EQ+success],colors_f[knothing * success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_caller, tmp_inf_mock->str_conditions, DEFAULT_K);
PRINT_VAR_CUR(tmp_inf_mock);
}else{
PRINTF("%s%s %s\t expect be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s %s\n" ,
PRINTF("%s%s%s %s\t expect %s,\t called %ld times and failed %ld times,\t call by: %s ,\t with condition: %s%s\n" ,
colors_f[!unicolour*(kred - success)],tab_hk_f[hk_EQ+success],colors_f[knothing*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_caller, tmp_inf_mock->str_conditions , DEFAULT_K);
/*PRINTF("%s%s %s\t expect %s,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s %s\n" ,
colors_f[kgreen],HK_TR,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller, DEFAULT_K);
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller, DEFAULT_K);*/
}
}else{/* will expect */
int success = !(tmp_inf_mock->failed_call);
if(tmp_inf_mock->l_current_var){
PRINTF("%s%s%s %s\t will %s,\t called %ld times and failed %ld times,\t called by: %s ,\t with condition: %s,%s\n" ,
colors_f[!unicolour*(kred + success)],tab_hk_f[hk_EQ+success],colors_f[knothing*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_caller, tmp_inf_mock->str_conditions , DEFAULT_K);
PRINT_VAR_CUR(tmp_inf_mock);
}else{
PRINTF("%s%s%s %s\t will %s,\t called %ld times and failed %ld times,\t called by: %s ,\t with condition: %s %s\n" ,
colors_f[!unicolour*(kred + success)],tab_hk_f[hk_EQ+success],colors_f[knothing*success],tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_caller, tmp_inf_mock->str_conditions , DEFAULT_K);
/*
if(tmp_inf_mock->failed_call){
PRINTF("%s%s%s %s\t will be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s \n" ,
PRINTF("%s%s%s %s\t will %s,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s \n" ,
colors_f[kred],HK_EQ,DEFAULT_K,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller);
}else{
PRINTF("%s%s %s\t will be call %s times,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s %s\n" ,
PRINTF("%s%s %s\t will %s,\t called %ld times and failed %ld times,\t with condition: %s,\t call by: %s %s\n" ,
colors_f[kyellow],HK_TR,tmp_inf_mock->str_namefunc, number_call_translate(tmp_inf_mock->init_times_left), tmp_inf_mock->call,
tmp_inf_mock->failed_call, tmp_inf_mock->str_conditions , tmp_inf_mock->str_caller, DEFAULT_K);
}*/
}
}
}
@@ -202,4 +291,3 @@ __attribute__((destructor))
pthread_mutex_destroy(&mut_count_f_mock);
pthread_mutex_destroy(&mut_count_expect_mock);
}
+46 -36
View File
@@ -8,11 +8,18 @@
#define INITSTATE -1
#define DONOTHING 0
struct list_current_variable{
char *str_current_variables;
struct list_current_variable *next;
};
struct func_mock_info_struct{
long id;
char *str_namefunc;
char *str_conditions;
char *str_caller;
//char *str_current_variables;
struct list_current_variable *l_current_var;
int expect_call;/* 1 if EXPECT_MOCK_CALL and 0 if WILL_MOCK_CALL */
long call;/* increment when call (try to executed) and 0 if not : init value */
long failed_call;/* increment when condition not fill and 0 if not : init value */
@@ -27,9 +34,11 @@ struct list_base_fmock{
};
int parse_count_args_(char *input);
void append_fmock_to_listmock(struct func_mock_info_struct **f_mock_list, struct func_mock_info_struct *f_mock);
void append_list_base_fmock(struct list_base_fmock **l_fmock, struct func_mock_info_struct *f_mock);
void append_variable_current(struct list_current_variable **lcurrent_var, char *current_var);
extern struct func_mock_info_struct *f_mock_glist;
extern struct list_base_fmock *g_list_base_fmock;
@@ -48,6 +57,7 @@ extern struct list_base_fmock *g_list_base_fmock;
struct list_mock_return_ ## namefunction{\
returntype (*run) args_prototype_with_parenthesis;\
int (*call_mock_condition) args_prototype_with_parenthesis ;/* to store condition */\
char* (*str_print_current_variables) args_prototype_with_parenthesis ;/* to store current variables CREATE by macro STR_PRINT_CUR_VAR same arguments as MOCK_FUNC without returntype whoch is always char * */\
/*int arg_count;*/\
struct func_mock_info_struct *info_mock;\
struct list_mock_return_ ## namefunction *next;\
@@ -58,6 +68,7 @@ extern struct list_base_fmock *g_list_base_fmock;
(list_mo_ ## namefunction.info_mock)->init_times_left = INITSTATE;\
/*list_mo_ ## namefunction.arg_count = parse_count_args_(#args_prototype_with_parenthesis);\
list_mo_ ## namefunction.call_mock_condition = malloc(list_mo_ ## namefunction.arg_count * sizeof( int (*)(void*))) ;*/\
list_mo_ ## namefunction.str_print_current_variables = NULL;\
list_mo_ ## namefunction.next = NULL;\
}\
returntype namefunction args_prototype_with_parenthesis {\
@@ -71,6 +82,8 @@ extern struct list_base_fmock *g_list_base_fmock;
}\
while(tmp_mock->next && (tmp_mock->info_mock)->times_left == 0) tmp_mock = tmp_mock->next ;\
++((tmp_mock->info_mock)->call);\
if(tmp_mock->str_print_current_variables)\
append_variable_current(&((tmp_mock->info_mock)->l_current_var), tmp_mock->str_print_current_variables args_call_with_parenthesis);\
/*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");*/\
if ((tmp_mock->info_mock)->times_left == 0) /*no longer response, default return */ \
@@ -107,33 +120,10 @@ extern struct list_base_fmock *g_list_base_fmock;
char* extract_name_func_mock(char *input);
#define EXPECT_EQ_IN_MOCKF(var1,var2, name_f_mocked)\
do{ HANDLE_OP_EXPECT_NAME(EQ,TYPE_INT,var1,var2,(list_mo_ ## name_f_mocked.info_mock)->str_caller,"mock test")}while(0)
#if 0
(tmp_mock->info_mock)->expect_call = f_expect_call;\
(tmp_mock->info_mock)->init_times_left = repeat;\
(tmp_mock->info_mock)->times_left = repeat;\
(tmp_mock->info_mock)->next = NULL;\
tmp_mock->call_mock_condition = CONCAT(namefunction ## _cond_, id);\
tmp_mock->run = CONCAT(run_ ## namefunction ## _line_, id);\
(tmp_mock->next)->run = CONCAT(run_ ## namefunction ## _line_, id);\
(tmp_mock->next)->call_mock_condition = CONCAT(namefunction ## _cond_, id);\
(tmp_mock->next)->info_mock = malloc(sizeof(struct func_mock_info_struct));\
((tmp_mock->next)->info_mock)->expect_call = f_expect_call;\
((tmp_mock->next)->info_mock)->init_times_left = repeat;\
((tmp_mock->next)->info_mock)->times_left = repeat;\
((tmp_mock->next)->info_mock)->str_namefunc = malloc(strlen(#namefunction));\
strcpy(((tmp_mock->next)->info_mock)->str_namefunc, #namefunction);\
((tmp_mock->next)->info_mock)->str_conditions = malloc(strlen(#condition_on_args_expression));\
strcpy(((tmp_mock->next)->info_mock)->str_conditions, #condition_on_args_expression;\
((tmp_mock->next)->info_mock)->next = NULL;\
(tmp_mock->next)->next = NULL;\
#endif
/*
* to inject the name TEST in the mock attribute info
@@ -148,54 +138,74 @@ char* extract_name_func_mock(char *input);
}\
}while(0);
#define FILL_MOCK_INFO(tmp_new_mock, namefunction, condition_on_args_expression , repeat, f_expect_call, id) \
(tmp_new_mock)->run = CONCAT(run_ ## namefunction ## _line_, id);\
#define STR_PRINT_CUR_VAR(namefunction, args_prototype_with_parenthesis, args_call_with_parenthesis)\
char* str_print_variables ## namefunction args_prototype_with_parenthesis;\
__attribute__((constructor)) void create_str_print_variables ## namefunction(){\
list_mo_ ## namefunction .str_print_current_variables = str_print_variables ## namefunction;\
}\
char* str_print_variables ## namefunction args_prototype_with_parenthesis
#define PRE_ID ___line_
#define FILL_MOCK_INFO(tmp_new_mock, namefunction, condition_on_args_expression , repeat, f_expect_call, pre_id, id, is_init) \
(tmp_new_mock)->run = CONCAT(run_ ## namefunction ## pre_id, id);\
(tmp_new_mock)->call_mock_condition = CONCAT(namefunction ## _cond_, id);\
if(!is_init)\
tmp_new_mock->str_print_current_variables = list_mo_ ## namefunction .str_print_current_variables;\
/*(tmp_new_mock)->info_mock = malloc(sizeof(struct func_mock_info_struct));*/\
((tmp_new_mock)->info_mock)->expect_call = f_expect_call;\
((tmp_new_mock)->info_mock)->call = 0;\
((tmp_new_mock)->info_mock)->failed_call = 0;\
((tmp_new_mock)->info_mock)->init_times_left = repeat;\
((tmp_new_mock)->info_mock)->times_left = repeat;\
((tmp_new_mock)->info_mock)->str_namefunc = malloc(strlen(#namefunction) + 32 + strlen("_line_"));\
sprintf(((tmp_new_mock)->info_mock)->str_namefunc,"%s_line_%d",#namefunction,id);\
((tmp_new_mock)->info_mock)->str_namefunc = malloc(strlen(#namefunction) + 32 + strlen(#pre_id));\
sprintf(((tmp_new_mock)->info_mock)->str_namefunc,"%s%s%d",#namefunction,#pre_id,id);\
((tmp_new_mock)->info_mock)->str_conditions = malloc(strlen(#condition_on_args_expression));\
strcpy(((tmp_new_mock)->info_mock)->str_conditions, #condition_on_args_expression);\
((tmp_new_mock)->info_mock)->str_caller = NULL;\
((tmp_new_mock)->info_mock)->l_current_var= NULL;\
((tmp_new_mock)->info_mock)->next = NULL;\
(tmp_new_mock)->next = NULL;\
append_fmock_to_listmock(&f_mock_glist, (tmp_new_mock)->info_mock);
#define ADD_RESPONSE(returntype, namefunction, args_prototype_with_parenthesis, condition_on_args_expression , repeat, f_expect_call, id)\
/*FUNC_type_ ## namefunction CONCAT(run_ ## namefunction ## _line_ , id);*/\
returntype CONCAT(run_ ## namefunction ## _line_ , id) args_prototype_with_parenthesis; \
#define ADD_RESPONSE_(returntype, namefunction, args_prototype_with_parenthesis, condition_on_args_expression , repeat, f_expect_call, pre_id, id)\
/*FUNC_type_ ## namefunction CONCAT(run_ ## namefunction ## pre_id , id);*/\
returntype CONCAT(run_ ## namefunction ## pre_id , id) args_prototype_with_parenthesis; \
int CONCAT(namefunction ## _cond_ , id) args_prototype_with_parenthesis {/*LOG("cond:%d\n",condition_on_args_expression);*/ return condition_on_args_expression;}\
__attribute__((constructor)) void CONCAT(append_list_ ## namefunction , id)(void){\
struct list_mock_return_ ## namefunction *tmp_mock = &list_mo_ ## namefunction;\
if((tmp_mock->info_mock)->times_left == INITSTATE){/* init state */\
FILL_MOCK_INFO(tmp_mock, namefunction, condition_on_args_expression , repeat, f_expect_call, id);\
FILL_MOCK_INFO(tmp_mock, namefunction, condition_on_args_expression , repeat, f_expect_call, pre_id, id, true);\
append_list_base_fmock( &g_list_base_fmock ,(tmp_mock->info_mock));\
}\
else{\
while(tmp_mock->next) tmp_mock = tmp_mock->next;\
tmp_mock->next = malloc(sizeof(list_mo_ ## namefunction));\
(tmp_mock->next)->info_mock = malloc(sizeof(struct func_mock_info_struct));\
FILL_MOCK_INFO(tmp_mock->next, namefunction, condition_on_args_expression , repeat, f_expect_call, id);\
FILL_MOCK_INFO(tmp_mock->next, namefunction, condition_on_args_expression , repeat, f_expect_call, pre_id, id, false);\
/*(tmp_mock->info_mock)->next = (tmp_mock->next)->info_mock ;*/\
}\
}\
returntype CONCAT(run_ ## namefunction ## _line_, id) args_prototype_with_parenthesis
returntype CONCAT(run_ ## namefunction ## pre_id, id) args_prototype_with_parenthesis
/*
* have to define this below macro to rewrite the right macro identifier (PRE_ID)
*/
#define ADD_RESPONSE(returntype, namefunction, args_prototype_with_parenthesis, condition_on_args_expression , repeat, f_expect_call, pre_id, id)\
ADD_RESPONSE_(returntype, namefunction, args_prototype_with_parenthesis, condition_on_args_expression , repeat, f_expect_call, pre_id, id)\
#define EXPECT_MOCK_CALL(returntype, namefunction, args_prototype_with_parenthesis, condition_on_args_expression ,repeat) \
ADD_RESPONSE(returntype,namefunction, args_prototype_with_parenthesis, condition_on_args_expression, repeat, 1, __LINE__)
ADD_RESPONSE(returntype,namefunction, args_prototype_with_parenthesis, condition_on_args_expression, repeat, 1, PRE_ID, __LINE__)
#define WILL_MOCK_CALL(returntype, namefunction, args_prototype_with_parenthesis, condition_on_args_expression ,repeat) \
ADD_RESPONSE(returntype,namefunction, args_prototype_with_parenthesis, condition_on_args_expression, repeat, 0, __LINE__)
ADD_RESPONSE(returntype,namefunction, args_prototype_with_parenthesis, condition_on_args_expression, repeat, 0, PRE_ID, __LINE__)
+50 -3
View File
@@ -111,7 +111,10 @@ char *default_bar_progress=" c";
//size_t width = 80;
char *colors_f[]={DEFAULT_K, GREEN_K, RED_K, YELLOW_K, BLUE_K, ""};
int kdefaukt=0, kgreen=1, kred=2, kyellow=3, kblue=4, knothing=5;
int kdefault=0, kgreen=1, kred=2, kyellow=3, kblue=4 , knothing= Dknothing;
char *tab_hk_f[]={ HK_EQ, HK_TR, HK_RN, HK_DN, HK_OK, HK_FL, HK_PS, HK_SK };
int hk_EQ=0, hk_TR=1, hk_RN=2, hk_DN=3, hk_OK=4, hk_FL=5, hk_PS=6, hk_SK=7 ;
bool some_tests_selected=0;
@@ -267,6 +270,43 @@ size_t extract_num__f(const char *name_f){
}
return val;
}
/* TEST_funcname___NUM -> TEST(funcname) */
char* extract_func_edited_TEST_from_exec_func_name(char* func_name){
size_t len=strlen(func_name);
char *ret_name=malloc(len);
strcpy(ret_name, func_name);
char *pad="____";
size_t len_pad=strlen(pad);
ret_name[4]='(';
for(size_t i=5;i<len-len_pad; ++i){
if(0==strncmp(func_name+i, pad,len_pad)){
ret_name[i]=')';
ret_name[i+1]='\0';
}
}
return ret_name;
}
// ========================== =================================
void setup_variables_before_exec(){
if(unicolour){
size_t len_bp = strlen(bar_progress);
size_t len_db = strlen(default_bar_progress);
if( len_bp >= len_db ){
char *tmp_bp=malloc(len_bp);
strcpy(tmp_bp,bar_progress);
tmp_bp[2]='u';
bar_progress=tmp_bp;
}
else{
char *tmp_bp=malloc(len_bp);
strcpy(tmp_bp,default_bar_progress);
tmp_bp[2]='u';
default_bar_progress=tmp_bp;
}
}
}
// ===================================== begin options handle =======================================================
@@ -305,6 +345,7 @@ void usage(int argc, char **argv){
exit(0);
}
if(only_usage) exit(0);
}
@@ -562,6 +603,7 @@ void parse_options(int argc, char **argv){
IF_NO_MATCH_DO_WRONG
}
setup_variables_before_exec();
}
// ==================================================== end handle option ================================
@@ -744,6 +786,8 @@ unsigned nnsleep(long long x) {
return 0;
}
#if 0
void progress_test_(){
struct func *tmp;
size_t num_test=0;
@@ -799,6 +843,8 @@ void progress_test_(){
printf("\n");
}
#endif
void bar_progress_test_(){
bar_progress_start();
@@ -951,7 +997,7 @@ GEN_IS_IN_ARRAY_PTR(TYPE_STRING)
GEN_IS_IN_ARRAY_NUM(TYPE_SIZE_T)
/*
* extract name test between () beacuse the syntax is TEST(name_test)
* extract name test between () because the syntax is TEST(name_test)
*/
void extract_name_test_from_name(char *name_org, char **name_f){
size_t len=strlen(name_org);
@@ -1351,10 +1397,11 @@ if(progress) pthread_join(thrd_progress, NULL);
final_parallel_test_();
}
void run_all_tests_args(int argc, char **argv){
parse_options(argc,argv);
if(help) usage(argc,argv);
if(is_parallel_nb) run_all_tests_parallel(parallel_nb);
else run_all_tests();
+14 -2
View File
@@ -19,8 +19,13 @@
#define YELLOW_K "\033[0;33m"
#define BLUE_K "\033[0;34m"
#define COLOR_SZ 6
extern char *colors_f[];
#define Dknothing COLOR_SZ - 1
#define SZ_TAB_HK 8
#ifdef HK
#define HK_EQ "[==========]"
@@ -58,7 +63,11 @@ extern bool unicolour;
extern bool ordered;
extern bool log_parallel;
extern int kdefaukt, kgreen, kred, kyellow, kblue, knothing;
extern char *colors_f[];
extern char *tab_hk_f[];
extern int kdefault, kgreen, kred, kyellow, kblue, knothing;
extern int hk_EQ, hk_TR, hk_RN, hk_DN, hk_OK, hk_FL, hk_PS, hk_SK;
#ifndef SAVE_LOG
#define SAVE_LOG 0
@@ -324,6 +333,9 @@ void parse_options(int argc, char **argv);
void run_all_tests();
void execute_all(struct func *fun);
void append_func(void (*run)(void), char *name);
char* extract_func_edited_TEST_from_exec_func_name(char* func_name); /* TEST_funcname___NUM -> TEST(funcname) */
/*
void run_some_tests(size_t cnt, ... );
void run_all_tests_exept(size_t cnt, ... );
+8
View File
@@ -196,6 +196,14 @@ TEST(mockf1){
MOCK_FUNC(int, f2_mock,(int a,int b),(a,b))
STR_PRINT_CUR_VAR(f2_mock, (int a,int b),(a,b)){
char *ret=malloc(150);
//char ret[150];
sprintf(ret,"(int)a: %d, (int)b: %d",a,b);
return ret;
}
EXPECT_MOCK_CALL(int, f2_mock, (int a,int b), (a<b), 3){
return a+b;
}