[FFmpeg-cvslog] avutil: Improved test coverage for avstring.c

Thomas Turner git at videolan.org
Tue Dec 20 19:21:48 EET 2016


ffmpeg | branch: master | Thomas Turner <thomastdt at googlemail.com> | Mon Dec 19 18:44:42 2016 -0800| [e303e3d4b972975640da92cb55b766dad951d90d] | committer: Michael Niedermayer

avutil: Improved test coverage for avstring.c

Signed-off-by: Thomas Turner <thomastdt at googlemail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e303e3d4b972975640da92cb55b766dad951d90d
---

 libavutil/tests/avstring.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/libavutil/tests/avstring.c b/libavutil/tests/avstring.c
index 1242b3f..290b170 100644
--- a/libavutil/tests/avstring.c
+++ b/libavutil/tests/avstring.c
@@ -25,7 +25,7 @@
 int main(void)
 {
     int i;
-    char *fullpath;
+    char *fullpath, *ptr;
     static const char * const strings[] = {
         "''",
         "",
@@ -54,6 +54,8 @@ int main(void)
         "'\\fo\\o:': blahblah",
         "\\'fo\\o\\:':  foo  '  :blahblah"
     };
+    const char *haystack = "Education consists mainly in what we have unlearned.";
+    const char * const needle[] = {"learned.", "unlearned.", "Unlearned"};
 
     printf("Testing av_get_token()\n");
     for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
@@ -79,5 +81,27 @@ int main(void)
     TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp");
     TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp");
     TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", "path/path2/comp/comp2");
+
+    /*Testing av_strnstr()*/
+    #define TEST_STRNSTR(haystack, needle, hay_length, expected) \
+        ptr = av_strnstr(haystack, needle, hay_length); \
+        if (ptr != expected){ \
+            printf("expected: %p, received %p\n", expected, ptr); \
+        }
+    TEST_STRNSTR(haystack, needle [0], strlen(haystack), haystack+44);
+    TEST_STRNSTR(haystack, needle [1], strlen(haystack), haystack+42);
+    TEST_STRNSTR(haystack, needle [2], strlen(haystack), NULL       );
+    TEST_STRNSTR(haystack, strings[1], strlen(haystack), haystack   );
+
+    /*Testing av_d2str()*/
+    #define TEST_D2STR(value, expected) \
+        if((ptr = av_d2str(value)) == NULL){ \
+            printf("error, received null pointer!\n"); \
+        } else if(strcmp(ptr, expected) != 0){ \
+            printf( "expected: %s, received: %s\n", expected, ptr); \
+        }
+    TEST_D2STR(0         ,  "0.000000");
+    TEST_D2STR(-1.2333234, "-1.233323");
+    TEST_D2STR(-1.2333237, "-1.233324");
     return 0;
 }



More information about the ffmpeg-cvslog mailing list