[FFmpeg-devel] [PATCH 3/3] parseutils: add av_parse_time() test.

Nicolas George nicolas.george at normalesup.org
Tue Apr 17 12:41:04 CEST 2012


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavutil/parseutils.c    |   51 ++++++++++++++++++++++++++++++++++++++++++++-
 tests/ref/fate/parseutils |   12 ++++++++++
 2 files changed, 62 insertions(+), 1 deletions(-)


Compared to the approved version, use the same #ifdef trick on time()
to test dates that depend on the current time.


diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 028d0b3..064d490 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;
 }
 
diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils
index 6e14c91..e6e4fb9 100644
--- a/tests/ref/fate/parseutils
+++ b/tests/ref/fate/parseutils
@@ -62,3 +62,15 @@ 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()
+(now is 2012-03-17 09:14:13 +0100, local time is UTC+1)
+now                      ->     1331972053.000000 = 2012-03-17T08:14:13Z
+12:35:46                 ->     1331984146.000000 = 2012-03-17T11:35:46Z
+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