avutil/avstring: improve av_strreplace implement

Use AVBprint to implement av_strreplace
add av_strreplace test case TEST_STRREPLACE

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
This commit is contained in:
Steven Liu
2017-04-11 10:54:35 +08:00
parent a44b3abb4c
commit 44cd7502c7
3 changed files with 28 additions and 66 deletions
+16
View File
@@ -93,6 +93,22 @@ int main(void)
TEST_STRNSTR(haystack, needle [2], strlen(haystack), NULL );
TEST_STRNSTR(haystack, strings[1], strlen(haystack), haystack );
/*Testing av_strireplace()*/
#define TEST_STRIREPLACE(haystack, needle, expected) \
ptr = av_strireplace(haystack, needle, "instead"); \
if (ptr == NULL) { \
printf("error, received null pointer!\n"); \
} else { \
if (strcmp(ptr, expected) != 0) \
printf( "expected: %s, received: %s\n", expected, ptr); \
av_free(ptr); \
}
TEST_STRIREPLACE(haystack, needle [0], "Education consists mainly in what we have uninstead");
TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead");
TEST_STRIREPLACE(haystack, needle [2], "Education consists mainly in what we have instead.");
TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead");
/*Testing av_d2str()*/
#define TEST_D2STR(value, expected) \
if((ptr = av_d2str(value)) == NULL){ \