diff mbox series

[FFmpeg-devel,v3,2/2] fate/imf: remove redundant code

Message ID 20230515183300.7252-2-pal@sandflow.com
State Accepted
Commit 283813897519d48bfdc3acb974e82f034f8a7727
Headers show
Series [FFmpeg-devel,v3,1/2] fate/imf: fix memory leak | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Pierre-Anthony Lemieux May 15, 2023, 6:33 p.m. UTC
From: Pierre-Anthony Lemieux <pal@palemieux.com>

---
 libavformat/tests/imf.c | 52 ++++++++++-------------------------------
 1 file changed, 12 insertions(+), 40 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index c02cd87ceb..068ee6c58a 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -257,7 +257,7 @@  const char *cpl_doc =
     "</SegmentList>"
     "</CompositionPlaylist>";
 
-const char *cpl_bad_doc = "<Composition></Composition>";
+const char *cpl_bad_empty_doc = "<Composition></Composition>";
 
 const char *asset_map_doc =
     "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
@@ -384,52 +384,31 @@  static int test_cpl_parsing(void)
     return 0;
 }
 
-static int test_bad_cpl_parsing(FFIMFCPL **cpl)
-{
-    xmlDocPtr doc;
-    int ret;
-
-    doc = xmlReadMemory(cpl_bad_doc, strlen(cpl_bad_doc), NULL, NULL, 0);
-    if (doc == NULL) {
-        printf("XML parsing failed.\n");
-        return 1;
-    }
-
-    ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl);
-    xmlFreeDoc(doc);
-    if (ret) {
-        printf("CPL parsing failed.\n");
-        return ret;
-    }
-
-    ff_imf_cpl_free(*cpl);
-    *cpl = NULL;
-
-    return 0;
-}
-
-static int test_bad_resource_cpl_parsing(FFIMFCPL **cpl)
-{
+static int test_cpl_from_doc(FFIMFCPL **cpl, const char* cpl_doc, int should_pass) {
     xmlDocPtr doc;
     int ret;
 
-    doc = xmlReadMemory(cpl_bad_resource_doc, strlen(cpl_bad_resource_doc), NULL, NULL, 0);
+    doc = xmlReadMemory(cpl_doc, strlen(cpl_doc), NULL, NULL, 0);
     if (doc == NULL) {
         printf("XML parsing failed.\n");
-        return 1;
+        return should_pass;
     }
 
     ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl);
     xmlFreeDoc(doc);
     if (ret) {
         printf("CPL parsing failed.\n");
-        return ret;
+        if (*cpl) {
+            printf("Improper cleanup after failed CPL parsing\n");
+            return 1;
+        }
+        return should_pass;
     }
 
     ff_imf_cpl_free(*cpl);
     *cpl = NULL;
 
-    return 0;
+    return !should_pass;
 }
 
 static int check_asset_locator_attributes(IMFAssetLocator *asset, IMFAssetLocator *expected_asset)
@@ -591,20 +570,13 @@  int main(int argc, char *argv[])
         ret = 1;
 
     printf("#### The following should fail ####\n");
-    if (test_bad_cpl_parsing(&cpl) == 0) {
+    if (test_cpl_from_doc(&cpl, cpl_bad_empty_doc, 0) != 0)
         ret = 1;
-    } else if (cpl) {
-        printf("Improper cleanup after failed CPL parsing\n");
-        ret = 1;
-    }
     printf("#### End failing test ####\n");
 
     printf("#### The following should emit errors ####\n");
-    if (test_bad_resource_cpl_parsing(&cpl) != 0) {
-        if (cpl)
-            printf("Improper cleanup after failed CPL parsing\n");
+    if (test_cpl_from_doc(&cpl, cpl_bad_resource_doc, 1) != 0)
         ret = 1;
-    }
     printf("#### End emission of errors ####\n");
 
     return ret;