From: mquinson Date: Tue, 22 Aug 2006 21:17:54 +0000 (+0000) Subject: Check that we can have the content being different of the key, and improve the tests... X-Git-Tag: v3.3~2636 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/efcb7beaff700ddcdca284436a934504be4d0b0b Check that we can have the content being different of the key, and improve the tests a tiny bit git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2723 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 8f2a80f98d..2f6101b5ce 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -458,11 +458,10 @@ static void print_str(void *str) { printf("%s",(char*)PRINTF_STR(str)); } -static void debuged_add(xbt_dict_t head,const char*key) -{ - char *data=xbt_strdup(key); +static void debuged_add_ext(xbt_dict_t head,const char*key,const char*data_to_fill) { + char *data=xbt_strdup(data_to_fill); - xbt_test_log1("Add %s",PRINTF_STR(key)); + xbt_test_log2("Add %s under %s",PRINTF_STR(data_to_fill),PRINTF_STR(key)); xbt_dict_set(head,key,data,&free); if (XBT_LOG_ISENABLED(xbt_dict,xbt_log_priority_debug)) { @@ -470,6 +469,9 @@ static void debuged_add(xbt_dict_t head,const char*key) fflush(stdout); } } +static void debuged_add(xbt_dict_t head,const char*key) { + debuged_add_ext(head,key,key); +} static void fill(xbt_dict_t *head) { xbt_test_add0("Fill in the dictionnary"); @@ -486,14 +488,21 @@ static void fill(xbt_dict_t *head) { debuged_add(*head,"123457"); } -static void search(xbt_dict_t head,const char*key) { - void *data; + +static void search_ext(xbt_dict_t head,const char*key, const char *data) { + void *found; xbt_test_add1("Search %s",key); - data=xbt_dict_get(head,key); - xbt_test_log1("Found %s",(char *)data); + found=xbt_dict_get(head,key); + xbt_test_log1("Found %s",(char *)found); if (data) - xbt_test_assert0(!strcmp((char*)data,key),"Key and data do not match"); + xbt_test_assert1(found,"data do not match expectations: found NULL while searching for %s",data); + if (found) + xbt_test_assert2(!strcmp((char*)data,found),"data do not match expectations: found %s while searching for %s", (char*)found, data); +} + +static void search(xbt_dict_t head,const char*key) { + search_ext(head,key,key); } static void debuged_remove(xbt_dict_t head,const char*key) { @@ -551,6 +560,10 @@ XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse") xbt_test_add0("Traverse the full dictionnary"); fill(&head); count(head, 7); + + debuged_add_ext(head,"toto","tutu"); + search_ext(head,"toto","tutu"); + debuged_remove(head,"toto"); search(head,"12a"); traverse(head); @@ -672,7 +685,7 @@ XBT_TEST_UNIT("nulldata",test_dict_nulldata,"NULL data management"){ xbt_test_add0("Store NULL under 'null'"); xbt_dict_set(head,"null",NULL,NULL); - search(head,"null"); + search_ext(head,"null",NULL); xbt_test_add0("Check whether I see it while traversing..."); {