2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "libavutil/common.h"
22 #include "libavutil/mem.h"
23 #include "libavutil/avstring.h"
29 static const char * const strings[] = {
51 " foo bar : blahblah",
53 "'foo : \\ \\ ' : blahblah",
54 "'\\fo\\o:': blahblah",
55 "\\'fo\\o\\:': foo ' :blahblah"
57 const char *haystack = "Education consists mainly in what we have unlearned.";
58 const char * const needle[] = {"learned.", "unlearned.", "Unlearned"};
60 printf("Testing av_get_token()\n");
61 for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
62 const char *p = strings[i];
65 q = av_get_token(&p, ":");
66 printf(" -> |%s|", q);
67 printf(" + |%s|\n", p);
71 printf("Testing av_append_path_component()\n");
72 #define TEST_APPEND_PATH_COMPONENT(path, component, expected) \
73 fullpath = av_append_path_component((path), (component)); \
74 printf("%s = %s\n", fullpath ? fullpath : "(null)", expected); \
76 TEST_APPEND_PATH_COMPONENT(NULL, NULL, "(null)")
77 TEST_APPEND_PATH_COMPONENT("path", NULL, "path");
78 TEST_APPEND_PATH_COMPONENT(NULL, "comp", "comp");
79 TEST_APPEND_PATH_COMPONENT("path", "comp", "path/comp");
80 TEST_APPEND_PATH_COMPONENT("path/", "comp", "path/comp");
81 TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp");
82 TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp");
83 TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", "path/path2/comp/comp2");
85 /*Testing av_strnstr()*/
86 #define TEST_STRNSTR(haystack, needle, hay_length, expected) \
87 ptr = av_strnstr(haystack, needle, hay_length); \
88 if (ptr != expected){ \
89 printf("expected: %p, received %p\n", expected, ptr); \
91 TEST_STRNSTR(haystack, needle [0], strlen(haystack), haystack+44);
92 TEST_STRNSTR(haystack, needle [1], strlen(haystack), haystack+42);
93 TEST_STRNSTR(haystack, needle [2], strlen(haystack), NULL );
94 TEST_STRNSTR(haystack, strings[1], strlen(haystack), haystack );
96 /*Testing av_strireplace()*/
97 #define TEST_STRIREPLACE(haystack, needle, expected) \
98 ptr = av_strireplace(haystack, needle, "instead"); \
100 printf("error, received null pointer!\n"); \
102 if (strcmp(ptr, expected) != 0) \
103 printf( "expected: %s, received: %s\n", expected, ptr); \
107 TEST_STRIREPLACE(haystack, needle [0], "Education consists mainly in what we have uninstead");
108 TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead");
109 TEST_STRIREPLACE(haystack, needle [2], "Education consists mainly in what we have instead.");
110 TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead");
112 /*Testing av_d2str()*/
113 #define TEST_D2STR(value, expected) \
114 if((ptr = av_d2str(value)) == NULL){ \
115 printf("error, received null pointer!\n"); \
117 if(strcmp(ptr, expected) != 0) \
118 printf( "expected: %s, received: %s\n", expected, ptr); \
121 TEST_D2STR(0 , "0.000000");
122 TEST_D2STR(-1.2333234, "-1.233323");
123 TEST_D2STR(-1.2333237, "-1.233324");