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
20 #include "libavutil/parseutils.c"
25 #include "libavutil/common.h"
26 #include "libavutil/log.h"
27 #include "libavutil/rational.h"
29 static uint32_t randomv
= MKTAG('L','A','V','U');
31 static uint32_t av_get_random_seed_deterministic(void)
33 return randomv
= randomv
* 1664525 + 1013904223;
36 static void test_av_parse_video_rate(void)
39 static const char *const rates
[] = {
67 for (i
= 0; i
< FF_ARRAY_ELEMS(rates
); i
++) {
69 AVRational q
= { 0, 0 };
70 ret
= av_parse_video_rate(&q
, rates
[i
]);
71 printf("'%s' -> %d/%d %s\n",
72 rates
[i
], q
.num
, q
.den
, ret
? "ERROR" : "OK");
76 static void test_av_parse_color(void)
80 static const char *const color_names
[] = {
119 av_log_set_level(AV_LOG_DEBUG
);
121 for (i
= 0; i
< FF_ARRAY_ELEMS(color_names
); i
++) {
122 if (av_parse_color(rgba
, color_names
[i
], -1, NULL
) >= 0)
123 printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
124 color_names
[i
], rgba
[0], rgba
[1], rgba
[2], rgba
[3]);
126 printf("%s -> error\n", color_names
[i
]);
130 static void test_av_small_strptime(void)
133 struct tm tm
= { 0 };
134 struct fmt_timespec_entry
{
135 const char *fmt
, *timespec
;
136 } fmt_timespec_entries
[] = {
137 { "%Y-%m-%d", "2012-12-21" },
138 { "%Y - %m - %d", "2012-12-21" },
139 { "%Y-%m-%d %H:%M:%S", "2012-12-21 20:12:21" },
140 { " %Y - %m - %d %H : %M : %S", " 2012 - 12 - 21 20 : 12 : 21" },
141 { " %Y - %b - %d %H : %M : %S", " 2012 - nOV - 21 20 : 12 : 21" },
142 { " %Y - %B - %d %H : %M : %S", " 2012 - nOVemBeR - 21 20 : 12 : 21" },
143 { " %Y - %B%d %H : %M : %S", " 2012 - may21 20 : 12 : 21" },
144 { " %Y - %B%d %H : %M : %S", " 2012 - mby21 20 : 12 : 21" },
145 { " %Y - %B - %d %H : %M : %S", " 2012 - JunE - 21 20 : 12 : 21" },
146 { " %Y - %B - %d %H : %M : %S", " 2012 - Jane - 21 20 : 12 : 21" },
147 { " %Y - %B - %d %H : %M : %S", " 2012 - January - 21 20 : 12 : 21" },
150 av_log_set_level(AV_LOG_DEBUG
);
151 for (i
= 0; i
< FF_ARRAY_ELEMS(fmt_timespec_entries
); i
++) {
153 struct fmt_timespec_entry
*e
= &fmt_timespec_entries
[i
];
154 printf("fmt:'%s' spec:'%s' -> ", e
->fmt
, e
->timespec
);
155 p
= av_small_strptime(e
->timespec
, e
->fmt
, &tm
);
157 printf("%04d-%02d-%2d %02d:%02d:%02d\n",
158 1900+tm
.tm_year
, tm
.tm_mon
+1, tm
.tm_mday
,
159 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
166 static void test_av_parse_time(void)
172 static char tzstr
[] = "TZ=CET-1";
173 static const char * const time_string
[] = {
176 "2000-12-20 0:02:47.5z",
177 "2012 - 02-22 17:44:07",
178 "2000-12-20T010247.6",
179 "2000-12-12 1:35:46+05:30",
180 "2002-12-12 22:30:40-02",
182 static const char * const duration_string
[] = {
191 "9223372036854775808us",
194 av_log_set_level(AV_LOG_DEBUG
);
196 printf("(now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)\n");
197 for (i
= 0; i
< FF_ARRAY_ELEMS(time_string
); i
++) {
198 printf("%-24s -> ", time_string
[i
]);
199 if (av_parse_time(&tv
, time_string
[i
], 0)) {
204 printf("%14"PRIi64
".%06d = %04d-%02d-%02dT%02d:%02d:%02dZ\n",
205 tv
/ 1000000, (int)(tv
% 1000000),
206 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
207 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
210 for (i
= 0; i
< FF_ARRAY_ELEMS(duration_string
); i
++) {
211 printf("%-24s -> ", duration_string
[i
]);
212 if (av_parse_time(&tv
, duration_string
[i
], 1)) {
215 printf("%+21"PRIi64
"\n", tv
);
220 static void test_av_get_known_color_name(void)
226 for (i
= 0; i
< FF_ARRAY_ELEMS(color_table
); ++i
) {
227 color
= av_get_known_color_name(i
, &rgba
);
229 printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
230 color
, rgba
[0], rgba
[1], rgba
[2], rgba
[3]);
232 printf("Color ID: %d not found\n", i
);
236 static void test_av_find_info_tag(void)
238 static const char args
[] = "?tag1=val1&tag2=val2&tag3=val3&tag41=value 41&tag42=random1";
239 static const char *tags
[] = {"tag1", "tag2", "tag3", "tag4", "tag41", "41", "random1"};
243 for (i
= 0; i
< FF_ARRAY_ELEMS(tags
); ++i
) {
244 if (av_find_info_tag(buff
, sizeof(buff
), tags
[i
], args
))
245 printf("%d. %s found: %s\n", i
, tags
[i
], buff
);
247 printf("%d. %s not found\n", i
, tags
[i
]);
253 printf("Testing av_parse_video_rate()\n");
254 test_av_parse_video_rate();
256 printf("\nTesting av_parse_color()\n");
257 test_av_parse_color();
259 printf("\nTesting av_small_strptime()\n");
260 test_av_small_strptime();
262 printf("\nTesting av_parse_time()\n");
263 test_av_parse_time();
265 printf("\nTesting av_get_known_color_name()\n");
266 test_av_get_known_color_name();
268 printf("\nTesting av_find_info_tag()\n");
269 test_av_find_info_tag();