From: mquinson Date: Mon, 10 Nov 2008 14:03:23 +0000 (+0000) Subject: Commit a bunch of auto-generated files (sorry) X-Git-Tag: v3.3~111 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/268c232e62981d322f66e2d3f75455c9fe56aa65 Commit a bunch of auto-generated files (sorry) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6010 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/config_unit.c b/src/config_unit.c index f1931ea43a..f63b83a9e9 100644 --- a/src/config_unit.c +++ b/src/config_unit.c @@ -8,13 +8,13 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -# 1145 "xbt/config.c" +# 1124 "xbt/config.c" #include "xbt.h" #include "xbt/ex.h" static xbt_cfg_t make_set(){ - xbt_cfg_t set=NULL; + xbt_cfg_t set=NULL; set = xbt_cfg_new(); xbt_cfg_register_str(set,"speed:1_to_2_int"); @@ -35,14 +35,14 @@ XBT_TEST_UNIT("memuse",test_config_memuse,"Alloc and free a config set") { XBT_TEST_UNIT("validation",test_config_validation,"Validation tests") { xbt_cfg_t set = set=make_set(); xbt_ex_t e; - + xbt_test_add0("Having too few elements for speed"); xbt_cfg_set_parse(set, "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand"); TRY { xbt_cfg_check(set); } CATCH(e) { - if (e.category != mismatch_error || - strncmp(e.msg,"Config elem speed needs",strlen("Config elem speed needs"))) + if (e.category != mismatch_error || + strncmp(e.msg,"Config elem speed needs",strlen("Config elem speed needs"))) xbt_test_fail1("Got an exception. msg=%s",e.msg); xbt_ex_free(e); } @@ -52,14 +52,14 @@ XBT_TEST_UNIT("validation",test_config_validation,"Validation tests") { xbt_test_add0("Having too much values of 'speed'"); - set=make_set(); + set=make_set(); xbt_cfg_set_parse(set,"peername:toto:42 user:alegrand"); TRY { xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34"); } CATCH(e) { if (e.category != mismatch_error || - strncmp(e.msg,"Cannot add value 34 to the config elem speed", - strlen("Config elem speed needs"))) + strncmp(e.msg,"Cannot add value 34 to the config elem speed", + strlen("Config elem speed needs"))) xbt_test_fail1("Got an exception. msg=%s",e.msg); xbt_ex_free(e); } @@ -72,30 +72,30 @@ XBT_TEST_UNIT("validation",test_config_validation,"Validation tests") { XBT_TEST_UNIT("use",test_config_use,"Data retrieving tests") { xbt_test_add0("Get a single value"); - { + { /* get_single_value */ int ival; xbt_cfg_t myset=make_set(); - + xbt_cfg_set_parse(myset,"peername:toto:42 speed:42"); - ival = xbt_cfg_get_int(myset,"speed"); - if (ival != 42) + ival = xbt_cfg_get_int(myset,"speed"); + if (ival != 42) xbt_test_fail1("Speed value = %d, I expected 42",ival); xbt_cfg_free(&myset); } xbt_test_add0("Get multiple values"); - { + { /* get_multiple_value */ - xbt_dynar_t dyn; + xbt_dynar_t dyn; xbt_cfg_t myset=make_set(); - + xbt_cfg_set_parse(myset, "peername:veloce user:foo\nuser:bar\tuser:toto"); xbt_cfg_set_parse(myset,"speed:42"); - xbt_cfg_check(myset); + xbt_cfg_check(myset); dyn = xbt_cfg_get_dynar(myset,"user"); - if (xbt_dynar_length(dyn) != 3) + if (xbt_dynar_length(dyn) != 3) xbt_test_fail1("Dynar length = %lu, I expected 3", xbt_dynar_length(dyn)); if (strcmp(xbt_dynar_get_as(dyn,0,char*),"foo")) @@ -106,15 +106,15 @@ XBT_TEST_UNIT("use",test_config_use,"Data retrieving tests") { if (strcmp(xbt_dynar_get_as(dyn,2,char*),"toto")) xbt_test_fail1("Dynar[2] = %s, I expected toto", xbt_dynar_get_as(dyn,2,char*)); - xbt_cfg_free(&myset); + xbt_cfg_free(&myset); } - + xbt_test_add0("Access to a non-existant entry"); - { + { /* non-existant_entry */ xbt_cfg_t myset=make_set(); xbt_ex_t e; - + TRY { xbt_cfg_set_parse(myset, "color:blue"); } CATCH(e) { @@ -122,7 +122,7 @@ XBT_TEST_UNIT("use",test_config_use,"Data retrieving tests") { xbt_test_exception(e); xbt_ex_free(e); } - xbt_cfg_free(&myset); + xbt_cfg_free(&myset); } } /*******************************/ diff --git a/src/cunit_unit.c b/src/cunit_unit.c index b4f05cf696..8772a34ab0 100644 --- a/src/cunit_unit.c +++ b/src/cunit_unit.c @@ -8,17 +8,17 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -# 731 "xbt/cunit.c" +# 752 "xbt/cunit.c" XBT_TEST_UNIT("expect",test_expected_failure,"expected failures") { - xbt_test_add0("Skipped test"); - xbt_test_skip(); + xbt_test_add0("Skipped test"); + xbt_test_skip(); - xbt_test_add2("%s %s","EXPECTED","FAILURE"); - xbt_test_expect_failure(); - xbt_test_log2("%s %s","Test","log"); - xbt_test_fail0("EXPECTED FAILURE"); + xbt_test_add2("%s %s","EXPECTED","FAILURE"); + xbt_test_expect_failure(); + xbt_test_log2("%s %s","Test","log"); + xbt_test_fail0("EXPECTED FAILURE"); } /*******************************/ diff --git a/src/dict_unit.c b/src/dict_unit.c index 52632f0907..7d5032e8f8 100644 --- a/src/dict_unit.c +++ b/src/dict_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -# 604 "xbt/dict.c" +# 639 "xbt/dict.c" #include "xbt.h" #include "xbt/ex.h" #include "portable.h" @@ -33,7 +33,7 @@ static void debuged_add_ext(xbt_dict_t head,const char*key,const char*data_to_fi } } static void debuged_add(xbt_dict_t head,const char*key) { - debuged_add_ext(head,key,key); + debuged_add_ext(head,key,key); } static void fill(xbt_dict_t *head) { @@ -54,7 +54,7 @@ static void fill(xbt_dict_t *head) { static void search_ext(xbt_dict_t head,const char*key, const char *data) { void *found; - + xbt_test_add1("Search %s",key); found=xbt_dict_get(head,key); xbt_test_log1("Found %s",(char *)found); @@ -83,13 +83,13 @@ static void traverse(xbt_dict_t head) { int i = 0; xbt_dict_foreach(head,cursor,key,data) { - if (!key || !data || strcmp(key,data)) { - xbt_test_log3("Seen #%d: %s->%s",++i,PRINTF_STR(key),PRINTF_STR(data)); + if (!key || !data || strcmp(key,data)) { + xbt_test_log3("Seen #%d: %s->%s",++i,PRINTF_STR(key),PRINTF_STR(data)); } else { - xbt_test_log2("Seen #%d: %s",++i,PRINTF_STR(key)); + xbt_test_log2("Seen #%d: %s",++i,PRINTF_STR(key)); } xbt_test_assert2(!data || !strcmp(key,data), - "Key(%s) != value(%s). Abording",key,data); + "Key(%s) != value(%s). Aborting",key,data); } } @@ -99,11 +99,11 @@ static void search_not_found(xbt_dict_t head, const char *data) { xbt_test_add1("Search %s (expected not to be found)",data); - TRY { + TRY { data = xbt_dict_get(head, data); THROW1(unknown_error,0,"Found something which shouldn't be there (%s)",data); } CATCH(e) { - if (e.category != not_found_error) + if (e.category != not_found_error) xbt_test_exception(e); xbt_ex_free(e); ok=1; @@ -120,7 +120,7 @@ static void count(xbt_dict_t dict, int length) { xbt_test_add1("Count elements (expecting %d)", length); xbt_test_assert2(xbt_dict_length(dict) == length, "Announced length(%d) != %d.", xbt_dict_length(dict), length); - + xbt_dict_foreach(dict,cursor,key,data) { effective++; } @@ -133,25 +133,25 @@ char *data; XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse"){ - xbt_test_add0("Traversal the null dictionnary"); + xbt_test_add0("Traversal the null dictionary"); traverse(head); - xbt_test_add0("Traversal and search the empty dictionnary"); + xbt_test_add0("Traversal and search the empty dictionary"); head = xbt_dict_new(); traverse(head); TRY { debuged_remove(head,"12346"); } CATCH(e) { - if (e.category != not_found_error) + if (e.category != not_found_error) xbt_test_exception(e); xbt_ex_free(e); } xbt_dict_free(&head); - xbt_test_add0("Traverse the full dictionnary"); + xbt_test_add0("Traverse the full dictionary"); fill(&head); count(head, 7); - + debuged_add_ext(head,"toto","tutu"); search_ext(head,"toto","tutu"); debuged_remove(head,"toto"); @@ -159,7 +159,7 @@ XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse") search(head,"12a"); traverse(head); - xbt_test_add0("Free the dictionnary (twice)"); + xbt_test_add0("Free the dictionary (twice)"); xbt_dict_free(&head); xbt_dict_free(&head); @@ -182,9 +182,9 @@ XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse") xbt_dict_set(head,"12a",strdup("12a"),&free); count(head, 7); - xbt_test_add0("Traverse the resulting dictionnary"); + xbt_test_add0("Traverse the resulting dictionary"); traverse(head); - + /* RETRIEVE */ xbt_test_add0("Search 123"); data = xbt_dict_get(head,"123"); @@ -202,16 +202,16 @@ XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse") search(head,"1234"); search(head,"123457"); - xbt_test_add0("Traverse the resulting dictionnary"); + xbt_test_add0("Traverse the resulting dictionary"); traverse(head); /* xbt_dict_dump(head,(void (*)(void*))&printf); */ - xbt_test_add0("Free the dictionnary twice"); + xbt_test_add0("Free the dictionary twice"); xbt_dict_free(&head); xbt_dict_free(&head); - xbt_test_add0("Traverse the resulting dictionnary"); + xbt_test_add0("Traverse the resulting dictionary"); traverse(head); } @@ -222,7 +222,7 @@ XBT_TEST_UNIT("remove",test_dict_remove,"Removing some values"){ TRY { debuged_remove(head,"Does not exist"); } CATCH(e) { - if (e.category != not_found_error) + if (e.category != not_found_error) xbt_test_exception(e); xbt_ex_free(e); } @@ -230,7 +230,7 @@ XBT_TEST_UNIT("remove",test_dict_remove,"Removing some values"){ xbt_dict_free(&head); - xbt_test_add0("Remove each data manually (traversing the resulting dictionnary each time)"); + xbt_test_add0("Remove each data manually (traversing the resulting dictionary each time)"); fill(&head); debuged_remove(head,"12a"); traverse(head); count(head, 6); @@ -243,22 +243,22 @@ XBT_TEST_UNIT("remove",test_dict_remove,"Removing some values"){ TRY { debuged_remove(head,"12346"); } CATCH(e) { - if (e.category != not_found_error) + if (e.category != not_found_error) xbt_test_exception(e); - xbt_ex_free(e); + xbt_ex_free(e); traverse(head); - } + } debuged_remove(head,"1234"); traverse(head); debuged_remove(head,"123457"); traverse(head); debuged_remove(head,"123"); traverse(head); TRY { debuged_remove(head,"12346"); } CATCH(e) { - if (e.category != not_found_error) + if (e.category != not_found_error) xbt_test_exception(e); xbt_ex_free(e); } traverse(head); - + xbt_test_add0("Free dict, create new fresh one, and then reset the dict"); xbt_dict_free(&head); fill(&head); @@ -266,9 +266,9 @@ XBT_TEST_UNIT("remove",test_dict_remove,"Removing some values"){ count(head, 0); traverse(head); - xbt_test_add0("Free the dictionnary twice"); + xbt_test_add0("Free the dictionary twice"); + xbt_dict_free(&head); xbt_dict_free(&head); - xbt_dict_free(&head); } XBT_TEST_UNIT("nulldata",test_dict_nulldata,"NULL data management"){ @@ -285,14 +285,14 @@ XBT_TEST_UNIT("nulldata",test_dict_nulldata,"NULL data management"){ int found=0; xbt_dict_foreach(head,cursor,key,data) { - if (!key || !data || strcmp(key,data)) { - xbt_test_log2("Seen: %s->%s",PRINTF_STR(key),PRINTF_STR(data)); + if (!key || !data || strcmp(key,data)) { + xbt_test_log2("Seen: %s->%s",PRINTF_STR(key),PRINTF_STR(data)); } else { - xbt_test_log1("Seen: %s",PRINTF_STR(key)); + xbt_test_log1("Seen: %s",PRINTF_STR(key)); } - + if (!strcmp(key,"null")) - found = 1; + found = 1; } xbt_test_assert0(found,"the key 'null', associated to NULL is not found"); } @@ -312,7 +312,7 @@ static int countelems(xbt_dict_t head) { } return res; } - + XBT_TEST_UNIT("crash",test_dict_crash,"Crash test"){ xbt_dict_t head=NULL; int i,j,k, nb; @@ -332,18 +332,18 @@ XBT_TEST_UNIT("crash",test_dict_crash,"Crash test"){ char *data = NULL; key=xbt_malloc(SIZEOFKEY); - do { - for (k=0;k0) printf("Test %d\n",i); /* else if (i%10) printf("."); else printf("%d",i/10);*/ - + for (j=0;j0) printf (" Add {"); - + for (l=0 ; l0) printf("%p=%s %s ",key, key,(l0) printf("%p=%s %s ",key, key,(l0) printf("in multitree %p.\n",mdict); - + xbt_multidict_set(mdict,keys,xbt_strdup(key),free); data = xbt_multidict_get(mdict,keys); xbt_test_assert2(data && !strcmp((char*)data,key), - "Retrieved value (%s) does not match the entrered one (%s)\n", - (char*)data,key); + "Retrieved value (%s) does not match the given one (%s)\n", + (char*)data,key); } xbt_dict_free(&mdict); } - + xbt_dynar_free(&keys); -/* if (verbose>0) + /* if (verbose>0) xbt_dict_dump(mdict,&xbt_dict_print);*/ - + xbt_dict_free(&mdict); xbt_dynar_free(&keys); diff --git a/src/dynar_unit.c b/src/dynar_unit.c index 3b34ae54fa..fefe9c5a03 100644 --- a/src/dynar_unit.c +++ b/src/dynar_unit.c @@ -16,410 +16,405 @@ XBT_LOG_EXTERNAL_CATEGORY(xbt_dyn); XBT_LOG_DEFAULT_CATEGORY(xbt_dyn); XBT_TEST_UNIT("int",test_dynar_int,"Dynars of integers") { - /* Vars_decl [doxygen cruft] */ - xbt_dynar_t d; - int i,cpt; - unsigned int cursor; - int *iptr; - - xbt_test_add0("==== Traverse the empty dynar"); - d=xbt_dynar_new(sizeof(int),NULL); - xbt_dynar_foreach(d,cursor,i){ - xbt_assert0(0,"Damnit, there is something in the empty dynar"); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - xbt_test_add1("==== Push %d int, set them again 3 times, traverse them, shift them", - NB_ELEM); - /* Populate_ints [doxygen cruft] */ - /* 1. Populate the dynar */ - d=xbt_dynar_new(sizeof(int),NULL); - for (cpt=0; cpt< NB_ELEM; cpt++) { - xbt_dynar_push_as(d,int,cpt); /* This is faster (and possible only with scalars) */ - /* xbt_dynar_push(d,&cpt); This would also work */ - xbt_test_log2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); - } - - /* 2. Traverse manually the dynar */ - for (cursor=0; cursor< NB_ELEM; cursor++) { - iptr=xbt_dynar_get_ptr(d,cursor); - xbt_test_assert2(cursor == *iptr, - "The retrieved value is not the same than the injected one (%d!=%d)", - cursor,cpt); - } - - /* 3. Traverse the dynar using the neat macro to that extend */ - xbt_dynar_foreach(d,cursor,cpt){ - xbt_test_assert2(cursor == cpt, - "The retrieved value is not the same than the injected one (%d!=%d)", - cursor,cpt); - } - /* end_of_traversal */ - - for (cpt=0; cpt< NB_ELEM; cpt++) - *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; - - for (cpt=0; cpt< NB_ELEM; cpt++) - *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; -/* xbt_dynar_set(d,cpt,&cpt);*/ - - for (cpt=0; cpt< NB_ELEM; cpt++) - *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; - - cpt=0; - xbt_dynar_foreach(d,cursor,i){ - xbt_test_assert2(i == cpt, - "The retrieved value is not the same than the injected one (%d!=%d)", - i,cpt); - cpt++; - } - xbt_test_assert2(cpt == NB_ELEM, - "Cannot retrieve my %d values. Last got one is %d", - NB_ELEM, cpt); - - /* shifting [doxygen cruft] */ - /* 4. Shift all the values */ - for (cpt=0; cpt< NB_ELEM; cpt++) { - xbt_dynar_shift(d,&i); - xbt_test_assert2(i == cpt, - "The retrieved value is not the same than the injected one (%d!=%d)", - i,cpt); - xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); - } - - /* 5. Free the resources */ - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add1("==== Unshift/pop %d int",NB_ELEM); - d=xbt_dynar_new(sizeof(int),NULL); - for (cpt=0; cpt< NB_ELEM; cpt++) { - xbt_dynar_unshift(d,&cpt); - DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); - } - for (cpt=0; cpt< NB_ELEM; cpt++) { - i=xbt_dynar_pop_as(d,int); - xbt_test_assert2(i == cpt, - "The retrieved value is not the same than the injected one (%d!=%d)", - i,cpt); - xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add1("==== Push %d int, insert 1000 int in the middle, shift everything",NB_ELEM); - d=xbt_dynar_new(sizeof(int),NULL); - for (cpt=0; cpt< NB_ELEM; cpt++) { - xbt_dynar_push_as(d,int,cpt); - DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); - } - for (cpt=0; cpt< 1000; cpt++) { - xbt_dynar_insert_at_as(d,2500,int,cpt); - DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); - } - - for (cpt=0; cpt< 2500; cpt++) { - xbt_dynar_shift(d,&i); - xbt_test_assert2(i == cpt, - "The retrieved value is not the same than the injected one at the begining (%d!=%d)", - i,cpt); - DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); - } - for (cpt=999; cpt>=0; cpt--) { - xbt_dynar_shift(d,&i); - xbt_test_assert2(i == cpt, - "The retrieved value is not the same than the injected one in the middle (%d!=%d)", - i,cpt); - } - for (cpt=2500; cpt< NB_ELEM; cpt++) { - xbt_dynar_shift(d,&i); - xbt_test_assert2(i == cpt, - "The retrieved value is not the same than the injected one at the end (%d!=%d)", - i,cpt); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest",NB_ELEM); - d=xbt_dynar_new(sizeof(int),NULL); - for (cpt=0; cpt< NB_ELEM; cpt++) - xbt_dynar_push_as(d,int,cpt); - - for (cpt=2000; cpt< 4000; cpt++) { - xbt_dynar_remove_at(d,2000,&i); - xbt_test_assert2(i == cpt, - "Remove a bad value. Got %d, expected %d", - i,cpt); - DEBUG2("remove %d, length=%lu",cpt, xbt_dynar_length(d)); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); + /* Vars_decl [doxygen cruft] */ + xbt_dynar_t d; + int i,cpt; + unsigned int cursor; + int *iptr; + + xbt_test_add0("==== Traverse the empty dynar"); + d=xbt_dynar_new(sizeof(int),NULL); + xbt_dynar_foreach(d,cursor,i){ + xbt_assert0(0,"Damnit, there is something in the empty dynar"); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + xbt_test_add1("==== Push %d int, set them again 3 times, traverse them, shift them", + NB_ELEM); + /* Populate_ints [doxygen cruft] */ + /* 1. Populate the dynar */ + d=xbt_dynar_new(sizeof(int),NULL); + for (cpt=0; cpt< NB_ELEM; cpt++) { + xbt_dynar_push_as(d,int,cpt); /* This is faster (and possible only with scalars) */ + /* xbt_dynar_push(d,&cpt); This would also work */ + xbt_test_log2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); + } + + /* 2. Traverse manually the dynar */ + for (cursor=0; cursor< NB_ELEM; cursor++) { + iptr=xbt_dynar_get_ptr(d,cursor); + xbt_test_assert2(cursor == *iptr, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor,cpt); + } + + /* 3. Traverse the dynar using the neat macro to that extend */ + xbt_dynar_foreach(d,cursor,cpt){ + xbt_test_assert2(cursor == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor,cpt); + } + /* end_of_traversal */ + + for (cpt=0; cpt< NB_ELEM; cpt++) + *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; + + for (cpt=0; cpt< NB_ELEM; cpt++) + *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; + /* xbt_dynar_set(d,cpt,&cpt);*/ + + for (cpt=0; cpt< NB_ELEM; cpt++) + *(int*)xbt_dynar_get_ptr(d,cpt) = cpt; + + cpt=0; + xbt_dynar_foreach(d,cursor,i){ + xbt_test_assert2(i == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + i,cpt); + cpt++; + } + xbt_test_assert2(cpt == NB_ELEM, + "Cannot retrieve my %d values. Last got one is %d", + NB_ELEM, cpt); + + /* shifting [doxygen cruft] */ + /* 4. Shift all the values */ + for (cpt=0; cpt< NB_ELEM; cpt++) { + xbt_dynar_shift(d,&i); + xbt_test_assert2(i == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + i,cpt); + xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); + } + + /* 5. Free the resources */ + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add1("==== Unshift/pop %d int",NB_ELEM); + d=xbt_dynar_new(sizeof(int),NULL); + for (cpt=0; cpt< NB_ELEM; cpt++) { + xbt_dynar_unshift(d,&cpt); + DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); + } + for (cpt=0; cpt< NB_ELEM; cpt++) { + i=xbt_dynar_pop_as(d,int); + xbt_test_assert2(i == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + i,cpt); + xbt_test_log2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add1("==== Push %d int, insert 1000 int in the middle, shift everything",NB_ELEM); + d=xbt_dynar_new(sizeof(int),NULL); + for (cpt=0; cpt< NB_ELEM; cpt++) { + xbt_dynar_push_as(d,int,cpt); + DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); + } + for (cpt=0; cpt< 1000; cpt++) { + xbt_dynar_insert_at_as(d,2500,int,cpt); + DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(d)); + } + + for (cpt=0; cpt< 2500; cpt++) { + xbt_dynar_shift(d,&i); + xbt_test_assert2(i == cpt, + "The retrieved value is not the same than the injected one at the begining (%d!=%d)", + i,cpt); + DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); + } + for (cpt=999; cpt>=0; cpt--) { + xbt_dynar_shift(d,&i); + xbt_test_assert2(i == cpt, + "The retrieved value is not the same than the injected one in the middle (%d!=%d)", + i,cpt); + } + for (cpt=2500; cpt< NB_ELEM; cpt++) { + xbt_dynar_shift(d,&i); + xbt_test_assert2(i == cpt, + "The retrieved value is not the same than the injected one at the end (%d!=%d)", + i,cpt); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add1("==== Push %d int, remove 2000-4000. free the rest",NB_ELEM); + d=xbt_dynar_new(sizeof(int),NULL); + for (cpt=0; cpt< NB_ELEM; cpt++) + xbt_dynar_push_as(d,int,cpt); + + for (cpt=2000; cpt< 4000; cpt++) { + xbt_dynar_remove_at(d,2000,&i); + xbt_test_assert2(i == cpt, + "Remove a bad value. Got %d, expected %d", + i,cpt); + DEBUG2("remove %d, length=%lu",cpt, xbt_dynar_length(d)); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); } /*******************************************************************************/ /*******************************************************************************/ /*******************************************************************************/ XBT_TEST_UNIT("double",test_dynar_double,"Dynars of doubles") { - xbt_dynar_t d; - int cpt; - unsigned int cursor; - double d1,d2; - - xbt_test_add0("==== Traverse the empty dynar"); - d=xbt_dynar_new(sizeof(int),NULL); - xbt_dynar_foreach(d,cursor,cpt){ - xbt_test_assert0(FALSE, - "Damnit, there is something in the empty dynar"); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - xbt_test_add0("==== Push/shift 5000 doubles"); - d=xbt_dynar_new(sizeof(double),NULL); - for (cpt=0; cpt< 5000; cpt++) { - d1=(double)cpt; - xbt_dynar_push(d,&d1); - } - xbt_dynar_foreach(d,cursor,d2){ - d1=(double)cursor; - xbt_test_assert2(d1 == d2, - "The retrieved value is not the same than the injected one (%f!=%f)", - d1,d2); - } - for (cpt=0; cpt< 5000; cpt++) { - d1=(double)cpt; - xbt_dynar_shift(d,&d2); - xbt_test_assert2(d1 == d2, - "The retrieved value is not the same than the injected one (%f!=%f)", - d1,d2); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add0("==== Unshift/pop 5000 doubles"); - d=xbt_dynar_new(sizeof(double),NULL); - for (cpt=0; cpt< 5000; cpt++) { - d1=(double)cpt; - xbt_dynar_unshift(d,&d1); - } - for (cpt=0; cpt< 5000; cpt++) { - d1=(double)cpt; - xbt_dynar_pop(d,&d2); - xbt_test_assert2 (d1 == d2, - "The retrieved value is not the same than the injected one (%f!=%f)", - d1,d2); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - - xbt_test_add0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything"); - d=xbt_dynar_new(sizeof(double),NULL); - for (cpt=0; cpt< 5000; cpt++) { - d1=(double)cpt; - xbt_dynar_push(d,&d1); - } - for (cpt=0; cpt< 1000; cpt++) { - d1=(double)cpt; - xbt_dynar_insert_at(d,2500,&d1); - } - - for (cpt=0; cpt< 2500; cpt++) { - d1=(double)cpt; - xbt_dynar_shift(d,&d2); - xbt_test_assert2(d1 == d2, - "The retrieved value is not the same than the injected one at the begining (%f!=%f)", - d1,d2); - DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); - } - for (cpt=999; cpt>=0; cpt--) { - d1=(double)cpt; - xbt_dynar_shift(d,&d2); - xbt_test_assert2 (d1 == d2, - "The retrieved value is not the same than the injected one in the middle (%f!=%f)", - d1,d2); - } - for (cpt=2500; cpt< 5000; cpt++) { - d1=(double)cpt; - xbt_dynar_shift(d,&d2); - xbt_test_assert2 (d1 == d2, - "The retrieved value is not the same than the injected one at the end (%f!=%f)", - d1,d2); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest"); - d=xbt_dynar_new(sizeof(double),NULL); - for (cpt=0; cpt< 5000; cpt++) { - d1=(double)cpt; - xbt_dynar_push(d,&d1); - } - for (cpt=2000; cpt< 4000; cpt++) { - d1=(double)cpt; - xbt_dynar_remove_at(d,2000,&d2); - xbt_test_assert2 (d1 == d2, - "Remove a bad value. Got %f, expected %f", - d2,d1); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); + xbt_dynar_t d; + int cpt; + unsigned int cursor; + double d1,d2; + + xbt_test_add0("==== Traverse the empty dynar"); + d=xbt_dynar_new(sizeof(int),NULL); + xbt_dynar_foreach(d,cursor,cpt){ + xbt_test_assert0(FALSE, + "Damnit, there is something in the empty dynar"); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + xbt_test_add0("==== Push/shift 5000 doubles"); + d=xbt_dynar_new(sizeof(double),NULL); + for (cpt=0; cpt< 5000; cpt++) { + d1=(double)cpt; + xbt_dynar_push(d,&d1); + } + xbt_dynar_foreach(d,cursor,d2){ + d1=(double)cursor; + xbt_test_assert2(d1 == d2, + "The retrieved value is not the same than the injected one (%f!=%f)", + d1,d2); + } + for (cpt=0; cpt< 5000; cpt++) { + d1=(double)cpt; + xbt_dynar_shift(d,&d2); + xbt_test_assert2(d1 == d2, + "The retrieved value is not the same than the injected one (%f!=%f)", + d1,d2); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add0("==== Unshift/pop 5000 doubles"); + d=xbt_dynar_new(sizeof(double),NULL); + for (cpt=0; cpt< 5000; cpt++) { + d1=(double)cpt; + xbt_dynar_unshift(d,&d1); + } + for (cpt=0; cpt< 5000; cpt++) { + d1=(double)cpt; + xbt_dynar_pop(d,&d2); + xbt_test_assert2 (d1 == d2, + "The retrieved value is not the same than the injected one (%f!=%f)", + d1,d2); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + + xbt_test_add0("==== Push 5000 doubles, insert 1000 doubles in the middle, shift everything"); + d=xbt_dynar_new(sizeof(double),NULL); + for (cpt=0; cpt< 5000; cpt++) { + d1=(double)cpt; + xbt_dynar_push(d,&d1); + } + for (cpt=0; cpt< 1000; cpt++) { + d1=(double)cpt; + xbt_dynar_insert_at(d,2500,&d1); + } + + for (cpt=0; cpt< 2500; cpt++) { + d1=(double)cpt; + xbt_dynar_shift(d,&d2); + xbt_test_assert2(d1 == d2, + "The retrieved value is not the same than the injected one at the begining (%f!=%f)", + d1,d2); + DEBUG2("Pop %d, length=%lu",cpt, xbt_dynar_length(d)); + } + for (cpt=999; cpt>=0; cpt--) { + d1=(double)cpt; + xbt_dynar_shift(d,&d2); + xbt_test_assert2 (d1 == d2, + "The retrieved value is not the same than the injected one in the middle (%f!=%f)", + d1,d2); + } + for (cpt=2500; cpt< 5000; cpt++) { + d1=(double)cpt; + xbt_dynar_shift(d,&d2); + xbt_test_assert2 (d1 == d2, + "The retrieved value is not the same than the injected one at the end (%f!=%f)", + d1,d2); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add0("==== Push 5000 double, remove 2000-4000. free the rest"); + d=xbt_dynar_new(sizeof(double),NULL); + for (cpt=0; cpt< 5000; cpt++) { + d1=(double)cpt; + xbt_dynar_push(d,&d1); + } + for (cpt=2000; cpt< 4000; cpt++) { + d1=(double)cpt; + xbt_dynar_remove_at(d,2000,&d2); + xbt_test_assert2 (d1 == d2, + "Remove a bad value. Got %f, expected %f", + d2,d1); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); } /* doxygen_string_cruft */ -/* The function we will use to free the data */ -static void free_string(void *d){ - free(*(void**)d); -} - /*******************************************************************************/ /*******************************************************************************/ /*******************************************************************************/ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") { - xbt_dynar_t d; - int cpt; - unsigned int iter; - char buf[1024]; - char *s1,*s2; - - xbt_test_add0("==== Traverse the empty dynar"); - d=xbt_dynar_new(sizeof(char *),&free_string); - xbt_dynar_foreach(d,iter,s1){ - xbt_test_assert0(FALSE, - "Damnit, there is something in the empty dynar"); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM); - /* Populate_str [doxygen cruft] */ - d=xbt_dynar_new(sizeof(char*),&free_string); - /* 1. Populate the dynar */ - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_push(d,&s1); - } - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_replace(d,cpt,&s1); - } - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_replace(d,cpt,&s1); - } - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_replace(d,cpt,&s1); - } - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - xbt_dynar_shift(d,&s2); - xbt_test_assert2 (!strcmp(buf,s2), - "The retrieved value is not the same than the injected one (%s!=%s)", - buf,s2); - free(s2); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add1("==== Unshift, traverse and pop %d strings",NB_ELEM); - d=xbt_dynar_new(sizeof(char**),&free_string); - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_unshift(d,&s1); - } - /* 2. Traverse the dynar with the macro */ - xbt_dynar_foreach(d,iter,s1) { - sprintf(buf,"%d",NB_ELEM - iter -1); - xbt_test_assert2 (!strcmp(buf,s1), - "The retrieved value is not the same than the injected one (%s!=%s)", - buf,s1); - } - /* 3. Traverse the dynar with the macro */ - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - xbt_dynar_pop(d,&s2); - xbt_test_assert2 (!strcmp(buf,s2), - "The retrieved value is not the same than the injected one (%s!=%s)", - buf,s2); - free(s2); - } - /* 4. Free the resources */ - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5); - d=xbt_dynar_new(sizeof(char*),&free_string); - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_push(d,&s1); - } - for (cpt=0; cpt< NB_ELEM/5; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_insert_at(d,NB_ELEM/2,&s1); - } - - for (cpt=0; cpt< NB_ELEM/2; cpt++) { - sprintf(buf,"%d",cpt); - xbt_dynar_shift(d,&s2); - xbt_test_assert2(!strcmp(buf,s2), - "The retrieved value is not the same than the injected one at the begining (%s!=%s)", - buf,s2); - free(s2); - } - for (cpt=(NB_ELEM/5)-1; cpt>=0; cpt--) { - sprintf(buf,"%d",cpt); - xbt_dynar_shift(d,&s2); - xbt_test_assert2 (!strcmp(buf,s2), - "The retrieved value is not the same than the injected one in the middle (%s!=%s)", - buf,s2); - free(s2); - } - for (cpt=NB_ELEM/2; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - xbt_dynar_shift(d,&s2); - xbt_test_assert2 (!strcmp(buf,s2), - "The retrieved value is not the same than the injected one at the end (%s!=%s)", - buf,s2); - free(s2); - } - xbt_dynar_free(&d); - xbt_dynar_free(&d); - - - xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5)); - d=xbt_dynar_new(sizeof(char*),&free_string); - for (cpt=0; cpt< NB_ELEM; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_push(d,&s1); - } - for (cpt=2*(NB_ELEM/5); cpt< 4*(NB_ELEM/5); cpt++) { - sprintf(buf,"%d",cpt); - xbt_dynar_remove_at(d,2*(NB_ELEM/5),&s2); - xbt_test_assert2(!strcmp(buf,s2), - "Remove a bad value. Got %s, expected %s", - s2,buf); - free(s2); - } - xbt_dynar_free(&d); /* end_of_doxygen */ + xbt_dynar_t d; + int cpt; + unsigned int iter; + char buf[1024]; + char *s1,*s2; + + xbt_test_add0("==== Traverse the empty dynar"); + d=xbt_dynar_new(sizeof(char *),&xbt_free_ref); + xbt_dynar_foreach(d,iter,s1){ + xbt_test_assert0(FALSE, + "Damnit, there is something in the empty dynar"); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + xbt_test_add1("==== Push %d strings, set them again 3 times, shift them",NB_ELEM); + /* Populate_str [doxygen cruft] */ + d=xbt_dynar_new(sizeof(char*),&xbt_free_ref); + /* 1. Populate the dynar */ + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_push(d,&s1); + } + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_replace(d,cpt,&s1); + } + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_replace(d,cpt,&s1); + } + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_replace(d,cpt,&s1); + } + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + xbt_dynar_shift(d,&s2); + xbt_test_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one (%s!=%s)", + buf,s2); + free(s2); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add1("==== Unshift, traverse and pop %d strings",NB_ELEM); + d=xbt_dynar_new(sizeof(char**),&xbt_free_ref); + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_unshift(d,&s1); + } + /* 2. Traverse the dynar with the macro */ + xbt_dynar_foreach(d,iter,s1) { + sprintf(buf,"%d",NB_ELEM - iter -1); + xbt_test_assert2 (!strcmp(buf,s1), + "The retrieved value is not the same than the injected one (%s!=%s)", + buf,s1); + } + /* 3. Traverse the dynar with the macro */ + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + xbt_dynar_pop(d,&s2); + xbt_test_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one (%s!=%s)", + buf,s2); + free(s2); + } + /* 4. Free the resources */ + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add2("==== Push %d strings, insert %d strings in the middle, shift everything",NB_ELEM,NB_ELEM/5); + d=xbt_dynar_new(sizeof(char*),&xbt_free_ref); + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_push(d,&s1); + } + for (cpt=0; cpt< NB_ELEM/5; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_insert_at(d,NB_ELEM/2,&s1); + } + + for (cpt=0; cpt< NB_ELEM/2; cpt++) { + sprintf(buf,"%d",cpt); + xbt_dynar_shift(d,&s2); + xbt_test_assert2(!strcmp(buf,s2), + "The retrieved value is not the same than the injected one at the begining (%s!=%s)", + buf,s2); + free(s2); + } + for (cpt=(NB_ELEM/5)-1; cpt>=0; cpt--) { + sprintf(buf,"%d",cpt); + xbt_dynar_shift(d,&s2); + xbt_test_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one in the middle (%s!=%s)", + buf,s2); + free(s2); + } + for (cpt=NB_ELEM/2; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + xbt_dynar_shift(d,&s2); + xbt_test_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one at the end (%s!=%s)", + buf,s2); + free(s2); + } + xbt_dynar_free(&d); + xbt_dynar_free(&d); + + + xbt_test_add3("==== Push %d strings, remove %d-%d. free the rest",NB_ELEM,2*(NB_ELEM/5),4*(NB_ELEM/5)); + d=xbt_dynar_new(sizeof(char*),&xbt_free_ref); + for (cpt=0; cpt< NB_ELEM; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_push(d,&s1); + } + for (cpt=2*(NB_ELEM/5); cpt< 4*(NB_ELEM/5); cpt++) { + sprintf(buf,"%d",cpt); + xbt_dynar_remove_at(d,2*(NB_ELEM/5),&s2); + xbt_test_assert2(!strcmp(buf,s2), + "Remove a bad value. Got %s, expected %s", + s2,buf); + free(s2); + } + xbt_dynar_free(&d); /* end_of_doxygen */ } @@ -428,45 +423,45 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") { /*******************************************************************************/ #include "xbt/synchro.h" static void pusher_f(void *a) { - xbt_dynar_t d=(xbt_dynar_t)a; - int i; - for (i=0; i<500; i++) { - xbt_dynar_push(d,&i); - } + xbt_dynar_t d=(xbt_dynar_t)a; + int i; + for (i=0; i<500; i++) { + xbt_dynar_push(d,&i); + } } static void poper_f(void *a) { - xbt_dynar_t d=(xbt_dynar_t)a; - int i; - int data; - xbt_ex_t e; - - for (i=0; i<500; i++) { - TRY { - xbt_dynar_pop(d,&data); - } CATCH(e) { - if (e.category == bound_error) { - xbt_ex_free(e); - i--; - } else { - RETHROW; - } + xbt_dynar_t d=(xbt_dynar_t)a; + int i; + int data; + xbt_ex_t e; + + for (i=0; i<500; i++) { + TRY { + xbt_dynar_pop(d,&data); + } CATCH(e) { + if (e.category == bound_error) { + xbt_ex_free(e); + i--; + } else { + RETHROW; } - } + } + } } - + XBT_TEST_UNIT("synchronized int",test_dynar_sync_int,"Synchronized dynars of integers") { - /* Vars_decl [doxygen cruft] */ - xbt_dynar_t d; - xbt_thread_t pusher,poper; - - xbt_test_add0("==== Have a pusher and a popper on the dynar"); - d=xbt_dynar_new_sync(sizeof(int),NULL); - pusher = xbt_thread_create("pusher",pusher_f,d); - poper = xbt_thread_create("poper",poper_f,d); - xbt_thread_join(pusher); - xbt_thread_join(poper); - xbt_dynar_free(&d); + /* Vars_decl [doxygen cruft] */ + xbt_dynar_t d; + xbt_thread_t pusher,poper; + + xbt_test_add0("==== Have a pusher and a popper on the dynar"); + d=xbt_dynar_new_sync(sizeof(int),NULL); + pusher = xbt_thread_create("pusher",pusher_f,d); + poper = xbt_thread_create("poper",poper_f,d); + xbt_thread_join(pusher); + xbt_thread_join(poper); + xbt_dynar_free(&d); } /*******************************/ diff --git a/src/ex_unit.c b/src/ex_unit.c index 199ecbbee4..2281e6bf75 100644 --- a/src/ex_unit.c +++ b/src/ex_unit.c @@ -14,124 +14,124 @@ XBT_TEST_UNIT("controlflow",test_controlflow, "basic nested control flow") { - xbt_ex_t ex; - volatile int n=1; + xbt_ex_t ex; + volatile int n=1; - xbt_test_add0("basic nested control flow"); + xbt_test_add0("basic nested control flow"); + TRY { + if (n != 1) + xbt_test_fail1("M1: n=%d (!= 1)", n); + n++; TRY { - if (n != 1) - xbt_test_fail1("M1: n=%d (!= 1)", n); - n++; - TRY { - if (n != 2) - xbt_test_fail1("M2: n=%d (!= 2)", n); - n++; - THROW0(unknown_error,0,"something"); - } CATCH (ex) { - if (n != 3) - xbt_test_fail1("M3: n=%d (!= 3)", n); - n++; - xbt_ex_free(ex); - } - n++; - TRY { - if (n != 5) - xbt_test_fail1("M2: n=%d (!= 5)", n); - n++; - THROW0(unknown_error,0,"something"); - } CATCH (ex) { - if (n != 6) - xbt_test_fail1("M3: n=%d (!= 6)", n); - n++; - RETHROW; - n++; - } - xbt_test_fail1("MX: n=%d (shouldn't reach this point)", n); + if (n != 2) + xbt_test_fail1("M2: n=%d (!= 2)", n); + n++; + THROW0(unknown_error,0,"something"); + } CATCH (ex) { + if (n != 3) + xbt_test_fail1("M3: n=%d (!= 3)", n); + n++; + xbt_ex_free(ex); } - CATCH(ex) { - if (n != 7) - xbt_test_fail1("M4: n=%d (!= 7)", n); - n++; - xbt_ex_free(ex); + n++; + TRY { + if (n != 5) + xbt_test_fail1("M2: n=%d (!= 5)", n); + n++; + THROW0(unknown_error,0,"something"); + } CATCH (ex) { + if (n != 6) + xbt_test_fail1("M3: n=%d (!= 6)", n); + n++; + RETHROW; + n++; } - if (n != 8) - xbt_test_fail1("M5: n=%d (!= 8)", n); + xbt_test_fail1("MX: n=%d (shouldn't reach this point)", n); + } + CATCH(ex) { + if (n != 7) + xbt_test_fail1("M4: n=%d (!= 7)", n); + n++; + xbt_ex_free(ex); + } + if (n != 8) + xbt_test_fail1("M5: n=%d (!= 8)", n); } XBT_TEST_UNIT("value",test_value,"exception value passing") { - xbt_ex_t ex; + xbt_ex_t ex; - TRY { - THROW0(unknown_error, 2, "toto"); - } CATCH(ex) { - xbt_test_add0("exception value passing"); - if (ex.category != unknown_error) - xbt_test_fail1("category=%d (!= 1)", ex.category); - if (ex.value != 2) - xbt_test_fail1("value=%d (!= 2)", ex.value); - if (strcmp(ex.msg,"toto")) - xbt_test_fail1("message=%s (!= toto)", ex.msg); - xbt_ex_free(ex); - } + TRY { + THROW0(unknown_error, 2, "toto"); + } CATCH(ex) { + xbt_test_add0("exception value passing"); + if (ex.category != unknown_error) + xbt_test_fail1("category=%d (!= 1)", ex.category); + if (ex.value != 2) + xbt_test_fail1("value=%d (!= 2)", ex.value); + if (strcmp(ex.msg,"toto")) + xbt_test_fail1("message=%s (!= toto)", ex.msg); + xbt_ex_free(ex); + } } XBT_TEST_UNIT("variables",test_variables,"variable value preservation") { - xbt_ex_t ex; - int r1, r2; - volatile int v1, v2; + xbt_ex_t ex; + int r1, r2; + volatile int v1, v2; - r1 = r2 = v1 = v2 = 1234; - TRY { - r2 = 5678; - v2 = 5678; - THROW0(unknown_error, 0, "toto"); - } CATCH(ex) { - xbt_test_add0("variable preservation"); - if (r1 != 1234) - xbt_test_fail1("r1=%d (!= 1234)", r1); - if (v1 != 1234) - xbt_test_fail1("v1=%d (!= 1234)", v1); - /* r2 is allowed to be destroyed because not volatile */ - if (v2 != 5678) - xbt_test_fail1("v2=%d (!= 5678)", v2); - xbt_ex_free(ex); - } + r1 = r2 = v1 = v2 = 1234; + TRY { + r2 = 5678; + v2 = 5678; + THROW0(unknown_error, 0, "toto"); + } CATCH(ex) { + xbt_test_add0("variable preservation"); + if (r1 != 1234) + xbt_test_fail1("r1=%d (!= 1234)", r1); + if (v1 != 1234) + xbt_test_fail1("v1=%d (!= 1234)", v1); + /* r2 is allowed to be destroyed because not volatile */ + if (v2 != 5678) + xbt_test_fail1("v2=%d (!= 5678)", v2); + xbt_ex_free(ex); + } } XBT_TEST_UNIT("cleanup",test_cleanup,"cleanup handling") { - xbt_ex_t ex; - volatile int v1; - int c; + xbt_ex_t ex; + volatile int v1; + int c; - xbt_test_add0("cleanup handling"); + xbt_test_add0("cleanup handling"); - v1 = 1234; - c = 0; - TRY { - v1 = 5678; - THROW0(1, 2, "blah"); - } CLEANUP { - if (v1 != 5678) - xbt_test_fail1("v1 = %d (!= 5678)", v1); - c = 1; - } CATCH(ex) { - if (v1 != 5678) - xbt_test_fail1("v1 = %d (!= 5678)", v1); - if (!(ex.category == 1 && ex.value == 2 && !strcmp(ex.msg,"blah"))) - xbt_test_fail0("unexpected exception contents"); - xbt_ex_free(ex); - } - if (!c) - xbt_test_fail0("xbt_ex_free not executed"); + v1 = 1234; + c = 0; + TRY { + v1 = 5678; + THROW0(1, 2, "blah"); + } CLEANUP { + if (v1 != 5678) + xbt_test_fail1("v1 = %d (!= 5678)", v1); + c = 1; + } CATCH(ex) { + if (v1 != 5678) + xbt_test_fail1("v1 = %d (!= 5678)", v1); + if (!(ex.category == 1 && ex.value == 2 && !strcmp(ex.msg,"blah"))) + xbt_test_fail0("unexpected exception contents"); + xbt_ex_free(ex); + } + if (!c) + xbt_test_fail0("xbt_ex_free not executed"); } /* - * The following is the example included in the documentation. It's a good + * The following is the example included in the documentation. It's a good * idea to check its syntax even if we don't try to run it. * And actually, it allows to put comments in the code despite doxygen. - */ + */ static char *mallocex(int size) { return NULL; } @@ -146,7 +146,7 @@ static void bad_example(void) { /* BAD_EXAMPLE */ TRY { char *cp1, *cp2, *cp3; - + cp1 = mallocex(SMALLAMOUNT); globalcontext->first = cp1; cp2 = mallocex(TOOBIG); @@ -165,7 +165,7 @@ static void bad_example(void) { } #endif typedef struct {char *first;} global_context_t; - + static void good_example(void) { global_context_t *global_context=malloc(sizeof(global_context_t)); xbt_ex_t ex; @@ -186,9 +186,9 @@ static void good_example(void) { } CLEANUP { /*04*/ printf("cp3=%s", cp3 == NULL /*02*/ ? "" : cp3); if (cp3 != NULL) - free(cp3); + free(cp3); if (cp2 != NULL) - free(cp2); + free(cp2); /*05 cp1 was given away */ } CATCH(ex) { /*05 global context untouched */ diff --git a/src/gras_config.h.in b/src/gras_config.h.in index dd0c895a07..69773ee1bc 100644 --- a/src/gras_config.h.in +++ b/src/gras_config.h.in @@ -74,7 +74,7 @@ /* Define to 1 if you have the `gettimeofday' function. */ #undef HAVE_GETTIMEOFDAY -/* Indicates whether we have the GTNETS library or not */ +/* Indicates that we have GTNETS support */ #undef HAVE_GTNETS /* Define to 1 if you have the header file. */ @@ -156,6 +156,9 @@ /* Define to 1 if you have the `usleep' function. */ #undef HAVE_USLEEP +/* Define to 1 if you have the header file. */ +#undef HAVE_VALGRIND_VALGRIND_H + /* Define if va_copy() macro exists (and no fallback implementation is required) */ #undef HAVE_VA_COPY @@ -172,6 +175,10 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WINSOCK_H +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + /* enable the asprintf replacement */ #undef NEED_ASPRINTF diff --git a/src/set_unit.c b/src/set_unit.c index 39337b1113..13ebb2cc66 100644 --- a/src/set_unit.c +++ b/src/set_unit.c @@ -35,8 +35,8 @@ static void my_elem_free(void *e) { } static void debuged_add(xbt_set_t set, - const char *name, - const char *data) { + const char *name, + const char *data) { my_elem_t elm; elm = xbt_new(s_my_elem_t,1); @@ -70,14 +70,14 @@ static void search_name(xbt_set_t head,const char*key) { xbt_test_add1("Search by name %s",key); elm = (my_elem_t)xbt_set_get_by_name(head,key); xbt_test_log2(" Found %s (under ID %d)\n", - elm? elm->data:"(null)", - elm? elm->ID:-1); + elm? elm->data:"(null)", + elm? elm->ID:-1); if (strcmp(key,elm->name)) THROW2(mismatch_error,0,"The key (%s) is not the one expected (%s)", - key,elm->name); + key,elm->name); if (strcmp(elm->name,elm->data)) THROW2(mismatch_error,0,"The name (%s) != data (%s)", - key,elm->name); + key,elm->name); fflush(stdout); } @@ -87,30 +87,30 @@ static void search_id(xbt_set_t head,int id,const char*key) { xbt_test_add1("Search by id %d",id); elm = (my_elem_t) xbt_set_get_by_id(head,id); xbt_test_log2("Found %s (data %s)", - elm? elm->name:"(null)", - elm? elm->data:"(null)"); + elm? elm->name:"(null)", + elm? elm->data:"(null)"); if (id != elm->ID) THROW2(mismatch_error,0,"The found ID (%d) is not the one expected (%d)", - elm->ID,id); + elm->ID,id); if (strcmp(key,elm->name)) THROW2(mismatch_error,0,"The key (%s) is not the one expected (%s)", - elm->name,key); + elm->name,key); if (strcmp(elm->name,elm->data)) THROW2(mismatch_error,0,"The name (%s) != data (%s)", - elm->name,elm->data); + elm->name,elm->data); } static void traverse(xbt_set_t set) { xbt_set_cursor_t cursor=NULL; my_elem_t elm=NULL; - + xbt_set_foreach(set,cursor,elm) { xbt_test_assert0(elm,"Dude ! Got a null elm during traversal!"); xbt_test_log3("Id(%d): %s->%s\n",elm->ID,elm->name,elm->data); xbt_test_assert2(!strcmp(elm->name,elm->data), - "Key(%s) != value(%s). Abording", - elm->name,elm->data); + "Key(%s) != value(%s). Abording", + elm->name,elm->data); } } @@ -122,9 +122,9 @@ static void search_not_found(xbt_set_t set, const char *data) { xbt_set_get_by_name(set,data); THROW1(unknown_error,0,"Found something which shouldn't be there (%s)",data); } CATCH(e) { - if (e.category != not_found_error) + if (e.category != not_found_error) xbt_test_exception(e); - xbt_ex_free(e); + xbt_ex_free(e); } } @@ -136,7 +136,7 @@ XBT_TEST_UNIT("basic",test_set_basic,"Basic usage") { xbt_test_add0("Traverse the empty set"); traverse(set); - + xbt_test_add0("Free a data set"); fill(&set); xbt_set_free(&set); diff --git a/src/simgrid_units_main.c b/src/simgrid_units_main.c index 909fdce9a3..60d81b8b8f 100644 --- a/src/simgrid_units_main.c +++ b/src/simgrid_units_main.c @@ -20,6 +20,19 @@ extern xbt_test_unit_t _xbt_current_unit; void test_cleanup(void); /* SGU: END FILE */ + /* SGU: BEGIN FILE xbt/xbt_str.c */ + void test_split_quoted(void); + void test_split_str(void); + /* SGU: END FILE */ + + /* SGU: BEGIN FILE xbt/xbt_strbuff.c */ + void test_strbuff_substitute(void); + /* SGU: END FILE */ + + /* SGU: BEGIN FILE xbt/xbt_sha.c */ + void test_crypto_sha(void); + /* SGU: END FILE */ + /* SGU: BEGIN FILE xbt/dynar.c */ void test_dynar_int(void); void test_dynar_double(void); @@ -46,15 +59,6 @@ extern xbt_test_unit_t _xbt_current_unit; void test_swag_basic(void); /* SGU: END FILE */ - /* SGU: BEGIN FILE xbt/xbt_str.c */ - void test_split_quoted(void); - void test_split_str(void); - /* SGU: END FILE */ - - /* SGU: BEGIN FILE xbt/xbt_sha.c */ - void test_crypto_sha(void); - /* SGU: END FILE */ - /* SGU: BEGIN FILE xbt/config.c */ void test_config_memuse(void); void test_config_validation(void); @@ -87,6 +91,22 @@ int main(int argc, char *argv[]) { xbt_test_suite_push(suite, "cleanup", test_cleanup, "cleanup handling"); /* SGU: END FILE */ + /* SGU: BEGIN FILE xbt/xbt_str.c */ + suite = xbt_test_suite_by_name("xbt_str","String Handling"); + xbt_test_suite_push(suite, "xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted"); + xbt_test_suite_push(suite, "xbt_str_split_str", test_split_str, "test the function xbt_str_split_str"); + /* SGU: END FILE */ + + /* SGU: BEGIN FILE xbt/xbt_strbuff.c */ + suite = xbt_test_suite_by_name("xbt_strbuff","String Buffers"); + xbt_test_suite_push(suite, "xbt_strbuff_substitute", test_strbuff_substitute, "test the function xbt_strbuff_substitute"); + /* SGU: END FILE */ + + /* SGU: BEGIN FILE xbt/xbt_sha.c */ + suite = xbt_test_suite_by_name("hash","Various hash functions"); + xbt_test_suite_push(suite, "sha", test_crypto_sha, "Test of the sha algorithm"); + /* SGU: END FILE */ + /* SGU: BEGIN FILE xbt/dynar.c */ suite = xbt_test_suite_by_name("dynar","Dynar data container"); xbt_test_suite_push(suite, "int", test_dynar_int, "Dynars of integers"); @@ -117,17 +137,6 @@ int main(int argc, char *argv[]) { xbt_test_suite_push(suite, "basic", test_swag_basic, "Basic usage"); /* SGU: END FILE */ - /* SGU: BEGIN FILE xbt/xbt_str.c */ - suite = xbt_test_suite_by_name("xbt_str","String Handling"); - xbt_test_suite_push(suite, "xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted"); - xbt_test_suite_push(suite, "xbt_str_split_str", test_split_str, "test the function xbt_str_split_str"); - /* SGU: END FILE */ - - /* SGU: BEGIN FILE xbt/xbt_sha.c */ - suite = xbt_test_suite_by_name("hash","Various hash functions"); - xbt_test_suite_push(suite, "sha", test_crypto_sha, "Test of the sha algorithm"); - /* SGU: END FILE */ - /* SGU: BEGIN FILE xbt/config.c */ suite = xbt_test_suite_by_name("config","Configuration support"); xbt_test_suite_push(suite, "memuse", test_config_memuse, "Alloc and free a config set"); @@ -183,6 +192,7 @@ int main(int argc, char *argv[]) { /* Got all my tests to do */ res = xbt_test_run(selection); + xbt_test_exit(); xbt_exit(); return res; } diff --git a/src/swag_unit.c b/src/swag_unit.c index 72846ba54b..b42d38a4dc 100644 --- a/src/swag_unit.c +++ b/src/swag_unit.c @@ -30,7 +30,7 @@ XBT_TEST_UNIT("basic",test_swag_basic,"Basic usage") { xbt_test_add0("Basic usage"); xbt_test_log3("%p %p %ld\n",obj1,&(obj1->setB), - (long)((char *)&(obj1->setB) - (char *)obj1)); + (long)((char *)&(obj1->setB) - (char *)obj1)); setA = xbt_swag_new(xbt_swag_offset(*obj1,setA)); setB = xbt_swag_new(xbt_swag_offset(*obj1,setB)); @@ -62,7 +62,7 @@ XBT_TEST_UNIT("basic",test_swag_basic,"Basic usage") { xbt_test_assert(xbt_swag_size(setA) == 2); xbt_test_assert(xbt_swag_size(setB) == 1); - + xbt_swag_free(setA); xbt_swag_free(setB); } diff --git a/src/xbt_sha_unit.c b/src/xbt_sha_unit.c index fea298cf36..597841688e 100644 --- a/src/xbt_sha_unit.c +++ b/src/xbt_sha_unit.c @@ -8,13 +8,13 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -# 164 "xbt/xbt_sha.c" +# 167 "xbt/xbt_sha.c" #include "xbt/hash.h" #include "portable.h" /* hexa_str */ static char* mycmp(const char *p1, const char *p2,size_t n) { int i; - + for (i=0; i +#include "xbt.h" +/*******************************/ +/* GENERATED FILE, DO NOT EDIT */ +/*******************************/ + +# 254 "xbt/xbt_strbuff.c" +#include "xbt/strbuff.h" + +/* buffstr have 512 chars by default. Adding 1000 chars like this will force a resize, allowing us to test that b->used and b->size are consistent */ +#define force_resize \ + "1.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "2.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "3.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "4.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "5.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "6.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "7.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "8.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "9.........1.........2.........3.........4.........5.........6.........7.........8.........9........." \ + "0.........1.........2.........3.........4.........5.........6.........7.........8.........9........." + +static void mytest(const char *input, const char *patterns, const char *expected) { + xbt_dynar_t dyn_patterns; /* splited string */ + xbt_dict_t p; /* patterns */ + unsigned int cpt; char *str; /*foreach*/ + xbt_strbuff_t sb; /* what we test */ + + p=xbt_dict_new(); + dyn_patterns=xbt_str_split(patterns," "); + xbt_dynar_foreach(dyn_patterns,cpt,str) { + xbt_dynar_t keyvals = xbt_str_split(str,"="); + char *key = xbt_dynar_get_as(keyvals,0,char*); + char *val = xbt_dynar_get_as(keyvals,1,char*); + xbt_str_subst(key,'_',' ',0); // to put space in names without breaking the enclosing dynar_foreach + xbt_dict_set(p,key,xbt_strdup(val),free); + xbt_dynar_free(&keyvals); + } + xbt_dynar_free(&dyn_patterns); + sb = xbt_strbuff_new(); + xbt_strbuff_append(sb,input); + xbt_strbuff_varsubst(sb, p); + xbt_dict_free(&p); + xbt_test_assert4(!strcmp(sb->data,expected), + "Input (%s) with patterns (%s) leads to (%s) instead of (%s)", + input,patterns,sb->data,expected); + xbt_strbuff_free(sb); +} + +XBT_TEST_UNIT("xbt_strbuff_substitute",test_strbuff_substitute, "test the function xbt_strbuff_substitute") { + xbt_test_add0("Empty");mytest("", "", ""); + + xbt_test_add0("Value shorter, no braces, only variable");mytest("$tutu", "tutu=t", "t"); + xbt_test_add0("Value shorter, braces, only variable");mytest("${tutu}", "tutu=t", "t"); + xbt_test_add0("Value shorter, no braces, data after");mytest("$tutu toto", "tutu=t", "t toto"); + xbt_test_add0("Value shorter, braces, data after");mytest("${tutu} toto", "tutu=t", "t toto"); + xbt_test_add0("Value shorter, no braces, data before");mytest("toto $tutu", "tutu=t", "toto t"); + xbt_test_add0("Value shorter, braces, data before");mytest("toto ${tutu}", "tutu=t", "toto t"); + xbt_test_add0("Value shorter, no braces, data before and after");mytest("toto $tutu tata", "tutu=t", "toto t tata"); + xbt_test_add0("Value shorter, braces, data before and after");mytest("toto ${tutu} tata", "tutu=t", "toto t tata"); + + xbt_test_add0("Value as long, no braces, only variable");mytest("$tutu", "tutu=12345", "12345"); + xbt_test_add0("Value as long, braces, only variable");mytest("${tutu}", "tutu=1234567", "1234567"); + xbt_test_add0("Value as long, no braces, data after");mytest("$tutu toto", "tutu=12345", "12345 toto"); + xbt_test_add0("Value as long, braces, data after");mytest("${tutu} toto", "tutu=1234567", "1234567 toto"); + xbt_test_add0("Value as long, no braces, data before");mytest("toto $tutu", "tutu=12345", "toto 12345"); + xbt_test_add0("Value as long, braces, data before");mytest("toto ${tutu}", "tutu=1234567", "toto 1234567"); + xbt_test_add0("Value as long, no braces, data before and after");mytest("toto $tutu tata", "tutu=12345", "toto 12345 tata"); + xbt_test_add0("Value as long, braces, data before and after");mytest("toto ${tutu} tata", "tutu=1234567", "toto 1234567 tata"); + + xbt_test_add0("Value longer, no braces, only variable");mytest("$t", "t=tututu", "tututu"); + xbt_test_add0("Value longer, braces, only variable");mytest("${t}", "t=tututu", "tututu"); + xbt_test_add0("Value longer, no braces, data after");mytest("$t toto", "t=tututu", "tututu toto"); + xbt_test_add0("Value longer, braces, data after");mytest("${t} toto", "t=tututu", "tututu toto"); + xbt_test_add0("Value longer, no braces, data before");mytest("toto $t", "t=tututu", "toto tututu"); + xbt_test_add0("Value longer, braces, data before");mytest("toto ${t}", "t=tututu", "toto tututu"); + xbt_test_add0("Value longer, no braces, data before and after");mytest("toto $t tata", "t=tututu", "toto tututu tata"); + xbt_test_add0("Value longer, braces, data before and after");mytest("toto ${t} tata", "t=tututu", "toto tututu tata"); + + xbt_test_add0("Value much longer, no braces, only variable");mytest("$t", "t=" force_resize, force_resize); + xbt_test_add0("Value much longer, no braces, data after");mytest("$t toto", "t=" force_resize, force_resize " toto"); + xbt_test_add0("Value much longer, braces, data after");mytest("${t} toto", "t=" force_resize, force_resize " toto"); + xbt_test_add0("Value much longer, no braces, data before");mytest("toto $t", "t=" force_resize, "toto " force_resize); + xbt_test_add0("Value much longer, braces, data before");mytest("toto ${t}", "t=" force_resize, "toto " force_resize); + xbt_test_add0("Value much longer, no braces, data before and after");mytest("toto $t tata", "t=" force_resize, "toto " force_resize " tata"); + xbt_test_add0("Value much longer, braces, data before and after");mytest("toto ${t} tata", "t=" force_resize, "toto " force_resize " tata"); + + xbt_test_add0("Escaped $");mytest("\\$tutu", "tutu=t", "\\$tutu"); + xbt_test_add0("Space in var name (with braces)");mytest("${tu ti}", "tu_ti=t", "t"); + + xbt_test_add0("Two variables");mytest("$toto $tutu","toto=1 tutu=2", "1 2"); + + // Commented: I'm too lazy to do a memmove in var name to remove the backslash after use. + // Users should use braces. + // xbt_test_add0("Escaped space in var name", "$tu\\ ti", "tu_ti=t", "t"); + + xbt_test_add0("Default value");mytest("${t:-toto}", "", "toto"); + xbt_test_add0("Useless default value (variable already defined)");mytest("${t:-toto}", "t=TRUC", "TRUC"); + +} + +/*******************************/ +/* GENERATED FILE, DO NOT EDIT */ +/*******************************/ +