X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/217e8b24b05ec8de6f7a639fa02aa999a066e6e5..476eed1ecf8f3103362011c05a81d7599ff385e6:/src/xbt_str_unit.c diff --git a/src/xbt_str_unit.c b/src/xbt_str_unit.c new file mode 100644 index 0000000000..68cc6f8030 --- /dev/null +++ b/src/xbt_str_unit.c @@ -0,0 +1,70 @@ +/*******************************/ +/* GENERATED FILE, DO NOT EDIT */ +/*******************************/ + +#include +#include "xbt.h" +/*******************************/ +/* GENERATED FILE, DO NOT EDIT */ +/*******************************/ + +# 426 "/home/navarrop/Developments/simgrid/src/xbt/xbt_str.c" +#include "xbt/str.h" + +#define mytest(name, input, expected) \ + xbt_test_add0(name); \ + d=xbt_str_split_quoted(input); \ + s=xbt_str_join(d,"XXX"); \ + xbt_test_assert3(!strcmp(s,expected),\ + "Input (%s) leads to (%s) instead of (%s)", \ + input,s,expected);\ + free(s); \ + xbt_dynar_free(&d); + +XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted,"test the function xbt_str_split_quoted") +{ + xbt_dynar_t d; + char *s; + + mytest("Empty", "", ""); + mytest("Basic test", "toto tutu", "totoXXXtutu"); + mytest("Useless backslashes", "\\t\\o\\t\\o \\t\\u\\t\\u", "totoXXXtutu"); + mytest("Protected space", "toto\\ tutu", "toto tutu"); + mytest("Several spaces", "toto tutu", "totoXXXtutu"); + mytest("LTriming", " toto tatu", "totoXXXtatu"); + mytest("Triming", " toto tutu ", "totoXXXtutu"); + mytest("Single quotes", "'toto tutu' tata", "toto tutuXXXtata"); + mytest("Double quotes", "\"toto tutu\" tata", "toto tutuXXXtata"); + mytest("Mixed quotes", "\"toto' 'tutu\" tata", "toto' 'tutuXXXtata"); + mytest("Backslashed quotes", "\\'toto tutu\\' tata", + "'totoXXXtutu'XXXtata"); + mytest("Backslashed quotes + quotes", "'toto \\'tutu' tata", + "toto 'tutuXXXtata"); + +} + +#define mytest_str(name, input, separator, expected) \ + xbt_test_add0(name); \ + d=xbt_str_split_str(input, separator); \ + s=xbt_str_join(d,"XXX"); \ + xbt_test_assert3(!strcmp(s,expected),\ + "Input (%s) leads to (%s) instead of (%s)", \ + input,s,expected);\ + free(s); \ + xbt_dynar_free(&d); + +XBT_TEST_UNIT("xbt_str_split_str", test_split_str,"test the function xbt_str_split_str") +{ + xbt_dynar_t d; + char *s; + + mytest_str("Empty string and separator", "", "", ""); + mytest_str("Empty string", "", "##", ""); + mytest_str("Empty separator", "toto", "", "toto"); + mytest_str("String with no separator in it", "toto", "##", "toto"); + mytest_str("Basic test", "toto##tutu", "##", "totoXXXtutu"); +} +/*******************************/ +/* GENERATED FILE, DO NOT EDIT */ +/*******************************/ +