X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/649e8032974d045864c789e291320f61bdce482f..1e4c1a3b0188099d75edef236de08c1fb7d579d5:/testsuite/xbt/dict_usage.c diff --git a/testsuite/xbt/dict_usage.c b/testsuite/xbt/dict_usage.c index b7bd396b3a..f3ae427b7d 100644 --- a/testsuite/xbt/dict_usage.c +++ b/testsuite/xbt/dict_usage.c @@ -10,6 +10,7 @@ #include #include "gras.h" +#include "portable.h" XBT_LOG_EXTERNAL_CATEGORY(dict); XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); @@ -22,7 +23,7 @@ static xbt_error_t traverse(xbt_dict_t head); static void print_str(void *str); static void print_str(void *str) { - printf("%s",(char*)str); + printf("%s",(char*)PRINTF_STR(str)); } static void fill(xbt_dict_t *head) { @@ -45,7 +46,7 @@ static void debuged_add(xbt_dict_t head,const char*key) { char *data=xbt_strdup(key); - printf(" - Add %s\n",key); + printf(" - Add %s\n",PRINTF_STR(key)); xbt_dict_set(head,key,data,&free); if (XBT_LOG_ISENABLED(dict,xbt_log_priority_debug)) { xbt_dict_dump(head,(void (*)(void*))&printf); @@ -59,7 +60,9 @@ static xbt_error_t search(xbt_dict_t head,const char*key) { errcode=xbt_dict_get(head,key,&data); - printf(" - Search %s. Found %s\n",key,data?(char*)data:"(null)");fflush(stdout); + printf(" - Search %s. Found %s\n",PRINTF_STR(key),(char*) PRINTF_STR(data));fflush(stdout); + if (!data) + return errcode; if (strcmp((char*)data,key)) return mismatch_error; return errcode; @@ -69,7 +72,7 @@ static xbt_error_t debuged_remove(xbt_dict_t head,const char*key) { xbt_error_t errcode; - printf(" Remove '%s'\n",key);fflush(stdout); + printf(" Remove '%s'\n",PRINTF_STR(key));fflush(stdout); errcode=xbt_dict_remove(head,key); /* xbt_dict_dump(head,(void (*)(void*))&printf); */ return errcode; @@ -82,8 +85,8 @@ static xbt_error_t traverse(xbt_dict_t head) { char *data; xbt_dict_foreach(head,cursor,key,data) { - printf(" - Seen: %s->%s\n",key,data); - xbt_assert2(!strcmp(key,data), + printf(" - Seen: %s->%s\n",PRINTF_STR(key),PRINTF_STR(data)); + xbt_assert2(!data || !strcmp(key,data), "Key(%s) != value(%s). Abording\n",key,data); } return no_error; @@ -94,7 +97,7 @@ int main(int argc,char **argv) { xbt_dict_t head=NULL; char *data; - xbt_init_defaultlog(&argc,argv,"dict.thresh=verbose"); + xbt_init(&argc,argv); printf("\nGeneric dictionnary: USAGE test:\n"); @@ -108,6 +111,26 @@ int main(int argc,char **argv) { fill(&head); + /* xbt_dict_dump(head,(void (*)(void*))&printf);*/ + printf(" - Test that it works with NULL data\n"); + printf(" - Store NULL under 'null'\n");fflush(stdout); + xbt_dict_set(head,"null",NULL,NULL); + TRYFAIL(search(head,"null")); + /* xbt_dict_dump(head,(void (*)(void*))&printf); */ + printf(" Check whether I see it while traversing\n");fflush(stdout); + { + xbt_dict_cursor_t cursor=NULL; + char *key; + int found=0; + + xbt_dict_foreach(head,cursor,key,data) { + printf(" - Seen: %s->%s\n",PRINTF_STR(key),PRINTF_STR(data));fflush(stdout); + if (!strcmp(key,"null")) + found = 1; + } + xbt_assert0(found,"the key 'null', associated to NULL is not found"); + } + printf(" - Change some values\n"); printf(" - Change 123 to 'Changed 123'\n"); xbt_dict_set(head,"123",strdup("Changed 123"),&free);