PR #22815 opened by itstanishkraj007
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22815
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22815.patch

Adds a FATE test covering failure and mode-handling branches in
libavutil/file_open.c.

The test verifies:
- avpriv_open failure on non-existent files
- avpriv_fopen_utf8 handling of invalid modes
- behavior across read, write, append, and read/write modes
- flag parsing for different fopen modes

This improves branch coverage for file_open.c.


From bbebfb2026507bd1c567f952eb9526752c5c2903 Mon Sep 17 00:00:00 2001
From: Tanishk Raj <[email protected]>
Date: Sun, 12 Apr 2026 14:26:46 +0530
Subject: [PATCH] avutil/tests: add test for avpriv_open and avpriv_fopen_utf8
 failure paths

Test the failure branches in libavutil/file_open.c by calling
avpriv_open and avpriv_fopen_utf8 with a non-existent file and
verifying the return value is negative.
---
 libavutil/Makefile          |  1 +
 libavutil/tests/file_open.c | 69 +++++++++++++++++++++++++++++++++++++
 tests/fate/libavutil.mak    |  5 +++
 3 files changed, 75 insertions(+)
 create mode 100644 libavutil/tests/file_open.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 1647952f8f..8fef44c2c5 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -307,6 +307,7 @@ TESTPROGS = adler32                                         
            \
             tree                                                        \
             twofish                                                     \
             utf8                                                        \
+            file_open                                                   \
             uuid                                                        \
             video_enc_params                                            \
             xtea                                                        \
diff --git a/libavutil/tests/file_open.c b/libavutil/tests/file_open.c
new file mode 100644
index 0000000000..b22fa1bd45
--- /dev/null
+++ b/libavutil/tests/file_open.c
@@ -0,0 +1,69 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include "libavutil/file_open.h"
+
+int main(void)
+{
+    FILE *f;
+    int   fd;
+
+    /* avpriv_open: non-existent file must return negative fd */
+    fd = avpriv_open("no_such_file_xyz", O_RDONLY);
+    if (fd >= 0)
+        return 1;
+
+    /* avpriv_fopen_utf8: invalid mode → default branch → must return NULL */
+    f = avpriv_fopen_utf8("no_such_file_xyz", "x");
+    if (f != NULL)
+        return 2;
+
+    /* avpriv_fopen_utf8: mode 'r' on non-existent file → fd==-1 branch */
+    f = avpriv_fopen_utf8("no_such_file_xyz", "r");
+    if (f != NULL)
+        return 3;
+
+    /* avpriv_fopen_utf8: mode 'w' → O_WRONLY|O_CREAT|O_TRUNC branch */
+    f = avpriv_fopen_utf8("fate_file_open_tmp", "w");
+    if (!f)
+        return 4;
+    fclose(f);
+
+    /* avpriv_fopen_utf8: mode 'a' → O_APPEND branch */
+    f = avpriv_fopen_utf8("fate_file_open_tmp", "a");
+    if (!f)
+        return 5;
+    fclose(f);
+
+    /* avpriv_fopen_utf8: mode 'r+' → while(*m) loop + '+' branch */
+    f = avpriv_fopen_utf8("fate_file_open_tmp", "r+");
+    if (!f)
+        return 6;
+    fclose(f);
+
+    /* avpriv_fopen_utf8: mode 'rb' → while(*m) loop + 'b' branch */
+    f = avpriv_fopen_utf8("fate_file_open_tmp", "rb");
+    if (!f)
+        return 7;
+    fclose(f);
+
+    remove("fate_file_open_tmp");
+    return 0;
+}
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index e25f1e2b9c..077d750d24 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -204,6 +204,11 @@ fate-file: libavutil/tests/file$(EXESUF)
 fate-file: CMD = run libavutil/tests/file$(EXESUF) 
$(SRC_PATH)/libavutil/tests/file.c
 fate-file: CMP = null
 
+FATE_LIBAVUTIL += fate-avutil-file-open
+fate-avutil-file-open: libavutil/tests/file_open$(EXESUF)
+fate-avutil-file-open: CMD = run libavutil/tests/file_open$(EXESUF)
+fate-avutil-file-open: CMP = null
+
 FATE_LIBAVUTIL += $(FATE_LIBAVUTIL-yes)
 FATE-$(CONFIG_AVUTIL) += $(FATE_LIBAVUTIL)
 fate-libavutil: $(FATE_LIBAVUTIL)
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to