tests: enhance str-test with a negative test on str_replace_str

This commit is contained in:
Nikos Mavrogiannopoulos
2015-10-30 13:32:29 +01:00
parent 1879891210
commit 4dd2fdf7b6

View File

@@ -54,10 +54,18 @@ int main()
STR_TAB_SET(5, "%U", "u1");
STR_TAB_TERM(6);
/* check proper operation */
#define STR2 "This is one route1, and one route2, while a route3 was replaced by dev1 and dev2 and dev1. That's all u1."
str_reset(&str);
str_append_str(&str, "This is one %R, and one %{R}, while a %{R2} was replaced by %{D} and %D and %{D}. That's all %U.");
str_replace_str(&str, tab);
if (str_append_str(&str, "This is one %R, and one %{R}, while a %{R2} was replaced by %{D} and %D and %{D}. That's all %U.") != 0) {
fprintf(stderr, "error in %d\n", __LINE__);
exit(1);
}
if (str_replace_str(&str, tab) != 0) {
fprintf(stderr, "error in %d\n", __LINE__);
exit(1);
}
if (str.length != sizeof(STR2)-1) {
fprintf(stderr, "error in %d\n", __LINE__);
@@ -69,5 +77,13 @@ int main()
exit(1);
}
/* check failure on unknown pattern */
str_reset(&str);
str_append_str(&str, "This is one %A.");
if (str_replace_str(&str, tab) == 0) {
fprintf(stderr, "error in %d\n", __LINE__);
exit(1);
}
return 0;
}