diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2012-04-16 15:58:21 +0200 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2012-04-23 14:39:01 +0200 |
commit | 9b84f8a987e7cd3bb966d065d50d79d453907bad (patch) | |
tree | 22f95cc062dd8305fee33f28c649a112fd464767 /libavutil/parseutils.c | |
parent | 43b70680706f1c275f0c4a67e1483e409e73538a (diff) | |
download | ffmpeg-9b84f8a987e7cd3bb966d065d50d79d453907bad.tar.gz |
parseutils: add av_parse_time() test.
Diffstat (limited to 'libavutil/parseutils.c')
-rw-r--r-- | libavutil/parseutils.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 028d0b3da4..064d490a04 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -31,11 +31,15 @@ #include "random_seed.h" #include "parseutils.h" +#undef time + #ifdef TEST #define av_get_random_seed av_get_random_seed_deterministic static uint32_t av_get_random_seed_deterministic(void); +#define time(t) 1331972053 + #endif int av_parse_ratio(AVRational *q, const char *str, int max, @@ -541,7 +545,6 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) q = NULL; *timeval = INT64_MIN; if (!duration) { -#undef time now = time(0); if (!av_strcasecmp(timestr, "now")) { @@ -776,6 +779,52 @@ int main(void) } } + printf("\nTesting av_parse_time()\n"); + { + int i; + int64_t tv; + time_t tvi; + struct tm *tm; + const char *time_string[] = { + "now", + "12:35:46", + "2000-12-20 0:02:47.5z", + "2000-12-20T010247.6", + }; + const char *duration_string[] = { + "2:34:56.79", + "-1:23:45.67", + "42.1729", + "-1729.42", + "12:34", + }; + + av_log_set_level(AV_LOG_DEBUG); + setenv("TZ", "CET-1", 1); + printf("(now is 2012-03-17 09:14:13 +0100, local time is UTC+1)\n"); + for (i = 0; i < FF_ARRAY_ELEMS(time_string); i++) { + printf("%-24s -> ", time_string[i]); + if (av_parse_time(&tv, time_string[i], 0)) { + printf("error\n"); + } else { + tvi = tv / 1000000; + tm = gmtime(&tvi); + printf("%14"PRIi64".%06d = %04d-%02d-%02dT%02d:%02d:%02dZ\n", + tv / 1000000, (int)(tv % 1000000), + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + } + } + for (i = 0; i < FF_ARRAY_ELEMS(duration_string); i++) { + printf("%-24s -> ", duration_string[i]); + if (av_parse_time(&tv, duration_string[i], 1)) { + printf("error\n"); + } else { + printf("%+21"PRIi64"\n", tv); + } + } + } + return 0; } |