[FFmpeg-devel] [PATCH 2/2] parseutils: add av_parse_time() test.
Nicolas George
nicolas.george at normalesup.org
Mon Apr 16 16:11:07 CEST 2012
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
libavutil/parseutils.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
tests/ref/fate/parseutils | 10 +++++++++
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index b5ce05a..7897db0 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -767,6 +767,52 @@ int main(int argc, char **argv)
}
}
+ 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("(local time is UTC+1)\n");
+ for (i = deterministic ? 2 : 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;
}
diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils
index d52cb3b..50e4165 100644
--- a/tests/ref/fate/parseutils
+++ b/tests/ref/fate/parseutils
@@ -59,3 +59,13 @@ red at 256 -> error
red at 10foo -> error
red at -1.0 -> error
red at -0.0 -> R(255) G(0) B(0) A(0)
+
+Testing av_parse_time()
+(local time is UTC+1)
+2000-12-20 0:02:47.5z -> 977270567.500000 = 2000-12-20T00:02:47Z
+2000-12-20T010247.6 -> 977270567.600000 = 2000-12-20T00:02:47Z
+2:34:56.79 -> +9296790000
+-1:23:45.67 -> -5025670000
+42.1729 -> +42172900
+-1729.42 -> -1729420000
+12:34 -> error
--
1.7.2.5
More information about the ffmpeg-devel
mailing list